1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
|
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimphelpui.c
* Copyright (C) 2000-2003 Michael Natterer <mitch@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "gimpwidgetstypes.h"
#include "gimpdialog.h"
#include "gimphelpui.h"
#include "gimpwidgets-private.h"
typedef enum
{
GIMP_WIDGET_HELP_TYPE_HELP = 0xff
} GimpWidgetHelpType;
/* local function prototypes */
static const gchar * gimp_help_get_help_data (GtkWidget *widget,
GtkWidget **help_widget,
gpointer *ret_data);
static gboolean gimp_help_callback (GtkWidget *widget,
GimpWidgetHelpType help_type,
GimpHelpFunc help_func);
static gboolean gimp_context_help_idle_start (gpointer widget);
static gboolean gimp_context_help_button_press (GtkWidget *widget,
GdkEventButton *bevent,
gpointer data);
static gboolean gimp_context_help_idle_show_help (gpointer data);
/* local variables */
static GtkTooltips *tool_tips = NULL;
/* public functions */
/**
* _gimp_help_init:
*
* This function initializes GIMP's help system.
*
* Currently it only creates a #GtkTooltips object with gtk_tooltips_new()
* which will be used by gimp_help_set_help_data().
*
* Nota that this function is called automatically by gimp_widgets_init().
**/
void
_gimp_help_init (void)
{
if (tool_tips)
{
g_warning ("_gimp_help_init() must only be called once!");
return;
}
tool_tips = gtk_tooltips_new ();
/* take ownership of the tooltips */
g_object_ref (tool_tips);
gtk_object_sink (GTK_OBJECT (tool_tips));
}
/**
* gimp_help_enable_tooltips:
*
* This function calls gtk_tooltips_enable().
**/
void
gimp_help_enable_tooltips (void)
{
gtk_tooltips_enable (tool_tips);
}
/**
* gimp_help_disable_tooltips:
*
* This function calls gtk_tooltips_disable().
**/
void
gimp_help_disable_tooltips (void)
{
gtk_tooltips_disable (tool_tips);
}
/**
* gimp_standard_help_func:
* @help_id: A unique help identifier.
* @help_data: The @help_data passed to gimp_help_connect().
*
* This is the standard GIMP help function which does nothing but calling
* gimp_help(). It is the right function to use in almost all cases.
**/
void
gimp_standard_help_func (const gchar *help_id,
gpointer help_data)
{
if (! _gimp_standard_help_func)
{
g_warning ("%s: you must call gimp_widgets_init() before using "
"the help system", G_STRFUNC);
return;
}
(* _gimp_standard_help_func) (help_id, help_data);
}
/**
* gimp_help_connect:
* @widget: The widget you want to connect the help accelerator for. Will
* be a #GtkWindow in most cases.
* @help_func: The function which will be called if the user presses "F1".
* @help_id: The @help_id which will be passed to @help_func.
* @help_data: The @help_data pointer which will be passed to @help_func.
*
* Note that this function is automatically called by all libgimp dialog
* constructors. You only have to call it for windows/dialogs you created
* "manually".
**/
void
gimp_help_connect (GtkWidget *widget,
GimpHelpFunc help_func,
const gchar *help_id,
gpointer help_data)
{
static gboolean initialized = FALSE;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (help_func != NULL);
/* set up the help signals
*/
if (! initialized)
{
GtkBindingSet *binding_set;
binding_set =
gtk_binding_set_by_class (g_type_class_peek (GTK_TYPE_WIDGET));
gtk_binding_entry_add_signal (binding_set, GDK_F1, 0,
"show_help", 1,
GTK_TYPE_WIDGET_HELP_TYPE,
GIMP_WIDGET_HELP_TYPE_HELP);
gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, 0,
"show_help", 1,
GTK_TYPE_WIDGET_HELP_TYPE,
GIMP_WIDGET_HELP_TYPE_HELP);
initialized = TRUE;
}
gimp_help_set_help_data (widget, NULL, help_id);
g_object_set_data (G_OBJECT (widget), "gimp-help-data", help_data);
g_signal_connect (widget, "show_help",
G_CALLBACK (gimp_help_callback),
help_func);
gtk_widget_add_events (widget, GDK_BUTTON_PRESS_MASK);
}
/**
* gimp_help_set_help_data:
* @widget: The #GtkWidget you want to set a @tooltip and/or @help_id for.
* @tooltip: The text for this widget's tooltip (or %NULL).
* @help_id: The @help_id for the #GtkTipsQuery tooltips inspector.
*
* The reason why we don't use gtk_tooltips_set_tip() is that it's
* impossible to set a @private_tip (aka @help_id) without a visible
* @tooltip.
*
* This function can be called with #NULL for @tooltip. Use this feature
* if you want to set a help link for a widget which shouldn't have
* a visible tooltip.
**/
void
gimp_help_set_help_data (GtkWidget *widget,
const gchar *tooltip,
const gchar *help_id)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
if (tooltip)
gtk_tooltips_set_tip (tool_tips, widget, tooltip, help_id);
else
g_object_set_qdata (G_OBJECT (widget), GIMP_HELP_ID, (gpointer) help_id);
}
/**
* gimp_context_help:
* @widget: Any #GtkWidget on the screen.
*
* This function invokes the context help inspector.
*
* The mouse cursor will turn turn into a question mark and the user can
* click on any widget of the application which started the inspector.
*
* If the widget the user clicked on has a @help_id string attached
* (see gimp_help_set_help_data()), the corresponding help page will
* be displayed. Otherwise the help system will ascend the widget hierarchy
* until it finds an attached @help_id string (which should be the
* case at least for every window/dialog).
**/
void
gimp_context_help (GtkWidget *widget)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
gimp_help_callback (widget, GTK_WIDGET_HELP_WHATS_THIS, NULL);
}
/**
* gimp_help_id_quark:
*
* This function returns the #GQuark which should be used as key when
* attaching help IDs to widgets and objects.
*
* Return value: The #GQuark.
*
* Since: GIMP 2.2
**/
GQuark
gimp_help_id_quark (void)
{
static GQuark quark = 0;
if (! quark)
quark = g_quark_from_static_string ("gimp-help-id");
return quark;
}
/* private functions */
static const gchar *
gimp_help_get_help_data (GtkWidget *widget,
GtkWidget **help_widget,
gpointer *ret_data)
{
GtkTooltipsData *tooltips_data;
gchar *help_id = NULL;
gpointer help_data = NULL;
for (; widget; widget = widget->parent)
{
tooltips_data = gtk_tooltips_data_get (widget);
if (tooltips_data && tooltips_data->tip_private)
help_id = tooltips_data->tip_private;
else
help_id = g_object_get_qdata (G_OBJECT (widget), GIMP_HELP_ID);
help_data = g_object_get_data (G_OBJECT (widget), "gimp-help-data");
if (help_id)
{
if (help_widget)
*help_widget = widget;
if (ret_data)
*ret_data = help_data;
return (const gchar *) help_id;
}
}
if (help_widget)
*help_widget = NULL;
if (ret_data)
*ret_data = NULL;
return NULL;
}
static gboolean
gimp_help_callback (GtkWidget *widget,
GimpWidgetHelpType help_type,
GimpHelpFunc help_func)
{
switch (help_type)
{
case GIMP_WIDGET_HELP_TYPE_HELP:
if (help_func)
{
GtkTooltipsData *tooltips_data;
gchar *help_id = NULL;
gpointer help_data = NULL;
tooltips_data = gtk_tooltips_data_get (widget);
if (tooltips_data && tooltips_data->tip_private)
help_id = tooltips_data->tip_private;
else
help_id = g_object_get_qdata (G_OBJECT (widget), GIMP_HELP_ID);
help_data = g_object_get_data (G_OBJECT (widget), "gimp-help-data");
(* help_func) (help_id, help_data);
}
return TRUE;
case GTK_WIDGET_HELP_WHATS_THIS:
g_idle_add (gimp_context_help_idle_start, widget);
return TRUE;
default:
break;
}
return FALSE;
}
/* Do all the actual context help calls in idle functions and check for
* some widget holding a grab before starting the query because strange
* things happen if (1) the help browser pops up while the query has
* grabbed the pointer or (2) the query grabs the pointer while some
* other part of the gimp has grabbed it (e.g. a tool, eek)
*/
static gboolean
gimp_context_help_idle_start (gpointer widget)
{
if (! gtk_grab_get_current ())
{
GtkWidget *invisible;
GdkCursor *cursor;
GdkGrabStatus status;
invisible = gtk_invisible_new_for_screen (gtk_widget_get_screen (widget));
gtk_widget_show (invisible);
cursor = gdk_cursor_new_for_display (gtk_widget_get_display (invisible),
GDK_QUESTION_ARROW);
status = gdk_pointer_grab (invisible->window, TRUE,
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK,
NULL, cursor,
GDK_CURRENT_TIME);
gdk_cursor_unref (cursor);
if (status != GDK_GRAB_SUCCESS)
{
gtk_widget_destroy (invisible);
return FALSE;
}
gtk_grab_add (invisible);
g_signal_connect (invisible, "button_press_event",
G_CALLBACK (gimp_context_help_button_press),
NULL);
}
return FALSE;
}
static gboolean
gimp_context_help_button_press (GtkWidget *widget,
GdkEventButton *bevent,
gpointer data)
{
GtkWidget *event_widget;
event_widget = gtk_get_event_widget ((GdkEvent *) bevent);
if (event_widget && bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS)
{
gtk_grab_remove (widget);
gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
bevent->time);
gtk_widget_destroy (widget);
if (event_widget != widget)
g_idle_add (gimp_context_help_idle_show_help, event_widget);
}
return TRUE;
}
static gboolean
gimp_context_help_idle_show_help (gpointer data)
{
GtkWidget *help_widget;
const gchar *help_id = NULL;
gpointer help_data = NULL;
help_id = gimp_help_get_help_data (GTK_WIDGET (data), &help_widget,
&help_data);
if (help_id)
gimp_standard_help_func (help_id, help_data);
return FALSE;
}
|