1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * mygal-combo-box.c - a customizable combobox
4 * Copyright 2000, 2001, Ximian, Inc.
7 * Miguel de Icaza (miguel@gnu.org)
8 * Adrian E Feiguin (feiguin@ifir.edu.ar)
9 * Paolo Molnaro (lupus@debian.org).
10 * Jon K Hellan (hellan@acm.org)
12 * Modified for gLabels by:
13 * Jim Evins <evins@snaught.com>
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public
17 * License, version 2, as published by the Free Software Foundation.
19 * This library is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 #include <gtk/gtkhbox.h>
32 #include <gtk/gtktogglebutton.h>
33 #include <gtk/gtkarrow.h>
34 #include <gtk/gtkeventbox.h>
35 #include <gtk/gtkmain.h>
36 #include <gtk/gtksignal.h>
37 #include <gtk/gtkwindow.h>
38 #include <gtk/gtkframe.h>
39 #include <gtk/gtkvbox.h>
40 #include <gtk/gtktearoffmenuitem.h>
41 #include <gdk/gdkkeysyms.h>
42 #include "mygal-combo-box.h"
45 #define PARENT_TYPE GTK_TYPE_HBOX
46 static GObjectClass *mygal_combo_box_parent_class;
48 static int mygal_combo_toggle_pressed (GtkToggleButton *tbutton,
49 MygalComboBox *combo_box);
50 static void mygal_combo_popup_tear_off (MygalComboBox *combo,
51 gboolean set_position);
52 static void mygal_combo_set_tearoff_state (MygalComboBox *combo,
54 static void mygal_combo_popup_reparent (GtkWidget *popup, GtkWidget *new_parent,
56 static gboolean cb_popup_delete (GtkWidget *w, GdkEventAny *event,
57 MygalComboBox *combo);
58 static void mygal_combo_tearoff_bg_copy (MygalComboBox *combo);
68 static guint mygal_combo_box_signals [LAST_SIGNAL] = { 0, };
70 struct _MygalComboBoxPrivate {
71 GtkWidget *pop_down_widget;
72 GtkWidget *display_widget;
75 * Internal widgets used to implement the ComboBox
78 GtkWidget *arrow_button;
80 GtkWidget *toplevel; /* Popup's toplevel when not torn off */
81 GtkWidget *tearoff_window; /* Popup's toplevel when torn off */
84 GtkWidget *tearable; /* The tearoff "button" */
85 GtkWidget *popup; /* Popup */
88 * Closure for invoking the callbacks above
94 mygal_combo_box_finalize (GObject *object)
96 MygalComboBox *combo_box = MYGAL_COMBO_BOX (object);
98 g_free (combo_box->priv);
100 mygal_combo_box_parent_class->finalize (object);
104 mygal_combo_box_destroy (GtkObject *object)
106 GtkObjectClass *klass = (GtkObjectClass *)mygal_combo_box_parent_class;
107 MygalComboBox *combo_box = MYGAL_COMBO_BOX (object);
109 if (combo_box->priv->toplevel) {
110 gtk_object_destroy (GTK_OBJECT (combo_box->priv->toplevel));
111 combo_box->priv->toplevel = NULL;
114 if (combo_box->priv->tearoff_window) {
115 gtk_object_destroy (GTK_OBJECT (combo_box->priv->tearoff_window));
116 combo_box->priv->tearoff_window = NULL;
120 klass->destroy (object);
124 mygal_combo_box_mnemonic_activate (GtkWidget *w, gboolean group_cycling)
126 MygalComboBox *combo_box = MYGAL_COMBO_BOX (w);
127 gtk_toggle_button_set_active (
128 GTK_TOGGLE_BUTTON (combo_box->priv->arrow_button), TRUE);
133 mygal_combo_box_class_init (GObjectClass *object_class)
135 GtkWidgetClass *widget_class = (GtkWidgetClass *)object_class;
136 mygal_combo_box_parent_class = g_type_class_peek_parent (object_class);
138 object_class->finalize = mygal_combo_box_finalize;
139 widget_class->mnemonic_activate = mygal_combo_box_mnemonic_activate;
140 ((GtkObjectClass *)object_class)->destroy = mygal_combo_box_destroy;
142 mygal_combo_box_signals [POP_DOWN_WIDGET] = g_signal_new (
144 G_OBJECT_CLASS_TYPE (object_class),
146 G_STRUCT_OFFSET (MygalComboBoxClass, pop_down_widget),
148 e_marshal_POINTER__NONE,
149 G_TYPE_POINTER, 0, G_TYPE_NONE);
151 mygal_combo_box_signals [POP_DOWN_DONE] = g_signal_new (
153 G_OBJECT_CLASS_TYPE (object_class),
155 G_STRUCT_OFFSET (MygalComboBoxClass, pop_down_done),
157 e_marshal_BOOLEAN__OBJECT,
158 G_TYPE_BOOLEAN, 1, G_TYPE_OBJECT);
160 mygal_combo_box_signals [PRE_POP_DOWN] = g_signal_new (
162 G_OBJECT_CLASS_TYPE (object_class),
164 G_STRUCT_OFFSET (MygalComboBoxClass, pre_pop_down),
166 e_marshal_NONE__NONE,
169 mygal_combo_box_signals [POST_POP_HIDE] = g_signal_new (
171 G_OBJECT_CLASS_TYPE (object_class),
173 G_STRUCT_OFFSET (MygalComboBoxClass, post_pop_hide),
175 e_marshal_NONE__NONE,
180 deactivate_arrow (MygalComboBox *combo_box)
182 GtkToggleButton *arrow;
184 arrow = GTK_TOGGLE_BUTTON (combo_box->priv->arrow_button);
185 g_signal_handlers_block_matched (arrow,
186 G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
188 mygal_combo_toggle_pressed, combo_box);
190 gtk_toggle_button_set_active (arrow, FALSE);
192 g_signal_handlers_unblock_matched (arrow,
193 G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
195 mygal_combo_toggle_pressed, combo_box);
199 * mygal_combo_box_popup_hide_unconditional
200 * @combo_box: Combo box
202 * Hide popup, whether or not it is torn off.
205 mygal_combo_box_popup_hide_unconditional (MygalComboBox *combo_box)
207 gboolean popup_info_destroyed = FALSE;
209 g_return_if_fail (combo_box != NULL);
210 g_return_if_fail (MYGAL_IS_COMBO_BOX (combo_box));
212 gtk_widget_hide (combo_box->priv->toplevel);
213 gtk_widget_hide (combo_box->priv->popup);
214 if (combo_box->priv->torn_off) {
215 GTK_TEAROFF_MENU_ITEM (combo_box->priv->tearable)->torn_off
217 mygal_combo_set_tearoff_state (combo_box, FALSE);
220 gtk_grab_remove (combo_box->priv->toplevel);
221 gdk_pointer_ungrab (GDK_CURRENT_TIME);
223 g_object_ref (combo_box->priv->pop_down_widget);
224 g_signal_emit (combo_box,
225 mygal_combo_box_signals [POP_DOWN_DONE], 0,
226 combo_box->priv->pop_down_widget, &popup_info_destroyed);
228 if (popup_info_destroyed){
229 gtk_container_remove (
230 GTK_CONTAINER (combo_box->priv->frame),
231 combo_box->priv->pop_down_widget);
232 combo_box->priv->pop_down_widget = NULL;
234 g_object_unref (combo_box->priv->pop_down_widget);
235 deactivate_arrow (combo_box);
237 g_signal_emit (combo_box, mygal_combo_box_signals [POST_POP_HIDE], 0);
241 * mygal_combo_box_popup_hide:
242 * @combo_box: Combo box
244 * Hide popup, but not when it is torn off.
245 * This is the external interface - for subclasses and apps which expect a
246 * regular combo which doesn't do tearoffs.
249 mygal_combo_box_popup_hide (MygalComboBox *combo_box)
251 if (!combo_box->priv->torn_off)
252 mygal_combo_box_popup_hide_unconditional (combo_box);
253 else if (GTK_WIDGET_VISIBLE (combo_box->priv->toplevel)) {
254 /* Both popup and tearoff window present. Get rid of just
256 mygal_combo_popup_tear_off (combo_box, FALSE);
257 deactivate_arrow (combo_box);
262 * Find best location for displaying
265 mygal_combo_box_get_pos (MygalComboBox *combo_box, int *x, int *y)
267 GtkWidget *wcombo = GTK_WIDGET (combo_box);
270 gdk_window_get_origin (wcombo->window, x, y);
271 *y += wcombo->allocation.height + wcombo->allocation.y;
272 *x += wcombo->allocation.x;
274 ph = combo_box->priv->popup->allocation.height;
275 pw = combo_box->priv->popup->allocation.width;
277 if ((*y + ph) > gdk_screen_height ())
278 *y = gdk_screen_height () - ph;
280 if ((*x + pw) > gdk_screen_width ())
281 *x = gdk_screen_width () - pw;
285 mygal_combo_box_popup_display (MygalComboBox *combo_box)
289 g_return_if_fail (combo_box != NULL);
290 g_return_if_fail (MYGAL_IS_COMBO_BOX (combo_box));
293 * If we have no widget to display on the popdown,
296 if (!combo_box->priv->pop_down_widget){
297 GtkWidget *pw = NULL;
299 g_signal_emit (combo_box,
300 mygal_combo_box_signals [POP_DOWN_WIDGET], 0, &pw);
301 g_assert (pw != NULL);
302 combo_box->priv->pop_down_widget = pw;
303 gtk_container_add (GTK_CONTAINER (combo_box->priv->frame), pw);
306 g_signal_emit (combo_box, mygal_combo_box_signals [PRE_POP_DOWN], 0);
308 if (combo_box->priv->torn_off) {
309 /* To give the illusion that tearoff still displays the
310 * popup, we copy the image in the popup window to the
311 * background. Thus, it won't be blank after reparenting */
312 mygal_combo_tearoff_bg_copy (combo_box);
314 /* We force an unrealize here so that we don't trigger
315 * redrawing/ clearing code - we just want to reveal our
318 mygal_combo_popup_reparent (combo_box->priv->popup,
319 combo_box->priv->toplevel, TRUE);
322 mygal_combo_box_get_pos (combo_box, &x, &y);
324 gtk_widget_set_uposition (combo_box->priv->toplevel, x, y);
325 gtk_widget_realize (combo_box->priv->popup);
326 gtk_widget_show (combo_box->priv->popup);
327 gtk_widget_realize (combo_box->priv->toplevel);
328 gtk_widget_show (combo_box->priv->toplevel);
330 gtk_grab_add (combo_box->priv->toplevel);
331 gdk_pointer_grab (combo_box->priv->toplevel->window, TRUE,
332 GDK_BUTTON_PRESS_MASK |
333 GDK_BUTTON_RELEASE_MASK |
334 GDK_POINTER_MOTION_MASK,
335 NULL, NULL, GDK_CURRENT_TIME);
339 mygal_combo_toggle_pressed (GtkToggleButton *tbutton, MygalComboBox *combo_box)
342 mygal_combo_box_popup_display (combo_box);
344 mygal_combo_box_popup_hide_unconditional (combo_box);
350 mygal_combo_box_button_press (GtkWidget *widget, GdkEventButton *event, MygalComboBox *combo_box)
354 child = gtk_get_event_widget ((GdkEvent *) event);
355 if (child != widget){
359 child = child->parent;
363 mygal_combo_box_popup_hide (combo_box);
368 * mygal_combo_box_key_press
371 * @combo_box: Combo box
373 * Key press handler which dismisses popup on escape.
374 * Popup is dismissed whether or not popup is torn off.
377 mygal_combo_box_key_press (GtkWidget *widget, GdkEventKey *event,
378 MygalComboBox *combo_box)
380 if (event->keyval == GDK_Escape) {
381 mygal_combo_box_popup_hide_unconditional (combo_box);
388 cb_state_change (GtkWidget *widget, GtkStateType old_state, MygalComboBox *combo_box)
390 GtkStateType const new_state = GTK_WIDGET_STATE(widget);
391 gtk_widget_set_state (combo_box->priv->display_widget, new_state);
395 mygal_combo_box_init (MygalComboBox *combo_box)
400 combo_box->priv = g_new0 (MygalComboBoxPrivate, 1);
405 combo_box->priv->arrow_button = gtk_toggle_button_new ();
406 gtk_button_set_relief (GTK_BUTTON (combo_box->priv->arrow_button), GTK_RELIEF_NONE);
407 GTK_WIDGET_UNSET_FLAGS (combo_box->priv->arrow_button, GTK_CAN_FOCUS);
409 arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
410 gtk_container_add (GTK_CONTAINER (combo_box->priv->arrow_button), arrow);
411 gtk_box_pack_end (GTK_BOX (combo_box), combo_box->priv->arrow_button, FALSE, FALSE, 0);
412 g_signal_connect (combo_box->priv->arrow_button, "toggled",
413 G_CALLBACK (mygal_combo_toggle_pressed), combo_box);
414 gtk_widget_show_all (combo_box->priv->arrow_button);
417 * prelight the display widget when mousing over the arrow.
419 g_signal_connect (combo_box->priv->arrow_button, "state-changed",
420 G_CALLBACK (cb_state_change), combo_box);
423 * The pop-down container
426 combo_box->priv->toplevel = gtk_window_new (GTK_WINDOW_POPUP);
427 gtk_widget_ref (combo_box->priv->toplevel);
428 gtk_object_sink (GTK_OBJECT (combo_box->priv->toplevel));
429 gtk_window_set_policy (GTK_WINDOW (combo_box->priv->toplevel),
432 combo_box->priv->popup = gtk_event_box_new ();
433 gtk_container_add (GTK_CONTAINER (combo_box->priv->toplevel),
434 combo_box->priv->popup);
435 gtk_widget_show (combo_box->priv->popup);
437 gtk_widget_realize (combo_box->priv->popup);
438 cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
439 gdk_window_set_cursor (combo_box->priv->popup->window, cursor);
440 gdk_cursor_unref (cursor);
442 combo_box->priv->torn_off = FALSE;
443 combo_box->priv->tearoff_window = NULL;
445 combo_box->priv->frame = gtk_frame_new (NULL);
446 gtk_container_add (GTK_CONTAINER (combo_box->priv->popup),
447 combo_box->priv->frame);
448 gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->frame), GTK_SHADOW_OUT);
450 g_signal_connect (combo_box->priv->toplevel, "button_press_event",
451 G_CALLBACK (mygal_combo_box_button_press), combo_box);
452 g_signal_connect (combo_box->priv->toplevel, "key_press_event",
453 G_CALLBACK (mygal_combo_box_key_press), combo_box);
456 E_MAKE_TYPE (mygal_combo_box,
459 mygal_combo_box_class_init,
460 mygal_combo_box_init,
464 * mygal_combo_box_set_display:
465 * @combo_box: the Combo Box to modify
466 * @display_widget: The widget to be displayed
468 * Sets the displayed widget for the @combo_box to be @display_widget
471 mygal_combo_box_set_display (MygalComboBox *combo_box, GtkWidget *display_widget)
473 g_return_if_fail (combo_box != NULL);
474 g_return_if_fail (MYGAL_IS_COMBO_BOX (combo_box));
475 g_return_if_fail (display_widget != NULL);
476 g_return_if_fail (GTK_IS_WIDGET (display_widget));
478 if (combo_box->priv->display_widget &&
479 combo_box->priv->display_widget != display_widget)
480 gtk_container_remove (GTK_CONTAINER (combo_box),
481 combo_box->priv->display_widget);
483 combo_box->priv->display_widget = display_widget;
485 gtk_box_pack_start (GTK_BOX (combo_box), display_widget, TRUE, TRUE, 0);
489 cb_tearable_enter_leave (GtkWidget *w, GdkEventCrossing *event, gpointer data)
491 gboolean const flag = GPOINTER_TO_INT(data);
492 gtk_widget_set_state (w, flag ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL);
497 * mygal_combo_popup_tear_off
499 * @set_position: Set to position of popup shell if true
504 * Gtk popup menus are toplevel windows, not dialogs. I think this is wrong,
505 * and make the popups dialogs. But may be there should be a way to make
506 * them toplevel. We can do this after creating:
507 * GTK_WINDOW (tearoff)->type = GTK_WINDOW_TOPLEVEL;
510 mygal_combo_popup_tear_off (MygalComboBox *combo, gboolean set_position)
514 if (!combo->priv->tearoff_window) {
518 /* FIXME: made this a toplevel, not a dialog ! */
519 tearoff = gtk_window_new (GTK_WINDOW_TOPLEVEL);
520 gtk_widget_ref (tearoff);
521 gtk_object_sink (GTK_OBJECT (tearoff));
522 combo->priv->tearoff_window = tearoff;
523 gtk_widget_set_app_paintable (tearoff, TRUE);
524 g_signal_connect (tearoff, "key_press_event",
525 G_CALLBACK (mygal_combo_box_key_press),
527 gtk_widget_realize (tearoff);
528 title = g_object_get_data (G_OBJECT (combo),
531 gdk_window_set_title (tearoff->window, title);
532 gtk_window_set_policy (GTK_WINDOW (tearoff),
534 gtk_window_set_transient_for
535 (GTK_WINDOW (tearoff),
536 GTK_WINDOW (gtk_widget_get_toplevel
537 GTK_WIDGET (combo)));
540 if (GTK_WIDGET_VISIBLE (combo->priv->popup)) {
541 gtk_widget_hide (combo->priv->toplevel);
543 gtk_grab_remove (combo->priv->toplevel);
544 gdk_pointer_ungrab (GDK_CURRENT_TIME);
547 mygal_combo_popup_reparent (combo->priv->popup,
548 combo->priv->tearoff_window, FALSE);
550 /* It may have got confused about size */
551 gtk_widget_queue_resize (GTK_WIDGET (combo->priv->popup));
554 mygal_combo_box_get_pos (combo, &x, &y);
555 gtk_widget_set_uposition (combo->priv->tearoff_window, x, y);
557 gtk_widget_show (GTK_WIDGET (combo->priv->popup));
558 gtk_widget_show (combo->priv->tearoff_window);
563 * mygal_combo_set_tearoff_state
564 * @combo_box: Combo box
565 * @torn_off: TRUE: Tear off. FALSE: Pop down and reattach
567 * Set the tearoff state of the popup
569 * Compare with gtk_menu_set_tearoff_state in gtk/gtkmenu.c
572 mygal_combo_set_tearoff_state (MygalComboBox *combo,
575 g_return_if_fail (combo != NULL);
576 g_return_if_fail (MYGAL_IS_COMBO_BOX (combo));
578 if (combo->priv->torn_off != torn_off) {
579 combo->priv->torn_off = torn_off;
581 if (combo->priv->torn_off) {
582 mygal_combo_popup_tear_off (combo, TRUE);
583 deactivate_arrow (combo);
585 gtk_widget_hide (combo->priv->tearoff_window);
586 mygal_combo_popup_reparent (combo->priv->popup,
587 combo->priv->toplevel,
594 * mygal_combo_tearoff_bg_copy
595 * @combo_box: Combo box
597 * Copy popup window image to the tearoff window.
600 mygal_combo_tearoff_bg_copy (MygalComboBox *combo)
604 GdkGCValues gc_values;
606 GtkWidget *widget = combo->priv->popup;
608 if (combo->priv->torn_off) {
609 gc_values.subwindow_mode = GDK_INCLUDE_INFERIORS;
610 gc = gdk_gc_new_with_values (widget->window,
611 &gc_values, GDK_GC_SUBWINDOW);
613 pixmap = gdk_pixmap_new (widget->window,
614 widget->allocation.width,
615 widget->allocation.height,
618 gdk_draw_drawable (pixmap, gc,
623 gtk_widget_set_usize (combo->priv->tearoff_window,
624 widget->allocation.width,
625 widget->allocation.height);
627 gdk_window_set_back_pixmap
628 (combo->priv->tearoff_window->window, pixmap, FALSE);
629 gdk_drawable_unref (pixmap);
634 * mygal_combo_popup_reparent
636 * @new_parent: New parent
637 * @unrealize: Unrealize popup if TRUE.
639 * Reparent the popup, taking care of the refcounting
641 * Compare with gtk_menu_reparent in gtk/gtkmenu.c
644 mygal_combo_popup_reparent (GtkWidget *popup,
645 GtkWidget *new_parent,
648 GtkObject *object = GTK_OBJECT (popup);
649 gboolean was_floating = GTK_OBJECT_FLOATING (object);
651 g_object_ref (object);
652 gtk_object_sink (object);
655 g_object_ref (object);
656 gtk_container_remove (GTK_CONTAINER (popup->parent), popup);
657 gtk_container_add (GTK_CONTAINER (new_parent), popup);
658 g_object_unref (object);
661 gtk_widget_reparent (GTK_WIDGET (popup), new_parent);
662 gtk_widget_set_usize (new_parent, -1, -1);
665 GTK_OBJECT_SET_FLAGS (object, GTK_FLOATING);
667 g_object_unref (object);
671 * cb_tearable_button_release
676 * Toggle tearoff state.
679 cb_tearable_button_release (GtkWidget *w, GdkEventButton *event,
680 MygalComboBox *combo)
682 GtkTearoffMenuItem *tearable;
684 g_return_val_if_fail (w != NULL, FALSE);
685 g_return_val_if_fail (GTK_IS_TEAROFF_MENU_ITEM (w), FALSE);
687 tearable = GTK_TEAROFF_MENU_ITEM (w);
688 tearable->torn_off = !tearable->torn_off;
690 if (!combo->priv->torn_off) {
691 gboolean need_connect;
693 need_connect = (!combo->priv->tearoff_window);
694 mygal_combo_set_tearoff_state (combo, TRUE);
696 g_signal_connect (combo->priv->tearoff_window,
698 G_CALLBACK (cb_popup_delete),
701 mygal_combo_box_popup_hide_unconditional (combo);
707 cb_popup_delete (GtkWidget *w, GdkEventAny *event, MygalComboBox *combo)
709 mygal_combo_box_popup_hide_unconditional (combo);
714 mygal_combo_box_construct (MygalComboBox *combo_box, GtkWidget *display_widget, GtkWidget *pop_down_widget)
719 g_return_if_fail (combo_box != NULL);
720 g_return_if_fail (MYGAL_IS_COMBO_BOX (combo_box));
721 g_return_if_fail (display_widget != NULL);
722 g_return_if_fail (GTK_IS_WIDGET (display_widget));
724 GTK_BOX (combo_box)->spacing = 0;
725 GTK_BOX (combo_box)->homogeneous = FALSE;
727 combo_box->priv->pop_down_widget = pop_down_widget;
728 combo_box->priv->display_widget = NULL;
730 vbox = gtk_vbox_new (FALSE, 5);
731 tearable = gtk_tearoff_menu_item_new ();
732 g_signal_connect (tearable, "enter-notify-event",
733 G_CALLBACK (cb_tearable_enter_leave),
734 GINT_TO_POINTER (TRUE));
735 g_signal_connect (tearable, "leave-notify-event",
736 G_CALLBACK (cb_tearable_enter_leave),
737 GINT_TO_POINTER (FALSE));
738 g_signal_connect (tearable, "button-release-event",
739 G_CALLBACK (cb_tearable_button_release),
740 (gpointer) combo_box);
741 gtk_box_pack_start (GTK_BOX (vbox), tearable, FALSE, FALSE, 0);
742 gtk_box_pack_start (GTK_BOX (vbox), pop_down_widget, TRUE, TRUE, 0);
743 combo_box->priv->tearable = tearable;
748 mygal_combo_box_set_display (combo_box, display_widget);
750 gtk_container_add (GTK_CONTAINER (combo_box->priv->frame), vbox);
751 gtk_widget_show_all (combo_box->priv->frame);
755 mygal_combo_box_new (GtkWidget *display_widget, GtkWidget *optional_popdown)
757 MygalComboBox *combo_box;
759 g_return_val_if_fail (display_widget != NULL, NULL);
760 g_return_val_if_fail (GTK_IS_WIDGET (display_widget), NULL);
762 combo_box = g_object_new (MYGAL_COMBO_BOX_TYPE, NULL);
763 mygal_combo_box_construct (combo_box, display_widget, optional_popdown);
764 return GTK_WIDGET (combo_box);
768 mygal_combo_box_set_arrow_relief (MygalComboBox *cc, GtkReliefStyle relief)
770 g_return_if_fail (cc != NULL);
771 g_return_if_fail (MYGAL_IS_COMBO_BOX (cc));
773 gtk_button_set_relief (GTK_BUTTON (cc->priv->arrow_button), relief);
777 * mygal_combo_box_set_title
781 * Set a title to display over the tearoff window.
785 * This should really change the title even when the popup is already torn off.
786 * I guess the tearoff window could attach a listener to title change or
787 * something. But I don't think we need the functionality, so I didn't bother
791 mygal_combo_box_set_title (MygalComboBox *combo,
794 g_return_if_fail (combo != NULL);
795 g_return_if_fail (MYGAL_IS_COMBO_BOX (combo));
797 g_object_set_data_full (G_OBJECT (combo), "gtk-combo-title",
798 g_strdup (title), (GDestroyNotify) g_free);
802 * mygal_combo_box_set_arrow_sensitive
804 * @sensitive: Sensitivity value
806 * Toggle the sensitivity of the arrow button
810 mygal_combo_box_set_arrow_sensitive (MygalComboBox *combo,
813 g_return_if_fail (combo != NULL);
815 gtk_widget_set_sensitive (combo->priv->arrow_button, sensitive);
819 * mygal_combo_box_set_tearable:
821 * @tearable: whether to allow the @combo to be tearable
823 * controls whether the combo box's pop up widget can be torn off.
826 mygal_combo_box_set_tearable (MygalComboBox *combo, gboolean tearable)
828 g_return_if_fail (combo != NULL);
829 g_return_if_fail (MYGAL_IS_COMBO_BOX (combo));
832 gtk_widget_show (combo->priv->tearable);
834 mygal_combo_set_tearoff_state (combo, FALSE);
835 gtk_widget_hide (combo->priv->tearable);