2 * This file is part of hildon-libs
4 * Copyright (C) 2005 Nokia Corporation.
6 * Contact: Luc Pionchon <luc.pionchon@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; either version 2.1 of
11 * the License, or (at your option) 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 * @file hildon-dialoghelp.c
28 * This file provides API for the help dialog with
34 #include "hildon-dialoghelp.h"
36 static guint help_signal = 0;
38 static GdkFilterReturn
39 handle_xevent(GdkXEvent * xevent, GdkEvent * event, gpointer data)
41 XAnyEvent *eventti = xevent;
43 if (eventti->type == ClientMessage) {
44 Atom help_atom, wm_atom;
46 XClientMessageEvent *cm;
51 help_atom = XInternAtom(disp, "_NET_WM_CONTEXT_HELP", True);
52 wm_atom = XInternAtom(disp, "WM_PROTOCOLS", True);
54 if (cm->message_type == wm_atom && cm->data.l[0] == help_atom) {
55 /* XClientMessageEvent *cm = xevent; */
56 g_signal_emit(G_OBJECT(data), help_signal, 0);
59 return GDK_FILTER_REMOVE; /* Event handled, don't process
63 return GDK_FILTER_CONTINUE; /* Event not handled */
67 * gtk_dialog_help_enable:
68 * @dialog: The dialog of which help is to be enabled.
70 * Enables context help button for given dialog. The signal "help" can be
71 * connected to handler by normal gtk methods. Note that this function
72 * has to be called before the dialog is shown.
74 * The "help" signal itself has no other parameters than the dialog where
75 * it is connected to, ie.:
76 * void user_function(GtkDialog *, gpointer user_data);
78 void gtk_dialog_help_enable(GtkDialog * dialog)
90 if (help_signal == 0) {
91 help_signal = g_signal_new("help", GTK_TYPE_DIALOG,
92 G_SIGNAL_ACTION, (guint) - 1, NULL,
93 NULL, g_cclosure_marshal_VOID__VOID,
97 g_return_if_fail(GTK_IS_DIALOG(dialog));
99 gtk_widget_realize(GTK_WIDGET(dialog));
100 window = GTK_WIDGET(dialog)->window;
101 display = gdk_drawable_get_display (window);
103 XGetWMProtocols(GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
106 protocols = (Atom *) malloc ((amount+1) * sizeof (Atom));
107 helpatom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_CONTEXT_HELP");
109 for (i=0; i<amount; i++)
111 protocols[n++] = list[i];
112 if (list[i] == helpatom)
121 protocols[n++] = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_CONTEXT_HELP");
124 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
127 gdk_window_add_filter(window, handle_xevent, dialog);
132 * gtk_dialog_help_disable:
133 * @dialog: The dialog of which help is to be disabled.
136 void gtk_dialog_help_disable(GtkDialog * dialog)
138 GdkWindow *window=NULL;
147 g_return_if_fail(GTK_IS_DIALOG(dialog));
149 gtk_widget_realize(GTK_WIDGET(dialog));
150 window = GTK_WIDGET(dialog)->window;
151 display = gdk_drawable_get_display (window);
153 XGetWMProtocols(GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
156 helpatom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_CONTEXT_HELP");
157 protocols = (Atom *) malloc (amount * sizeof (Atom));
159 for (i=0; i<amount; i++)
161 if (list[i] != helpatom)
163 protocols[n++] = list[i];
168 XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window), protocols, n);
171 gdk_window_add_filter(window, handle_xevent, dialog);