notes on combo boxes


Miguel requested that I look at the various combo boxes. I'm not going
to fool with a patch until my current patch collection gets merged
(and maybe not even after that), but since I looked at them tonight
here's my brain dump. If anyone wants to work on this, feel free.
I'm not sure if it's a GTK+ 2.0 item or a 2.2 item.

Tim has GtkClueHunter in beast/beast-gtk/bstutils.h. I think this
looks like a pretty good widget for a text-entry combo box; it is
reasonably simple, and it has tab completion which is the primary
feature people request for these boxes (the only other one I can think
of is putting a pixmap by each item in the popdown, but I doubt that
feature is important).

Gnumeric contains a GtkComboBox which I believe originated in
GtkExtra, and has subclasses for text and for pixmaps. The files are:

GtkComboBox is an abstract base that handles the details of dropping
down a selection widget underneath another widget. Subclasses define
what the button widget contains (entry, button, etc.) and what the
drop down contains (grid of color buttons, list of strings).
GtkComboBox isn't _that_ abstract, conceivably you could even
instantiate it and create a "subclass" just by packing in some widgets
and connecting to a couple signals.

 - GtkClueHunter is a more complete text-entry combo than 
   GtkComboText, with tab completion and stuff
 - GtkClueHunter should not be named that ;-) also a couple 
   of the functions and signals could use better names 
 - GtkComboBox should probably be called something else, 
   and GtkComboBox should likely be the name of the 
   text combo 
 - I think the PixmapCombo is quite useful. I assume this is used
   for the color combo in Gnumeric. But you could also use it 
   for symbols to place on a plot, brushes for a paint program,
 - In general I think the GtkComboBox abstract base class is 
   pretty useful, because the popdown window is tricky to 
   implement yourself
 - GtkComboBox is currently implemented with GtkList, and 
   GtkClueHunter uses the CList, both are deprecated, if this 
   is relevant
 - PixmapCombo needs moving to GtkImage instead of GnomePixmap 
   in order to go in GTK, but this is trivial
 - PixmapCombo could probably just allow any widgets to go in 
   the grid to be chosen from.

It's sort of unclear what the hell a combo box actually is, because it
blurs with option menu. In fact Qt uses a combo box with an "editable"
flag, where an ineditable combo is just an option menu. For GTK, if
someone wants a widget that displays a fixed set of uneditable strings
to choose from, we want them to use GtkOptionMenu. The PixmapCombo is
also really an option menu, but because of the way GtkMenu works the
grid of images is much easier to implement in this combo framework
than it would be as an option menu.

On the other hand, if you think about it GtkOptionMenu derives from
GtkButton, and the "combo" in ComboBox is that it's a combo of a
button and a list of items to choose from, so maybe we are on crack. ;-)

I also looked at QComboBox. QComboBox as I said doubles as an option
menu. It can't contain arbitrary widgets; like CList, it contains
text, pixmap, or pixmap with text. 

One useful feature it has is:

 enum Policy { NoInsertion, AtTop, AtCurrent, AtBottom, AfterCurrent, BeforeCurrent }
 virtual void setInsertionPolicy ( Policy policy );

So you can set where new items appear (presumably if the user enters a
string, this controls where the string ends up in the history).

It also has these which look useful:

     // like the Internet Explorer location bar I assume
     virtual void setAutoCompletion ( bool ) 
     bool autoCompletion () const

     // allow duplicate strings in the list
     void setDuplicatesEnabled ( bool enable ) 
     bool duplicatesEnabled () const

     // put a max size on the history
     virtual void setMaxCount ( int ) 
     int maxCount () const

JComboBox from Swing is of course insanely complicated and contains
enough vtables to write a whole widget set. But, I don't see any
reasonably-implementable features there that haven't already been
mentioned. JComboBox is also used for an option menu.

Some reworking of the existing code is likely good before a GTK merge,
I guess my current sense is that an abstract base similar to
GtkComboBox is useful, and that the two subclasses in GTK itself
should be an editable text combo with auto and/or tab completion, and
a select-from-a-grid-of-widgets combo where a grid of GtkImage will be
the most common use and we might have convenience functions for that.
The text combo should basically be like the Netscape or IE location
entry, and the grid-of-widgets combo should basically be like the
color-chooser widget on the Gnumeric toolbar.

If that seems like too much or too complicated (I don't think it is,
these widgets are pretty simple and small), then I'd just go for
the text combo, GtkClueHunter is probably fine for that.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]