简体   繁体   中英

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.
在此输入图像描述
here is not any colormap on the form, and manager style is platform default

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM