work around for TActionMainMenuBar painting bug where item is not unselecting

773 Views Asked by At

TActionMainMenuBar have a bug with painting root elemetnts without child items.

Using Delphi XE2 / w7-32bit**

how to reproduce:
build menu with TActionMainMenuBar, add some actions to it:

 file  | options | help
 - New
 - Open
 - Save
  -Exit

assign to all actions one empty method

procedure TfrmMain.ActionExecute(Sender: TObject); 
begin 
// 
end;

now run application and try to click on options or help element.
now click on form, but the menu element is still pressed!

any workarounds exists?

upd: look at screenshot, menu element is down, but mouse cursor not on menu, and autocheck is false, and checked is false too.
enter image description here
here is not any colormap on the form, and manager style is platform default

2

There are 2 best solutions below

0
utmost On

here is my workaround:
create custom class like this:


type
  TFastThemedButton = class(TThemedMenuButton)
  protected
    procedure DrawBackground(var PaintRect: TRect); override;
end;

...


procedure TFastThemedButton.DrawBackground(var PaintRect: TRect);
const
  MenuStates: array[Boolean {MouseInControl}, Boolean {Selected}] of TThemedMenu =
    ((tmMenuBarItemNormal, tmMenuBarItemPushed), (tmMenuBarItemHot, tmMenuBarItemPushed));
var
  BannerRect: TRect;
  StartCol, EndCol: TColor;
begin
   Canvas.Brush.Color := ActionBar.ColorMap.Color;
   Canvas.Font := ActionBar.Font;
   StyleServices.DrawElement(Canvas.Handle, StyleServices.GetElementDetails(MenuStates[MouseInControl, (State=bsDown)]), PaintRect);
end;

now in you TActionMainMenuBar.OnGetControlClass add this simple code, and set to buggy actionclients tag=-100


procedure TfrmActions.ActionMainMenuBar1GetControlClass(Sender: TCustomActionBar; AnItem: TActionClient; var ControlClass: TCustomActionControlClass);
begin
  if ControlClass.InheritsFrom(TCustomMenuButton) and then
   begin
    if (AnItem.Tag =-100) and (ControlClass = TThemedMenuButton) then
      ControlClass := TFastThemedButton;
   end;
end;

well, now all root items with -100 tag, works as we wish

0
Mario.Green On

I am using the event MainMenuExitMenuLoop with MainMenu.RecreateControls on all forms with a menu. So far this removes the stuck selection from the menu items.