Page 1 of 1

Problems in context menu related code in TFPC/TTFPC

Posted: Wed Oct 01, 2008 9:46 pm
by jpierce
I've been working on a unit to allow Flex to have complex popup menus (without Flash Player Limitations) in f-in-box, and I've run into an issue that I think could use some improvement. In TFlashPlayerControl.WndProc, there is the following code:

Code: Select all

  if not (csDesigning in ComponentState) then
    begin
      if (Message.Msg = WM_RBUTTONUP) then
        begin
          if Assigned(PopupMenu) then
          begin
            Point.X := Message.LParamLo;
            Point.Y := Message.LParamHi;

            Point := Self.ClientToScreen(Point);

            PopupMenu.Popup(Point.X, Point.Y);

            Exit;
          end;
    end;


When you call PopupMenu.Popup like this, it doesn't set PopupComponent. There are also some other things like checking for AutoPopup that are normally done by a TControl.

So instead, I propose this code replace the former:

Code: Select all

  if (Message.Msg = WM_RBUTTONUP) then
    begin
      Point.X := Message.LParamLo;
      Point.Y := Message.LParamHi;

      Point := Self.ClientToScreen(Point);

      Message.Result := Perform(WM_CONTEXTMENU, Message.WParam, MakeLParam(Point.X, Point.Y));

      Exit;
    end;


This would allow it to be processed just like a normal context menu click. Don't worry about ComponentState, the TControl checks that.

A similar thing needs to change in TTransparentFlashPlayerControl.ParentWndProc

Code: Select all

  if ((Message.Msg = WM_KEYDOWN) And (Message.WParam = VK_APPS) And (Not FStandartMenu)) then Exit;


By exiting on the VK_APPS key, you prevent being able to use a popup menu with the control that can be brought up with the apps key.

It should change to:

Code: Select all

  if (Message.Msg = WM_KEYDOWN) And (Message.WParam = VK_APPS) then
    if PopupMenu <> nil then
    begin
      Message.Result := Perform(WM_CONTEXTMENU, Message.WParam, MakeLParam(Word(-1), Word(-1)));

      Exit;
    end
    else if not StandartMenu then
      Exit;


This allows the underlying context menu event be properly processed.

I'd love to see these changes in the next version or otherwise relatively soon. This is the only thing holding me up from posting my ExternalPopupMenus code. It's some pretty cool code that lets you define and connect popup menus in Flex and have Delphi pop them up. It includes icons and submenus and has no restrictions like always having "About" and "Settings..." menu options.

Posted: Fri Oct 03, 2008 12:01 pm
by Softanics
Thank you very much for the suggestions. They seems to be correct. So we will include the changes in the nearest release.

Thank you.

Posted: Wed Nov 19, 2008 7:00 pm
by Softanics
The fix is included in the new version 3.4.

Thank you!

Posted: Wed Nov 19, 2008 7:13 pm
by jpierce
Excellent! I'll have to clean up my context menu code and post it now.