another patch for gtkoptionmenu
- From: George <jirka 5z com>
- To: gtk-devel-list redhat com
- Subject: another patch for gtkoptionmenu
- Date: Tue, 25 Jan 2000 15:25:41 -0800
Problem: There is no signal to catch changes occuring to an option menu.
The only way to do it currently is to catch 'activate' signal, and if by any
chance you do gtk_option_menu_set_history you need to properly update the UI
as well.
So this patch adds a 'history_set' signal which is emitted when the current
item changes to something else. This makes it much easier to for example
update the UI on certain dialogs or to catch the changes.
George
Index: gtkoptionmenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkoptionmenu.c,v
retrieving revision 1.27
diff -u -r1.27 gtkoptionmenu.c
--- gtkoptionmenu.c 1999/12/03 20:15:32 1.27
+++ gtkoptionmenu.c 2000/01/25 23:06:49
@@ -39,6 +39,11 @@
#define OPTION_INDICATOR_HEIGHT 8
#define OPTION_INDICATOR_SPACING 2
+/* Signals */
+enum {
+ HISTORY_SET,
+ LAST_SIGNAL
+};
static void gtk_option_menu_class_init (GtkOptionMenuClass *klass);
static void gtk_option_menu_init (GtkOptionMenu *option_menu);
@@ -73,6 +78,7 @@
static GtkButtonClass *parent_class = NULL;
+static guint option_menu_signals[LAST_SIGNAL] = {0};
GtkType
@@ -117,6 +123,16 @@
object_class->destroy = gtk_option_menu_destroy;
+ option_menu_signals[HISTORY_SET] =
+ gtk_signal_new ("history_set",
+ GTK_RUN_FIRST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (GtkOptionMenuClass, history_set),
+ gtk_marshal_NONE__INT,
+ GTK_TYPE_NONE, 1,
+ GTK_TYPE_INT);
+ gtk_object_class_add_signals (object_class, option_menu_signals, LAST_SIGNAL);
+
widget_class->draw = gtk_option_menu_draw;
widget_class->size_request = gtk_option_menu_size_request;
widget_class->size_allocate = gtk_option_menu_size_allocate;
@@ -126,6 +142,8 @@
widget_class->show_all = gtk_option_menu_show_all;
widget_class->hide_all = gtk_option_menu_hide_all;
+ class->history_set = NULL;
+
container_class->child_type = gtk_option_menu_child_type;
}
@@ -540,6 +555,7 @@
gtk_option_menu_update_contents (GtkOptionMenu *option_menu)
{
GtkWidget *child;
+ GtkWidget *active_item;
GtkRequisition child_requisition;
g_return_if_fail (option_menu != NULL);
@@ -548,8 +564,17 @@
if (option_menu->menu)
{
gtk_option_menu_remove_contents (option_menu);
+
+ active_item = gtk_menu_get_active (GTK_MENU (option_menu->menu));
+
+ /* if a new item was selected emit 'history_set' */
+ if (option_menu->menu_item != active_item)
+ gtk_signal_emit (GTK_OBJECT (option_menu),
+ option_menu_signals[HISTORY_SET],
+ gtk_option_menu_get_history (option_menu));
+
+ option_menu->menu_item = active_item;
- option_menu->menu_item = gtk_menu_get_active (GTK_MENU (option_menu->menu));
if (option_menu->menu_item)
{
gtk_widget_ref (option_menu->menu_item);
Index: gtkoptionmenu.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkoptionmenu.h,v
retrieving revision 1.7
diff -u -r1.7 gtkoptionmenu.h
--- gtkoptionmenu.h 1999/12/03 20:15:32 1.7
+++ gtkoptionmenu.h 2000/01/25 23:06:49
@@ -60,7 +60,10 @@
struct _GtkOptionMenuClass
{
- GtkButtonClass parent_class;
+ GtkButtonClass parent_class;
+
+ void (* history_set) (GtkOptionMenu *option_menu,
+ gint index);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]