[George <jirka 5z com>] Default behaviour patch
- From: Owen Taylor <otaylor redhat com>
- To: gtk-devel-list redhat com
- Subject: [George <jirka@5z.com>] Default behaviour patch
- Date: 19 Jan 1999 16:13:05 -0500
[ George had trouble getting this to this list, so I'm
forwarding it for him ]
------- Start of forwarded message -------
Message-ID: <19990118184948.E408@julia.linux.bogus>
Date: Mon, 18 Jan 1999 18:49:48 -0800
From: George <jirka@5z.com>
To: gtk-devel-list@redhat.com, gnome-hackers@gnome.org
Cc: nat@nat.org
Subject: Default behaviour patch
--s/l3CgOIzMHHjg/5
Content-Type: text/plain; charset=us-ascii
Here is the patch to emulate motif behaviour with respect to default
button handeling it adds a widget flag RECEIVE_DEFAULT which marks
widgets that will take default when they are focused (currently
gtkbutton and gtktogglebutton are set up like that) ... also drawing
of the default frame is now conditional to if there is a RECEIVE_DEFAULT
widget focused or not, and if it CAN_DEFAULT then the frame is
drawn around the focused RECEIVE_DEFAULT widget
also this makes the gnome-dialog patch obscolete
George
--
------------------------------------------------------------------------------
George Lebl <jirka@5z.com> http://www.5z.com/jirka/
------------------------------------------------------------------------------
The following implements RSA in perl and is illegal to export from the US:
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)
--s/l3CgOIzMHHjg/5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="def.patch"
? allocation.y
Index: gtkbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkbutton.c,v
retrieving revision 1.37
diff -u -r1.37 gtkbutton.c
--- gtkbutton.c 1999/01/14 06:04:32 1.37
+++ gtkbutton.c 1999/01/19 02:44:10
@@ -17,6 +17,7 @@
* Boston, MA 02111-1307, USA.
*/
#include <string.h>
+#include "gtkwindow.h"
#include "gtkbutton.h"
#include "gtklabel.h"
#include "gtkmain.h"
@@ -205,7 +206,7 @@
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;
@@ -524,6 +525,7 @@
{
GtkButton *button;
GtkShadowType shadow_type;
+ GtkWindow *toplevel;
gint width, height;
gint x, y;
@@ -539,8 +541,17 @@
gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height);
- if (GTK_WIDGET_HAS_DEFAULT (widget) &&
- GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL)
+ /* get the toplevel to see if we should really draw the default border */
+ toplevel = GTK_WINDOW (gtk_widget_get_toplevel (widget));
+
+ if ((GTK_WIDGET_HAS_DEFAULT (widget) &&
+ GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL &&
+ (!toplevel->focus_widget ||
+ toplevel->focus_widget == widget ||
+ !GTK_WIDGET_RECEIVES_DEFAULT (toplevel->focus_widget))) ||
+ (GTK_WIDGET_CAN_DEFAULT (widget) &&
+ GTK_WIDGET_HAS_FOCUS (widget) &&
+ GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL))
{
gtk_paint_box (widget->style, widget->window,
GTK_STATE_NORMAL, GTK_SHADOW_IN,
Index: gtkcheckbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcheckbutton.c,v
retrieving revision 1.17
diff -u -r1.17 gtkcheckbutton.c
--- gtkcheckbutton.c 1999/01/15 16:00:13 1.17
+++ gtkcheckbutton.c 1999/01/19 02:44:10
@@ -95,6 +95,7 @@
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;
}
Index: gtkoptionmenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkoptionmenu.c,v
retrieving revision 1.22
diff -u -r1.22 gtkoptionmenu.c
--- gtkoptionmenu.c 1998/12/22 20:55:30 1.22
+++ gtkoptionmenu.c 1999/01/19 02:44:10
@@ -131,7 +131,7 @@
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;
Index: gtkradiobutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkradiobutton.c,v
retrieving revision 1.17
diff -u -r1.17 gtkradiobutton.c
--- gtkradiobutton.c 1999/01/12 15:12:09 1.17
+++ gtkradiobutton.c 1999/01/19 02:44:10
@@ -99,6 +99,7 @@
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);
radio_button->group = g_slist_prepend (NULL, radio_button);
}
Index: gtkwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
retrieving revision 1.135
diff -u -r1.135 gtkwidget.c
--- gtkwidget.c 1999/01/17 23:12:16 1.135
+++ gtkwidget.c 1999/01/19 02:44:10
@@ -107,6 +107,7 @@
ARG_HAS_FOCUS,
ARG_CAN_DEFAULT,
ARG_HAS_DEFAULT,
+ ARG_RECEIVES_DEFAULT,
ARG_COMPOSITE_CHILD,
ARG_STYLE,
ARG_EVENTS,
@@ -276,6 +277,7 @@
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 @@
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);
@@ -939,6 +947,9 @@
break;
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);
Index: gtkwidget.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.h,v
retrieving revision 1.57
diff -u -r1.57 gtkwidget.h
--- gtkwidget.h 1999/01/17 23:12:18 1.57
+++ gtkwidget.h 1999/01/19 02:44:11
@@ -51,7 +51,8 @@
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 @@
#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.
*/
Index: gtkwindow.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwindow.c,v
retrieving revision 1.65
diff -u -r1.65 gtkwindow.c
--- gtkwindow.c 1999/01/11 12:22:51 1.65
+++ gtkwindow.c 1999/01/19 02:44:11
@@ -1033,7 +1033,9 @@
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,10 +1496,11 @@
GtkWidget *focus)
{
GdkEventFocus event;
+ int redraw_default = FALSE;
g_return_if_fail (window != NULL);
g_return_if_fail (GTK_IS_WINDOW (window));
-
+
if (window->focus_widget)
{
event.type = GDK_FOCUS_CHANGE;
@@ -1505,7 +1508,20 @@
event.in = FALSE;
gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
+
+ if ((focus &&
+ GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) !=
+ GTK_WIDGET_RECEIVES_DEFAULT (focus)) ||
+ (focus && window->focus_widget == window->default_widget &&
+ GTK_WIDGET_RECEIVES_DEFAULT (focus)) ||
+ (!focus && GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget)))
+ redraw_default = TRUE;
+
}
+ else if (focus && GTK_WIDGET_RECEIVES_DEFAULT (focus))
+ {
+ redraw_default = TRUE;
+ }
window->focus_widget = focus;
@@ -1517,6 +1533,9 @@
gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
}
+
+ if (redraw_default && window->default_widget)
+ gtk_widget_queue_draw (window->default_widget);
}
static void
--s/l3CgOIzMHHjg/5--
------- End of forwarded message -------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]