]> git.street.me.uk Git - andy/viking.git/commitdiff
Add Gtk+ utility functions from Geany 1.24.1
authorRob Norris <rw_norris@hotmail.com>
Sun, 20 Jul 2014 09:46:28 +0000 (10:46 +0100)
committerRob Norris <rw_norris@hotmail.com>
Sun, 3 Aug 2014 23:43:21 +0000 (00:43 +0100)
Primarily for use with toolbar code, but of course may be used elsewhere.

src/ui_util.c
src/ui_util.h
src/viktrwlayer.c
src/vikwebtool.c

index 0f67f866d65ef474017b54562d55860aa7f428f2..13e9764dfc682f48e4fa19b556d70bbd8b5fe494 100644 (file)
@@ -94,3 +94,77 @@ void new_email(GtkWindow *parent, const gchar * address)
   g_free(uri);
   uri = NULL;
 }
+
+/** Creates a @c GtkButton with custom text and a stock image similar to
+ * @c gtk_button_new_from_stock().
+ * @param stock_id A @c GTK_STOCK_NAME string.
+ * @param text Button label text, can include mnemonics.
+ * @return The new @c GtkButton.
+ */
+GtkWidget *ui_button_new_with_image(const gchar *stock_id, const gchar *text)
+{
+       GtkWidget *image, *button;
+
+       button = gtk_button_new_with_mnemonic(text);
+       gtk_widget_show(button);
+       image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_BUTTON);
+       gtk_button_set_image(GTK_BUTTON(button), image);
+       // note: image is shown by gtk
+       return button;
+}
+
+/** Reads an integer from the GTK default settings registry
+ * (see http://library.gnome.org/devel/gtk/stable/GtkSettings.html).
+ * @param property_name The property to read.
+ * @param default_value The default value in case the value could not be read.
+ * @return The value for the property if it exists, otherwise the @a default_value.
+ */
+gint ui_get_gtk_settings_integer(const gchar *property_name, gint default_value)
+{
+       if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(
+               gtk_settings_get_default())), property_name))
+       {
+               gint value;
+               g_object_get(G_OBJECT(gtk_settings_get_default()), property_name, &value, NULL);
+               return value;
+       }
+       else
+               return default_value;
+}
+
+
+/** Returns a widget from a name in a component, usually created by Glade.
+ * Call it with the toplevel widget in the component (i.e. a window/dialog),
+ * or alternatively any widget in the component, and the name of the widget
+ * you want returned.
+ * @param widget Widget with the @a widget_name property set.
+ * @param widget_name Name to lookup.
+ * @return The widget found.
+ * @see ui_hookup_widget().
+ *
+ */
+GtkWidget *ui_lookup_widget(GtkWidget *widget, const gchar *widget_name)
+{
+       GtkWidget *parent, *found_widget;
+
+       g_return_val_if_fail(widget != NULL, NULL);
+       g_return_val_if_fail(widget_name != NULL, NULL);
+
+       for (;;)
+       {
+               if (GTK_IS_MENU(widget))
+                       parent = gtk_menu_get_attach_widget(GTK_MENU(widget));
+               else
+                       parent = gtk_widget_get_parent(widget);
+               if (parent == NULL)
+                       parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey");
+               if (parent == NULL)
+                       break;
+               widget = parent;
+       }
+
+       found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget), widget_name);
+       if (G_UNLIKELY(found_widget == NULL))
+               g_warning("Widget not found: %s", widget_name);
+       return found_widget;
+}
index c79e704ae9044e69d5575785d4d08542625329e7..1ce64b19c58b51a2ee8d33ec5f43553c4b975a3f 100644 (file)
@@ -3,6 +3,7 @@
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
  * Copyright (C) 2007-2009, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ * Copyright (C) 2014, Rob Norris <rw_norris@hotmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -31,6 +32,10 @@ G_BEGIN_DECLS
 void open_url(GtkWindow *parent, const gchar * url);
 void new_email(GtkWindow *parent, const gchar * address);
 
+GtkWidget *ui_button_new_with_image(const gchar *stock_id, const gchar *text);
+gint ui_get_gtk_settings_integer(const gchar *property_name, gint default_value);
+GtkWidget *ui_lookup_widget(GtkWidget *widget, const gchar *widget_name);
+
 G_END_DECLS
 
 #endif
index 9aa427dfa50c64d97f78334eae107fea417ace41..d0a6ba3fb1714a6febb55e9a1a611056240f2084 100644 (file)
@@ -61,6 +61,7 @@
 #include "datasource_gps.h"
 #include "vikexttool_datasources.h"
 #include "util.h"
+#include "ui_util.h"
 #include "vikutils.h"
 
 #include "vikrouting.h"
index 0c5e051f67d55f124684acc19eda879743b6d405..a6e234e3022f485bb41ae238f538a7b2cf5e4858 100644 (file)
@@ -29,7 +29,7 @@
 
 #include <glib/gi18n.h>
 
-#include "util.h"
+#include "ui_util.h"
 
 static GObjectClass *parent_class;