Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0004218 [JEDI VCL] 00 JVCL Components minor always 2007-08-28 11:09 2008-02-20 09:39
Reporter maxp View Status public  
Assigned To obones
Priority normal Resolution fixed  
Status resolved   Product Version
Summary 0004218: Issue 0002603 (wrong TJvMainMenu bar painting if style other then msXP is used) was not resolved:workaround
Description Recently I've encountered the same problem as was described in the Issue 0002603 using the LATEST SVN. I propose a workaround to make the menu bar have correct color (at least for Office-style painter).

My workaround is to create custom painter derived from TJvOfficeMenuItemPainter and assign it to JvMainMenu.ItemPainter. The actual fix is shown by the "(***FIX***)" comment:

type
  TMxOfficeMenuItemPainter = class(TJvOfficeMenuItemPainter)
  private
    FCurrentItem: TMenuItem;
    FCurrentState: TMenuOwnerDrawState;
  protected
    procedure PreparePaint(Item: TMenuItem; ItemRect: TRect; State: TMenuOwnerDrawState; Measure: Boolean); override;
    procedure DrawItemText(ARect: TRect; const Text: string; Flags: Integer); override;
  end;

procedure TMxOfficeMenuItemPainter.PreparePaint(Item: TMenuItem; ItemRect: TRect; State: TMenuOwnerDrawState; Measure: Boolean);
begin
  FCurrentItem := Item;
  FCurrentState := State;
  inherited;
end;

procedure TMxOfficeMenuItemPainter.DrawItemText(ARect: TRect; const Text: string; Flags: Integer);
begin
  if not IsPopup(FCurrentItem) and (FCurrentState * [mdSelected, mdFocused, mdHotlight] = []) then begin
    Canvas.Brush.Color := clBtnFace{clMenuBar};(***FIX***)
    Canvas.FillRect(ARect);(***FIX***)
  end;
  inherited;
end;


Then assign this painter (in OnCreate handler, for example):
MainMenu.ItemPainter := TMxOfficeMenuItemPainter.Create(Self);

Additional Information Is it worthy to implement this fix in the TJvOfficeMenuItemPainter ?
Tags No tags attached.
Attached Files ? file icon clMenuBar.bmp [^] (154,278 bytes) 2007-10-15 03:44

- Relationships

-  Notes
(0013935)
obones (administrator)
2007-10-12 08:36

I'm wondering if it's ok as this means it will not respect the color a user has chosen for the menu bar, but rather use the one for a button.
(0013964)
maxp (reporter)
2007-10-15 03:44

My first approach was to use clMenuBar while drawing menu bar. However, under Windows XP with "Classic" theme enabled, color of the menu bar SLIGHTLY differs from a color of the window (see attached picture). When I use clBtnFace, all is OK (for both "Classic" and "Win XP" themes).
By the way, I use Delphi 2005 (+ Update3).
(0014154)
maxp (reporter)
2008-01-15 10:19
edited on: 2008-01-15 10:34

After some investigations I've found then better code for DrawItemText is:

procedure TMxOfficeMenuItemPainter.DrawItemText(ARect: TRect; const Text: string; Flags: Integer);
var
  B: BOOL;
begin
  if not IsPopup(FCurrentItem) and (FCurrentState * [mdSelected, mdFocused, mdHotlight] = []) then begin
    if SystemParametersInfo(SPI_GETFLATMENU, 0, @B, 0) and B then
      Canvas.Brush.Color := clMenuBar
    else
      Canvas.Brush.Color := clBtnFace;
    Canvas.FillRect(ARect);
  end;
  inherited;
end;

(0014189)
obones (administrator)
2008-02-20 09:38

This is now in SVN

- Issue History
Date Modified Username Field Change
2007-08-28 11:09 maxp New Issue
2007-10-12 08:36 obones Note Added: 0013935
2007-10-12 08:36 obones Status new => feedback
2007-10-15 03:44 maxp File Added: clMenuBar.bmp
2007-10-15 03:44 maxp Note Added: 0013964
2008-01-15 10:19 maxp Note Added: 0014154
2008-01-15 10:34 maxp Note Edited: 0014154
2008-02-20 09:38 obones Status feedback => resolved
2008-02-20 09:38 obones Fixed in Version => Daily / SVN
2008-02-20 09:38 obones Resolution open => fixed
2008-02-20 09:38 obones Assigned To => obones
2008-02-20 09:38 obones Note Added: 0014189


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker