View Issue Details

IDProjectCategoryView StatusLast Update
0004218JEDI VCL00 JVCL Componentspublic2008-02-20 09:39
ReportermaxpAssigned Toobones 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version3.34 
Summary0004218: Issue 0002603 (wrong TJvMainMenu bar painting if style other then msXP is used) was not resolved:workaround
DescriptionRecently 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 InformationIs it worthy to implement this fix in the TJvOfficeMenuItemPainter ?
TagsNo tags attached.

Activities

obones

2007-10-12 08:36

administrator   ~0013935

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.

2007-10-15 03:44

 

clMenuBar.bmp (154,278 bytes)
clMenuBar.bmp (154,278 bytes)

maxp

2007-10-15 03:44

reporter   ~0013964

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).

maxp

2008-01-15 10:19

reporter   ~0014154

Last edited: 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;

obones

2008-02-20 09:38

administrator   ~0014189

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