Commit e0cad47a authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen

Add show-popup and hide-popup signals and emit them when the popup is

2005-11-10  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkcombobox.c: Add show-popup and hide-popup signals and
	emit them when the popup is shown or hidden.  (#162531, Tommi
	Komulainen)
parent b94e9ee5
2005-11-10 Matthias Clasen <mclasen@redhat.com> 2005-11-10 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkcombobox.c: Add show-popup and hide-popup signals and
emit them when the popup is shown or hidden. (#162531, Tommi
Komulainen)
* tests/testcombo.c: Add an example of popuplating a combobox
on click.
* gtk/gtktreeview.c (gtk_tree_view_motion_resize_column): Another * gtk/gtktreeview.c (gtk_tree_view_motion_resize_column): Another
erroneous semicolon. erroneous semicolon.
......
2005-11-10 Matthias Clasen <mclasen@redhat.com> 2005-11-10 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkcombobox.c: Add show-popup and hide-popup signals and
emit them when the popup is shown or hidden. (#162531, Tommi
Komulainen)
* tests/testcombo.c: Add an example of popuplating a combobox
on click.
* gtk/gtktreeview.c (gtk_tree_view_motion_resize_column): Another * gtk/gtktreeview.c (gtk_tree_view_motion_resize_column): Another
erroneous semicolon. erroneous semicolon.
......
...@@ -183,6 +183,8 @@ struct _GtkComboBoxPrivate ...@@ -183,6 +183,8 @@ struct _GtkComboBoxPrivate
enum { enum {
CHANGED, CHANGED,
POPUP_SHOW,
POPUP_HIDE,
LAST_SIGNAL LAST_SIGNAL
}; };
...@@ -205,6 +207,7 @@ static guint combo_box_signals[LAST_SIGNAL] = {0,}; ...@@ -205,6 +207,7 @@ static guint combo_box_signals[LAST_SIGNAL] = {0,};
#define SCROLL_TIME 100 #define SCROLL_TIME 100
/* common */ /* common */
static void gtk_combo_box_class_init (GtkComboBoxClass *klass); static void gtk_combo_box_class_init (GtkComboBoxClass *klass);
static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface); static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface);
static void gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface); static void gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface);
...@@ -421,6 +424,11 @@ static void combo_cell_data_func (GtkCellLayout *c ...@@ -421,6 +424,11 @@ static void combo_cell_data_func (GtkCellLayout *c
GtkTreeModel *tree_model, GtkTreeModel *tree_model,
GtkTreeIter *iter, GtkTreeIter *iter,
gpointer data); gpointer data);
static void gtk_combo_box_child_show (GtkWidget *widget,
gpointer user_data);
static void gtk_combo_box_child_hide (GtkWidget *widget,
gpointer user_data);
/* GtkCellEditable method implementations */ /* GtkCellEditable method implementations */
static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable, static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
...@@ -538,6 +546,25 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass) ...@@ -538,6 +546,25 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
g_cclosure_marshal_VOID__VOID, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
combo_box_signals[POPUP_SHOW] =
g_signal_new ("popup-show",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
NULL,
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
combo_box_signals[POPUP_HIDE] =
g_signal_new ("popup-hide",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
NULL,
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/* properties */ /* properties */
/** /**
* GtkComboBox:model: * GtkComboBox:model:
...@@ -1056,6 +1083,8 @@ gtk_combo_box_menu_show (GtkWidget *menu, ...@@ -1056,6 +1083,8 @@ gtk_combo_box_menu_show (GtkWidget *menu,
{ {
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data); GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
gtk_combo_box_child_show (menu, user_data);
combo_box->priv->popup_in_progress = TRUE; combo_box->priv->popup_in_progress = TRUE;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
TRUE); TRUE);
...@@ -1068,6 +1097,8 @@ gtk_combo_box_menu_hide (GtkWidget *menu, ...@@ -1068,6 +1097,8 @@ gtk_combo_box_menu_hide (GtkWidget *menu,
{ {
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data); GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
gtk_combo_box_child_hide(menu,user_data);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo_box->priv->button),
FALSE); FALSE);
} }
...@@ -1143,6 +1174,13 @@ gtk_combo_box_set_popup_widget (GtkComboBox *combo_box, ...@@ -1143,6 +1174,13 @@ gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP); combo_box->priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
g_signal_connect (GTK_WINDOW(combo_box->priv->popup_window),"show",
G_CALLBACK (gtk_combo_box_child_show),
combo_box);
g_signal_connect (GTK_WINDOW(combo_box->priv->popup_window),"hide",
G_CALLBACK (gtk_combo_box_child_hide),
combo_box);
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box)); toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
if (GTK_IS_WINDOW (toplevel)) if (GTK_IS_WINDOW (toplevel))
gtk_window_group_add_window (_gtk_window_get_group (GTK_WINDOW (toplevel)), gtk_window_group_add_window (_gtk_window_get_group (GTK_WINDOW (toplevel)),
...@@ -2084,6 +2122,24 @@ gtk_combo_box_forall (GtkContainer *container, ...@@ -2084,6 +2122,24 @@ gtk_combo_box_forall (GtkContainer *container,
(* callback) (GTK_BIN (container)->child, callback_data); (* callback) (GTK_BIN (container)->child, callback_data);
} }
static void
gtk_combo_box_child_show (GtkWidget *widget,
gpointer user_data)
{
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
g_signal_emit_by_name (combo_box, "popup-show", NULL, NULL);
}
static void
gtk_combo_box_child_hide (GtkWidget *widget,
gpointer user_data)
{
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
g_signal_emit_by_name (combo_box, "popup-hide", NULL, NULL);
}
static gboolean static gboolean
gtk_combo_box_expose_event (GtkWidget *widget, gtk_combo_box_expose_event (GtkWidget *widget,
GdkEventExpose *event) GdkEventExpose *event)
...@@ -3314,6 +3370,19 @@ gtk_combo_box_list_destroy (GtkComboBox *combo_box) ...@@ -3314,6 +3370,19 @@ gtk_combo_box_list_destroy (GtkComboBox *combo_box)
0, 0, NULL, 0, 0, NULL,
gtk_combo_box_list_button_released, gtk_combo_box_list_button_released,
NULL); NULL);
g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
G_SIGNAL_MATCH_DATA,
0, 0, NULL,
gtk_combo_box_child_show,
NULL);
g_signal_handlers_disconnect_matched (combo_box->priv->popup_window,
G_SIGNAL_MATCH_DATA,
0, 0, NULL,
gtk_combo_box_child_hide,
NULL);
if (combo_box->priv->box) if (combo_box->priv->box)
g_signal_handlers_disconnect_matched (combo_box->priv->box, g_signal_handlers_disconnect_matched (combo_box->priv->box,
G_SIGNAL_MATCH_DATA, G_SIGNAL_MATCH_DATA,
......
...@@ -206,6 +206,90 @@ create_tree_blaat (void) ...@@ -206,6 +206,90 @@ create_tree_blaat (void)
return GTK_TREE_MODEL (store); return GTK_TREE_MODEL (store);
} }
static GtkTreeModel *
create_empty_list_blaat (void)
{
GdkPixbuf *pixbuf;
GtkWidget *cellview;
GtkTreeIter iter;
GtkListStore *store;
cellview = gtk_cell_view_new ();
store = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_DIALOG_WARNING,
GTK_ICON_SIZE_BUTTON, NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-dialog-warning",
-1);
gtk_widget_destroy (cellview);
return GTK_TREE_MODEL (store);
}
static void
populate_list_blaat (gpointer data)
{
GtkComboBox *combo_box = GTK_COMBO_BOX (data);
GtkListStore *store;
GdkPixbuf *pixbuf;
GtkWidget *cellview;
GtkTreeIter iter;
store = GTK_LIST_STORE (gtk_combo_box_get_model (combo_box));
gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
if (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter))
return;
cellview = gtk_cell_view_new ();
pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_STOP,
GTK_ICON_SIZE_BUTTON, NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-stop",
-1);
pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_NEW,
GTK_ICON_SIZE_BUTTON, NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-new",
-1);
pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_CLEAR,
GTK_ICON_SIZE_BUTTON, NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-clear",
-1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, NULL,
1, "separator",
-1);
pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_OPEN,
GTK_ICON_SIZE_BUTTON, NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-open",
-1);
gtk_widget_destroy (cellview);
}
static GtkTreeModel * static GtkTreeModel *
create_list_blaat (void) create_list_blaat (void)
{ {
...@@ -998,6 +1082,51 @@ main (int argc, char **argv) ...@@ -998,6 +1082,51 @@ main (int argc, char **argv)
gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0);
/* GtkComboBox dynamic list */
tmp = gtk_frame_new ("GtkComboBox (dynamic list)");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
boom = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (boom), 5);
gtk_container_add (GTK_CONTAINER (tmp), boom);
model = create_empty_list_blaat ();
combobox = gtk_combo_box_new_with_model (model);
g_signal_connect (combobox, "popup-show",
G_CALLBACK (populate_list_blaat), combobox);
gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (combobox), TRUE);
g_object_unref (model);
gtk_container_add (GTK_CONTAINER (boom), combobox);
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
renderer,
FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
"pixbuf", 0,
NULL);
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox),
renderer,
set_sensitive,
NULL, NULL);
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
renderer,
TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
"text", 1,
NULL);
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox),
renderer,
set_sensitive,
NULL, NULL);
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox),
is_separator, NULL, NULL);
gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0);
/* GtkComboBox custom entry */ /* GtkComboBox custom entry */
tmp = gtk_frame_new ("GtkComboBox (custom)"); tmp = gtk_frame_new ("GtkComboBox (custom)");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
...@@ -1162,7 +1291,7 @@ main (int argc, char **argv) ...@@ -1162,7 +1291,7 @@ main (int argc, char **argv)
gtk_container_add (GTK_CONTAINER (tmp), boom); gtk_container_add (GTK_CONTAINER (tmp), boom);
model = create_capital_tree (); model = create_capital_tree ();
combobox = gtk_combo_box_new_with_model (model); combobox = gtk_combo_box_new_with_model (model);
gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (combobox), TRUE); gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (combobox), TRUE);
g_object_unref (model); g_object_unref (model);
gtk_container_add (GTK_CONTAINER (boom), combobox); gtk_container_add (GTK_CONTAINER (boom), combobox);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment