1999-09-28 01:58:10 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2003-03-13 21:08:37 +08:00
|
|
|
* gimpwidgets-utils.c
|
|
|
|
* Copyright (C) 1999-2003 Michael Natterer <mitch@gimp.org>
|
1999-09-28 01:58:10 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
1999-12-29 02:30:01 +08:00
|
|
|
#include "config.h"
|
2000-02-02 09:21:36 +08:00
|
|
|
|
2004-10-25 06:26:11 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2001-02-04 12:51:17 +08:00
|
|
|
#include <string.h>
|
2004-10-25 06:26:11 +08:00
|
|
|
#include <sys/types.h>
|
2005-02-07 09:38:18 +08:00
|
|
|
|
2004-10-25 06:26:11 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2005-02-07 09:38:18 +08:00
|
|
|
#include <glib/gstdio.h>
|
2004-10-25 06:26:11 +08:00
|
|
|
|
2005-03-05 03:13:21 +08:00
|
|
|
#include <glib.h>
|
|
|
|
|
2004-10-25 06:26:11 +08:00
|
|
|
#ifdef G_OS_WIN32
|
2004-10-28 03:02:04 +08:00
|
|
|
#include "libgimpbase/gimpwin32-io.h"
|
2004-10-25 06:26:11 +08:00
|
|
|
#endif
|
2000-02-02 09:21:36 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
#ifdef GDK_WINDOWING_WIN32
|
|
|
|
#include <gdk/gdkwin32.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#endif
|
|
|
|
|
2003-05-29 19:34:30 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2003-06-11 00:44:44 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-05-26 00:04:54 +08:00
|
|
|
#include "widgets-types.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2004-08-26 01:58:52 +08:00
|
|
|
#include "gimperrordialog.h"
|
2001-05-26 00:04:54 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
/**
|
|
|
|
* gimp_menu_position:
|
|
|
|
* @menu: a #GtkMenu widget
|
|
|
|
* @x: pointer to horizontal position
|
|
|
|
* @y: pointer to vertical position
|
|
|
|
*
|
|
|
|
* Positions a #GtkMenu so that it pops up on screen. This function
|
|
|
|
* takes care of the preferred popup direction (taken from the widget
|
|
|
|
* render direction) and it handles multiple monitors representing a
|
|
|
|
* single #GdkScreen (Xinerama).
|
|
|
|
*
|
|
|
|
* You should call this function with @x and @y initialized to the
|
|
|
|
* origin of the menu. This is typically the center of the widget the
|
|
|
|
* menu is popped up from. gimp_menu_position() will then decide if
|
|
|
|
* and how these initial values need to be changed.
|
|
|
|
**/
|
2001-04-21 00:27:44 +08:00
|
|
|
void
|
2003-11-20 02:08:15 +08:00
|
|
|
gimp_menu_position (GtkMenu *menu,
|
|
|
|
gint *x,
|
|
|
|
gint *y)
|
2001-04-21 00:27:44 +08:00
|
|
|
{
|
2003-11-20 02:08:15 +08:00
|
|
|
GtkWidget *widget;
|
2003-09-09 19:35:27 +08:00
|
|
|
GdkScreen *screen;
|
2003-11-20 02:08:15 +08:00
|
|
|
GtkRequisition requisition;
|
|
|
|
GdkRectangle rect;
|
|
|
|
gint monitor;
|
2001-08-05 04:38:54 +08:00
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
g_return_if_fail (GTK_IS_MENU (menu));
|
2001-08-05 04:38:54 +08:00
|
|
|
g_return_if_fail (x != NULL);
|
|
|
|
g_return_if_fail (y != NULL);
|
2001-04-21 00:27:44 +08:00
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
widget = GTK_WIDGET (menu);
|
2001-04-21 00:27:44 +08:00
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
screen = gtk_widget_get_screen (widget);
|
2000-03-29 07:02:05 +08:00
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
monitor = gdk_screen_get_monitor_at_point (screen, *x, *y);
|
|
|
|
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
|
2003-09-09 19:35:27 +08:00
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
gtk_menu_set_screen (menu, screen);
|
2001-04-21 00:27:44 +08:00
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
gtk_widget_size_request (widget, &requisition);
|
2003-09-24 22:23:32 +08:00
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
|
|
|
{
|
|
|
|
*x -= requisition.width;
|
|
|
|
if (*x < rect.x)
|
|
|
|
*x += requisition.width;
|
2003-09-24 22:23:32 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-20 02:08:15 +08:00
|
|
|
if (*x + requisition.width > rect.x + rect.width)
|
|
|
|
*x -= requisition.width;
|
2003-09-24 22:23:32 +08:00
|
|
|
}
|
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
if (*x < rect.x)
|
|
|
|
*x = rect.x;
|
2001-08-05 04:38:54 +08:00
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
if (*y + requisition.height > rect.y + rect.height)
|
|
|
|
*y -= requisition.height;
|
2001-04-21 00:27:44 +08:00
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
if (*y < rect.y)
|
|
|
|
*y = rect.y;
|
2001-08-05 04:38:54 +08:00
|
|
|
}
|
|
|
|
|
2003-09-24 04:27:12 +08:00
|
|
|
/**
|
|
|
|
* gimp_button_menu_position:
|
|
|
|
* @button: a button widget to popup the menu from
|
|
|
|
* @menu: the menu to position
|
|
|
|
* @position: the preferred popup direction for the menu (left or right)
|
|
|
|
* @x: return location for x coordinate
|
|
|
|
* @y: return location for y coordinate
|
|
|
|
*
|
|
|
|
* Utility function to position a menu that pops up from a button.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_button_menu_position (GtkWidget *button,
|
|
|
|
GtkMenu *menu,
|
|
|
|
GtkPositionType position,
|
|
|
|
gint *x,
|
|
|
|
gint *y)
|
|
|
|
{
|
|
|
|
GdkScreen *screen;
|
|
|
|
GtkRequisition menu_requisition;
|
2003-11-20 02:08:15 +08:00
|
|
|
GdkRectangle rect;
|
|
|
|
gint monitor;
|
2003-09-24 04:27:12 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_WIDGET_REALIZED (button));
|
|
|
|
g_return_if_fail (GTK_IS_MENU (menu));
|
|
|
|
g_return_if_fail (x != NULL);
|
|
|
|
g_return_if_fail (y != NULL);
|
|
|
|
|
|
|
|
if (gtk_widget_get_direction (button) == GTK_TEXT_DIR_RTL)
|
|
|
|
{
|
|
|
|
switch (position)
|
|
|
|
{
|
|
|
|
case GTK_POS_LEFT: position = GTK_POS_RIGHT; break;
|
|
|
|
case GTK_POS_RIGHT: position = GTK_POS_LEFT; break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_window_get_origin (button->window, x, y);
|
|
|
|
|
|
|
|
gtk_widget_size_request (GTK_WIDGET (menu), &menu_requisition);
|
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
screen = gtk_widget_get_screen (button);
|
|
|
|
|
|
|
|
monitor = gdk_screen_get_monitor_at_point (screen, *x, *y);
|
|
|
|
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
|
|
|
|
|
|
|
|
gtk_menu_set_screen (menu, screen);
|
|
|
|
|
2003-09-24 04:27:12 +08:00
|
|
|
*x += button->allocation.x;
|
|
|
|
|
|
|
|
switch (position)
|
|
|
|
{
|
|
|
|
case GTK_POS_LEFT:
|
|
|
|
*x -= menu_requisition.width;
|
2003-11-20 02:08:15 +08:00
|
|
|
if (*x < rect.x)
|
2003-09-24 04:27:12 +08:00
|
|
|
*x += menu_requisition.width + button->allocation.width;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_POS_RIGHT:
|
|
|
|
*x += button->allocation.width;
|
2003-11-20 02:08:15 +08:00
|
|
|
if (*x + menu_requisition.width > rect.x + rect.width)
|
2003-09-24 04:27:12 +08:00
|
|
|
*x -= button->allocation.width + menu_requisition.width;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-05-12 16:13:33 +08:00
|
|
|
g_warning ("%s: unhandled position (%d)", G_STRFUNC, position);
|
2003-09-24 04:27:12 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*y += button->allocation.y + button->allocation.height / 2;
|
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
if (*y + menu_requisition.height > rect.y + rect.height)
|
2003-09-24 04:27:12 +08:00
|
|
|
*y -= menu_requisition.height;
|
2003-11-20 02:08:15 +08:00
|
|
|
if (*y < rect.y)
|
|
|
|
*y = rect.y;
|
2003-09-24 04:27:12 +08:00
|
|
|
}
|
|
|
|
|
2002-10-09 23:42:38 +08:00
|
|
|
void
|
|
|
|
gimp_table_attach_stock (GtkTable *table,
|
|
|
|
gint row,
|
2005-09-03 01:22:29 +08:00
|
|
|
const gchar *stock_id,
|
2003-02-06 06:15:39 +08:00
|
|
|
GtkWidget *widget,
|
2003-02-21 08:42:53 +08:00
|
|
|
gint colspan,
|
2005-09-03 01:22:29 +08:00
|
|
|
gboolean left_align)
|
2002-10-09 23:42:38 +08:00
|
|
|
{
|
2003-02-06 06:15:39 +08:00
|
|
|
GtkWidget *image;
|
2002-10-09 23:42:38 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TABLE (table));
|
2005-09-03 01:22:29 +08:00
|
|
|
g_return_if_fail (stock_id != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
2003-02-06 02:23:58 +08:00
|
|
|
|
2005-09-03 01:22:29 +08:00
|
|
|
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (image), 1.0, 0.5);
|
|
|
|
gtk_table_attach (table, image, 0, 1, row, row + 1,
|
2003-02-06 06:15:39 +08:00
|
|
|
GTK_FILL, GTK_FILL, 0, 0);
|
2005-09-03 01:22:29 +08:00
|
|
|
gtk_widget_show (image);
|
2003-09-09 19:35:27 +08:00
|
|
|
|
2005-09-03 01:22:29 +08:00
|
|
|
if (left_align)
|
2003-02-06 06:15:39 +08:00
|
|
|
{
|
2005-09-03 01:22:29 +08:00
|
|
|
GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
|
2002-10-09 23:42:38 +08:00
|
|
|
|
2005-09-03 01:22:29 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
|
2003-02-06 06:15:39 +08:00
|
|
|
gtk_widget_show (widget);
|
2002-10-09 23:42:38 +08:00
|
|
|
|
2005-09-03 01:22:29 +08:00
|
|
|
widget = hbox;
|
2003-02-06 06:15:39 +08:00
|
|
|
}
|
2002-10-09 23:42:38 +08:00
|
|
|
|
2005-09-03 01:22:29 +08:00
|
|
|
gtk_table_attach (table, widget, 1, 1 + colspan, row, row + 1,
|
|
|
|
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (widget);
|
2002-10-09 23:42:38 +08:00
|
|
|
}
|
2002-12-20 00:33:29 +08:00
|
|
|
|
2004-10-12 20:06:50 +08:00
|
|
|
void
|
|
|
|
gimp_enum_radio_frame_add (GtkFrame *frame,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint enum_value)
|
|
|
|
{
|
2004-10-14 21:44:06 +08:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GList *children;
|
|
|
|
GList *list;
|
|
|
|
gint pos;
|
2004-10-12 20:06:50 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_FRAME (frame));
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
vbox = gtk_bin_get_child (GTK_BIN (frame));
|
2004-10-12 20:06:50 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
g_return_if_fail (GTK_IS_VBOX (vbox));
|
2004-10-12 20:06:50 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (vbox));
|
2004-10-12 20:06:50 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
for (list = children, pos = 1;
|
2004-10-12 20:06:50 +08:00
|
|
|
list;
|
2004-10-14 21:44:06 +08:00
|
|
|
list = g_list_next (list), pos++)
|
2004-10-12 20:06:50 +08:00
|
|
|
{
|
2004-10-14 21:44:06 +08:00
|
|
|
if (GTK_IS_RADIO_BUTTON (list->data) &&
|
|
|
|
GPOINTER_TO_INT (g_object_get_data (list->data, "gimp-item-data")) ==
|
2004-10-12 20:06:50 +08:00
|
|
|
enum_value)
|
|
|
|
{
|
2004-10-14 21:44:06 +08:00
|
|
|
GtkWidget *radio = list->data;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *spacer;
|
|
|
|
gint indicator_size;
|
|
|
|
gint indicator_spacing;
|
|
|
|
gint focus_width;
|
|
|
|
gint focus_padding;
|
|
|
|
|
|
|
|
gtk_widget_style_get (radio,
|
|
|
|
"indicator-size", &indicator_size,
|
|
|
|
"indicator-spacing", &indicator_spacing,
|
|
|
|
"focus-line-width", &focus_width,
|
|
|
|
"focus-padding", &focus_padding,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
|
|
|
|
|
|
|
spacer = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_widget_set_size_request (spacer,
|
|
|
|
indicator_size +
|
|
|
|
3 * indicator_spacing +
|
|
|
|
focus_width +
|
|
|
|
focus_padding +
|
|
|
|
GTK_CONTAINER (radio)->border_width,
|
|
|
|
-1);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), spacer, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (spacer);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (widget);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (radio), "set_sensitive", hbox);
|
|
|
|
g_signal_connect (radio, "toggled",
|
2004-10-12 20:06:50 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_sensitive_update),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (hbox,
|
|
|
|
GTK_TOGGLE_BUTTON (list->data)->active);
|
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_box_reorder_child (GTK_BOX (vbox), hbox, pos);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2004-10-12 20:06:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
g_list_free (children);
|
2004-10-12 20:06:50 +08:00
|
|
|
}
|
|
|
|
|
2003-03-13 21:08:37 +08:00
|
|
|
GtkIconSize
|
|
|
|
gimp_get_icon_size (GtkWidget *widget,
|
|
|
|
const gchar *stock_id,
|
|
|
|
GtkIconSize max_size,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
GtkIconSet *icon_set;
|
|
|
|
GtkIconSize *sizes;
|
|
|
|
gint n_sizes;
|
|
|
|
gint i;
|
|
|
|
gint width_diff = 1024;
|
|
|
|
gint height_diff = 1024;
|
|
|
|
gint max_width;
|
|
|
|
gint max_height;
|
|
|
|
GtkIconSize icon_size = GTK_ICON_SIZE_MENU;
|
2003-11-02 04:06:01 +08:00
|
|
|
GtkSettings *settings;
|
2003-03-13 21:08:37 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), icon_size);
|
|
|
|
g_return_val_if_fail (stock_id != NULL, icon_size);
|
|
|
|
g_return_val_if_fail (width > 0, icon_size);
|
|
|
|
g_return_val_if_fail (height > 0, icon_size);
|
|
|
|
|
2003-04-12 05:23:34 +08:00
|
|
|
icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
|
|
|
|
|
|
|
|
if (! icon_set)
|
|
|
|
return GTK_ICON_SIZE_INVALID;
|
|
|
|
|
2005-11-03 04:18:13 +08:00
|
|
|
settings = gtk_widget_get_settings (widget);
|
2003-11-02 04:06:01 +08:00
|
|
|
|
|
|
|
if (! gtk_icon_size_lookup_for_settings (settings, max_size,
|
|
|
|
&max_width, &max_height))
|
2003-03-13 21:08:37 +08:00
|
|
|
{
|
|
|
|
max_width = 1024;
|
|
|
|
max_height = 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_icon_set_get_sizes (icon_set, &sizes, &n_sizes);
|
|
|
|
|
|
|
|
for (i = 0; i < n_sizes; i++)
|
|
|
|
{
|
|
|
|
gint icon_width;
|
|
|
|
gint icon_height;
|
|
|
|
|
2003-11-02 04:06:01 +08:00
|
|
|
if (gtk_icon_size_lookup_for_settings (settings, sizes[i],
|
|
|
|
&icon_width, &icon_height))
|
2003-03-13 21:08:37 +08:00
|
|
|
{
|
|
|
|
if (icon_width <= width &&
|
|
|
|
icon_height <= height &&
|
|
|
|
icon_width <= max_width &&
|
|
|
|
icon_height <= max_height &&
|
|
|
|
((width - icon_width) < width_diff ||
|
|
|
|
(height - icon_height) < height_diff))
|
|
|
|
{
|
|
|
|
width_diff = width - icon_width;
|
|
|
|
height_diff = height - icon_height;
|
|
|
|
|
|
|
|
icon_size = sizes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (sizes);
|
|
|
|
|
|
|
|
return icon_size;
|
|
|
|
}
|
|
|
|
|
2002-12-20 00:33:29 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_get_mod_name_shift (void)
|
|
|
|
{
|
|
|
|
static gchar *mod_name_shift = NULL;
|
|
|
|
|
|
|
|
if (! mod_name_shift)
|
|
|
|
{
|
|
|
|
GtkAccelLabelClass *accel_label_class;
|
|
|
|
|
|
|
|
accel_label_class = g_type_class_ref (GTK_TYPE_ACCEL_LABEL);
|
2005-09-14 06:17:05 +08:00
|
|
|
mod_name_shift = g_strdup (accel_label_class->mod_name_shift);
|
2002-12-20 00:33:29 +08:00
|
|
|
g_type_class_unref (accel_label_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (const gchar *) mod_name_shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
gimp_get_mod_name_control (void)
|
|
|
|
{
|
|
|
|
static gchar *mod_name_control = NULL;
|
|
|
|
|
|
|
|
if (! mod_name_control)
|
|
|
|
{
|
|
|
|
GtkAccelLabelClass *accel_label_class;
|
|
|
|
|
|
|
|
accel_label_class = g_type_class_ref (GTK_TYPE_ACCEL_LABEL);
|
2005-09-14 06:17:05 +08:00
|
|
|
mod_name_control = g_strdup (accel_label_class->mod_name_control);
|
2002-12-20 00:33:29 +08:00
|
|
|
g_type_class_unref (accel_label_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (const gchar *) mod_name_control;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
gimp_get_mod_name_alt (void)
|
|
|
|
{
|
|
|
|
static gchar *mod_name_alt = NULL;
|
|
|
|
|
|
|
|
if (! mod_name_alt)
|
|
|
|
{
|
|
|
|
GtkAccelLabelClass *accel_label_class;
|
|
|
|
|
|
|
|
accel_label_class = g_type_class_ref (GTK_TYPE_ACCEL_LABEL);
|
2005-09-14 06:17:05 +08:00
|
|
|
mod_name_alt = g_strdup (accel_label_class->mod_name_alt);
|
2002-12-20 00:33:29 +08:00
|
|
|
g_type_class_unref (accel_label_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (const gchar *) mod_name_alt;
|
|
|
|
}
|
2003-06-11 00:44:44 +08:00
|
|
|
|
2002-12-20 00:33:29 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_get_mod_separator (void)
|
|
|
|
{
|
|
|
|
static gchar *mod_separator = NULL;
|
|
|
|
|
|
|
|
if (! mod_separator)
|
|
|
|
{
|
|
|
|
GtkAccelLabelClass *accel_label_class;
|
|
|
|
|
|
|
|
accel_label_class = g_type_class_ref (GTK_TYPE_ACCEL_LABEL);
|
|
|
|
mod_separator = g_strdup (accel_label_class->mod_separator);
|
|
|
|
g_type_class_unref (accel_label_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (const gchar *) mod_separator;
|
|
|
|
}
|
2003-05-29 19:34:30 +08:00
|
|
|
|
2004-06-29 07:30:57 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_get_mod_string (GdkModifierType modifiers)
|
|
|
|
{
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
GdkModifierType modifiers;
|
|
|
|
gchar *name;
|
|
|
|
}
|
|
|
|
modifier_strings[] =
|
|
|
|
{
|
|
|
|
{ GDK_SHIFT_MASK, NULL },
|
|
|
|
{ GDK_CONTROL_MASK, NULL },
|
|
|
|
{ GDK_MOD1_MASK, NULL },
|
|
|
|
{ GDK_SHIFT_MASK | GDK_CONTROL_MASK, NULL },
|
|
|
|
{ GDK_SHIFT_MASK | GDK_MOD1_MASK, NULL },
|
|
|
|
{ GDK_CONTROL_MASK | GDK_MOD1_MASK, NULL },
|
|
|
|
{ GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (modifier_strings); i++)
|
|
|
|
{
|
|
|
|
if (modifiers == modifier_strings[i].modifiers)
|
|
|
|
{
|
|
|
|
if (! modifier_strings[i].name)
|
|
|
|
{
|
|
|
|
GString *str = g_string_new ("");
|
|
|
|
|
|
|
|
if (modifiers & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
g_string_append (str, gimp_get_mod_name_shift ());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modifiers & GDK_CONTROL_MASK)
|
|
|
|
{
|
|
|
|
if (str->len)
|
|
|
|
g_string_append (str, gimp_get_mod_separator ());
|
|
|
|
|
|
|
|
g_string_append (str, gimp_get_mod_name_control ());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modifiers & GDK_MOD1_MASK)
|
|
|
|
{
|
|
|
|
if (str->len)
|
|
|
|
g_string_append (str, gimp_get_mod_separator ());
|
|
|
|
|
|
|
|
g_string_append (str, gimp_get_mod_name_alt ());
|
|
|
|
}
|
|
|
|
|
|
|
|
modifier_strings[i].name = g_string_free (str, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return modifier_strings[i].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-21 02:50:20 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_substitute_underscores (gchar *str)
|
|
|
|
{
|
|
|
|
gchar *p;
|
|
|
|
|
|
|
|
for (p = str; *p; p++)
|
|
|
|
if (*p == '_')
|
|
|
|
*p = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
|
|
|
gimp_get_accel_string (guint key,
|
|
|
|
GdkModifierType modifiers)
|
|
|
|
{
|
|
|
|
GtkAccelLabelClass *accel_label_class;
|
|
|
|
GString *gstring;
|
|
|
|
gunichar ch;
|
|
|
|
|
|
|
|
accel_label_class = g_type_class_peek (GTK_TYPE_ACCEL_LABEL);
|
|
|
|
|
|
|
|
gstring = g_string_new (gimp_get_mod_string (modifiers));
|
|
|
|
|
|
|
|
if (gstring->len > 0)
|
|
|
|
g_string_append (gstring, gimp_get_mod_separator ());
|
|
|
|
|
|
|
|
ch = gdk_keyval_to_unicode (key);
|
|
|
|
|
|
|
|
if (ch && (g_unichar_isgraph (ch) || ch == ' ') &&
|
|
|
|
(ch < 0x80 || accel_label_class->latin1_to_char))
|
|
|
|
{
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case ' ':
|
|
|
|
g_string_append (gstring, "Space");
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
g_string_append (gstring, "Backslash");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_string_append_unichar (gstring, g_unichar_toupper (ch));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *tmp;
|
|
|
|
|
|
|
|
tmp = gtk_accelerator_name (key, 0);
|
|
|
|
|
|
|
|
if (tmp[0] != 0 && tmp[1] == 0)
|
|
|
|
tmp[0] = g_ascii_toupper (tmp[0]);
|
|
|
|
|
|
|
|
gimp_substitute_underscores (tmp);
|
|
|
|
g_string_append (gstring, tmp);
|
|
|
|
g_free (tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_string_free (gstring, FALSE);
|
2004-06-29 07:30:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-11 00:44:44 +08:00
|
|
|
/**
|
|
|
|
* gimp_get_screen_resolution:
|
|
|
|
* @screen: a #GdkScreen or %NULL
|
|
|
|
* @xres: returns the horizontal screen resolution (in dpi)
|
|
|
|
* @yres: returns the vertical screen resolution (in dpi)
|
2003-09-09 19:35:27 +08:00
|
|
|
*
|
2003-06-11 00:44:44 +08:00
|
|
|
* Retrieves the screen resolution from GDK. If @screen is %NULL, the
|
|
|
|
* default screen is used.
|
|
|
|
**/
|
2003-05-29 19:34:30 +08:00
|
|
|
void
|
|
|
|
gimp_get_screen_resolution (GdkScreen *screen,
|
|
|
|
gdouble *xres,
|
|
|
|
gdouble *yres)
|
|
|
|
{
|
|
|
|
gint width, height;
|
|
|
|
gint width_mm, height_mm;
|
|
|
|
gdouble x = 0.0;
|
|
|
|
gdouble y = 0.0;
|
|
|
|
|
|
|
|
g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
|
|
|
|
g_return_if_fail (xres != NULL);
|
|
|
|
g_return_if_fail (yres != NULL);
|
|
|
|
|
|
|
|
if (!screen)
|
|
|
|
screen = gdk_screen_get_default ();
|
|
|
|
|
|
|
|
width = gdk_screen_get_width (screen);
|
|
|
|
height = gdk_screen_get_height (screen);
|
|
|
|
|
|
|
|
width_mm = gdk_screen_get_width_mm (screen);
|
|
|
|
height_mm = gdk_screen_get_height_mm (screen);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* From xdpyinfo.c:
|
|
|
|
*
|
|
|
|
* there are 2.54 centimeters to an inch; so there are 25.4 millimeters.
|
|
|
|
*
|
|
|
|
* dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch))
|
|
|
|
* = N pixels / (M inch / 25.4)
|
|
|
|
* = N * 25.4 pixels / M inch
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (width_mm > 0 && height_mm > 0)
|
|
|
|
{
|
|
|
|
x = (width * 25.4) / (gdouble) width_mm;
|
|
|
|
y = (height * 25.4) / (gdouble) height_mm;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x < GIMP_MIN_RESOLUTION || x > GIMP_MAX_RESOLUTION ||
|
|
|
|
y < GIMP_MIN_RESOLUTION || y > GIMP_MAX_RESOLUTION)
|
|
|
|
{
|
|
|
|
g_warning ("GDK returned bogus values for the screen resolution, "
|
|
|
|
"using 75 dpi instead.");
|
|
|
|
|
|
|
|
x = 75.0;
|
|
|
|
y = 75.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* round the value to full integers to give more pleasant results */
|
|
|
|
*xres = ROUND (x);
|
|
|
|
*yres = ROUND (y);
|
|
|
|
}
|
2003-06-11 00:44:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_rgb_get_gdk_color:
|
2003-08-09 03:30:23 +08:00
|
|
|
* @rgb: the source color as #GimpRGB
|
2003-06-11 00:44:44 +08:00
|
|
|
* @gdk_color: pointer to a #GdkColor
|
2003-09-09 19:35:27 +08:00
|
|
|
*
|
2003-06-11 00:44:44 +08:00
|
|
|
* Initializes @gdk_color from a #GimpRGB. This function does not
|
|
|
|
* allocate the color for you. Depending on how you want to use it,
|
|
|
|
* you may have to call gdk_colormap_alloc_color().
|
|
|
|
**/
|
2003-09-09 19:35:27 +08:00
|
|
|
void
|
2003-08-09 03:30:23 +08:00
|
|
|
gimp_rgb_get_gdk_color (const GimpRGB *rgb,
|
2003-06-11 00:44:44 +08:00
|
|
|
GdkColor *gdk_color)
|
|
|
|
{
|
|
|
|
guchar r, g, b;
|
|
|
|
|
2003-08-09 03:30:23 +08:00
|
|
|
g_return_if_fail (rgb != NULL);
|
2003-06-11 00:44:44 +08:00
|
|
|
g_return_if_fail (gdk_color != NULL);
|
2003-09-09 19:35:27 +08:00
|
|
|
|
2003-08-09 03:30:23 +08:00
|
|
|
gimp_rgb_get_uchar (rgb, &r, &g, &b);
|
2003-09-09 19:35:27 +08:00
|
|
|
|
2003-06-11 00:44:44 +08:00
|
|
|
gdk_color->red = (r << 8) | r;
|
|
|
|
gdk_color->green = (g << 8) | g;
|
|
|
|
gdk_color->blue = (b << 8) | b;
|
|
|
|
}
|
2003-10-22 22:31:44 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_rgb_set_gdk_color:
|
|
|
|
* @rgb: a #GimpRGB that is to be set
|
|
|
|
* @gdk_color: pointer to the source #GdkColor
|
|
|
|
*
|
|
|
|
* Initializes @rgb from a #GdkColor. This function does not touch
|
|
|
|
* the alpha value of @rgb.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_rgb_set_gdk_color (GimpRGB *rgb,
|
|
|
|
const GdkColor *gdk_color)
|
|
|
|
{
|
|
|
|
guchar r, g, b;
|
|
|
|
|
|
|
|
g_return_if_fail (rgb != NULL);
|
|
|
|
g_return_if_fail (gdk_color != NULL);
|
|
|
|
|
|
|
|
r = gdk_color->red >> 8;
|
|
|
|
g = gdk_color->green >> 8;
|
|
|
|
b = gdk_color->blue >> 8;
|
|
|
|
|
|
|
|
gimp_rgb_set_uchar (rgb, r, g, b);
|
|
|
|
}
|
2003-11-21 04:36:55 +08:00
|
|
|
|
2004-01-17 07:18:23 +08:00
|
|
|
void
|
|
|
|
gimp_window_set_hint (GtkWindow *window,
|
|
|
|
GimpWindowHint hint)
|
2003-11-21 04:36:55 +08:00
|
|
|
{
|
2004-01-17 07:18:23 +08:00
|
|
|
g_return_if_fail (GTK_IS_WINDOW (window));
|
|
|
|
|
2003-11-21 04:36:55 +08:00
|
|
|
switch (hint)
|
|
|
|
{
|
2004-01-17 07:18:23 +08:00
|
|
|
case GIMP_WINDOW_HINT_NORMAL:
|
|
|
|
gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_NORMAL);
|
|
|
|
break;
|
2003-11-21 04:36:55 +08:00
|
|
|
|
2004-01-17 07:18:23 +08:00
|
|
|
case GIMP_WINDOW_HINT_UTILITY:
|
|
|
|
gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_UTILITY);
|
|
|
|
break;
|
2004-05-04 21:31:57 +08:00
|
|
|
|
|
|
|
case GIMP_WINDOW_HINT_KEEP_ABOVE:
|
|
|
|
gtk_window_set_keep_above (window, TRUE);
|
|
|
|
break;
|
2003-11-21 04:36:55 +08:00
|
|
|
}
|
|
|
|
}
|
2004-08-11 06:21:56 +08:00
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
/**
|
|
|
|
* gimp_window_get_native:
|
|
|
|
* @window: a #GtkWindow
|
|
|
|
*
|
|
|
|
* This function is used to pass a window handle to plug-ins so that
|
|
|
|
* they can set their dialog windows transient to the parent window.
|
|
|
|
*
|
|
|
|
* Return value: a native window handle of the window's #GdkWindow or 0
|
|
|
|
* if the window isn't realized yet
|
|
|
|
*/
|
|
|
|
GdkNativeWindow
|
|
|
|
gimp_window_get_native (GtkWindow *window)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_WINDOW (window), 0);
|
|
|
|
|
|
|
|
#ifdef GDK_NATIVE_WINDOW_POINTER
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning gimp_window_get_native() unimplementable for the target windowing system
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_WIN32
|
|
|
|
if (window && GTK_WIDGET_REALIZED (window))
|
2005-09-26 03:30:55 +08:00
|
|
|
return (GdkNativeWindow)GDK_WINDOW_HWND (GTK_WIDGET (window)->window);
|
2005-09-10 02:07:31 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
if (window && GTK_WIDGET_REALIZED (window))
|
|
|
|
return GDK_WINDOW_XID (GTK_WIDGET (window)->window);
|
|
|
|
#endif
|
|
|
|
|
2005-09-26 03:30:55 +08:00
|
|
|
return (GdkNativeWindow)0;
|
2005-09-10 02:07:31 +08:00
|
|
|
}
|
|
|
|
|
2004-08-11 06:21:56 +08:00
|
|
|
void
|
|
|
|
gimp_dialog_set_sensitive (GtkDialog *dialog,
|
|
|
|
gboolean sensitive)
|
|
|
|
{
|
|
|
|
GList *children;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_DIALOG (dialog));
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (dialog->vbox));
|
|
|
|
|
|
|
|
for (list = children; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
/* skip the last item (the action area) */
|
|
|
|
if (! g_list_next (list))
|
|
|
|
break;
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (list->data, sensitive);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
|
|
if (sensitive)
|
|
|
|
gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_CANCEL, sensitive);
|
|
|
|
|
|
|
|
gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_OK, sensitive);
|
|
|
|
}
|
2004-10-25 06:26:11 +08:00
|
|
|
|
2004-11-04 22:24:32 +08:00
|
|
|
gboolean
|
|
|
|
gimp_text_buffer_load (GtkTextBuffer *buffer,
|
|
|
|
const gchar *filename,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
gchar buf[2048];
|
|
|
|
gint remaining = 0;
|
|
|
|
GtkTextIter iter;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2005-02-07 09:38:18 +08:00
|
|
|
file = g_fopen (filename, "r");
|
2004-11-04 22:24:32 +08:00
|
|
|
|
|
|
|
if (! file)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
|
|
|
g_strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_text_buffer_set_text (buffer, "", 0);
|
|
|
|
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
|
|
|
|
|
|
|
|
while (! feof (file))
|
|
|
|
{
|
|
|
|
const char *leftover;
|
|
|
|
gint count;
|
|
|
|
gint to_read = sizeof (buf) - remaining - 1;
|
|
|
|
|
|
|
|
count = fread (buf + remaining, 1, to_read, file);
|
|
|
|
buf[count + remaining] = '\0';
|
|
|
|
|
|
|
|
g_utf8_validate (buf, count + remaining, &leftover);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, buf, leftover - buf);
|
2005-06-05 01:38:27 +08:00
|
|
|
gtk_text_buffer_get_iter_at_offset (buffer, &iter, -1);
|
2004-11-04 22:24:32 +08:00
|
|
|
|
|
|
|
remaining = (buf + remaining + count) - leftover;
|
|
|
|
g_memmove (buf, leftover, remaining);
|
|
|
|
|
|
|
|
if (remaining > 6 || count < to_read)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remaining)
|
|
|
|
g_message (_("Invalid UTF-8 data in file '%s'."),
|
|
|
|
gimp_filename_to_utf8 (filename));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-10-25 06:26:11 +08:00
|
|
|
gboolean
|
|
|
|
gimp_text_buffer_save (GtkTextBuffer *buffer,
|
|
|
|
const gchar *filename,
|
|
|
|
gboolean selection_only,
|
|
|
|
GError **error)
|
|
|
|
{
|
2004-11-04 22:24:32 +08:00
|
|
|
GtkTextIter start_iter;
|
2004-10-25 06:26:11 +08:00
|
|
|
GtkTextIter end_iter;
|
|
|
|
gint fd;
|
|
|
|
gchar *text_contents;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2005-03-05 05:02:10 +08:00
|
|
|
fd = g_open (filename, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
|
2004-10-25 06:26:11 +08:00
|
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
|
|
|
g_strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selection_only)
|
|
|
|
gtk_text_buffer_get_selection_bounds (buffer, &start_iter, &end_iter);
|
|
|
|
else
|
|
|
|
gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter);
|
|
|
|
|
|
|
|
text_contents = gtk_text_buffer_get_text (buffer,
|
|
|
|
&start_iter, &end_iter, TRUE);
|
|
|
|
|
|
|
|
if (text_contents)
|
|
|
|
{
|
|
|
|
gint text_length = strlen (text_contents);
|
|
|
|
|
|
|
|
if (text_length > 0)
|
|
|
|
{
|
|
|
|
gint bytes_written;
|
|
|
|
|
|
|
|
bytes_written = write (fd, text_contents, text_length);
|
|
|
|
|
|
|
|
if (bytes_written != text_length)
|
|
|
|
{
|
|
|
|
g_free (text_contents);
|
|
|
|
close (fd);
|
|
|
|
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
|
|
|
g_strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (text_contents);
|
|
|
|
}
|
|
|
|
|
|
|
|
close (fd);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-11-24 01:01:51 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_toggle_button_set_visible (GtkToggleButton *toggle,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle));
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
|
|
if (gtk_toggle_button_get_active (toggle))
|
|
|
|
gtk_widget_show (widget);
|
|
|
|
else
|
|
|
|
gtk_widget_hide (widget);
|
|
|
|
}
|
|
|
|
|
2005-01-21 22:58:03 +08:00
|
|
|
#ifdef __GNUC__
|
2005-09-10 02:07:31 +08:00
|
|
|
#warning FIXME: remove this function as soon as we depend on GTK >= 2.8
|
2005-01-21 22:58:03 +08:00
|
|
|
#endif
|
|
|
|
GClosure *
|
|
|
|
gimp_action_get_accel_closure (GtkAction *action)
|
|
|
|
{
|
|
|
|
GtkWidget *menu_item;
|
|
|
|
GClosure *closure = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
|
|
|
|
|
|
|
|
menu_item = gtk_action_create_menu_item (action);
|
|
|
|
|
|
|
|
if (GTK_IS_MENU_ITEM (menu_item) &&
|
|
|
|
GTK_IS_ACCEL_LABEL (GTK_BIN (menu_item)->child))
|
|
|
|
{
|
|
|
|
GtkWidget *accel_label = GTK_BIN (menu_item)->child;
|
|
|
|
|
|
|
|
g_object_get (accel_label, "accel-closure", &closure, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menu_item)
|
|
|
|
gtk_object_sink (GTK_OBJECT (menu_item));
|
|
|
|
|
|
|
|
if (closure)
|
|
|
|
g_closure_unref (closure);
|
|
|
|
|
|
|
|
return closure;
|
|
|
|
}
|
2005-09-16 08:46:21 +08:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_widget_accel_find_func (GtkAccelKey *key,
|
|
|
|
GClosure *closure,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
return (GClosure *) data == closure;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_widget_accel_changed (GtkAccelGroup *accel_group,
|
|
|
|
guint unused1,
|
|
|
|
GdkModifierType unused2,
|
|
|
|
GClosure *accel_closure,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GClosure *widget_closure;
|
|
|
|
|
|
|
|
widget_closure = g_object_get_data (G_OBJECT (widget), "gimp-accel-closure");
|
|
|
|
|
|
|
|
if (accel_closure == widget_closure)
|
|
|
|
{
|
|
|
|
GtkAction *action;
|
|
|
|
GtkAccelKey *accel_key;
|
|
|
|
gchar *orig_tooltip;
|
|
|
|
gchar *tooltip;
|
|
|
|
const gchar *help_id;
|
|
|
|
|
|
|
|
action = g_object_get_data (G_OBJECT (widget), "gimp-accel-action");
|
|
|
|
|
|
|
|
g_object_get (action, "tooltip", &orig_tooltip, NULL);
|
|
|
|
help_id = g_object_get_qdata (G_OBJECT (action), GIMP_HELP_ID);
|
|
|
|
|
|
|
|
accel_key = gtk_accel_group_find (accel_group,
|
|
|
|
gimp_widget_accel_find_func,
|
|
|
|
accel_closure);
|
|
|
|
|
|
|
|
if (accel_key &&
|
|
|
|
accel_key->accel_key &&
|
|
|
|
accel_key->accel_flags & GTK_ACCEL_VISIBLE)
|
|
|
|
{
|
2005-10-31 19:29:01 +08:00
|
|
|
gchar *tmp = gimp_get_accel_string (accel_key->accel_key,
|
|
|
|
accel_key->accel_mods);
|
|
|
|
|
|
|
|
tooltip = g_strconcat (orig_tooltip, " ", tmp, NULL);
|
|
|
|
|
|
|
|
g_free (tmp);
|
2005-09-16 08:46:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tooltip = g_strdup (orig_tooltip);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_help_set_help_data (widget, tooltip, help_id);
|
|
|
|
|
|
|
|
g_free (tooltip);
|
|
|
|
g_free (orig_tooltip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_widget_set_accel_help (GtkWidget *widget,
|
|
|
|
GtkAction *action)
|
|
|
|
{
|
|
|
|
GClosure *accel_closure = NULL;
|
|
|
|
|
|
|
|
accel_closure = gimp_action_get_accel_closure (action);
|
|
|
|
|
|
|
|
if (accel_closure)
|
|
|
|
{
|
|
|
|
GtkAccelGroup *accel_group;
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (widget), "gimp-accel-closure",
|
|
|
|
accel_closure);
|
|
|
|
g_object_set_data (G_OBJECT (widget), "gimp-accel-action",
|
|
|
|
action);
|
|
|
|
|
|
|
|
accel_group = gtk_accel_group_from_accel_closure (accel_closure);
|
|
|
|
|
|
|
|
g_signal_connect_object (accel_group, "accel-changed",
|
|
|
|
G_CALLBACK (gimp_widget_accel_changed),
|
|
|
|
widget, 0);
|
|
|
|
|
|
|
|
gimp_widget_accel_changed (accel_group,
|
|
|
|
0, 0,
|
|
|
|
accel_closure,
|
|
|
|
widget);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *tooltip;
|
|
|
|
gchar *help_id;
|
|
|
|
|
|
|
|
g_object_get (action, "tooltip", &tooltip, NULL);
|
2005-10-31 02:41:18 +08:00
|
|
|
help_id = g_object_get_qdata (G_OBJECT (action), GIMP_HELP_ID);
|
2005-09-16 08:46:21 +08:00
|
|
|
|
|
|
|
gimp_help_set_help_data (widget, tooltip, help_id);
|
|
|
|
|
|
|
|
g_free (tooltip);
|
|
|
|
}
|
|
|
|
}
|