doc: use docbook tags instead of |[ ]|
[adg.git] / src / adg / adg-gtk-utils.c
blob2feb1092e56117ce257d308a39e9dd6f2ac047a8
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012,2013 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 /**
22 * SECTION:adg-gtk-utils
23 * @Section_Id:gtk-utilities
24 * @title: GTK+ utilities
25 * @short_description: Assorted macros and backward compatible fallbacks
27 * Collection of macros and functions that do not fit inside any other topic.
29 * Since: 1.0
30 **/
33 /**
34 * ADG_GTK_MODIFIERS:
36 * A GDK mask of the key/mouse modifiers accepted by the GTK+ widgets
37 * of the ADG library. This means the state of the specified modifiers
38 * is always checked: for example %GDK_CONTROL_MASK and %GDK_SHIFT_MASK
39 * are included, hence keeping %CTRL and %SHIFT pressed is different
40 * from keeping only %SHIFT pressed. %GDK_LOCK_MASK instead is not
41 * considered, so having it enabled or disabled does not make any
42 * difference while monitoring the status %SHIFT or %CTRL.
44 * Since: 1.0
45 **/
48 #include "adg-internal.h"
49 #include <gtk/gtk.h>
51 #include "adg-gtk-utils.h"
54 #if GTK_CHECK_VERSION(2, 14, 0)
55 #else
57 /**
58 * gtk_widget_get_window:
59 * @widget: a #GtkWidget
61 * Returns the widget's window if it is realized, %NULL otherwise.
62 * This is an API fallback for GTK+ prior to 2.14.
64 * Return value: @widget's window.
66 * Since: 1.0
67 **/
68 GdkWindow *
69 gtk_widget_get_window(GtkWidget *widget)
71 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
73 return widget->window;
76 #endif
78 /**
79 * adg_gtk_window_hide_here:
80 * @window: a #GtkWindow
82 * A convenient function that hides @window and tries to store the
83 * current position. Any subsequent call to gtk_widget_show() will
84 * hopefully reopen the window at the same position.
86 * It can be used instead of gtk_widget_hide() or by connecting it
87 * to a #GtkDialog::response signal, for instance:
89 * <informalexample><programlisting language="C">
90 * g_signal_connect(dialog, "response",
91 * G_CALLBACK(adg_gtk_window_hide_here), NULL);
92 * </programlisting></informalexample>
94 * Since: 1.0
95 **/
96 void
97 adg_gtk_window_hide_here(GtkWindow *window)
99 gint x, y;
101 g_return_if_fail(GTK_IS_WINDOW(window));
103 gtk_window_get_position(window, &x, &y);
104 gtk_widget_hide((GtkWidget *) window);
105 gtk_window_set_position(window, GTK_WIN_POS_NONE);
106 gtk_window_move(window, x, y);
110 * adg_gtk_toggle_button_sensitivize:
111 * @toggle_button: a #GtkToggleButton
112 * @widget: the #GtkWidget
114 * Assigns the value of the #GtkToggleButton:active property of
115 * @toggle_button to the #GtkWidget:sensitive property of @widget.
116 * Useful to set or reset the sensitiveness of @widget depending
117 * of the state of a check button, for example:
119 * <informalexample><programlisting language="C">
120 * g_signal_connect(toggle_button, "toggled",
121 * G_CALLBACK(adg_gtk_toggle_button_sensitivize), widget1);
122 * g_signal_connect(toggle_button, "toggled",
123 * G_CALLBACK(adg_gtk_toggle_button_sensitivize), widget2);
124 * g_signal_connect(toggle_button, "toggled",
125 * G_CALLBACK(adg_gtk_toggle_button_sensitivize), widget3);
126 * </programlisting></informalexample>
128 * Since: 1.0
130 void
131 adg_gtk_toggle_button_sensitivize(GtkToggleButton *toggle_button,
132 GtkWidget *widget)
134 gboolean is_active;
136 g_return_if_fail(GTK_IS_TOGGLE_BUTTON(toggle_button));
137 g_return_if_fail(GTK_IS_WIDGET(widget));
139 is_active = gtk_toggle_button_get_active(toggle_button);
140 gtk_widget_set_sensitive(widget, is_active);
144 * adg_gtk_use_default_icons:
145 * @dir: the directory where the icons should be installed
147 * Sets the default icon list of every #GtkWindow to a hand-coded
148 * list of ADG icons. Check gtk gtk_window_set_default_icon_list()
149 * for further details.
151 void
152 adg_gtk_use_default_icons(const gchar *dir)
154 const gchar **p_file;
155 const gchar *files[] = {
156 "adg-16.png",
157 "adg-32.png",
158 "adg-48.png",
159 "adg-64.png",
160 "adg-128.png",
161 NULL
163 GList *list;
164 gchar *path;
165 GdkPixbuf *icon;
167 list = NULL;
168 for (p_file = files; *p_file != NULL; ++p_file) {
169 path = adg_find_file(*p_file, dir, NULL);
170 if (path == NULL)
171 continue;
172 icon = gdk_pixbuf_new_from_file(path, NULL);
173 g_free(path);
174 if (icon != NULL)
175 list = g_list_append(list, icon);
178 if (list != NULL) {
179 gtk_window_set_default_icon_list(list);
180 g_list_free(list);