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
|
|
|
|
2001-02-04 12:51:17 +08:00
|
|
|
#include <string.h>
|
2000-02-02 09:21:36 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/*
|
|
|
|
* Message Boxes...
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct _MessageBox MessageBox;
|
|
|
|
|
|
|
|
struct _MessageBox
|
|
|
|
{
|
2000-02-02 09:21:36 +08:00
|
|
|
GtkWidget *mbox;
|
2002-10-18 23:16:05 +08:00
|
|
|
GtkWidget *vbox;
|
2000-02-02 09:21:36 +08:00
|
|
|
GtkWidget *repeat_label;
|
2003-06-13 22:37:00 +08:00
|
|
|
gchar *domain;
|
2000-02-02 09:21:36 +08:00
|
|
|
gchar *message;
|
|
|
|
gint repeat_count;
|
|
|
|
GtkCallback callback;
|
|
|
|
gpointer data;
|
1999-09-28 01:58:10 +08:00
|
|
|
};
|
|
|
|
|
2002-10-18 23:16:05 +08:00
|
|
|
/* the maximum number of concurrent dialog boxes */
|
|
|
|
#define MESSAGE_BOX_MAXIMUM 4
|
1999-11-21 04:51:41 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
|
|
|
|
static void gimp_message_box_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
MessageBox *msg_box);
|
|
|
|
|
|
|
|
|
|
|
|
extern gchar *prog_name;
|
|
|
|
|
2000-02-11 05:54:12 +08:00
|
|
|
static GList *message_boxes = NULL;
|
1999-11-21 04:51:41 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2000-02-02 09:21:36 +08:00
|
|
|
void
|
2003-06-13 22:37:00 +08:00
|
|
|
gimp_message_box (const gchar *stock_id,
|
|
|
|
const gchar *domain,
|
|
|
|
const gchar *message,
|
1999-09-28 01:58:10 +08:00
|
|
|
GtkCallback callback,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2003-06-13 22:37:00 +08:00
|
|
|
MessageBox *msg_box;
|
|
|
|
GtkWidget *mbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *label;
|
|
|
|
GList *list;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
PangoAttribute *attr;
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
g_return_if_fail (stock_id != NULL);
|
|
|
|
g_return_if_fail (message != NULL);
|
|
|
|
|
|
|
|
if (! domain)
|
|
|
|
domain = _("GIMP");
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2000-02-02 09:21:36 +08:00
|
|
|
if (g_list_length (message_boxes) > MESSAGE_BOX_MAXIMUM)
|
1999-11-21 04:51:41 +08:00
|
|
|
{
|
2003-10-22 02:14:58 +08:00
|
|
|
g_printerr ("%s: %s\n\n", domain, message);
|
2000-02-02 09:21:36 +08:00
|
|
|
return;
|
1999-11-21 04:51:41 +08:00
|
|
|
}
|
2000-02-02 09:21:36 +08:00
|
|
|
|
|
|
|
for (list = message_boxes; list; list = list->next)
|
1999-11-21 04:51:41 +08:00
|
|
|
{
|
2000-02-02 09:21:36 +08:00
|
|
|
msg_box = list->data;
|
2003-06-13 22:37:00 +08:00
|
|
|
|
|
|
|
if (strcmp (msg_box->message, message) == 0 &&
|
|
|
|
strcmp (msg_box->domain, domain) == 0)
|
2000-02-02 09:21:36 +08:00
|
|
|
{
|
|
|
|
msg_box->repeat_count++;
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2000-02-02 09:21:36 +08:00
|
|
|
if (msg_box->repeat_count > 1)
|
|
|
|
{
|
2003-09-09 19:35:27 +08:00
|
|
|
gchar *text = g_strdup_printf (_("Message repeated %d times."),
|
2000-02-02 09:21:36 +08:00
|
|
|
msg_box->repeat_count);
|
|
|
|
gtk_label_set_text (GTK_LABEL (msg_box->repeat_label), text);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-10-18 23:16:05 +08:00
|
|
|
GtkWidget *label;
|
2000-02-02 09:21:36 +08:00
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
|
|
|
|
attr = pango_attr_style_new (PANGO_STYLE_OBLIQUE);
|
|
|
|
attr->start_index = 0;
|
|
|
|
attr->end_index = -1;
|
|
|
|
pango_attr_list_insert (attrs, attr);
|
|
|
|
|
2002-10-18 23:16:05 +08:00
|
|
|
label = gtk_label_new (_("Message repeated once."));
|
2003-06-13 22:37:00 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
gtk_label_set_attributes (GTK_LABEL (label), attrs);
|
2002-10-18 23:16:05 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (msg_box->vbox), label,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
2000-02-02 09:21:36 +08:00
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
|
2002-10-18 23:16:05 +08:00
|
|
|
msg_box->repeat_label = label;
|
2000-02-02 09:21:36 +08:00
|
|
|
}
|
2002-10-18 23:16:05 +08:00
|
|
|
|
2002-10-25 09:11:24 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (msg_box->mbox));
|
2000-02-02 09:21:36 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-11-21 04:51:41 +08:00
|
|
|
}
|
|
|
|
|
2000-02-02 09:21:36 +08:00
|
|
|
if (g_list_length (message_boxes) == MESSAGE_BOX_MAXIMUM)
|
|
|
|
{
|
2003-10-22 02:14:58 +08:00
|
|
|
g_printerr ("%s: %s\n\n", domain, message);
|
2000-02-02 09:21:36 +08:00
|
|
|
message = _("WARNING:\n"
|
|
|
|
"Too many open message dialogs.\n"
|
2000-02-13 20:04:32 +08:00
|
|
|
"Messages are redirected to stderr.");
|
2000-02-02 09:21:36 +08:00
|
|
|
}
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2000-02-02 09:21:36 +08:00
|
|
|
msg_box = g_new0 (MessageBox, 1);
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2001-07-31 01:17:36 +08:00
|
|
|
mbox = gimp_dialog_new (_("GIMP Message"), "gimp-message",
|
2003-11-06 23:27:05 +08:00
|
|
|
NULL, 0,
|
1999-09-28 01:58:10 +08:00
|
|
|
NULL, NULL,
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_CLOSE,
|
1999-09-28 01:58:10 +08:00
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (mbox), FALSE);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
|
|
|
g_signal_connect (mbox, "response",
|
|
|
|
G_CALLBACK (gimp_message_box_response),
|
|
|
|
msg_box);
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2002-10-18 23:16:05 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 10);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
|
2002-01-10 04:39:49 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (mbox)->vbox), hbox);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_DIALOG);
|
2003-06-13 22:37:00 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
|
2002-01-10 04:39:49 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
|
2003-09-09 19:35:27 +08:00
|
|
|
gtk_widget_show (image);
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 6);
|
2002-10-18 23:16:05 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
|
2003-06-13 22:37:00 +08:00
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
|
|
|
|
attr = pango_attr_scale_new (PANGO_SCALE_LARGE);
|
|
|
|
attr->start_index = 0;
|
|
|
|
attr->end_index = -1;
|
|
|
|
pango_attr_list_insert (attrs, attr);
|
|
|
|
|
|
|
|
attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
|
|
|
|
attr->start_index = 0;
|
|
|
|
attr->end_index = -1;
|
|
|
|
pango_attr_list_insert (attrs, attr);
|
|
|
|
|
|
|
|
str = g_strdup_printf (_("%s Message"), domain);
|
|
|
|
label = gtk_label_new (str);
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
gtk_label_set_attributes (GTK_LABEL (label), attrs);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
pango_attr_list_unref (attrs);
|
2002-10-18 23:16:05 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
label = gtk_label_new (message);
|
2003-06-13 22:37:00 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
2003-11-14 23:33:40 +08:00
|
|
|
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
|
2002-10-18 23:16:05 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
1999-09-28 01:58:10 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2002-10-18 23:16:05 +08:00
|
|
|
msg_box->mbox = mbox;
|
|
|
|
msg_box->vbox = vbox;
|
2003-06-13 22:37:00 +08:00
|
|
|
msg_box->domain = g_strdup (domain);
|
2002-10-18 23:16:05 +08:00
|
|
|
msg_box->message = g_strdup (message);
|
1999-09-28 01:58:10 +08:00
|
|
|
msg_box->callback = callback;
|
2002-10-18 23:16:05 +08:00
|
|
|
msg_box->data = data;
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
message_boxes = g_list_prepend (message_boxes, msg_box);
|
1999-11-21 04:51:41 +08:00
|
|
|
|
2000-02-02 09:21:36 +08:00
|
|
|
gtk_widget_show (mbox);
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_message_box_response (GtkWidget *widget,
|
|
|
|
gint resonse_id,
|
|
|
|
MessageBox *msg_box)
|
1999-09-28 01:58:10 +08:00
|
|
|
{
|
|
|
|
/* If there is a valid callback, invoke it */
|
|
|
|
if (msg_box->callback)
|
|
|
|
(* msg_box->callback) (widget, msg_box->data);
|
|
|
|
|
|
|
|
/* Destroy the box */
|
|
|
|
gtk_widget_destroy (msg_box->mbox);
|
2003-09-09 19:35:27 +08:00
|
|
|
|
1999-11-21 04:51:41 +08:00
|
|
|
/* make this box available again */
|
2000-02-02 09:21:36 +08:00
|
|
|
message_boxes = g_list_remove (message_boxes, msg_box);
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
g_free (msg_box->domain);
|
2000-02-02 09:21:36 +08:00
|
|
|
g_free (msg_box->message);
|
1999-09-28 01:58:10 +08:00
|
|
|
g_free (msg_box);
|
|
|
|
}
|
2000-03-29 07:02:05 +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:
|
|
|
|
g_warning ("gimp_button_menu_position: "
|
|
|
|
"unhandled position (%d)", position);
|
|
|
|
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,
|
2003-02-06 06:15:39 +08:00
|
|
|
const gchar *label_text,
|
|
|
|
gdouble yalign,
|
|
|
|
GtkWidget *widget,
|
2003-02-21 08:42:53 +08:00
|
|
|
gint colspan,
|
2003-02-06 06:15:39 +08:00
|
|
|
const gchar *stock_id)
|
2002-10-09 23:42:38 +08:00
|
|
|
{
|
2003-02-06 06:15:39 +08:00
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *label;
|
2002-10-09 23:42:38 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TABLE (table));
|
2003-02-06 06:15:39 +08:00
|
|
|
g_return_if_fail (label_text != NULL);
|
2002-10-09 23:42:38 +08:00
|
|
|
|
2003-02-06 06:15:39 +08:00
|
|
|
label = gtk_label_new_with_mnemonic (label_text);
|
2003-02-06 02:23:58 +08:00
|
|
|
|
2003-02-06 06:15:39 +08:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, yalign);
|
|
|
|
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
|
|
|
|
gtk_table_attach (table, label, 0, 1, row, row + 1,
|
|
|
|
GTK_FILL, GTK_FILL, 0, 0);
|
2002-10-09 23:42:38 +08:00
|
|
|
gtk_widget_show (label);
|
2003-09-09 19:35:27 +08:00
|
|
|
|
2003-02-06 06:15:39 +08:00
|
|
|
if (widget)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
2002-10-09 23:42:38 +08:00
|
|
|
|
2003-02-21 08:42:53 +08:00
|
|
|
gtk_table_attach (table, widget, 1, 1 + colspan, row, row + 1,
|
2003-02-06 06:15:39 +08:00
|
|
|
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (widget);
|
2002-10-09 23:42:38 +08:00
|
|
|
|
2003-02-06 06:15:39 +08:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
|
|
|
|
}
|
2002-10-09 23:42:38 +08:00
|
|
|
|
2003-02-06 06:15:39 +08:00
|
|
|
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
|
2003-09-09 19:35:27 +08:00
|
|
|
|
2003-02-06 06:15:39 +08:00
|
|
|
if (image)
|
|
|
|
{
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (image), 0.0, 0.5);
|
2003-02-21 08:42:53 +08:00
|
|
|
gtk_table_attach (table, image, 1 + colspan, 2 + colspan, row, row + 1,
|
|
|
|
GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
2003-02-06 06:15:39 +08:00
|
|
|
gtk_widget_show (image);
|
|
|
|
}
|
2002-10-09 23:42:38 +08:00
|
|
|
}
|
2002-12-20 00:33:29 +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
|
|
|
GdkScreen *screen;
|
|
|
|
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;
|
|
|
|
|
2003-11-02 04:06:01 +08:00
|
|
|
screen = gtk_widget_get_screen (widget);
|
|
|
|
settings = gtk_settings_get_for_screen (screen);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/* The format string which is used to display modifier names
|
|
|
|
* <Shift>, <Ctrl> and <Alt>
|
|
|
|
*/
|
|
|
|
#define GIMP_MOD_NAME_FORMAT_STRING N_("<%s>")
|
|
|
|
|
|
|
|
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);
|
|
|
|
mod_name_shift = g_strdup_printf (gettext (GIMP_MOD_NAME_FORMAT_STRING),
|
|
|
|
accel_label_class->mod_name_shift);
|
|
|
|
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);
|
|
|
|
mod_name_control = g_strdup_printf (gettext (GIMP_MOD_NAME_FORMAT_STRING),
|
|
|
|
accel_label_class->mod_name_control);
|
|
|
|
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);
|
|
|
|
mod_name_alt = g_strdup_printf (gettext (GIMP_MOD_NAME_FORMAT_STRING),
|
|
|
|
accel_label_class->mod_name_alt);
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
GdkWindowTypeHint
|
|
|
|
gimp_window_type_hint_to_gdk_hint (GimpWindowTypeHint hint)
|
|
|
|
{
|
|
|
|
switch (hint)
|
|
|
|
{
|
|
|
|
case GIMP_WINDOW_TYPE_HINT_NORMAL:
|
|
|
|
return GDK_WINDOW_TYPE_HINT_NORMAL;
|
|
|
|
|
|
|
|
case GIMP_WINDOW_TYPE_HINT_UTILITY:
|
|
|
|
return GDK_WINDOW_TYPE_HINT_UTILITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GDK_WINDOW_TYPE_HINT_NORMAL;
|
|
|
|
}
|