diff options
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkbutton.c | 4 | ||||
-rw-r--r-- | gtk/gtkcheckbutton.c | 1 | ||||
-rw-r--r-- | gtk/gtkoptionmenu.c | 2 | ||||
-rw-r--r-- | gtk/gtkplug.c | 4 | ||||
-rw-r--r-- | gtk/gtkradiobutton.c | 1 | ||||
-rw-r--r-- | gtk/gtkwidget.c | 11 | ||||
-rw-r--r-- | gtk/gtkwidget.h | 4 | ||||
-rw-r--r-- | gtk/gtkwindow.c | 44 |
8 files changed, 63 insertions, 8 deletions
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index 60e6dbf66..8e3593bff 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -205,7 +205,7 @@ gtk_button_class_init (GtkButtonClass *klass) static void gtk_button_init (GtkButton *button) { - GTK_WIDGET_SET_FLAGS (button, GTK_CAN_FOCUS); + GTK_WIDGET_SET_FLAGS (button, GTK_CAN_FOCUS | GTK_RECEIVES_DEFAULT); GTK_WIDGET_UNSET_FLAGS (button, GTK_NO_WINDOW); button->child = NULL; @@ -672,8 +672,6 @@ gtk_button_button_press (GtkWidget *widget, { button = GTK_BUTTON (widget); - if (GTK_WIDGET_CAN_DEFAULT (widget) && (event->button == 1)) - gtk_widget_grab_default (widget); if (!GTK_WIDGET_HAS_FOCUS (widget)) gtk_widget_grab_focus (widget); diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c index 1e69eb56d..429cd25e6 100644 --- a/gtk/gtkcheckbutton.c +++ b/gtk/gtkcheckbutton.c @@ -95,6 +95,7 @@ static void gtk_check_button_init (GtkCheckButton *check_button) { GTK_WIDGET_SET_FLAGS (check_button, GTK_NO_WINDOW); + GTK_WIDGET_UNSET_FLAGS (check_button, GTK_RECEIVES_DEFAULT); GTK_TOGGLE_BUTTON (check_button)->draw_indicator = TRUE; } diff --git a/gtk/gtkoptionmenu.c b/gtk/gtkoptionmenu.c index 025331db4..bf42d863e 100644 --- a/gtk/gtkoptionmenu.c +++ b/gtk/gtkoptionmenu.c @@ -131,7 +131,7 @@ static void gtk_option_menu_init (GtkOptionMenu *option_menu) { GTK_WIDGET_SET_FLAGS (option_menu, GTK_CAN_FOCUS); - GTK_WIDGET_UNSET_FLAGS (option_menu, GTK_CAN_DEFAULT); + GTK_WIDGET_UNSET_FLAGS (option_menu, GTK_CAN_DEFAULT | GTK_RECEIVES_DEFAULT); option_menu->menu = NULL; option_menu->menu_item = NULL; diff --git a/gtk/gtkplug.c b/gtk/gtkplug.c index ba2e90648..3e6a564d2 100644 --- a/gtk/gtkplug.c +++ b/gtk/gtkplug.c @@ -204,7 +204,9 @@ gtk_plug_key_press_event (GtkWidget *widget, break; case GDK_Return: case GDK_KP_Enter: - if (window->default_widget) + if (window->default_widget && + (!window->focus_widget || + !GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget))) { gtk_widget_activate (window->default_widget); return_val = TRUE; diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c index b517214d6..2f2498795 100644 --- a/gtk/gtkradiobutton.c +++ b/gtk/gtkradiobutton.c @@ -99,6 +99,7 @@ static void gtk_radio_button_init (GtkRadioButton *radio_button) { GTK_WIDGET_SET_FLAGS (radio_button, GTK_NO_WINDOW); + GTK_WIDGET_UNSET_FLAGS (radio_button, GTK_RECEIVES_DEFAULT); GTK_TOGGLE_BUTTON (radio_button)->active = TRUE; diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index b73581e95..6bda63275 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -107,6 +107,7 @@ enum { ARG_HAS_FOCUS, ARG_CAN_DEFAULT, ARG_HAS_DEFAULT, + ARG_RECEIVES_DEFAULT, ARG_COMPOSITE_CHILD, ARG_STYLE, ARG_EVENTS, @@ -276,6 +277,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) gtk_object_add_arg_type ("GtkWidget::has_focus", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HAS_FOCUS); gtk_object_add_arg_type ("GtkWidget::can_default", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_CAN_DEFAULT); gtk_object_add_arg_type ("GtkWidget::has_default", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HAS_DEFAULT); + gtk_object_add_arg_type ("GtkWidget::receives_default", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_RECEIVES_DEFAULT); gtk_object_add_arg_type ("GtkWidget::composite_child", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_COMPOSITE_CHILD); gtk_object_add_arg_type ("GtkWidget::style", GTK_TYPE_STYLE, GTK_ARG_READWRITE, ARG_STYLE); gtk_object_add_arg_type ("GtkWidget::events", GTK_TYPE_GDK_EVENT_MASK, GTK_ARG_READWRITE, ARG_EVENTS); @@ -838,6 +840,12 @@ gtk_widget_set_arg (GtkObject *object, if (GTK_VALUE_BOOL (*arg)) gtk_widget_grab_default (widget); break; + case ARG_RECEIVES_DEFAULT: + if (GTK_VALUE_BOOL (*arg)) + GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT); + else + GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT); + break; case ARG_COMPOSITE_CHILD: if (GTK_VALUE_BOOL(*arg)) GTK_WIDGET_SET_FLAGS (widget, GTK_COMPOSITE_CHILD); @@ -940,6 +948,9 @@ gtk_widget_get_arg (GtkObject *object, case ARG_HAS_DEFAULT: GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE); break; + case ARG_RECEIVES_DEFAULT: + GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE); + break; case ARG_COMPOSITE_CHILD: GTK_VALUE_BOOL (*arg) = (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE); break; diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index c2f30d58e..f41442cb4 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -51,7 +51,8 @@ typedef enum GTK_RC_STYLE = 1 << 16, GTK_COMPOSITE_CHILD = 1 << 17, GTK_NO_REPARENT = 1 << 18, - GTK_APP_PAINTABLE = 1 << 19 + GTK_APP_PAINTABLE = 1 << 19, + GTK_RECEIVES_DEFAULT = 1 << 20 } GtkWidgetFlags; /* Macro for casting a pointer to a GtkWidget or GtkWidgetClass pointer. @@ -90,6 +91,7 @@ typedef enum #define GTK_WIDGET_RC_STYLE(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_RC_STYLE) != 0) #define GTK_WIDGET_COMPOSITE_CHILD(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_COMPOSITE_CHILD) != 0) #define GTK_WIDGET_APP_PAINTABLE(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_APP_PAINTABLE) != 0) +#define GTK_WIDGET_RECEIVES_DEFAULT(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_RECEIVES_DEFAULT) != 0) /* Macros for setting and clearing widget flags. */ diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 21b997fcd..cff073879 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -1033,7 +1033,9 @@ gtk_window_key_press_event (GtkWidget *widget, break; case GDK_Return: case GDK_KP_Enter: - if (window->default_widget) + if (window->default_widget && + (!window->focus_widget || + !GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget))) { gtk_widget_activate (window->default_widget); handled = TRUE; @@ -1494,16 +1496,31 @@ gtk_window_real_set_focus (GtkWindow *window, GtkWidget *focus) { GdkEventFocus event; + gboolean def_flags = 0; g_return_if_fail (window != NULL); g_return_if_fail (GTK_IS_WINDOW (window)); - + + if (window->default_widget) + def_flags = GTK_WIDGET_HAS_DEFAULT (window->default_widget); + if (window->focus_widget) { event.type = GDK_FOCUS_CHANGE; event.window = window->focus_widget->window; event.in = FALSE; + if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) && + (window->focus_widget != window->default_widget)) + { + GTK_WIDGET_UNSET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT); + /* if any widget had the default set there should be + a default_widget, but might not so this is a sanity + check */ + if (window->default_widget) + GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT); + } + gtk_widget_event (window->focus_widget, (GdkEvent*) &event); } @@ -1514,9 +1531,32 @@ gtk_window_real_set_focus (GtkWindow *window, event.type = GDK_FOCUS_CHANGE; event.window = window->focus_widget->window; event.in = TRUE; + + if (window->default_widget) + { + if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) && + (window->focus_widget != window->default_widget)) + { + if (GTK_WIDGET_CAN_DEFAULT (window->focus_widget)) + GTK_WIDGET_SET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT); + GTK_WIDGET_UNSET_FLAGS (window->default_widget, GTK_HAS_DEFAULT); + } + else + { + GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT); + } + } gtk_widget_event (window->focus_widget, (GdkEvent*) &event); } + else if (window->default_widget) + { + GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT); + } + + if (window->default_widget && + (def_flags != GTK_WIDGET_FLAGS (window->default_widget))) + gtk_widget_queue_draw (window->default_widget); } static void |