Event Bubbling lazarus / 31-LCL ---------------------------------------------------------------------- pebe · 2022-04-15 06:17 Hi I have tried on my own to find information related to event propagation (event bubbling) but with poor results. I found this https ://forum.lazarus.freepascal.org/index.php/topic,22275.msg131221.html#m sg131221 but, it doesn't really work, besides, as far as I can see, it requires adding an event to each control and doesn't work for inactive controls. I would like to ask if there is a mechanism in FPC that would allow such behavior (event bubbling)? From what I noticed, event propagation is not natively supported. What I mean is that if a control receives an event and it is in the "area" of another control, the rest of the controls (from this area) will not receive the event. Code: [Select]+----------------- TFrame ---------------------+ |                                              | | TLabel                                       | | +- TEdit ----------------------------------+ | | |                                          | | | +------------------------------------------+ | |                                              | | +------+------+                              | | | Tab1 | Tab2 |                              | | +      +------+------ PageControl ---------+ | | |                                          | | | | TLabel                                   | | | | +- TEdit ------------------------------+ | | | | |                                      | | | | | +--------------------------------------+ | | | |                                          | | | | TLabel                                   | | | | +- TEdit ------------------------------+ | | | | |                                      | | | | | +--------------------------------------+ | | | |                                          | | | +------------------------------------------+ | |                                              | +----------------------------------------------+ Looking at the above diagram, I wanted to be able to: - get an event in the TFrame component when the user clicks on any element inside it; - event in the TFrame, it must occur regardless of the activity of the control (TControl.Enabled). Are the above assumptions feasible? If so, how can I achieve this? I would appreciate your help. ---------------------------------------------------------------------- Thaddy · 2022-04-15 11:35 The event will usually, but not in all cases and platforms, be propagated from the Parent downto the control. ---------------------------------------------------------------------- pebe · 2022-04-15 13:58 @Thaddy: That I did manage to notice And I need the opposite situation. How about I introduce why I need it? (maybe there is another solution) I am using AnchorDocking and there is a problem with docked windows. When the window is undocked, the toggle happens without problems, i.e. the OnActivate event occurs or, I am able to use Screen.ActiveControl to figure out which window is active using a trick like this: Code: [Select]function getActiveForm:TForm; begin   TControl(result):=Screen.ActiveControl;   if result<>nil then   begin     while not ((result is TVehicleForm) or (result=nil)) do       TControl(result):=result.Parent;   end; end; When the window is docked, the only way to find out is to follow Screen.ActiveControl. However the problem is, that the area of docked window is not taken into account, but the controls included in it. In addition, they must be active, ie the property Enabled must be on True. I thought maybe I will use a trick, where the content of the window, I will put in TFrame, which I will set the event OnMouseDown as "activator" (I did the same in JavaScript) However, this did not work, precisely because of the lack of event bubbling. Maybe someone has some idea how to solve the above problem? ---------------------------------------------------------------------- balazsszekely · 2022-04-15 14:20 @pebe Not quite what are you after, but might be worth a look: https://forum .lazarus.freepascal.org/index.php/topic,38014.msg257890.html#msg257890 You should read the whole thread. ---------------------------------------------------------------------- jamie · 2022-04-15 14:56 Transparent Window overlay. ---------------------------------------------------------------------- pebe · 2022-04-15 18:05 @GetMem: I read the whole thread. Funny interjections by the interviewees At the moment, I don't really know how to use the information gathered there. Of course, that doesn't mean they are useless. They'll probably come in handy at some point @jamie: your idea with the "Transparent Overlay" seems very interesting - such a "thing" that is there, but you can't see it. How to construct such a marvel? Do you have any collections of information on this subject? ---------------------------------------------------------------------- jamie · 2022-04-16 15:43 using a transparent overlay isn't really going to help you much since you still be left with lots of work sending the messages onto the child controls.  The TFrame as like the TPanel has a OnEnter event which fires whenever any of the Window based child controls are clicked on. This Event should report the actual control that is being entered. Also I believe the panel and most likely the Frame can be flagged mask to make it think it receives input.  As for the Frame itself, you will receive a Mouse down and MouseUP there. in either case if you need the location of the X,Y mouse plots you can get them at that time or you can call the Application.MouseControl or something like that which reports the control under the mouse. P.S.   No WinControl bases do not fire a OnEnter event.   And if you don't like that, you can always subclass the TCONTROL in the local unit so that you can capture the WM_CLICK event from all TCONTROL based items! etc. Have fun. ---------------------------------------------------------------------- Martin_fr · 2022-04-17 11:13 I don't see any practical way to add bubbling events.... If you are after Mouse/Key-Up/Down/Move => Application.OnUserInput  Then search the control and do what you need. Though, this may not include KeyPress and Click events. For all else, if you want to investigate the available options, a few general hints. 1) Know the difference between TWinControl (TForm, TButton, TEdit) descendants and TGraphicControl (TLabel, TSpeedButton, TToolButton). - When the OS (Win,Gtk,Qt,MacOs) does send an event, it will sent it to TWinControls only. - The OS does not even know that any TGraphicControl exists. TGraphicControl are just painted onto the containing TWinControl. The LCL then redirects the events accordingly. - See functions like CheckMouseButtonDownUp in unit Controls 2) The events come in form of WM_KEYDOWN and other such messages (and the LCL translates them to LM_KEYDOWN). - The handling of those messages would probably be the best place to intercept and try to add bubbling. - But to handle those yourself, you must inherit the class. So you would need TMyButton, TMyForm, TMyLabel ..... And your entire form would only be allowed such inherited classes => not very practical.... 3) To see what happens on Windows - follow TWindowProcHelper.DoWindowProc - But be aware that each OS/Widgetset has a different function for that.