2 * This file is part of hildon-libs
4 * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
11 * the License or any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * SECTION:hildon-dialoghelp
27 * @short_description: A helper which contains a button in a normal dialog to
28 * open a help if required
30 * #HildonDialoghelp is a helper that provides an API for enabling or
31 * disabling a help button in the titlebar area of normal dialogs that
32 * are derived from GtkDialog.
37 #include "hildon-dialoghelp.h"
39 static guint help_signal = 0;
41 static GdkFilterReturn
42 handle_xevent(GdkXEvent * xevent, GdkEvent * event, gpointer dialog)
44 XAnyEvent *eventti = xevent;
46 if (eventti->type == ClientMessage) {
47 Atom help_atom, wm_atom;
49 XClientMessageEvent *cm;
54 help_atom = XInternAtom(disp, "_NET_WM_CONTEXT_HELP", True);
55 wm_atom = XInternAtom(disp, "WM_PROTOCOLS", True);
57 if (cm->message_type == wm_atom && cm->data.l[0] == help_atom) {
58 /* XClientMessageEvent *cm = xevent; */
59 g_signal_emit(G_OBJECT(dialog), help_signal, 0);
62 return GDK_FILTER_REMOVE; /* Event handled, don't process
66 return GDK_FILTER_CONTINUE; /* Event not handled */
70 * gtk_dialog_help_enable:
71 * @dialog: The dialog for which help is to be enabled.
73 * Enables context help button for a given dialog. The signal "help" can be
74 * connected to handler by normal GTK methods. Note that this function
75 * has to be called before the dialog is shown.
77 * The "help" signal itself has no other parameters than the dialog where
78 * it is connected to, ie.:
79 * void user_function(GtkDialog *dialog, gpointer user_data);
81 void gtk_dialog_help_enable(GtkDialog * dialog)
93 /* Create help signal if it didn't exist */
94 if (help_signal == 0) {
95 help_signal = g_signal_new("help", GTK_TYPE_DIALOG,
96 G_SIGNAL_ACTION, (guint) - 1, NULL,
97 NULL, g_cclosure_marshal_VOID__VOID,
101 g_return_if_fail(GTK_IS_DIALOG(dialog));
103 gtk_widget_realize(GTK_WIDGET(dialog));
104 window = GTK_WIDGET(dialog)->window;
105 display = gdk_drawable_get_display (window);
107 /* Create a list of atoms stored in GdkWindow */
108 XGetWMProtocols(GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
111 protocols = (Atom *) malloc ((amount+1) * sizeof (Atom));
112 helpatom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_CONTEXT_HELP");
114 /* Enable the dialoghelp if help_atom is in the atoms' list */
115 for (i=0; i<amount; i++)
117 protocols[n++] = list[i];
118 if (list[i] == helpatom)
125 /* Add the help_atom to the atoms' list if it was not in it */
128 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_CONTEXT_HELP");
131 /* Replace the protocol property of the GdkWindow with the new atoms' list */
132 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
135 /* Add a callback function as event filter */
136 gdk_window_add_filter(window, handle_xevent, dialog);
141 * gtk_dialog_help_disable:
142 * @dialog: The dialog for which help is to be disabled.
144 * Disables context help button for the given dialog.
146 void gtk_dialog_help_disable(GtkDialog * dialog)
148 GdkWindow *window=NULL;
157 g_return_if_fail(GTK_IS_DIALOG(dialog));
159 gtk_widget_realize(GTK_WIDGET(dialog));
160 window = GTK_WIDGET(dialog)->window;
161 display = gdk_drawable_get_display (window);
163 /* Create a list of atoms stored in GdkWindow */
164 XGetWMProtocols(GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
167 helpatom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_CONTEXT_HELP");
168 protocols = (Atom *) malloc (amount * sizeof (Atom));
170 /* Remove the help_atom if it is in the atoms' list */
171 for (i=0; i<amount; i++)
173 if (list[i] != helpatom)
175 protocols[n++] = list[i];
180 /* Replace the protocol property of the GdkWindow with the new atoms' list */
181 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
184 /* Remove the event filter */
185 gdk_window_remove_filter(window, handle_xevent, dialog);