3
* Copyright (c) 2006 Benedikt Meurer <benny@xfce.org>.
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
29
#include <gdk/gdkkeysyms.h>
31
#include "xfce-heading.h"
32
#include "xfce-titled-dialog.h"
36
#define XFCE_TITLED_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XFCE_TYPE_TITLED_DIALOG, XfceTitledDialogPrivate))
40
/* Property identifiers */
49
static void xfce_titled_dialog_class_init (XfceTitledDialogClass *klass);
50
static void xfce_titled_dialog_init (XfceTitledDialog *titled_dialog);
51
static void xfce_titled_dialog_finalize (GObject *object);
52
static void xfce_titled_dialog_get_property (GObject *object,
56
static void xfce_titled_dialog_set_property (GObject *object,
60
static void xfce_titled_dialog_close (GtkDialog *dialog);
61
static void xfce_titled_dialog_update_heading (XfceTitledDialog *titled_dialog);
65
struct _XfceTitledDialogPrivate
73
G_DEFINE_TYPE (XfceTitledDialog, xfce_titled_dialog, GTK_TYPE_DIALOG);
78
xfce_titled_dialog_class_init (XfceTitledDialogClass *klass)
80
GtkDialogClass *gtkdialog_class;
81
GtkBindingSet *binding_set;
82
GObjectClass *gobject_class;
84
/* add our private data to the class */
85
g_type_class_add_private (klass, sizeof (XfceTitledDialogPrivate));
87
gobject_class = G_OBJECT_CLASS (klass);
88
gobject_class->finalize = xfce_titled_dialog_finalize;
89
gobject_class->get_property = xfce_titled_dialog_get_property;
90
gobject_class->set_property = xfce_titled_dialog_set_property;
92
gtkdialog_class = GTK_DIALOG_CLASS (klass);
93
gtkdialog_class->close = xfce_titled_dialog_close;
96
* XfceTitledDialog:subtitle:
98
* The subtitle displayed below the main dialog title.
102
g_object_class_install_property (gobject_class,
104
g_param_spec_string ("subtitle",
110
/* connect additional key bindings to the GtkDialog::close action signal */
111
binding_set = gtk_binding_set_by_class (klass);
112
gtk_binding_entry_add_signal (binding_set, GDK_w, GDK_CONTROL_MASK, "close", 0);
113
gtk_binding_entry_add_signal (binding_set, GDK_W, GDK_CONTROL_MASK, "close", 0);
119
xfce_titled_dialog_init (XfceTitledDialog *titled_dialog)
124
/* connect the private data */
125
titled_dialog->priv = XFCE_TITLED_DIALOG_GET_PRIVATE (titled_dialog);
127
/* remove the main dialog box from the window */
128
g_object_ref (G_OBJECT (GTK_DIALOG (titled_dialog)->vbox));
129
gtk_container_remove (GTK_CONTAINER (titled_dialog), GTK_DIALOG (titled_dialog)->vbox);
131
/* add a new vbox w/o border to the main window */
132
vbox = gtk_vbox_new (FALSE, 0);
133
gtk_container_add (GTK_CONTAINER (titled_dialog), vbox);
134
gtk_widget_show (vbox);
136
/* add the heading to the window */
137
titled_dialog->priv->heading = xfce_heading_new ();
138
gtk_box_pack_start (GTK_BOX (vbox), titled_dialog->priv->heading, FALSE, FALSE, 0);
139
gtk_widget_show (titled_dialog->priv->heading);
141
/* add the separator between header and content */
142
line = gtk_hseparator_new ();
143
gtk_box_pack_start (GTK_BOX (vbox), line, FALSE, FALSE, 0);
144
gtk_widget_show (line);
146
/* add the main dialog box to the new vbox */
147
gtk_box_pack_start (GTK_BOX (vbox), GTK_DIALOG (titled_dialog)->vbox, TRUE, TRUE, 0);
148
g_object_unref (G_OBJECT (GTK_DIALOG (titled_dialog)->vbox));
150
/* make sure to update the heading whenever one of the relevant window properties changes */
151
g_signal_connect (G_OBJECT (titled_dialog), "notify::icon", G_CALLBACK (xfce_titled_dialog_update_heading), NULL);
152
g_signal_connect (G_OBJECT (titled_dialog), "notify::icon-name", G_CALLBACK (xfce_titled_dialog_update_heading), NULL);
153
g_signal_connect (G_OBJECT (titled_dialog), "notify::title", G_CALLBACK (xfce_titled_dialog_update_heading), NULL);
155
/* initially update the heading properties */
156
xfce_titled_dialog_update_heading (titled_dialog);
163
xfce_titled_dialog_finalize (GObject *object)
165
XfceTitledDialog *titled_dialog = XFCE_TITLED_DIALOG (object);
167
/* release the subtitle */
168
g_free (titled_dialog->priv->subtitle);
170
(*G_OBJECT_CLASS (xfce_titled_dialog_parent_class)->finalize) (object);
176
xfce_titled_dialog_get_property (GObject *object,
181
XfceTitledDialog *titled_dialog = XFCE_TITLED_DIALOG (object);
186
g_value_set_string (value, xfce_titled_dialog_get_subtitle (titled_dialog));
190
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
198
xfce_titled_dialog_set_property (GObject *object,
203
XfceTitledDialog *titled_dialog = XFCE_TITLED_DIALOG (object);
208
xfce_titled_dialog_set_subtitle (titled_dialog, g_value_get_string (value));
212
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
220
xfce_titled_dialog_close (GtkDialog *dialog)
224
/* verify that the dialog is realized */
225
if (G_LIKELY (GTK_WIDGET_REALIZED (dialog)))
227
/* send a delete event to the dialog */
228
event = gdk_event_new (GDK_DELETE);
229
event->any.window = g_object_ref (GTK_WIDGET (dialog)->window);
230
event->any.send_event = TRUE;
231
gtk_main_do_event (event);
232
gdk_event_free (event);
239
xfce_titled_dialog_update_heading (XfceTitledDialog *titled_dialog)
241
/* update the heading properties using the window property values */
242
xfce_heading_set_icon (XFCE_HEADING (titled_dialog->priv->heading), gtk_window_get_icon (GTK_WINDOW (titled_dialog)));
243
xfce_heading_set_icon_name (XFCE_HEADING (titled_dialog->priv->heading), gtk_window_get_icon_name (GTK_WINDOW (titled_dialog)));
244
xfce_heading_set_title (XFCE_HEADING (titled_dialog->priv->heading), gtk_window_get_title (GTK_WINDOW (titled_dialog)));
250
* xfce_titled_dialog_new:
252
* Allocates a new #XfceTitledDialog instance.
254
* Return value: the newly allocated #XfceTitledDialog.
259
xfce_titled_dialog_new (void)
261
return g_object_new (XFCE_TYPE_TITLED_DIALOG, NULL);
267
* xfce_titled_dialog_new_with_buttons:
268
* @title : title of the dialog, or %NULL.
269
* @parent : transient parent window of the dialog, or %NULL.
270
* @flags : from #GtkDialogFlags.
271
* @first_button_text : stock ID or text to go in first, or %NULL.
272
* @... : response ID for the first button, then additional buttons, ending with %NULL.
274
* See the documentation of gtk_dialog_new_with_buttons() for details about the
275
* parameters and the returned dialog.
277
* Return value: the newly allocated #XfceTitledDialog.
282
xfce_titled_dialog_new_with_buttons (const gchar *title,
284
GtkDialogFlags flags,
285
const gchar *first_button_text,
288
const gchar *button_text;
293
/* allocate the dialog */
294
dialog = g_object_new (XFCE_TYPE_TITLED_DIALOG,
295
"destroy-with-parent", ((flags & GTK_DIALOG_DESTROY_WITH_PARENT) != 0),
296
"has-separator", ((flags & GTK_DIALOG_NO_SEPARATOR) == 0),
297
"modal", ((flags & GTK_DIALOG_MODAL) != 0),
301
/* set the transient parent (if any) */
302
if (G_LIKELY (parent != NULL))
303
gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
305
/* add all additional buttons */
306
va_start (args, first_button_text);
307
for (button_text = first_button_text; button_text != NULL; )
309
response_id = va_arg (args, gint);
310
gtk_dialog_add_button (GTK_DIALOG (dialog), button_text, response_id);
311
button_text = va_arg (args, const gchar *);
321
* xfce_titled_dialog_get_subtitle:
322
* @titled_dialog : a #XfceTitledDialog.
324
* Returns the subtitle of the @titled_dialog, or %NULL
325
* if no subtitle is displayed in the @titled_dialog.
327
* Return value: the subtitle of @titled_dialog, or %NULL.
331
G_CONST_RETURN gchar*
332
xfce_titled_dialog_get_subtitle (XfceTitledDialog *titled_dialog)
334
g_return_val_if_fail (XFCE_IS_TITLED_DIALOG (titled_dialog), NULL);
335
return titled_dialog->priv->subtitle;
341
* xfce_titled_dialog_set_subtitle:
342
* @titled_dialog : a #XfceTitledDialog.
343
* @subtitle : the new subtitle for the @titled_dialog, or %NULL.
345
* Sets the subtitle displayed by @titled_dialog to @subtitle; if
346
* @subtitle is %NULL no subtitle will be displayed by the @titled_dialog.
351
xfce_titled_dialog_set_subtitle (XfceTitledDialog *titled_dialog,
352
const gchar *subtitle)
354
g_return_if_fail (XFCE_IS_TITLED_DIALOG (titled_dialog));
355
g_return_if_fail (subtitle == NULL || g_utf8_validate (subtitle, -1, NULL));
357
/* release the previous subtitle */
358
g_free (titled_dialog->priv->subtitle);
360
/* activate the new subtitle */
361
titled_dialog->priv->subtitle = g_strdup (subtitle);
363
/* update the subtitle for the heading */
364
xfce_heading_set_subtitle (XFCE_HEADING (titled_dialog->priv->heading), subtitle);
366
/* notify listeners */
367
g_object_notify (G_OBJECT (titled_dialog), "subtitle");