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.
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.
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.
48 #include "adg-internal.h"
51 #include "adg-gtk-utils.h"
54 #if GTK_CHECK_VERSION(2, 14, 0)
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.
69 gtk_widget_get_window(GtkWidget
*widget
)
71 g_return_val_if_fail (GTK_IS_WIDGET (widget
), NULL
);
73 return widget
->window
;
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:
90 * g_signal_connect(dialog, "response",
91 * G_CALLBACK(adg_gtk_window_hide_here), NULL);
97 adg_gtk_window_hide_here(GtkWindow
*window
)
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:
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);
131 adg_gtk_toggle_button_sensitivize(GtkToggleButton
*toggle_button
,
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.
152 adg_gtk_use_default_icons(const gchar
*dir
)
154 const gchar
**p_file
;
155 const gchar
*files
[] = {
168 for (p_file
= files
; *p_file
!= NULL
; ++p_file
) {
169 path
= adg_find_file(*p_file
, dir
, NULL
);
172 icon
= gdk_pixbuf_new_from_file(path
, NULL
);
175 list
= g_list_append(list
, icon
);
179 gtk_window_set_default_icon_list(list
);