Page 1 of 1

Extending wxComboBox - thin separator line between items

Posted: Mon Nov 28, 2016 6:49 pm
by Forbin
I need to extend wxComboBox (or develop a combobox-like control) so that I can add one or more thin separator lines between choices, very much like the below:

comboWithSep.jpg
comboWithSep.jpg (5.58 KiB) Viewed 1004 times

Details:
  • I am using wxWidgets 3.0.2, and have no options to use any other version (this is an existing software project with many other dependencies)
  • I am relatively new to wxWidgets but reasonably knowledgable in C++
  • The combo box is text-only and does not need icons or other decorative enhancements
  • I need to build for Windows 7/8.1/10 and Mac OSX 10.x, but not other OSes

I've seen conflicting information as to whether I should overload the OnPaint event handler or not.
Regardless of how I implement this, I need to avoid any labor-intensive approaches if possible.

I would value your recommendations and suggestions!

Re: Extending wxComboBox - thin separator line between items

Posted: Mon Nov 28, 2016 7:29 pm
by doublemax
wxComboCtrl allows more customization than wxComboBox:
http://docs.wxwidgets.org/trunk/classwx_combo_ctrl.html

The "combo" sample that comes with wxWidgets shows how to use it.

Re: Extending wxComboBox - thin separator line between items

Posted: Mon Nov 28, 2016 7:53 pm
by Forbin
Aha... I'm browsing it now. Thanks!! It looks like it "manually" manages its popup control.

I'm thinking perhaps I could intercept the OnPaint for just the popup control, and be able to draw the dividing line there?

Re: Extending wxComboBox - thin separator line between items

Posted: Mon Nov 28, 2016 8:44 pm
by PB
Just be aware that IIRC wxComboCtrl (at least on MSW) does not behave like a wxComboBox. For example, there is no support for navigating the items with keyboard at all, i.e. selecting items with cursor keys (Up, Dn, PgUp, PgDn, Home, End) or by typing their first few letters or even closing the pop-up with Esc/Enter etc. All this must be implemented anew (aka copied from wxComboBox).

Maybe just using a regular menu (perhaps something like this) instead may be a better idea...

Re: Extending wxComboBox - thin separator line between items

Posted: Mon Nov 28, 2016 9:52 pm
by Forbin
PB wrote:Maybe just using a regular menu (perhaps something like this) instead may be a better idea...


Very clever! And it would certainly get me the dividing lines, since menus in both OSX and MSW have them.

Are you saying that I should use the menu for my popup section but build the rest of the control myself, as was done with your SplitButton example? (Obviously using an edit control or whatever so my version looks like a combo box.)

How would doing that differ from using wxComboCtrl, but wrapping the menu object in a class derived from wxComboPopup?

(The existing combo box in the app I"m working on allows you to all the keyboard actions you described; I'm adding an MRU list section to the combo box, and I'm guessing the product manager won't want to lose functionality to gain the divider bar and the MRU.)

Thanks!
--forbin

Re: Extending wxComboBox - thin separator line between items

Posted: Tue Nov 29, 2016 5:35 pm
by PB
I actually meant using just a pop-up menu with another control as the easiest way to do that. If the control has to look and behave like a combox, you cannot do that then.

Re: Extending wxComboBox - thin separator line between items

Posted: Wed Dec 21, 2016 8:22 pm
by Forbin
I ended up using wxOwnerDrawnComboBox and just extending the text list class within.
Thanks for the help and advice!