[gtk+] Add a function to determine the text direction
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Add a function to determine the text direction
- Date: Tue, 10 Dec 2013 22:34:37 +0000 (UTC)
commit 73bd03c9edee9debe6f22d1c79f8351ee126fb30
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 10 16:27:24 2013 -0500
Add a function to determine the text direction
This function can be used in the rare cases where the locale
has to be changed after gtk_init(). Based on a patch
by Jehan <jehan girinstud io>.
https://bugzilla.gnome.org/show_bug.cgi?id=720096
docs/reference/gtk/gtk3-sections.txt | 1 +
gtk/gtkmain.c | 61 +++++++++++++++++++++++++++-------
gtk/gtkmain.h | 7 ++++
3 files changed, 57 insertions(+), 12 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 8a69bad..c4a7345 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -5715,6 +5715,7 @@ gtk_window_group_get_type
<TITLE>General</TITLE>
gtk_disable_setlocale
gtk_get_default_language
+gtk_get_locale_direction
gtk_parse_args
gtk_init
gtk_init_check
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index eba38cc..bbf1370 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -696,18 +696,7 @@ do_post_parse_initialization (int *argc,
if (debug_flags & GTK_DEBUG_UPDATES)
gdk_window_set_debug_updates (TRUE);
- {
- /* Translate to default:RTL if you want your widgets
- * to be RTL, otherwise translate to default:LTR.
- * Do *not* translate it to "predefinito:LTR", if it
- * it isn't default:LTR or default:RTL it will not work
- */
- char *e = _("default:LTR");
- if (strcmp (e, "default:RTL")==0)
- gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
- else if (strcmp (e, "default:LTR"))
- g_warning ("Whoever translated default:LTR did so wrongly.\n");
- }
+ gtk_widget_set_default_direction (gtk_get_locale_direction ());
_gtk_ensure_resources ();
@@ -1114,6 +1103,54 @@ gtk_init_check_abi_check (int *argc, char ***argv, int num_checks, size_t sizeof
#endif
/**
+ * gtk_get_locale_direction:
+ *
+ * Get the direction of the current locale. This is the expected
+ * reading direction for text and UI.
+ *
+ * This function depends on the current locale being set with
+ * setlocale() and will default to setting the %GTK_TEXT_DIR_LTR
+ * direction otherwise. %GTK_TEXT_DIR_NONE will never be returned.
+ *
+ * GTK+ sets the default text direction according to the locale
+ * during gtk_init(), and you should normally use
+ * gtk_widget_get_direction() or gtk_widget_get_default_direction()
+ * to obtain the current direcion.
+ *
+ * This function is only needed rare cases when the locale is
+ * changed after GTK+ has already been initialized. In this case,
+ * you can use it to update the default text direction as follows:
+ *
+ * |[
+ * setlocale (LC_ALL, new_locale);
+ * direction = gtk_get_locale_direction ();
+ * gtk_widget_set_default_direction (direction);
+ * ]|
+ *
+ * Returns: the #GtkTextDirection of the current locale
+ *
+ * Since: 3.12
+ */
+GtkTextDirection
+gtk_get_locale_direction (void)
+{
+ gchar *e = _("default:LTR");
+ GtkTextDirection dir = GTK_TEXT_DIR_LTR;
+
+ /* Translate to default:RTL if you want your widgets
+ * to be RTL, otherwise translate to default:LTR.
+ * Do *not* translate it to "predefinito:LTR", if it
+ * it isn't default:LTR or default:RTL it will not work
+ */
+ if (g_strcmp0 (e, "default:RTL") == 0)
+ dir = GTK_TEXT_DIR_RTL;
+ else if (g_strcmp0 (e, "default:LTR") != 0)
+ g_warning ("Whoever translated default:LTR did so wrongly. Defaulting to LTR.\n");
+
+ return dir;
+}
+
+/**
* gtk_get_default_language:
*
* Returns the #PangoLanguage for the default language currently in
diff --git a/gtk/gtkmain.h b/gtk/gtkmain.h
index 75f3fbc..38665a5 100644
--- a/gtk/gtkmain.h
+++ b/gtk/gtkmain.h
@@ -143,9 +143,16 @@ GDK_AVAILABLE_IN_ALL
void gtk_disable_setlocale (void);
GDK_AVAILABLE_IN_ALL
PangoLanguage *gtk_get_default_language (void);
+GDK_AVAILABLE_IN_3_12
+GtkTextDirection gtk_get_locale_direction (void);
GDK_AVAILABLE_IN_ALL
gboolean gtk_events_pending (void);
+#ifndef GTK_DISABLE_DEPRECATED
+void gtk_exit (gint error_code);
+gchar * gtk_set_locale (void);
+#endif /* GTK_DISABLE_DEPRECATED */
+
GDK_AVAILABLE_IN_ALL
void gtk_main_do_event (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]