Recent

Author Topic: Restrict TComboBox dropdown  (Read 8176 times)

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Restrict TComboBox dropdown
« on: September 02, 2014, 11:12:54 pm »
Hi,
any idea how to restrict TComboBox dropdown - other than Enabled:=False?
I'm working on TCheckComboBox. It is readonly, Style=csOwnerDrawFixed.
See screenshot. I need that - let's say - left half of the component will toggle the state while right half will dropdown list. It is probably not problem with Windows (it has always "Edit") but GTK2 and Qt4 always dropdown (on left-mouse down).

Currently, I hooked on WMLButtonDown(); which is triggered before dropdown but I cannot find way to restrict dropdown.
I tried for example:
Code: [Select]
ControlState:=ControlState-[csLButtonDown, csClicked];I guess it is not easy since it is native component.

Thanks.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Restrict TComboBox dropdown
« Reply #1 on: September 03, 2014, 03:05:34 am »
Based on reading the source code (and only reading):
GTK2:
Code: [Select]
class procedure TGtk2WSCustomComboBox.SetDroppedDown(
...
  case ADroppedDown of
    True : gtk_combo_box_popup(Combo);
    False: gtk_combo_box_popdown(Combo);
  end;
end;
In GTK2, gtk_combo_box_pop[up/down]  are called only in:
  TGtk2WSCustomComboBox.SetDroppedDown
which is called directly/indirectly through:
  TCustomComboBox
    procedure KeyDown - using property DroppedDown
    property DroppedDown
    procedure SetDroppedDown - setter of property DroppedDown

I assume if you override SetDroppedDown and pass the call to it when you want or neglect the call when you don't need it to go through seems to be ok, maybe?

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Restrict TComboBox dropdown
« Reply #2 on: September 03, 2014, 08:21:26 am »
This might give you an idea
http://embarcadero.newsgroups.archived.at/public.delphi.vcl.components.using/200910/0910223332.html

or maybe a coditional call to Abort in ondropdown event?
« Last Edit: September 03, 2014, 08:24:15 am by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Restrict TComboBox dropdown
« Reply #3 on: September 03, 2014, 01:47:52 pm »
I tried message-methods approach and overriding SetDroppedDown as well but no luck.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Restrict TComboBox dropdown
« Reply #4 on: September 03, 2014, 03:11:45 pm »
This
Code: [Select]
procedure TForm1.ComboBox1DropDown(Sender: TObject);
begin
  Abort;
end;

blocks the list to drop down
Also this one
Code: [Select]
procedure TForm1.ComboBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ComboBox1.Style:=csSimple;
end;

procedure TForm1.ComboBox1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ComboBox1.Style:=csOwnerDrawFixed
end;
but needs screen to stop update until  mouse up
« Last Edit: September 03, 2014, 03:41:47 pm by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Restrict TComboBox dropdown
« Reply #5 on: September 03, 2014, 03:44:20 pm »
Yes but only in Windows. It has no effect in Qt and it blocks GTK2 so I have to execute: killall -9 gdb
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Restrict TComboBox dropdown
« Reply #6 on: September 03, 2014, 04:20:04 pm »
I will solve it with TTimer with a very small interval (~5 ms). It seems to be the only way.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Restrict TComboBox dropdown
« Reply #7 on: September 03, 2014, 06:30:22 pm »
i think i found something

Code: [Select]
procedure TForm1.ComboBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
   ComboBox1.DroppedDown:=false;
end;

does the job easy and clean
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Restrict TComboBox dropdown
« Reply #8 on: September 03, 2014, 06:40:09 pm »
It doesn't work on Qt4 and GTK2 too.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Restrict TComboBox dropdown
« Reply #9 on: September 03, 2014, 07:05:42 pm »
just read this [ http://qt-project.org/forums/viewthread/3150  ] for qt
is it possible ? to change the width, height and border style of the dropdown area and reset it back again ?
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Restrict TComboBox dropdown
« Reply #10 on: September 04, 2014, 10:16:10 am »
Currently, I hooked on WMLButtonDown(); which is triggered before dropdown but I cannot find way to restrict dropdown.

Just set Msg.Result to 1 in WMLButtonDown(), then it should result with TRUE in WS and that should work.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Restrict TComboBox dropdown
« Reply #11 on: September 04, 2014, 10:30:39 am »
Thanks, but it doesn't work too.

And I wasn't right, DropDown is triggered before WMLButtonDown.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Restrict TComboBox dropdown
« Reply #12 on: September 04, 2014, 11:19:09 am »
Finally, I hooked on DrawItem();, there's a negligible flickering but it's better solution than TTimer.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Restrict TComboBox dropdown
« Reply #13 on: September 04, 2014, 02:01:15 pm »
Thanks, but it doesn't work too.

And I wasn't right, DropDown is triggered before WMLButtonDown.

hm....strange. My wild guess is that it should trigger in order mousedown,dropdown,mouseup (if mouseup need to be triggered).
How it looks in delphi ?

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Restrict TComboBox dropdown
« Reply #14 on: September 04, 2014, 03:22:54 pm »
Quick test in Delphi7: DropDown is before MouseDown too, so in this regard is Lazarus compatible.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018