[gtk+/gtk-3-22] menusectionbox: add support for "text-direction" attribute
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-22] menusectionbox: add support for "text-direction" attribute
- Date: Fri, 14 Oct 2016 14:45:14 +0000 (UTC)
commit 17bcd0d1270314ec131198b896f2d44b05345808
Author: Christian Hergert <chergert redhat com>
Date: Wed Oct 12 13:56:57 2016 -0700
menusectionbox: add support for "text-direction" attribute
This allows the use of a "text-direction" hint set to one of "none", "rtl",
or "ltr" to enforce the text direction of a "horizontal-buttons"
display-hint.
This is useful when a menu has buttons that map to physical space in the
UI and therefore must match the application widgetry.
https://bugzilla.gnome.org/show_bug.cgi?id=772775
gtk/gtkapplicationwindow.c | 3 +++
gtk/gtkmenusectionbox.c | 14 ++++++++++++++
gtk/gtkmenutrackeritem.c | 10 ++++++++++
gtk/gtkmenutrackeritem.h | 2 ++
4 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkapplicationwindow.c b/gtk/gtkapplicationwindow.c
index 59a15b9..3e1e969 100644
--- a/gtk/gtkapplicationwindow.c
+++ b/gtk/gtkapplicationwindow.c
@@ -135,6 +135,9 @@
* - "label": a user-visible string to use as section heading
* - "display-hint": a string used to determine special formatting for the section.
* Possible values include "horizontal-buttons".
+ * - "text-direction": a string used to determine the #GtkTextDirection to use
+ * when "display-hint" is set to "horizontal-buttons". Possible values
+ * include "rtl", "ltr", and "none".
*
* The following attributes are used when constructing submenus:
* - "label": a user-visible string to display
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index 61c761b..b790825 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -483,6 +483,7 @@ gtk_menu_section_box_new_section (GtkMenuTrackerItem *item,
GtkMenuSectionBox *box;
const gchar *label;
const gchar *hint;
+ const gchar *text_direction;
box = g_object_new (GTK_TYPE_MENU_SECTION_BOX, NULL);
box->toplevel = parent->toplevel;
@@ -490,12 +491,25 @@ gtk_menu_section_box_new_section (GtkMenuTrackerItem *item,
label = gtk_menu_tracker_item_get_label (item);
hint = gtk_menu_tracker_item_get_display_hint (item);
+ text_direction = gtk_menu_tracker_item_get_text_direction (item);
if (hint && g_str_equal (hint, "horizontal-buttons"))
{
gtk_orientable_set_orientation (GTK_ORIENTABLE (box->item_box), GTK_ORIENTATION_HORIZONTAL);
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (box->item_box)),
GTK_STYLE_CLASS_LINKED);
box->iconic = TRUE;
+
+ if (text_direction)
+ {
+ GtkTextDirection dir = GTK_TEXT_DIR_NONE;
+
+ if (g_str_equal (text_direction, "rtl"))
+ dir = GTK_TEXT_DIR_RTL;
+ else if (g_str_equal (text_direction, "ltr"))
+ dir = GTK_TEXT_DIR_LTR;
+
+ gtk_widget_set_direction (GTK_WIDGET (box->item_box), dir);
+ }
}
if (label != NULL)
diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c
index 7d89521..ef1b60c 100644
--- a/gtk/gtkmenutrackeritem.c
+++ b/gtk/gtkmenutrackeritem.c
@@ -726,6 +726,16 @@ gtk_menu_tracker_item_get_display_hint (GtkMenuTrackerItem *self)
return display_hint;
}
+const gchar *
+gtk_menu_tracker_item_get_text_direction (GtkMenuTrackerItem *self)
+{
+ const gchar *text_direction = NULL;
+
+ g_menu_item_get_attribute (self->item, "text-direction", "&s", &text_direction);
+
+ return text_direction;
+}
+
GMenuModel *
_gtk_menu_tracker_item_get_link (GtkMenuTrackerItem *self,
const gchar *link_name)
diff --git a/gtk/gtkmenutrackeritem.h b/gtk/gtkmenutrackeritem.h
index 6b4fcb5..2f4f04a 100644
--- a/gtk/gtkmenutrackeritem.h
+++ b/gtk/gtkmenutrackeritem.h
@@ -53,6 +53,8 @@ const gchar * gtk_menu_tracker_item_get_special (GtkMenu
const gchar * gtk_menu_tracker_item_get_display_hint (GtkMenuTrackerItem *self);
+const gchar * gtk_menu_tracker_item_get_text_direction (GtkMenuTrackerItem *self);
+
GtkActionObservable * _gtk_menu_tracker_item_get_observable (GtkMenuTrackerItem *self);
gboolean gtk_menu_tracker_item_get_is_separator (GtkMenuTrackerItem *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]