Recent

Author Topic: [Solved] Custom PopupMenu  (Read 5951 times)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: [Solved] Custom PopupMenu
« Reply #15 on: August 19, 2023, 03:53:51 am »
I am unsure if I understood that On(de)Activate problem, cant you:
Code: Pascal  [Select][+][-]
  1. FOldActivate := TForm(FOwner).OnActivate;
  2. FOldDeactivate := TForm(FOwner).OnDeactivate;
  3. TForm(FOwner).OnActivate := nil;
  4. TForm(FOwner).OnDeactivate := nil;
  5.  
on creation before "Visible := True" ?
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

aydın

  • Jr. Member
  • **
  • Posts: 86
Re: [Solved] Custom PopupMenu
« Reply #16 on: August 19, 2023, 09:23:54 am »
Because we have a custom combobox in bgracontrols, that has exactly this issue...

We're using a form, with a listbox.
I believe this could possibly be solved with unfocusable forms.

An on-screen keyboard handles this quite effectively.
Lazarus 4.99, FPC 3.3.1 on Fedora 42

lainz

  • Hero Member
  • *****
  • Posts: 4740
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: [Solved] Custom PopupMenu
« Reply #17 on: August 19, 2023, 02:23:53 pm »
I am unsure if I understood that On(de)Activate problem, cant you:
Code: Pascal  [Select][+][-]
  1. FOldActivate := TForm(FOwner).OnActivate;
  2. FOldDeactivate := TForm(FOwner).OnDeactivate;
  3. TForm(FOwner).OnActivate := nil;
  4. TForm(FOwner).OnDeactivate := nil;
  5.  
on creation before "Visible := True" ?

It didn't work.

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: [Solved] Custom PopupMenu
« Reply #18 on: August 19, 2023, 02:39:39 pm »
I am unsure if I understood that On(de)Activate problem, cant you:
Code: Pascal  [Select][+][-]
  1. FOldActivate := TForm(FOwner).OnActivate;
  2. FOldDeactivate := TForm(FOwner).OnDeactivate;
  3. TForm(FOwner).OnActivate := nil;
  4. TForm(FOwner).OnDeactivate := nil;
  5.  
on creation before "Visible := True" ?

It didn't work.

It didn't perhaps of the FOwner. Try that way, before "Visible := True" in TBCComboBox.ButtonClick:
Code: Pascal  [Select][+][-]
  1.     if Assigned(FOnDropDown) then FOnDropDown(self);
  2.  
  3.     PF := GetParentForm(Self, False);
  4.     FOldActivate := PF.OnActivate;
  5.     FOldDeactivate := PF.OnDeactivate;
  6.     PF.OnActivate := {@}ParentReactivate;
  7.     PF.OnDeactivate := Nil;
  8.  
  9.     FForm.Visible := True;  

With:
Code: Pascal  [Select][+][-]
  1. procedure TBCComboBox.ParentReactivate(Sender: TObject);
  2. var
  3.   PF: TCustomForm;
  4. begin
  5.   PF := GetParentForm(Self, False);
  6.   PF.OnActivate := FOldActivate;
  7.   PF.OnDeactivate := FOldDeactivate;
  8. end;
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: [Solved] Custom PopupMenu
« Reply #19 on: August 19, 2023, 02:47:54 pm »
Yes, I was meaning it in a theoretical way spoken, had no idea about actual code  :-[
Store old event, turn events off, make own things visible, before leaving restore old etc ...
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

lainz

  • Hero Member
  • *****
  • Posts: 4740
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: [Solved] Custom PopupMenu
« Reply #20 on: August 19, 2023, 03:12:12 pm »
I am unsure if I understood that On(de)Activate problem, cant you:
Code: Pascal  [Select][+][-]
  1. FOldActivate := TForm(FOwner).OnActivate;
  2. FOldDeactivate := TForm(FOwner).OnDeactivate;
  3. TForm(FOwner).OnActivate := nil;
  4. TForm(FOwner).OnDeactivate := nil;
  5.  
on creation before "Visible := True" ?

It didn't work.

It didn't perhaps of the FOwner. Try that way, before "Visible := True" in TBCComboBox.ButtonClick:
Code: Pascal  [Select][+][-]
  1.     if Assigned(FOnDropDown) then FOnDropDown(self);
  2.  
  3.     PF := GetParentForm(Self, False);
  4.     FOldActivate := PF.OnActivate;
  5.     FOldDeactivate := PF.OnDeactivate;
  6.     PF.OnActivate := {@}ParentReactivate;
  7.     PF.OnDeactivate := Nil;
  8.  
  9.     FForm.Visible := True;  

With:
Code: Pascal  [Select][+][-]
  1. procedure TBCComboBox.ParentReactivate(Sender: TObject);
  2. var
  3.   PF: TCustomForm;
  4. begin
  5.   PF := GetParentForm(Self, False);
  6.   PF.OnActivate := FOldActivate;
  7.   PF.OnDeactivate := FOldDeactivate;
  8. end;

Tested this new way and didn't work too. The background form loses focus and the focus goes to the new visible form.

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: [Solved] Custom PopupMenu
« Reply #21 on: August 19, 2023, 03:46:57 pm »
Tested this new way and didn't work too. The background form loses focus and the focus goes to the new visible form.
I'm not sure what do you expect to happen. That workaround is not to fire OnDeactivate/OnActivate events on the parent form when opening/closing the pulldown (because that is presumed as the potential problem).  It is not to stop the form of losing its focus. There is no way your listbox to work without a focus, i.e. it should receive it.

FYI TDateEdit, TDateTimePicker, etc. all trigger OnDeactivate/OnActivate events in the same way as TBCComboBox.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

lainz

  • Hero Member
  • *****
  • Posts: 4740
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: [Solved] Custom PopupMenu
« Reply #22 on: August 19, 2023, 04:03:49 pm »
Tested this new way and didn't work too. The background form loses focus and the focus goes to the new visible form.
I'm not sure what do you expect to happen. That workaround is not to fire OnDeactivate/OnActivate events on the parent form when opening/closing the pulldown (because that is presumed as the potential problem).  It is not to stop the form of losing its focus. There is no way your listbox to work without a focus, i.e. it should receive it.

FYI TDateEdit, TDateTimePicker, etc. all trigger OnDeactivate/OnActivate events in the same way as TBCComboBox.

I quote aydin that has the same idea as me

Because we have a custom combobox in bgracontrols, that has exactly this issue...

We're using a form, with a listbox.
I believe this could possibly be solved with unfocusable forms.

An on-screen keyboard handles this quite effectively.

I think the idea was clear we was talking about that not about events getting fired
...

aydın

  • Jr. Member
  • **
  • Posts: 86
Re: [Solved] Custom PopupMenu
« Reply #23 on: August 19, 2023, 04:14:53 pm »
I found this, but it's not working at all:

Code: Pascal  [Select][+][-]
  1. ShowWindow(Form2.Handle, SW_SHOWNOACTIVATE);

If this doesn't work, what's its purpose?
Lazarus 4.99, FPC 3.3.1 on Fedora 42

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: [Solved] Custom PopupMenu
« Reply #24 on: August 19, 2023, 04:16:27 pm »

Because we have a custom combobox in bgracontrols, that has exactly this issue...

We're using a form, with a listbox.
I believe this could possibly be solved with unfocusable forms.

An on-screen keyboard handles this quite effectively.

I think the idea was clear we was talking about that not about events getting fired
...
That is an idea for a solution. Please, specify the problem for the solution.
And what is the definition of "unfocusable form", BTW?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

lainz

  • Hero Member
  • *****
  • Posts: 4740
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: [Solved] Custom PopupMenu
« Reply #25 on: August 19, 2023, 04:26:46 pm »
That is an idea for a solution. Please, specify the problem for the solution.
And what is the definition of "unfocusable form", BTW?

That's the problem

The reason I didn't use a form in the popup is because the main form loses its activity.
I think there were a few WinAPI methods for this, but WinAPI doesn't always work properly.

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: [Solved] Custom PopupMenu
« Reply #26 on: August 19, 2023, 04:32:36 pm »
What is "activity" then?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

lainz

  • Hero Member
  • *****
  • Posts: 4740
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: [Solved] Custom PopupMenu
« Reply #27 on: August 19, 2023, 04:39:53 pm »
What is "activity" then?

I think he means focus.

Edit: It's easy to see and understand. Drop a TBCComboBox into a form, add a few items with the object inspector. Run the application. When the popup shows, the main form looses it focus.

Unlike aydin says, what happens with a virtual keyboard like the one that comes with windows, you open it and the focus remains in the main form.
« Last Edit: August 19, 2023, 04:57:13 pm by lainz »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: [Solved] Custom PopupMenu
« Reply #28 on: August 19, 2023, 05:18:05 pm »
I found this, but it's not working at all:

Code: Pascal  [Select][+][-]
  1. ShowWindow(Form2.Handle, SW_SHOWNOACTIVATE);

If this doesn't work, what's its purpose?
Code: Pascal  [Select][+][-]
  1. procedure TForm2.CreateParams(var Params: TCreateParams);
  2. begin
  3.   inherited CreateParams(Params);
  4.   Params.ExStyle := Params.ExStyle or WS_EX_NOACTIVATE;
  5. end;
but somehow freepascal or lcl is working against such mechanism....

what i try to say, the window must be created with that flag, you can not force it that way AFAIK
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

aydın

  • Jr. Member
  • **
  • Posts: 86
Re: [Solved] Custom PopupMenu
« Reply #29 on: August 19, 2023, 06:22:07 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm2.CreateParams(var Params: TCreateParams);
  2. begin
  3.   inherited CreateParams(Params);
  4.   Params.ExStyle := Params.ExStyle or WS_EX_NOACTIVATE;
  5. end;
but somehow freepascal or lcl is working against such mechanism....

what i try to say, the window must be created with that flag, you can not force it that way AFAIK
I don't know where I went wrong.

No matter what I do, the popup takes the focus.
Lazarus 4.99, FPC 3.3.1 on Fedora 42

 

TinyPortal © 2005-2018