Re: #52434 - Lock accelerators by default
- From: Havoc Pennington <hp redhat com>
- To: Owen Taylor <otaylor redhat com>
- Cc: timj gtk org, gtk-devel-list gtk org
- Subject: Re: #52434 - Lock accelerators by default
- Date: 07 May 2001 14:45:50 -0400
Hi,
So here is the patch slightly modified to add a global
"gtk-accelerators-locked" user preference which controls whether
accelerators are actually unlocked when the program unlocks them.
i.e. if the program says "yes I handle unlocked accelerators" by
calling gtk_widget_unlock_accelerators(), then the user setting comes
into effect and determines whether the accelerators can actually be
edited.
Havoc
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.1941
diff -u -u -r1.1941 ChangeLog
--- ChangeLog 2001/05/07 15:58:24 1.1941
+++ ChangeLog 2001/05/07 18:41:34
@@ -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-04 Havoc Pennington <hp redhat com>
* configure.in: fix some shell typos
Index: docs/reference/gtk/tmpl/gtk-unused.sgml
===================================================================
RCS file: /cvs/gnome/gtk+/docs/reference/gtk/tmpl/gtk-unused.sgml,v
retrieving revision 1.38
diff -u -u -r1.38 gtk-unused.sgml
--- docs/reference/gtk/tmpl/gtk-unused.sgml 2001/05/07 15:58:38 1.38
+++ docs/reference/gtk/tmpl/gtk-unused.sgml 2001/05/07 18:41:34
@@ -1621,3 +1621,19 @@
@window:
@Returns:
+<!-- ##### FUNCTION gtk_window_set_decorations_hint ##### -->
+<para>
+
+</para>
+
+ window:
+ decorations:
+
+<!-- ##### FUNCTION gtk_window_set_functions_hint ##### -->
+<para>
+
+</para>
+
+ window:
+ functions:
+
Index: docs/reference/gtk/tmpl/gtkwindow.sgml
===================================================================
RCS file: /cvs/gnome/gtk+/docs/reference/gtk/tmpl/gtkwindow.sgml,v
retrieving revision 1.15
diff -u -u -r1.15 gtkwindow.sgml
--- docs/reference/gtk/tmpl/gtkwindow.sgml 2001/05/07 15:58:39 1.15
+++ docs/reference/gtk/tmpl/gtkwindow.sgml 2001/05/07 18:41:34
@@ -393,15 +393,6 @@
@setting:
-<!-- ##### FUNCTION gtk_window_set_decorations_hint ##### -->
-<para>
-
-</para>
-
- window:
- decorations:
-
-
<!-- ##### FUNCTION gtk_window_set_frame_dimensions ##### -->
<para>
@@ -412,15 +403,6 @@
@top:
@right:
@bottom:
-
-
-<!-- ##### FUNCTION gtk_window_set_functions_hint ##### -->
-<para>
-
-</para>
-
- window:
- functions:
<!-- ##### FUNCTION gtk_window_set_has_frame ##### -->
Index: gtk/gtkitemfactory.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkitemfactory.c,v
retrieving revision 1.38
diff -u -u -r1.38 gtkitemfactory.c
--- gtk/gtkitemfactory.c 2001/04/03 13:17:59 1.38
+++ gtk/gtkitemfactory.c 2001/05/07 18:41:34
@@ -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);
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/07 18:41:34
@@ -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/gtkwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
retrieving revision 1.214
diff -u -u -r1.214 gtkwidget.c
--- gtk/gtkwidget.c 2001/05/03 20:11:07 1.214
+++ gtk/gtkwidget.c 2001/05/07 18:41:34
@@ -173,10 +173,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);
@@ -208,6 +219,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 };
@@ -219,6 +234,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;
@@ -318,8 +334,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;
@@ -1014,6 +1030,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
@@ -1272,6 +1302,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);
@@ -2282,22 +2313,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
@@ -2305,18 +2326,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
@@ -2324,28 +2335,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
@@ -3739,6 +3741,44 @@
GtkTextDirection previous_direction)
{
gtk_widget_queue_resize (widget);
+}
+
+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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]