Re: #52434 - Lock accelerators by default



Hi,

Going to check in this change soon unless there are complaints, it's
been around for a month or so.

Havoc

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.1973
diff -u -u -r1.1973 ChangeLog
--- ChangeLog	2001/05/20 22:48:37	1.1973
+++ ChangeLog	2001/05/20 22:57:17
@@ -1,3 +1,14 @@
+2001-05-07  Havoc Pennington  <hp redhat com>
+
+	* gtk/gtkwidget.c, gtk/gtkprivate.h, gtk/gtkitemfactory.c: Apply
+	Owen's patch for an ACCELS_LOCKED private widget flag, setting
+	that flag by default, and unsetting it in GtkItemFactory
+	(gtk_widget_class_init): Install global setting for whether 
+	to allow accel changing (i.e. if the flag is FALSE, we pretend
+	the locked flag is always set)
+	(gtk_widget_accelerators_locked): return TRUE if accelerators
+	aren't editable according to the user setting
+
 2001-05-11  Havoc Pennington  <hp pobox com>
 	
 	* gdk/x11/gdkmain-x11.c: Improve error messages for X errors and
Index: gtk/gtkwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
retrieving revision 1.217
diff -u -u -r1.217 gtkwidget.c
--- gtk/gtkwidget.c	2001/05/18 22:31:02	1.217
+++ gtk/gtkwidget.c	2001/05/20 22:57:17
@@ -174,10 +174,21 @@
 static gboolean gtk_widget_real_focus_out_event   (GtkWidget     *widget,
 						   GdkEventFocus *event);
 
-static void gtk_widget_style_set		 (GtkWidget	    *widget,
-						  GtkStyle          *previous_style);
-static void gtk_widget_direction_changed	 (GtkWidget	    *widget,
-						  GtkTextDirection   previous_direction);
+static void gtk_widget_style_set               (GtkWidget        *widget,
+						GtkStyle         *previous_style);
+static void gtk_widget_direction_changed       (GtkWidget        *widget,
+						GtkTextDirection  previous_direction);
+static void gtk_widget_real_add_accelerator    (GtkWidget        *widget,
+						guint             accel_signal_id,
+						GtkAccelGroup    *accel_group,
+						guint             accel_key,
+						GdkModifierType   accel_mods,
+						GtkAccelFlags     accel_flags);
+static void gtk_widget_real_remove_accelerator (GtkWidget        *widget,
+						GtkAccelGroup    *accel_group,
+						guint             accel_key,
+						GdkModifierType   accel_mods);
+
 static void gtk_widget_real_grab_focus           (GtkWidget         *focus_widget);
 
 static GdkColormap*  gtk_widget_peek_colormap      (void);
@@ -209,6 +220,10 @@
 static void              gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
 static AtkObject *       gtk_widget_ref_accessible (AtkImplementor *implementor);
 
+static void              gtk_widget_accels_editable_changed (GObject    *object,
+                                                             GParamSpec *pspec);
+
+
 static gpointer         parent_class = NULL;
 static guint            widget_signals[LAST_SIGNAL] = { 0 };
 
@@ -220,6 +235,7 @@
 static guint            composite_child_stack = 0;
 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
 static GParamSpecPool  *style_property_spec_pool = NULL;
+static gboolean         accels_editable = FALSE;
 
 static GQuark quark_property_parser = 0;
 static GQuark quark_aux_info = 0;
@@ -319,8 +335,8 @@
   klass->hierarchy_changed = NULL;
   klass->style_set = gtk_widget_style_set;
   klass->direction_changed = gtk_widget_direction_changed;
-  klass->add_accelerator = (void*) gtk_accel_group_handle_add;
-  klass->remove_accelerator = (void*) gtk_accel_group_handle_remove;
+  klass->add_accelerator = gtk_widget_real_add_accelerator;
+  klass->remove_accelerator = gtk_widget_real_remove_accelerator;
   klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
   klass->grab_focus = gtk_widget_real_grab_focus;
   klass->event = NULL;
@@ -1015,6 +1031,20 @@
 								 _("Whether to draw the focus indicator inside widgets."),
 								 TRUE,
 								 G_PARAM_READABLE));
+  
+  accels_editable = (strcmp (g_get_user_name (), "timj") == 0) ? TRUE : FALSE;
+  
+  gtk_settings_install_property (gtk_settings_get_global (),
+                                 g_param_spec_boolean ("gtk-accelerators-editable",
+                                                       _("Accelerators editable"),
+                                                       _("Allow in-place accelerator editing for widgets that support it"),
+                                                       accels_editable,
+                                                       G_PARAM_READWRITE));
+
+  g_signal_connect_data (G_OBJECT (gtk_settings_get_global ()),
+                         "notify::gtk-accelerators-editable",
+                         G_CALLBACK (gtk_widget_accels_editable_changed),
+                         NULL, NULL, FALSE, FALSE);
 }
 
 static void
@@ -1276,6 +1306,7 @@
 			GTK_PARENT_SENSITIVE |
 			(composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
 			GTK_DOUBLE_BUFFERED);
+  GTK_PRIVATE_SET_FLAG (widget, GTK_ACCELS_LOCKED);
 
   widget->style = gtk_widget_peek_style ();
   gtk_style_ref (widget->style);
@@ -2265,22 +2296,12 @@
      }
 }
 
-static void
-gtk_widget_stop_add_accelerator (GtkWidget *widget)
-{
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-
-  gtk_signal_emit_stop (GTK_OBJECT (widget), widget_signals[ADD_ACCELERATOR]);
-}
 
 static void
-gtk_widget_stop_remove_accelerator (GtkWidget *widget)
+gtk_widget_accels_editable_changed (GObject    *object,
+                                    GParamSpec *pspec)
 {
-  g_return_if_fail (widget != NULL);
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-
-  gtk_signal_emit_stop (GTK_OBJECT (widget), widget_signals[REMOVE_ACCELERATOR]);
+  g_object_get (object, pspec->name, &accels_editable, NULL);
 }
 
 void
@@ -2288,18 +2309,8 @@
 {
   g_return_if_fail (widget != NULL);
   g_return_if_fail (GTK_IS_WIDGET (widget));
-  
-  if (!gtk_widget_accelerators_locked (widget))
-    {
-      gtk_signal_connect (GTK_OBJECT (widget),
-			  "add_accelerator",
-			  GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
-			  NULL);
-      gtk_signal_connect (GTK_OBJECT (widget),
-			  "remove_accelerator",
-			  GTK_SIGNAL_FUNC (gtk_widget_stop_remove_accelerator),
-			  NULL);
-    }
+
+  GTK_PRIVATE_SET_FLAG (widget, GTK_ACCELS_LOCKED);
 }
 
 void
@@ -2307,28 +2318,19 @@
 {
   g_return_if_fail (widget != NULL);
   g_return_if_fail (GTK_IS_WIDGET (widget));
-  
-  if (gtk_widget_accelerators_locked (widget))
-    {
-      gtk_signal_disconnect_by_func (GTK_OBJECT (widget),
-				     GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
-				     NULL);
-      gtk_signal_disconnect_by_func (GTK_OBJECT (widget),
-				     GTK_SIGNAL_FUNC (gtk_widget_stop_remove_accelerator),
-				     NULL);
-    }
+
+  GTK_PRIVATE_UNSET_FLAG (widget, GTK_ACCELS_LOCKED);
 }
 
 gboolean
 gtk_widget_accelerators_locked (GtkWidget *widget)
 {
   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-  
-  return gtk_signal_handler_pending_by_func (GTK_OBJECT (widget),
-					     widget_signals[ADD_ACCELERATOR],
-					     TRUE,
-					     GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
-					     NULL) > 0;
+
+  if (!accels_editable)
+    return TRUE;
+  else
+    return GTK_WIDGET_ACCELS_LOCKED (widget);
 }
 
 void
@@ -3725,6 +3727,44 @@
 }
 
 static void
+gtk_widget_real_add_accelerator (GtkWidget        *widget,
+				 guint             accel_signal_id,
+				 GtkAccelGroup    *accel_group,
+				 guint             accel_key,
+				 GdkModifierType   accel_mods,
+				 GtkAccelFlags     accel_flags)
+{
+  /* We now only stop interactive changing through the menus when an accelerator
+   * is locked.
+   */
+#if 0  
+  if (gtk_widget_accelerators_locked (widget))
+    return;
+#endif  
+
+  gtk_accel_group_handle_add (GTK_OBJECT (widget), accel_signal_id, accel_group,
+			      accel_key, accel_mods, accel_flags);
+}
+
+static void
+gtk_widget_real_remove_accelerator (GtkWidget        *widget,
+				    GtkAccelGroup    *accel_group,
+				    guint             accel_key,
+				    GdkModifierType   accel_mods)
+{
+  /* We now only stop interactive changing through the menus when an accelerator
+   * is locked.
+   */
+#if 0
+  if (gtk_widget_accelerators_locked (widget))
+    return;
+#endif  
+
+  gtk_accel_group_handle_remove (GTK_OBJECT (widget), accel_group,
+				 accel_key, accel_mods);
+}
+
+static void
 gtk_widget_style_set (GtkWidget *widget,
 		      GtkStyle  *previous_style)
 {
@@ -4022,7 +4062,7 @@
  * A convenience function that uses the theme engine and RC file
  * settings for @widget to look up @stock_id and render it to
  * a pixbuf. @stock_id should be a stock icon ID such as
- * #GTK_STOCK_OPEN or #GTK_STOCK_BUTTON_OK. @size should be a size
+ * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
  * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
  * identifies the widget or code doing the rendering, so that
  * theme engines can special-case rendering for that widget or code.
Index: gtk/gtkprivate.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkprivate.h,v
retrieving revision 1.22
diff -u -u -r1.22 gtkprivate.h
--- gtk/gtkprivate.h	2001/03/08 06:14:42	1.22
+++ gtk/gtkprivate.h	2001/05/20 22:57:17
@@ -49,7 +49,8 @@
   PRIVATE_GTK_IN_REPARENT       = 1 <<  6,
   PRIVATE_GTK_DIRECTION_SET     = 1 <<  7,   /* If the reading direction is not DIR_NONE */
   PRIVATE_GTK_DIRECTION_LTR     = 1 <<  8,   /* If the reading direction is DIR_LTR */
-  PRIVATE_GTK_ANCHORED          = 1 <<  9    /* If widget has a GtkWindow ancestor */
+  PRIVATE_GTK_ANCHORED          = 1 <<  9,   /* If widget has a GtkWindow ancestor */
+  PRIVATE_GTK_ACCELS_LOCKED     = 1 <<  10   /* If accelerators are locked in widget */
 } GtkPrivateFlags;
 
 /* Macros for extracting a widgets private_flags from GtkWidget.
@@ -64,6 +65,7 @@
 #define GTK_WIDGET_DIRECTION_SET(obj)	  ((GTK_PRIVATE_FLAGS (obj) & PRIVATE_GTK_DIRECTION_SET) != 0)
 #define GTK_WIDGET_DIRECTION_LTR(obj)     ((GTK_PRIVATE_FLAGS (obj) & PRIVATE_GTK_DIRECTION_LTR) != 0)
 #define GTK_WIDGET_ANCHORED(obj)          ((GTK_PRIVATE_FLAGS (obj) & PRIVATE_GTK_ANCHORED) != 0)
+#define GTK_WIDGET_ACCELS_LOCKED(obj)     ((GTK_PRIVATE_FLAGS (obj) & PRIVATE_GTK_ACCELS_LOCKED) != 0)
 
 /* Macros for setting and clearing private widget flags.
  * we use a preprocessor string concatenation here for a clear
Index: gtk/gtkitemfactory.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkitemfactory.c,v
retrieving revision 1.39
diff -u -u -r1.39 gtkitemfactory.c
--- gtk/gtkitemfactory.c	2001/05/18 17:35:20	1.39
+++ gtk/gtkitemfactory.c	2001/05/20 22:57:17
@@ -1221,6 +1221,7 @@
 						    type_id != quark_type_title),
 			   "GtkWidget::parent", parent,
 			   NULL);
+  gtk_widget_unlock_accelerators (widget);
   if (option_menu && !option_menu->menu_item)
     gtk_option_menu_set_history (option_menu, 0);
 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]