How to close THintWindow after click on other form / application? lazarus / 31-LCL ---------------------------------------------------------------------- Dibo · 2016-01-06 14:48 Hi, I need component which popup TTrackBar when click on button (something like volume slider in multimedia players). Main form should not lose its focus so I'm using THintWindow with TTrackBar aligned as alClient. This popup should immediately close when user click on something else than internal "volume slider", this include my app forms / controls but also when activating form of another application. Problem is that events THintWindow.OnDeactivate / OnExit are never fired. Currently I'm testing it on Qt widgetset (Kubuntu 14.04 64 bit, Lazarus from SVN) but also need for Gtk and Winapi widgetsets. Is it a bug? Regards ---------------------------------------------------------------------- x2nie · 2016-01-06 15:23 if your flying Trackbar is always positioned inside a form, you may replace the THintWindow with plain TPanel. I see the LazPaint used TPanel to mimic the TMenuPopup (without menu item, but graphical one). Anyway, I would very happy if we can solve the "Form should not lose it's focus" things! ---------------------------------------------------------------------- zeljko · 2016-01-06 20:35 You can use normal borderless form, just put csNoFocus in constructor, set popupmode to pmAuto ---------------------------------------------------------------------- taazz · 2016-01-06 21:43 Sorry there is nothing that I know of that would work on all systems with out problems. Even on windows after 95 some one decided that the windows that get focus must always be activated as well and combined the two calls in to one (idiots!). There are wispers on the net that the moment your popup form gets focus you can send a wm_ncactivate on the parent form to keep its title bar painted as active but I haven't been able to duplicate it in lcl yet. If the floating window does not have focus then it has already been exited and deactivated those events will never fire again. You best bet is to use the OnMouseUp event of the trackbar to close the float window ala photoshop. I do not know if you can also mimic the way photoshop handles those trackbars also, then again I find it a bit frightening the way it shows and closes the moment you release the mouse it does not give you enough time to make micro calibration as needed, it can't be used by the keyboard (which for me is a must) also. ---------------------------------------------------------------------- x2nie · 2016-01-07 04:05 Hey, is it possible to inherit THintWindow? The idea is show THintWIndow as TTrackbar. So the new ancestor should completely mimic TTrackbar visually by override Paint method. ---------------------------------------------------------------------- taazz · 2016-01-07 08:47 Quote from: x2nie on January 07, 2016, 05:05:21 amHey, is it possible to inherit THintWindow? Yes, as far I know there is nothing special needed to inherit from a THintwindow in fact I have inherited  one my self for a custom hint window in one of my applications. Quote from: x2nie on January 07, 2016, 05:05:21 amThe idea is show THintWIndow as TTrackbar. So the new ancestor should completely mimic TTrackbar visually by override Paint method. What would you gain that a trackbar inside a hint window does not provide already? ---------------------------------------------------------------------- Dibo · 2016-01-09 21:10 Quote from: zeljko on January 06, 2016, 09:35:32 pmYou can use normal borderless form, just put csNoFocus in constructor, set popupmode to pmAuto Good idea but same problem like with THintWindow - don't know how to close it. OnDeactivate and OnExit are not fired with csNoFocus option :/ Quote from: x2nie on January 06, 2016, 04:23:40 pmif your flying Trackbar is always positioned inside a form, you may replace the THintWindow with plain TPanel. I see the LazPaint used TPanel to mimic the TMenuPopup (without menu item, but graphical one). Anyway, I would very happy if we can solve the "Form should not lose it's focus" things!  Interesting. I'll stick to this solution until found something else ---------------------------------------------------------------------- zeljko · 2016-01-10 09:41 Of course that there's no OnDeactivate since there's no OnActivate too when csNoFocus is set. ---------------------------------------------------------------------- balazsszekely · 2016-01-10 12:09 Quote@Dibo Good idea but same problem like with THintWindow - don't know how to close it. OnDeactivate and OnExit are not fired with csNoFocus option :/Use what @zeljko suggested and detect the HintWindow deactivate like this: 1. The user click outside the application:    use Application.OnDeactivate 2. The user click something on the main form:   use main form OnActivate Something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  //... TForm1 = class(TForm)    //...    procedure FormActivate(Sender: TObject);    procedure FormCreate(Sender: TObject);  private    procedure ApplicationDeactivate(Sender: TObject);    //...  end; //...procedure TForm1.FormCreate(Sender: TObject);begin  Application.OnDeactivate := @ApplicationDeactivate;end; procedure TForm1.ApplicationDeactivate(Sender: TObject);begin   if Assigned(fHintWindow) then //or fHintWindow.Visible     fHintWindow.Closeend; procedure TForm1.FormActivate(Sender: TObject);begin   if Assigned(fHintWindow) then //or fHintWindow.Visible     fHintWindow.Closeend; ---------------------------------------------------------------------- Dibo · 2016-01-12 21:47 Sorry for delay. Since trick with TPanel ontop instead of THintWindow is working well so far, I stick to this solution. But I'm curious boy and if someone want a little contest for coffee time then I attached example demo. Tried everything mentioned here and failed. Note that in demo I used THintWindow instead of TCustomForm with csNoFocus because on Lazarus 1.4.4 (stable) csNoFocus doesn't have effect (on Lazarus from SVN - yes. For the record I'm testing it on Kubuntu 14.04, 64 bit, Qt widgetset). So the major chalenge is: make volumetrackbar disappear when clicking on mainform, clicking on form of another program and clicking on TEdit (or any other control). First two are solved. Problem is with subcontrols and Edit1.OnEnter := @CloseVolume is not solution which I'm looking for (although loop over all main form controls sounds interesting) I see zeljko posts from Lazarus team here so result could be implemented / fixed in source. Sometimes I'm coding in Qt and in that case I'll just use QActionWidget in TPopMenu (QMenu) item but with all Gtk and Winapi dependencies I need LCL solution Quote from: GetMem on January 10, 2016, 01:09:25 pmUse what @zeljko suggested and detect the HintWindow deactivate like this: 1. The user click outside the application:    use Application.OnDeactivate 2. The user click something on the main form:   use main form OnActivate Doesn't work neither (I'm referring to mainform.OnActivate). Showing THintWindow (or TCustomForm with csNoFocus) doesn't adopt focus so main form is still as Active form and clicking back on it doesn't trigger mainform.OnActivate . If I'm not wrong, in Delphi was event like OnActivateControl/OnFocusControl or something like that. Can't find anything in LCL TForm or TApplication. LCL "Activate" or "Enter" events are fired only when form changed, not subcontrols ---------------------------------------------------------------------- taazz · 2016-01-13 14:01 Well on windows this code works as expected although it stills the activation from the underline window did I missed something? Try overriding the method ActiveChanged on your form. IT is called when ever the ActiveControl properties changes to a new control and it seems to be what you need. There is no event property to handle it as far as I can see. ---------------------------------------------------------------------- Dibo · 2016-01-13 20:41 Quote from: taazz on January 13, 2016, 03:01:23 pmWell on windows this code works as expected although it stills the activation from the underline window did I missed something? Weird. On Kubuntu with Qt widgetset, main form keep its focus. Maybe in Lazarus from SVN it is already fixed as problem csNoFocus on Qt widgetset QuoteTry overriding the method ActiveChanged on your form. IT is called when ever the ActiveControl properties changes to a new control and it seems to be what you need. There is no event property to handle it as far as I can see. Well, ActiveChanged is called only on form activate, not its subcontrols. Tested on stable 1.4.4 but also on svn version ---------------------------------------------------------------------- x2nie · 2016-01-14 02:11 this solution will (logically) solves both THintWindow or fake TPanel: * add one TTimer to check whether active-control / focused-control is that trackbar. If not, then hide the TPanel or close the THintWindow. ---------------------------------------------------------------------- Dibo · 2016-01-15 14:07 Nope . THintWindow.ActiveControl always has TTrackBar even when clicking on major form edits Chalenge still ON