[Lazarus] Suggest LCL refactor for ShowContextMenu

AlexeyT aaa5500 at ya.ru
Sat Mar 10 17:09:21 CET 2018


Maybe it's good to have LCL method to show context menu, w/o using 
Perform(LM_contextmenu,...). Name it ShowContextMenu(X, Y) - method must 
be main part of TControl.WMContextMenu


procedure TControl.WMContextMenu(var Message: TLMContextMenu);
var
   TempPopupMenu: TPopupMenu;
   P: TPoint;
   Handled: Boolean;
begin
   if (csDesigning in ComponentState) or (Message.Result <> 0) then Exit;
   P := GetMousePosFromMessage(Message.Pos);
   // X and Y = -1 when user clicks on keyboard menu button
   if P.X <> -1 then
     P := ScreenToClient(P);

   Handled := False;
   DoContextPopup(P, Handled);
   if Handled then
   begin
     Message.Result := 1;
     Exit;
   end;

   TempPopupMenu := GetPopupMenu;
   if (TempPopupMenu <> nil) then
   begin
     if not TempPopupMenu.AutoPopup then Exit;
     TempPopupMenu.PopupComponent := Self;
     if P.X = -1 then
       P := Point(0, 0);
     P := ClientToScreen(P);
     TempPopupMenu.Popup(P.X, P.Y);
     Message.Result := 1;
   end;
end;


so WMCOntextMenu will be some checks + getting X/Y + call to new 
ShowContextMenu(X,Y) + Message.Result:=1.

-- 
Regards,
Alexey



More information about the Lazarus mailing list