Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

work around for TActionMainMenuBar painting bug where item is not unselecting

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

like image 566
utmost Avatar asked Nov 13 '22 11:11

utmost


1 Answers

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

like image 112
utmost Avatar answered Nov 15 '22 07:11

utmost