]> Pileus Git - ~andy/gtk/blob - gtk/gtkcombo.c
05e510293d427d53083591bfe2d08f64201c65de
[~andy/gtk] / gtk / gtkcombo.c
1 /* gtkcombo - combo widget for gtk+
2  * Copyright 1997 Paolo Molaro
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <string.h>
20
21 #include "gtkarrow.h"
22 #include "gtklabel.h"
23 #include "gtklist.h"
24 #include "gtkentry.h"
25 #include "gtkeventbox.h"
26 #include "gtkbutton.h"
27 #include "gtklistitem.h"
28 #include "gtkscrolledwindow.h"
29 #include "gtkmain.h"
30 #include "gtksignal.h"
31 #include "gtkwindow.h"
32 #include "gdk/gdkkeysyms.h"
33 #include "gtkcombo.h"
34 #include "gtkframe.h"
35
36 const gchar *gtk_combo_string_key = "gtk-combo-string-value";
37
38 #define COMBO_LIST_MAX_HEIGHT 400
39
40 static void         gtk_combo_class_init      (GtkComboClass *klass);
41 static void         gtk_combo_init            (GtkCombo      *combo);
42 static void         gtk_combo_destroy         (GtkObject     *combo);
43 static GtkListItem *gtk_combo_find            (GtkCombo      *combo);
44 static gchar *      gtk_combo_func            (GtkListItem  *li);
45 static gint         gtk_combo_focus_idle      (GtkCombo      *combo);
46 static gint         gtk_combo_entry_focus_out (GtkEntry      *entry, 
47                                                GdkEventFocus *event, 
48                                                GtkCombo      *combo);
49 static void         gtk_combo_get_pos         (GtkCombo      *combo, 
50                                                gint          *x, 
51                                                gint          *y, 
52                                                gint          *height, 
53                                                gint          *width);
54 static void         gtk_combo_popup_list      (GtkButton     *button, 
55                                                GtkCombo      *combo);
56 static void         gtk_combo_update_entry    (GtkList       *list, 
57                                                GtkCombo      *combo);
58 static void         gtk_combo_update_list     (GtkEntry      *entry, 
59                                                GtkCombo      *combo);
60 static gint         gtk_combo_button_press    (GtkWidget     *widget,
61                                                GdkEvent      *event,
62                                                GtkCombo      *combo);
63 static gint         gtk_combo_list_key_press  (GtkWidget     *widget, 
64                                                GdkEventKey   *event, 
65                                                GtkCombo      *combo);
66 static gint         gtk_combo_entry_key_press (GtkEntry      *widget, 
67                                                GdkEventKey   *event, 
68                                                GtkCombo      *combo);
69 static void         gtk_combo_item_destroy    (GtkObject     *object);
70 static void         gtk_combo_size_allocate   (GtkWidget     *widget,
71                                                GtkAllocation *allocation);
72
73 static GtkHBoxClass *parent_class = NULL;
74
75 static void
76 gtk_combo_class_init (GtkComboClass * klass)
77 {
78   GtkObjectClass *oclass;
79   GtkWidgetClass *widget_class;
80
81   parent_class = gtk_type_class (gtk_hbox_get_type ());
82   oclass = (GtkObjectClass *) klass;
83   widget_class = (GtkWidgetClass *) klass;
84
85   oclass->destroy = gtk_combo_destroy;
86   
87   widget_class->size_allocate = gtk_combo_size_allocate;
88 }
89
90 static void
91 gtk_combo_destroy (GtkObject * combo)
92 {
93   gtk_widget_destroy (GTK_COMBO (combo)->popwin);
94   gtk_widget_unref (GTK_COMBO (combo)->popwin);
95
96   if (GTK_OBJECT_CLASS (parent_class)->destroy)
97     (*GTK_OBJECT_CLASS (parent_class)->destroy) (combo);
98 }
99
100 static int
101 gtk_combo_entry_key_press (GtkEntry * entry, GdkEventKey * event, GtkCombo * combo)
102 {
103   GList *li;
104   /* completion? */
105   /*if ( event->keyval == GDK_Tab ) {
106      gtk_signal_emit_stop_by_name (GTK_OBJECT (entry), "key_press_event");
107      return TRUE;
108      } else */
109   if (!combo->use_arrows || !GTK_LIST (combo->list)->children)
110     return FALSE;
111   li = g_list_find (GTK_LIST (combo->list)->children, gtk_combo_find (combo));
112
113   if ((event->keyval == GDK_Up)
114       || (event->keyval == GDK_KP_Up)
115       || ((event->state & GDK_MOD1_MASK) && ((event->keyval == 'p') || (event->keyval == 'P'))))
116     {
117       if (li)
118         li = li->prev;
119       if (!li && combo->use_arrows_always)
120         {
121           li = g_list_last (GTK_LIST (combo->list)->children);
122         }
123       if (li)
124         {
125           gtk_list_select_child (GTK_LIST (combo->list), GTK_WIDGET (li->data));
126           gtk_signal_emit_stop_by_name (GTK_OBJECT (entry), "key_press_event");
127           return TRUE;
128         }
129     }
130   else if ((event->keyval == GDK_Down)
131            || (event->keyval == GDK_KP_Down)
132            || ((event->state & GDK_MOD1_MASK) && ((event->keyval == 'n') || (event->keyval == 'N'))))
133     {
134       if (li)
135         li = li->next;
136       if (!li && combo->use_arrows_always)
137         {
138           li = GTK_LIST (combo->list)->children;
139         }
140       if (li)
141         {
142           gtk_list_select_child (GTK_LIST (combo->list), GTK_WIDGET (li->data));
143           gtk_signal_emit_stop_by_name (GTK_OBJECT (entry), "key_press_event");
144           return TRUE;
145         }
146     }
147   return FALSE;
148 }
149
150 static GtkListItem *
151 gtk_combo_find (GtkCombo * combo)
152 {
153   gchar *text;
154   gchar *ltext;
155   GList *clist;
156   int (*string_compare) (const char *, const char *);
157
158   if (combo->case_sensitive)
159     string_compare = strcmp;
160   else
161     string_compare = g_strcasecmp;
162
163   text = gtk_entry_get_text (GTK_ENTRY (combo->entry));
164   clist = GTK_LIST (combo->list)->children;
165
166   while (clist && clist->data)
167     {
168       ltext = gtk_combo_func (GTK_LIST_ITEM (clist->data));
169       if (!ltext)
170         continue;
171       if (!(*string_compare) (ltext, text))
172         return (GtkListItem *) clist->data;
173       clist = clist->next;
174     }
175
176   return NULL;
177 }
178
179 static gchar *
180 gtk_combo_func (GtkListItem * li)
181 {
182   GtkWidget *label;
183   gchar *ltext = NULL;
184
185   ltext = (gchar *) gtk_object_get_data (GTK_OBJECT (li), gtk_combo_string_key);
186   if (!ltext)
187     {
188       label = GTK_BIN (li)->child;
189       if (!label || !GTK_IS_LABEL (label))
190         return NULL;
191       gtk_label_get (GTK_LABEL (label), &ltext);
192     }
193   return ltext;
194 }
195
196 static gint
197 gtk_combo_focus_idle (GtkCombo * combo)
198 {
199   if (combo)
200     gtk_widget_grab_focus (combo->entry);
201   return FALSE;
202 }
203
204 static gint
205 gtk_combo_entry_focus_out (GtkEntry * entry, GdkEventFocus * event, GtkCombo * combo)
206 {
207
208   if (combo->value_in_list && !gtk_combo_find (combo))
209     {
210       /* gdk_beep(); *//* this can be annoying */
211       if (combo->ok_if_empty && !strcmp (gtk_entry_get_text (entry), ""))
212         return FALSE;
213 #ifdef TEST
214       printf ("INVALID ENTRY: `%s'\n", gtk_entry_get_text (entry));
215 #endif
216       gtk_grab_add (GTK_WIDGET (combo));
217       /* this is needed because if we call gtk_widget_grab_focus() 
218          it isn't guaranteed it's the *last* call before the main-loop,
219          so the focus can be lost anyway...
220          the signal_emit_stop doesn't seem to work either...
221        */
222       gtk_idle_add ((GtkFunction) gtk_combo_focus_idle, combo);
223       /*gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "focus_out_event"); */
224       return TRUE;
225     }
226   return FALSE;
227 }
228
229 static void
230 gtk_combo_get_pos (GtkCombo * combo, gint * x, gint * y, gint * height, gint * width)
231 {
232   GtkBin *popwin;
233   GtkWidget *widget;
234   GtkScrolledWindow *popup;
235
236   gint real_height;
237   GtkRequisition list_requisition;
238   gboolean show_hscroll = FALSE;
239   gboolean show_vscroll = FALSE;
240   gint avail_height;
241   gint min_height;
242   gint alloc_width;
243   gint work_height;
244   gint old_height;
245   gint old_width;
246
247   widget = GTK_WIDGET(combo);
248   popup  = GTK_SCROLLED_WINDOW (combo->popup);
249   popwin = GTK_BIN (combo->popwin);
250
251   gdk_window_get_origin (combo->entry->window, x, y);
252   real_height = MIN (combo->entry->requisition.height, 
253                      combo->entry->allocation.height);
254   *y += real_height;
255   avail_height = gdk_screen_height () - *y;
256
257   gtk_widget_size_request (combo->list, &list_requisition);
258   min_height = MIN (list_requisition.height, 
259                     popup->vscrollbar->requisition.height);
260
261
262   alloc_width = widget->allocation.width -
263     2 * popwin->child->style->klass->xthickness -
264     2 * GTK_CONTAINER (popwin->child)->border_width -
265     2 * GTK_CONTAINER (combo->popup)->border_width -
266     2 * GTK_CONTAINER (popup->viewport)->border_width - 
267     2 * popup->viewport->style->klass->xthickness;
268
269   work_height =  
270     2 * popwin->child->style->klass->ythickness +
271     2 * GTK_CONTAINER (popwin->child)->border_width +
272     2 * GTK_CONTAINER (combo->popup)->border_width +
273     2 * GTK_CONTAINER (popup->viewport)->border_width +
274     2 * popup->viewport->style->klass->xthickness;
275
276   do 
277     {
278       old_width = alloc_width;
279       old_height = work_height;
280
281       if (!show_hscroll &&
282           alloc_width < list_requisition.width)
283         {
284           work_height += popup->hscrollbar->requisition.height +
285             GTK_SCROLLED_WINDOW_CLASS 
286             (GTK_OBJECT (combo->popup)->klass)->scrollbar_spacing;
287           show_hscroll = TRUE;
288         }
289       if (!show_vscroll && 
290           work_height + list_requisition.height > avail_height)
291         {
292           if (work_height + min_height > avail_height && 
293               *y - real_height > avail_height)
294             {
295               *y -= (work_height +list_requisition.height + real_height);
296               break;
297             }
298           alloc_width -= 
299             popup->vscrollbar->requisition.width +
300             GTK_SCROLLED_WINDOW_CLASS 
301             (GTK_OBJECT (combo->popup)->klass)->scrollbar_spacing;
302           show_vscroll = TRUE;
303         }
304     } while (old_width != alloc_width || old_height != work_height);
305
306   *width = widget->allocation.width;
307   if (show_vscroll)
308       *height = avail_height;
309   else
310     *height = work_height + list_requisition.height;
311   
312   if (*x < 0)
313     *x = 0;
314 }
315
316 static void
317 gtk_combo_popup_list (GtkButton * button, GtkCombo * combo)
318 {
319   gint height, width, x, y;
320   gint old_width, old_height;
321
322   if (!GTK_LIST (combo->list)->children)
323     return;
324
325   old_width = combo->popwin->allocation.width;
326   old_height  = combo->popwin->allocation.height;
327
328   gtk_combo_get_pos (combo, &x, &y, &height, &width);
329
330   /* workaround for gtk_scrolled_window_size_allocate bug */
331   if (old_width != width || old_height != height)
332     {
333       gtk_widget_hide (GTK_SCROLLED_WINDOW (combo->popup)->hscrollbar);
334       gtk_widget_hide (GTK_SCROLLED_WINDOW (combo->popup)->vscrollbar);
335     }
336
337   gtk_widget_set_uposition (combo->popwin, x, y);
338   gtk_widget_set_usize (combo->popwin, width, height);
339   gtk_widget_realize (combo->popwin);
340   gdk_window_resize (combo->popwin->window, width, height);
341   gtk_widget_show (combo->popwin);
342
343   gtk_widget_grab_focus (combo->popwin);
344   gtk_grab_add (combo->popwin);
345   gdk_pointer_grab (combo->popwin->window, TRUE,
346                     GDK_BUTTON_PRESS_MASK | 
347                     GDK_BUTTON_RELEASE_MASK |
348                     GDK_POINTER_MOTION_MASK, 
349                     NULL, NULL, GDK_CURRENT_TIME);
350 }
351
352 #if 0
353 static void
354 prelight_bug (GtkButton * b, GtkCombo * combo)
355 {
356   /* avoid prelight state... */
357   gtk_widget_set_state (combo->button, GTK_STATE_NORMAL);
358
359 }
360 #endif
361
362 static void
363 gtk_combo_update_entry (GtkList * list, GtkCombo * combo)
364 {
365   char *text;
366
367   gtk_grab_remove (GTK_WIDGET (combo));
368   gtk_signal_handler_block (GTK_OBJECT (list), combo->list_change_id);
369   if (list->selection)
370     {
371       text = gtk_combo_func (GTK_LIST_ITEM (list->selection->data));
372       if (!text)
373         text = "";
374       gtk_entry_set_text (GTK_ENTRY (combo->entry), text);
375     }
376   gtk_widget_hide (combo->popwin);
377   gtk_grab_remove (combo->popwin);
378   gdk_pointer_ungrab (GDK_CURRENT_TIME);
379   gtk_signal_handler_unblock (GTK_OBJECT (list), combo->list_change_id);
380 }
381
382 static void
383 gtk_combo_update_list (GtkEntry * entry, GtkCombo * combo)
384 {
385   GtkList *list = GTK_LIST (combo->list);
386   GList *slist = list->selection;
387   GtkListItem *li;
388
389   gtk_grab_remove (GTK_WIDGET (combo));
390
391   gtk_signal_handler_block (GTK_OBJECT (entry), combo->entry_change_id);
392   if (slist && slist->data)
393     gtk_list_unselect_child (list, GTK_WIDGET (slist->data));
394   li = gtk_combo_find (combo);
395   if (li)
396     gtk_list_select_child (list, GTK_WIDGET (li));
397   gtk_signal_handler_unblock (GTK_OBJECT (entry), combo->entry_change_id);
398 }
399
400 static gint
401 gtk_combo_button_press (GtkWidget * widget, GdkEvent * event, GtkCombo * combo)
402 {
403   GtkWidget *child;
404
405   child = gtk_get_event_widget (event);
406
407   /* We don't ask for button press events on the grab widget, so
408    *  if an event is reported directly to the grab widget, it must
409    *  be on a window outside the application (and thus we remove
410    *  the popup window). Otherwise, we check if the widget is a child
411    *  of the grab widget, and only remove the popup window if it
412    *  is not.
413    */
414   if (child != widget)
415     {
416       while (child)
417         {
418           if (child == widget)
419             return FALSE;
420           child = child->parent;
421         }
422     }
423
424   gtk_widget_hide (combo->popwin);
425   gtk_grab_remove (combo->popwin);
426   gdk_pointer_ungrab (GDK_CURRENT_TIME);
427
428   return TRUE;
429 }
430
431 static int
432 gtk_combo_list_key_press (GtkWidget * widget, GdkEventKey * event, GtkCombo * combo)
433 {
434   if (event->keyval == GDK_Escape)
435     {
436       gtk_widget_hide (combo->popwin);
437       gtk_grab_remove (combo->popwin);
438       gdk_pointer_ungrab (GDK_CURRENT_TIME);
439       return TRUE;
440     }
441   return FALSE;
442 }
443
444 static void
445 gtk_combo_init (GtkCombo * combo)
446 {
447   GtkWidget *arrow;
448   GtkWidget *frame;
449   GtkWidget *event_box;
450   GdkCursor *cursor;
451
452   combo->case_sensitive = 0;
453   combo->value_in_list = 0;
454   combo->ok_if_empty = 1;
455   combo->use_arrows = 1;
456   combo->use_arrows_always = 0;
457   combo->entry = gtk_entry_new ();
458   combo->button = gtk_button_new ();
459   arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
460   gtk_widget_show (arrow);
461   gtk_container_add (GTK_CONTAINER (combo->button), arrow);
462   gtk_box_pack_start (GTK_BOX (combo), combo->entry, TRUE, TRUE, 0);
463   gtk_box_pack_end (GTK_BOX (combo), combo->button, FALSE, FALSE, 0);
464   gtk_widget_show (combo->entry);
465   gtk_widget_show (combo->button);
466   combo->entry_change_id = gtk_signal_connect (GTK_OBJECT (combo->entry), "changed",
467                               (GtkSignalFunc) gtk_combo_update_list, combo);
468   gtk_signal_connect (GTK_OBJECT (combo->entry), "key_press_event",
469                       (GtkSignalFunc) gtk_combo_entry_key_press, combo);
470   gtk_signal_connect_after (GTK_OBJECT (combo->entry), "focus_out_event",
471                             (GtkSignalFunc) gtk_combo_entry_focus_out, combo);
472   combo->activate_id = gtk_signal_connect (GTK_OBJECT (combo->entry), "activate",
473                       (GtkSignalFunc) gtk_combo_popup_list, combo);
474   gtk_signal_connect (GTK_OBJECT (combo->button), "clicked",
475                       (GtkSignalFunc) gtk_combo_popup_list, combo);
476   /*gtk_signal_connect(GTK_OBJECT(combo->button), "clicked",
477      (GtkSignalFunc)prelight_bug, combo); */
478
479   combo->popwin = gtk_window_new (GTK_WINDOW_POPUP);
480   gtk_widget_ref (combo->popwin);
481   gtk_window_set_policy (GTK_WINDOW (combo->popwin), 1, 1, 0);
482   
483   gtk_widget_set_events (combo->popwin, GDK_KEY_PRESS_MASK);
484
485   event_box = gtk_event_box_new ();
486   gtk_container_add (GTK_CONTAINER (combo->popwin), event_box);
487   gtk_widget_show (event_box);
488
489   gtk_widget_realize (event_box);
490   cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
491   gdk_window_set_cursor (event_box->window, cursor);
492   gdk_cursor_destroy (cursor);
493
494   frame = gtk_frame_new (NULL);
495   gtk_container_add (GTK_CONTAINER (event_box), frame);
496   gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
497   gtk_widget_show (frame);
498
499   combo->popup = gtk_scrolled_window_new (NULL, NULL);
500   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (combo->popup),
501                                 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
502
503   combo->list = gtk_list_new ();
504   gtk_list_set_selection_mode(GTK_LIST(combo->list), GTK_SELECTION_BROWSE);
505   gtk_container_add (GTK_CONTAINER (frame), combo->popup);
506   gtk_container_add (GTK_CONTAINER (combo->popup), combo->list);
507   gtk_widget_show (combo->list);
508   gtk_widget_show (combo->popup);
509
510   combo->list_change_id = gtk_signal_connect (GTK_OBJECT (combo->list), "selection_changed",
511                              (GtkSignalFunc) gtk_combo_update_entry, combo);
512   gtk_signal_connect (GTK_OBJECT (combo->popwin), "key_press_event",
513                       (GtkSignalFunc) gtk_combo_list_key_press, combo);
514   gtk_signal_connect (GTK_OBJECT (combo->popwin), "button_press_event",
515                       GTK_SIGNAL_FUNC (gtk_combo_button_press), combo);
516   
517 }
518
519 guint
520 gtk_combo_get_type ()
521 {
522   static guint combo_type = 0;
523
524   if (!combo_type)
525     {
526       GtkTypeInfo combo_info =
527       {
528         "GtkCombo",
529         sizeof (GtkCombo),
530         sizeof (GtkComboClass),
531         (GtkClassInitFunc) gtk_combo_class_init,
532         (GtkObjectInitFunc) gtk_combo_init,
533         (GtkArgSetFunc) NULL,
534         (GtkArgGetFunc) NULL,
535       };
536       combo_type = gtk_type_unique (gtk_hbox_get_type (), &combo_info);
537     }
538   return combo_type;
539 }
540
541 GtkWidget *
542 gtk_combo_new ()
543 {
544   return GTK_WIDGET (gtk_type_new (gtk_combo_get_type ()));
545 }
546
547 void
548 gtk_combo_set_value_in_list (GtkCombo * combo, gint val, gint ok_if_empty)
549 {
550   g_return_if_fail (combo != NULL);
551   g_return_if_fail (GTK_IS_COMBO (combo));
552
553   combo->value_in_list = val;
554   combo->ok_if_empty = ok_if_empty;
555 }
556
557 void
558 gtk_combo_set_case_sensitive (GtkCombo * combo, gint val)
559 {
560   g_return_if_fail (combo != NULL);
561   g_return_if_fail (GTK_IS_COMBO (combo));
562
563   combo->case_sensitive = val;
564 }
565
566 void
567 gtk_combo_set_use_arrows (GtkCombo * combo, gint val)
568 {
569   g_return_if_fail (combo != NULL);
570   g_return_if_fail (GTK_IS_COMBO (combo));
571
572   combo->use_arrows = val;
573 }
574
575 void
576 gtk_combo_set_use_arrows_always (GtkCombo * combo, gint val)
577 {
578   g_return_if_fail (combo != NULL);
579   g_return_if_fail (GTK_IS_COMBO (combo));
580
581   combo->use_arrows_always = val;
582   combo->use_arrows = 1;
583 }
584
585 void
586 gtk_combo_set_popdown_strings (GtkCombo * combo, GList * strings)
587 {
588   GList *list;
589   GtkWidget *li;
590
591   g_return_if_fail (combo != NULL);
592   g_return_if_fail (GTK_IS_COMBO (combo));
593   g_return_if_fail (strings != NULL);
594
595   gtk_list_clear_items (GTK_LIST (combo->list), 0, -1);
596   list = strings;
597   while (list)
598     {
599       li = gtk_list_item_new_with_label ((gchar *) list->data);
600       gtk_widget_show (li);
601       gtk_container_add (GTK_CONTAINER (combo->list), li);
602       list = list->next;
603     }
604 }
605
606 static void
607 gtk_combo_item_destroy (GtkObject * object)
608 {
609   gchar *key;
610
611   key = gtk_object_get_data (object, gtk_combo_string_key);
612   if (key)
613     g_free (key);
614 }
615
616 void
617 gtk_combo_set_item_string (GtkCombo * combo, GtkItem * item, const gchar * item_value)
618 {
619   gchar *val;
620   gint connected = 0;
621
622   g_return_if_fail (combo != NULL);
623   g_return_if_fail (GTK_IS_COMBO (combo));
624   g_return_if_fail (item != NULL);
625
626   val = gtk_object_get_data (GTK_OBJECT (item), gtk_combo_string_key);
627   if (val) 
628     {
629       g_free (val);
630       connected = 1;
631     }
632   if (item_value)
633     {
634       val = g_strdup(item_value);
635       gtk_object_set_data (GTK_OBJECT (item), gtk_combo_string_key, val);
636       if (!connected)
637         gtk_signal_connect (GTK_OBJECT (item), "destroy",
638                           (GtkSignalFunc) gtk_combo_item_destroy, val);
639     }
640   else 
641     {
642       gtk_object_set_data (GTK_OBJECT (item), gtk_combo_string_key, NULL);
643       if (connected)
644         gtk_signal_disconnect_by_data(GTK_OBJECT (item), val);
645     }
646 }
647
648 static void
649 gtk_combo_size_allocate (GtkWidget     *widget,
650                          GtkAllocation *allocation)
651 {
652   GtkCombo *combo;
653
654   g_return_if_fail (widget != NULL);
655   g_return_if_fail (GTK_IS_COMBO (widget));
656   g_return_if_fail (allocation != NULL);
657
658   GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
659   
660   combo = GTK_COMBO (widget);
661
662   if (combo->entry->allocation.height > combo->entry->requisition.height)
663     {
664       GtkAllocation button_allocation;
665
666       button_allocation = combo->button->allocation;
667       button_allocation.height = combo->entry->requisition.height;
668       button_allocation.y = combo->entry->allocation.y + 
669         (combo->entry->allocation.height - combo->entry->requisition.height) 
670         / 2;
671       gtk_widget_size_allocate (combo->button, &button_allocation);
672     }
673 }
674
675 void
676 gtk_combo_disable_activate (GtkCombo* combo)
677 {
678   g_return_if_fail (combo != NULL);
679   g_return_if_fail (GTK_IS_COMBO (combo));
680
681   if ( combo->activate_id ) {
682     gtk_signal_disconnect(GTK_OBJECT(combo), combo->activate_id);
683     combo->activate_id = 0;
684   }
685 }