1999-02-22 03:50:37 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
1999-04-05 20:48:48 +08:00
|
|
|
* Copyright (C) 1995-1999 Peter Mattis and Spencer Kimball
|
1999-02-22 03:50:37 +08:00
|
|
|
*
|
|
|
|
* gimpunitmenu.c
|
|
|
|
* Copyright (C) 1999 Michael Natterer <mitschel@cs.tu-berlin.de>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library 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 Library 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.
|
|
|
|
*/
|
1999-05-30 00:35:47 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
#include "gimpunitmenu.h"
|
|
|
|
|
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
1999-04-05 20:48:48 +08:00
|
|
|
/* private functions */
|
|
|
|
static const gchar * gimp_unit_menu_build_string (gchar *format,
|
|
|
|
GUnit unit);
|
|
|
|
static void gimp_unit_menu_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
1999-02-22 03:50:37 +08:00
|
|
|
|
|
|
|
enum {
|
1999-06-18 03:13:08 +08:00
|
|
|
UNIT_CHANGED,
|
1999-02-22 03:50:37 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint gimp_unit_menu_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
1999-03-26 07:14:36 +08:00
|
|
|
static GtkOptionMenuClass *parent_class = NULL;
|
|
|
|
|
|
|
|
static void
|
1999-06-18 03:13:08 +08:00
|
|
|
gimp_unit_menu_destroy (GtkObject *object)
|
1999-03-26 07:14:36 +08:00
|
|
|
{
|
|
|
|
GimpUnitMenu *gum;
|
|
|
|
|
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (GIMP_IS_UNIT_MENU (object));
|
|
|
|
|
|
|
|
gum = GIMP_UNIT_MENU (object);
|
|
|
|
|
1999-06-18 03:13:08 +08:00
|
|
|
if (gum->format)
|
|
|
|
g_free (gum->format);
|
1999-03-26 07:14:36 +08:00
|
|
|
|
|
|
|
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
|
|
|
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
|
|
|
}
|
1999-02-22 03:50:37 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_unit_menu_class_init (GimpUnitMenuClass *class)
|
|
|
|
{
|
|
|
|
GtkObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = (GtkObjectClass*) class;
|
|
|
|
|
1999-03-26 07:14:36 +08:00
|
|
|
parent_class = gtk_type_class (gtk_option_menu_get_type ());
|
|
|
|
|
1999-06-18 03:13:08 +08:00
|
|
|
gimp_unit_menu_signals[UNIT_CHANGED] =
|
1999-02-22 03:50:37 +08:00
|
|
|
gtk_signal_new ("unit_changed",
|
|
|
|
GTK_RUN_FIRST,
|
|
|
|
object_class->type,
|
1999-06-18 03:13:08 +08:00
|
|
|
GTK_SIGNAL_OFFSET (GimpUnitMenuClass,
|
|
|
|
unit_changed),
|
1999-02-22 03:50:37 +08:00
|
|
|
gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
gtk_object_class_add_signals (object_class, gimp_unit_menu_signals,
|
|
|
|
LAST_SIGNAL);
|
1999-03-26 07:14:36 +08:00
|
|
|
|
1999-06-18 03:13:08 +08:00
|
|
|
class->unit_changed = NULL;
|
1999-02-22 03:50:37 +08:00
|
|
|
|
1999-06-18 03:13:08 +08:00
|
|
|
object_class->destroy = gimp_unit_menu_destroy;
|
|
|
|
}
|
1999-02-22 03:50:37 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_unit_menu_init (GimpUnitMenu *gum)
|
|
|
|
{
|
1999-03-17 04:14:07 +08:00
|
|
|
gum->selection = NULL;
|
1999-03-26 07:14:36 +08:00
|
|
|
gum->clist = NULL;
|
|
|
|
gum->format = NULL;
|
1999-02-22 03:50:37 +08:00
|
|
|
gum->unit = UNIT_PIXEL;
|
1999-04-05 20:48:48 +08:00
|
|
|
gum->show_pixels = FALSE;
|
|
|
|
gum->show_percent = FALSE;
|
1999-02-22 03:50:37 +08:00
|
|
|
}
|
|
|
|
|
1999-06-18 03:13:08 +08:00
|
|
|
GtkType
|
1999-02-22 03:50:37 +08:00
|
|
|
gimp_unit_menu_get_type ()
|
|
|
|
{
|
1999-06-18 03:13:08 +08:00
|
|
|
static GtkType gum_type = 0;
|
1999-02-22 03:50:37 +08:00
|
|
|
|
|
|
|
if (!gum_type)
|
|
|
|
{
|
|
|
|
GtkTypeInfo gum_info =
|
|
|
|
{
|
|
|
|
"GimpUnitMenu",
|
|
|
|
sizeof (GimpUnitMenu),
|
|
|
|
sizeof (GimpUnitMenuClass),
|
|
|
|
(GtkClassInitFunc) gimp_unit_menu_class_init,
|
|
|
|
(GtkObjectInitFunc) gimp_unit_menu_init,
|
|
|
|
/* reserved_1 */ NULL,
|
|
|
|
/* reserved_2 */ NULL,
|
|
|
|
(GtkClassInitFunc) NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
gum_type = gtk_type_unique (gtk_option_menu_get_type (), &gum_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gum_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget*
|
1999-03-17 04:14:07 +08:00
|
|
|
gimp_unit_menu_new (gchar *format,
|
|
|
|
GUnit unit,
|
1999-04-05 20:48:48 +08:00
|
|
|
gboolean show_pixels,
|
|
|
|
gboolean show_percent,
|
|
|
|
gboolean show_custom)
|
1999-02-22 03:50:37 +08:00
|
|
|
{
|
1999-03-17 04:14:07 +08:00
|
|
|
GimpUnitMenu *gum;
|
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *menuitem;
|
|
|
|
GUnit u;
|
|
|
|
|
|
|
|
g_return_val_if_fail ((unit >= UNIT_PIXEL) &&
|
1999-04-06 20:13:54 +08:00
|
|
|
(unit < gimp_unit_get_number_of_units ()) ||
|
|
|
|
(unit == UNIT_PERCENT), NULL);
|
1999-02-22 03:50:37 +08:00
|
|
|
|
1999-04-06 20:13:54 +08:00
|
|
|
if ((unit >= gimp_unit_get_number_of_built_in_units ()) &&
|
|
|
|
(unit != UNIT_PERCENT))
|
1999-04-05 20:48:48 +08:00
|
|
|
show_custom = TRUE;
|
1999-02-22 03:50:37 +08:00
|
|
|
|
|
|
|
gum = gtk_type_new (gimp_unit_menu_get_type ());
|
|
|
|
|
1999-03-17 04:14:07 +08:00
|
|
|
gum->format = g_strdup (format);
|
1999-04-05 20:48:48 +08:00
|
|
|
gum->show_pixels = show_pixels;
|
|
|
|
gum->show_percent = show_percent;
|
1999-02-22 03:50:37 +08:00
|
|
|
|
|
|
|
menu = gtk_menu_new();
|
1999-04-05 20:48:48 +08:00
|
|
|
for (u = show_pixels ? UNIT_PIXEL : UNIT_INCH;
|
|
|
|
u < gimp_unit_get_number_of_built_in_units();
|
|
|
|
u++)
|
1999-02-22 03:50:37 +08:00
|
|
|
{
|
1999-04-06 20:13:54 +08:00
|
|
|
/* special cases "pixels" and "percent" */
|
|
|
|
if (u == UNIT_INCH)
|
|
|
|
{
|
|
|
|
if (show_percent)
|
|
|
|
{
|
|
|
|
menuitem =
|
|
|
|
gtk_menu_item_new_with_label (gimp_unit_menu_build_string (format, UNIT_PERCENT));
|
|
|
|
gtk_menu_append (GTK_MENU (menu), menuitem);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
|
|
|
|
(GtkSignalFunc) gimp_unit_menu_callback, gum);
|
|
|
|
gtk_object_set_data (GTK_OBJECT (menuitem),
|
|
|
|
"gimp_unit_menu", (gpointer) UNIT_PERCENT);
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_pixels || show_percent)
|
|
|
|
{
|
|
|
|
menuitem = gtk_menu_item_new ();
|
|
|
|
gtk_menu_append (GTK_MENU (menu), menuitem);
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
menuitem =
|
1999-03-17 04:14:07 +08:00
|
|
|
gtk_menu_item_new_with_label (gimp_unit_menu_build_string (format, u));
|
1999-02-22 03:50:37 +08:00
|
|
|
gtk_menu_append (GTK_MENU (menu), menuitem);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
|
|
|
|
(GtkSignalFunc) gimp_unit_menu_callback, gum);
|
|
|
|
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu", (gpointer)u);
|
1999-03-26 07:14:36 +08:00
|
|
|
gtk_widget_show (menuitem);
|
1999-03-17 04:14:07 +08:00
|
|
|
}
|
1999-03-26 07:14:36 +08:00
|
|
|
|
1999-04-06 20:13:54 +08:00
|
|
|
if ((unit >= gimp_unit_get_number_of_built_in_units ()) &&
|
|
|
|
(unit != UNIT_PERCENT))
|
1999-03-17 04:14:07 +08:00
|
|
|
{
|
|
|
|
menuitem = gtk_menu_item_new ();
|
|
|
|
gtk_menu_append (GTK_MENU (menu), menuitem);
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
|
|
|
|
menuitem =
|
|
|
|
gtk_menu_item_new_with_label (gimp_unit_menu_build_string (format, unit));
|
|
|
|
gtk_menu_append (GTK_MENU (menu), menuitem);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
|
|
|
|
(GtkSignalFunc) gimp_unit_menu_callback, gum);
|
|
|
|
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu", (gpointer)unit);
|
|
|
|
gtk_widget_show(menuitem);
|
|
|
|
}
|
1999-02-22 03:50:37 +08:00
|
|
|
|
1999-04-05 20:48:48 +08:00
|
|
|
if (show_custom)
|
1999-03-26 07:14:36 +08:00
|
|
|
{
|
|
|
|
menuitem = gtk_menu_item_new ();
|
|
|
|
gtk_menu_append (GTK_MENU (menu), menuitem);
|
|
|
|
gtk_widget_show (menuitem);
|
1999-04-06 20:13:54 +08:00
|
|
|
|
1999-03-26 07:14:36 +08:00
|
|
|
menuitem =
|
|
|
|
gtk_menu_item_new_with_label (_("More..."));
|
|
|
|
gtk_menu_append (GTK_MENU (menu), menuitem);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
|
|
|
|
(GtkSignalFunc) gimp_unit_menu_callback, gum);
|
|
|
|
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu",
|
1999-04-06 20:13:54 +08:00
|
|
|
(gpointer) (UNIT_PERCENT + 1));
|
1999-03-26 07:14:36 +08:00
|
|
|
gtk_widget_show(menuitem);
|
|
|
|
}
|
1999-04-06 20:13:54 +08:00
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (gum), menu);
|
|
|
|
|
|
|
|
gum->unit = unit;
|
1999-03-12 11:44:59 +08:00
|
|
|
gtk_option_menu_set_history (GTK_OPTION_MENU (gum),
|
1999-04-05 20:48:48 +08:00
|
|
|
(unit == UNIT_PIXEL) ? 0 :
|
1999-04-06 20:13:54 +08:00
|
|
|
((unit == UNIT_PERCENT) ? (show_pixels ? 1 : 0) :
|
|
|
|
(((show_pixels || show_percent) ? 2 : 0) +
|
|
|
|
((show_pixels && show_percent) ? 1 : 0) +
|
|
|
|
((unit < UNIT_END) ? (unit - 1) : UNIT_END))));
|
1999-02-22 03:50:37 +08:00
|
|
|
return GTK_WIDGET (gum);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_unit_menu_set_unit (GimpUnitMenu *gum,
|
|
|
|
GUnit unit)
|
|
|
|
{
|
1999-03-17 04:14:07 +08:00
|
|
|
GtkWidget *menuitem = NULL;
|
|
|
|
GList *items;
|
|
|
|
gint user_unit;
|
|
|
|
|
1999-03-12 11:44:59 +08:00
|
|
|
g_return_if_fail (gum != NULL);
|
|
|
|
g_return_if_fail (GIMP_IS_UNIT_MENU (gum));
|
1999-04-06 20:13:54 +08:00
|
|
|
g_return_if_fail (((unit >= UNIT_PIXEL) &&
|
|
|
|
((unit > UNIT_PIXEL) || gum->show_pixels) &&
|
|
|
|
(unit < gimp_unit_get_number_of_units ())) ||
|
|
|
|
((unit == UNIT_PERCENT) && gum->show_percent));
|
1999-03-12 11:44:59 +08:00
|
|
|
|
1999-03-17 04:14:07 +08:00
|
|
|
if (unit == gum->unit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
items = GTK_MENU_SHELL (GTK_OPTION_MENU (gum)->menu)->children;
|
1999-04-06 20:13:54 +08:00
|
|
|
user_unit = UNIT_END + (((gum->show_pixels || gum->show_percent) ? 2 : 0) +
|
|
|
|
((gum->show_pixels && gum->show_percent) ? 1 : 0));
|
1999-03-12 11:44:59 +08:00
|
|
|
|
1999-04-06 20:13:54 +08:00
|
|
|
if ((unit >= UNIT_END) && (unit != UNIT_PERCENT))
|
1999-03-17 04:14:07 +08:00
|
|
|
{
|
|
|
|
if ((g_list_length (items) - 3) >= user_unit)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (GTK_WIDGET (g_list_nth_data (items,
|
|
|
|
user_unit - 1)));
|
|
|
|
gtk_widget_destroy (GTK_WIDGET (g_list_nth_data (items,
|
|
|
|
user_unit - 1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
menuitem = gtk_menu_item_new ();
|
|
|
|
gtk_menu_append (GTK_MENU (GTK_OPTION_MENU (gum)->menu), menuitem);
|
|
|
|
gtk_menu_reorder_child (GTK_MENU (GTK_OPTION_MENU (gum)->menu),
|
|
|
|
menuitem, user_unit - 1);
|
|
|
|
gtk_widget_show(menuitem);
|
|
|
|
|
|
|
|
menuitem =
|
|
|
|
gtk_menu_item_new_with_label (gimp_unit_menu_build_string (gum->format, unit));
|
|
|
|
gtk_menu_append (GTK_MENU (GTK_OPTION_MENU (gum)->menu), menuitem);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
|
|
|
|
(GtkSignalFunc) gimp_unit_menu_callback, gum);
|
|
|
|
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu", (gpointer)unit);
|
|
|
|
gtk_menu_reorder_child (GTK_MENU (GTK_OPTION_MENU (gum)->menu),
|
|
|
|
menuitem, user_unit);
|
|
|
|
gtk_widget_show(menuitem);
|
|
|
|
}
|
1999-02-22 03:50:37 +08:00
|
|
|
|
|
|
|
gum->unit = unit;
|
1999-03-12 11:44:59 +08:00
|
|
|
gtk_option_menu_set_history (GTK_OPTION_MENU (gum),
|
1999-04-05 20:48:48 +08:00
|
|
|
(unit == UNIT_PIXEL) ? 0 :
|
1999-04-06 20:13:54 +08:00
|
|
|
((unit == UNIT_PERCENT) ?
|
|
|
|
(gum->show_pixels ? 1 : 0) :
|
|
|
|
(((gum->show_pixels ||
|
|
|
|
gum->show_percent) ? 2 : 0) +
|
|
|
|
((gum->show_pixels &&
|
|
|
|
gum->show_percent) ? 1 : 0) +
|
|
|
|
((unit < UNIT_END) ? (unit - 1) : UNIT_END))));
|
1999-02-22 03:50:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GUnit
|
|
|
|
gimp_unit_menu_get_unit (GimpUnitMenu *gum)
|
|
|
|
{
|
1999-03-12 11:44:59 +08:00
|
|
|
g_return_val_if_fail (gum != NULL, UNIT_INCH);
|
|
|
|
g_return_val_if_fail (GIMP_IS_UNIT_MENU (gum), UNIT_INCH);
|
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
return gum->unit;
|
|
|
|
}
|
|
|
|
|
1999-04-05 20:48:48 +08:00
|
|
|
/* most of the next two functions is stolen from app/gdisplay.c */
|
1999-02-22 03:50:37 +08:00
|
|
|
static int
|
|
|
|
print (char *buf, int len, int start, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int printed;
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
|
|
|
|
printed = g_vsnprintf (buf + start, len - start, fmt, args);
|
|
|
|
if (printed < 0)
|
|
|
|
printed = len - start;
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
return printed;
|
|
|
|
}
|
|
|
|
|
1999-03-04 01:10:50 +08:00
|
|
|
static const gchar*
|
|
|
|
gimp_unit_menu_build_string (gchar *format, GUnit unit)
|
1999-02-22 03:50:37 +08:00
|
|
|
{
|
|
|
|
#define BUFFER_LEN 64
|
|
|
|
|
|
|
|
static gchar buffer[BUFFER_LEN];
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (i < (BUFFER_LEN - 1) && *format)
|
|
|
|
{
|
|
|
|
switch (*format)
|
|
|
|
{
|
|
|
|
case '%':
|
|
|
|
format++;
|
|
|
|
switch (*format)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
g_warning (_("unit-menu-format string ended within %%-sequence"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
buffer[i++] = '%';
|
|
|
|
break;
|
1999-03-26 07:14:36 +08:00
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
case 'f': /* factor (how many units make up an inch) */
|
1999-03-26 07:14:36 +08:00
|
|
|
i += print (buffer, BUFFER_LEN, i, "%f",
|
1999-02-22 03:50:37 +08:00
|
|
|
gimp_unit_get_factor (unit));
|
|
|
|
break;
|
1999-03-26 07:14:36 +08:00
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
case 'y': /* symbol ("''" for inch) */
|
|
|
|
i += print (buffer, BUFFER_LEN, i, "%s",
|
|
|
|
gimp_unit_get_symbol (unit));
|
|
|
|
break;
|
1999-03-26 07:14:36 +08:00
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
case 'a': /* abbreviation */
|
|
|
|
i += print (buffer, BUFFER_LEN, i, "%s",
|
|
|
|
gimp_unit_get_abbreviation (unit));
|
|
|
|
break;
|
1999-03-26 07:14:36 +08:00
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
case 's': /* singular */
|
|
|
|
i += print (buffer, BUFFER_LEN, i, "%s",
|
|
|
|
gimp_unit_get_singular (unit));
|
|
|
|
break;
|
1999-03-26 07:14:36 +08:00
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
case 'p': /* plural */
|
|
|
|
i += print (buffer, BUFFER_LEN, i, "%s",
|
|
|
|
gimp_unit_get_plural (unit));
|
|
|
|
break;
|
1999-03-26 07:14:36 +08:00
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
default:
|
1999-07-22 10:58:26 +08:00
|
|
|
g_warning (_("unit-menu-format contains unknown "
|
1999-02-22 03:50:37 +08:00
|
|
|
"format sequence '%%%c'"), *format);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1999-03-26 07:14:36 +08:00
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
default:
|
|
|
|
buffer[i++] = *format;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[MIN(i, BUFFER_LEN - 1)] = 0;
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
1999-06-18 03:13:08 +08:00
|
|
|
#undef BUFFER_LEN
|
|
|
|
}
|
1999-03-17 04:14:07 +08:00
|
|
|
|
1999-06-18 03:13:08 +08:00
|
|
|
/* private callbacks of gimp_unit_menu_create_selection () */
|
1999-03-17 04:14:07 +08:00
|
|
|
static void
|
|
|
|
gimp_unit_menu_selection_select_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpUnitMenu *gum;
|
|
|
|
GUnit unit;
|
|
|
|
|
|
|
|
gum = GIMP_UNIT_MENU (data);
|
|
|
|
|
|
|
|
if (gum->selection && GTK_CLIST (gum->clist)->selection)
|
|
|
|
{
|
1999-04-05 20:48:48 +08:00
|
|
|
unit = (GUnit) gtk_clist_get_row_data (GTK_CLIST (gum->clist),
|
|
|
|
(int) (GTK_CLIST (gum->clist)->selection->data));
|
1999-03-17 04:14:07 +08:00
|
|
|
gimp_unit_menu_set_unit (gum, unit);
|
|
|
|
gtk_signal_emit (GTK_OBJECT (gum),
|
1999-06-18 03:13:08 +08:00
|
|
|
gimp_unit_menu_signals[UNIT_CHANGED]);
|
1999-03-17 04:14:07 +08:00
|
|
|
|
|
|
|
gtk_widget_destroy (gum->selection);
|
|
|
|
gum->selection = NULL;
|
|
|
|
gum->clist = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_unit_menu_selection_close_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpUnitMenu *gum;
|
|
|
|
|
|
|
|
gum = GIMP_UNIT_MENU (data);
|
|
|
|
|
|
|
|
if (gum->selection)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (gum->selection);
|
|
|
|
gum->selection = NULL;
|
|
|
|
gum->clist = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gimp_unit_menu_selection_delete_callback (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gimp_unit_menu_selection_close_callback (NULL, data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-06-18 03:13:08 +08:00
|
|
|
/* private function of gimp_unit_menu_callback () */
|
1999-03-17 04:14:07 +08:00
|
|
|
static void
|
|
|
|
gimp_unit_menu_create_selection (GimpUnitMenu *gum)
|
|
|
|
{
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *hbbox;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *scrolled_win;
|
|
|
|
GtkWidget *button;
|
|
|
|
gchar *row[2];
|
|
|
|
GUnit unit;
|
|
|
|
gint num_units;
|
|
|
|
|
|
|
|
gum->selection = gtk_dialog_new ();
|
|
|
|
gtk_window_set_wmclass (GTK_WINDOW (gum->selection),
|
1999-05-23 01:56:35 +08:00
|
|
|
"unit_selection", "Gimp");
|
1999-03-17 04:14:07 +08:00
|
|
|
gtk_window_set_title (GTK_WINDOW (gum->selection), _("Unit Selection"));
|
1999-05-23 01:56:35 +08:00
|
|
|
gtk_window_set_policy (GTK_WINDOW (gum->selection), FALSE, TRUE, FALSE);
|
|
|
|
gtk_window_position (GTK_WINDOW (gum->selection), GTK_WIN_POS_MOUSE);
|
1999-03-17 04:14:07 +08:00
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (gum->selection)->vbox), vbox);
|
|
|
|
gtk_container_border_width (GTK_CONTAINER (vbox), 2);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT (gum->selection), "delete_event",
|
|
|
|
GTK_SIGNAL_FUNC (gimp_unit_menu_selection_delete_callback),
|
|
|
|
gum);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (gum), "destroy",
|
|
|
|
GTK_SIGNAL_FUNC (gimp_unit_menu_selection_close_callback),
|
|
|
|
gum);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (gum), "unmap",
|
|
|
|
GTK_SIGNAL_FUNC (gimp_unit_menu_selection_close_callback),
|
|
|
|
gum);
|
|
|
|
|
1999-04-05 20:48:48 +08:00
|
|
|
/* build the selection list */
|
1999-03-17 04:14:07 +08:00
|
|
|
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gum->clist = gtk_clist_new (2);
|
|
|
|
gtk_clist_set_shadow_type (GTK_CLIST (gum->clist), GTK_SHADOW_IN);
|
|
|
|
gtk_clist_set_selection_mode (GTK_CLIST (gum->clist), GTK_SELECTION_BROWSE);
|
|
|
|
gtk_widget_set_usize (gum->clist, 200, 150);
|
|
|
|
|
1999-04-05 20:48:48 +08:00
|
|
|
gtk_clist_set_column_title (GTK_CLIST (gum->clist), 0, _("Unit "));
|
1999-03-17 04:14:07 +08:00
|
|
|
gtk_clist_set_column_auto_resize (GTK_CLIST (gum->clist), 0, TRUE);
|
|
|
|
gtk_clist_set_column_title (GTK_CLIST (gum->clist), 1, _("Factor"));
|
|
|
|
gtk_clist_set_column_auto_resize (GTK_CLIST (gum->clist), 1, TRUE);
|
|
|
|
gtk_clist_column_titles_show (GTK_CLIST (gum->clist));
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 8);
|
|
|
|
gtk_container_border_width (GTK_CONTAINER (hbox), 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), scrolled_win, TRUE, TRUE, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_win), gum->clist);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_ALWAYS);
|
|
|
|
|
|
|
|
gtk_widget_show(scrolled_win);
|
|
|
|
gtk_widget_show(gum->clist);
|
|
|
|
|
1999-04-05 20:48:48 +08:00
|
|
|
/* build the action area */
|
1999-06-18 03:13:08 +08:00
|
|
|
gtk_container_set_border_width
|
|
|
|
(GTK_CONTAINER (GTK_DIALOG (gum->selection)->action_area), 2);
|
1999-03-17 04:14:07 +08:00
|
|
|
gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (gum->selection)->action_area),
|
|
|
|
FALSE);
|
|
|
|
hbbox = gtk_hbutton_box_new ();
|
|
|
|
gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbbox), 4);
|
|
|
|
gtk_box_pack_end(GTK_BOX (GTK_DIALOG (gum->selection)->action_area), hbbox,
|
|
|
|
FALSE, FALSE, 0);
|
1999-04-05 20:48:48 +08:00
|
|
|
gtk_widget_show (hbbox);
|
1999-03-17 04:14:07 +08:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label (_("Select"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
|
|
|
(GtkSignalFunc) gimp_unit_menu_selection_select_callback,
|
|
|
|
gum);
|
|
|
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label (_("Close"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
|
|
|
(GtkSignalFunc) gimp_unit_menu_selection_close_callback,
|
|
|
|
gum);
|
|
|
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
|
|
|
gtk_widget_grab_default (button);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
1999-04-05 20:48:48 +08:00
|
|
|
/* insert the unit lines */
|
1999-03-17 04:14:07 +08:00
|
|
|
num_units = gimp_unit_get_number_of_units ();
|
|
|
|
for (unit = UNIT_END; unit < num_units; unit++)
|
|
|
|
{
|
1999-03-26 07:14:36 +08:00
|
|
|
row[0] = g_strdup (gimp_unit_menu_build_string (gum->format, unit));
|
|
|
|
row[1] = g_strdup (gimp_unit_menu_build_string ("(%f)", unit));
|
1999-03-17 04:14:07 +08:00
|
|
|
|
|
|
|
gtk_clist_append (GTK_CLIST (gum->clist), row);
|
|
|
|
gtk_clist_set_row_data (GTK_CLIST (gum->clist),
|
|
|
|
unit - UNIT_END, (gpointer)unit);
|
1999-03-26 07:14:36 +08:00
|
|
|
|
|
|
|
g_free (row[0]);
|
|
|
|
g_free (row[1]);
|
1999-03-17 04:14:07 +08:00
|
|
|
}
|
|
|
|
|
1999-04-05 20:48:48 +08:00
|
|
|
/* now show the dialog */
|
1999-03-17 04:14:07 +08:00
|
|
|
gtk_widget_show(vbox);
|
|
|
|
gtk_widget_show(gum->selection);
|
|
|
|
|
|
|
|
if(gum->unit >= UNIT_END)
|
|
|
|
{
|
|
|
|
gtk_clist_select_row (GTK_CLIST (gum->clist), gum->unit - UNIT_END, 0);
|
|
|
|
gtk_clist_moveto (GTK_CLIST (gum->clist), gum->unit - UNIT_END,
|
|
|
|
0, 0.0, 0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
static void
|
|
|
|
gimp_unit_menu_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpUnitMenu *gum;
|
|
|
|
GUnit new_unit;
|
|
|
|
|
|
|
|
gum = data;
|
|
|
|
new_unit = (guint) gtk_object_get_data (GTK_OBJECT (widget),
|
|
|
|
"gimp_unit_menu");
|
|
|
|
|
|
|
|
if (gum->unit == new_unit)
|
|
|
|
return;
|
|
|
|
|
1999-04-05 20:48:48 +08:00
|
|
|
/* was "More..." selected? */
|
1999-04-06 20:13:54 +08:00
|
|
|
if (new_unit == (UNIT_PERCENT + 1))
|
1999-03-17 04:14:07 +08:00
|
|
|
{
|
|
|
|
gtk_option_menu_set_history (GTK_OPTION_MENU (gum),
|
1999-04-05 20:48:48 +08:00
|
|
|
(gum->unit == UNIT_PIXEL) ? 0 :
|
1999-04-06 20:13:54 +08:00
|
|
|
((gum->unit == UNIT_PERCENT) ?
|
|
|
|
(gum->show_pixels ? 1 : 0) :
|
|
|
|
((gum->show_pixels ||
|
|
|
|
gum->show_percent ? 2 : 0) +
|
|
|
|
(gum->show_pixels &&
|
|
|
|
gum->show_percent ? 1 : 0) +
|
|
|
|
((gum->unit < UNIT_END) ?
|
|
|
|
gum->unit - 1 : UNIT_END))));
|
1999-03-17 04:14:07 +08:00
|
|
|
if (! gum->selection)
|
|
|
|
gimp_unit_menu_create_selection (gum);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (gum->selection)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (gum->selection);
|
|
|
|
gum->selection = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_unit_menu_set_unit (gum, new_unit);
|
1999-02-22 03:50:37 +08:00
|
|
|
gtk_signal_emit (GTK_OBJECT (gum),
|
1999-06-18 03:13:08 +08:00
|
|
|
gimp_unit_menu_signals[UNIT_CHANGED]);
|
1999-02-22 03:50:37 +08:00
|
|
|
}
|