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
|
1999-11-18 05:13:50 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1999-02-22 03:50:37 +08:00
|
|
|
* 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.
|
|
|
|
*
|
1999-11-18 05:13:50 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1999-02-22 03:50:37 +08:00
|
|
|
* 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
|
|
|
|
1999-12-02 21:00:18 +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-12-02 21:00:18 +08:00
|
|
|
gum->selection = NULL;
|
|
|
|
gum->clist = NULL;
|
|
|
|
gum->format = NULL;
|
|
|
|
gum->unit = UNIT_PIXEL;
|
|
|
|
gum->show_pixels = FALSE;
|
1999-04-05 20:48:48 +08:00
|
|
|
gum->show_percent = FALSE;
|
1999-02-22 03:50:37 +08:00
|
|
|
}
|
|
|
|
|
1999-06-18 03:13:08 +08:00
|
|
|
GtkType
|
1999-12-02 21:00:18 +08:00
|
|
|
gimp_unit_menu_get_type (void)
|
1999-02-22 03:50:37 +08:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
1999-12-02 21:00:18 +08:00
|
|
|
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-12-02 21:00:18 +08:00
|
|
|
gum->format = g_strdup (format);
|
|
|
|
gum->show_pixels = show_pixels;
|
1999-04-05 20:48:48 +08:00
|
|
|
gum->show_percent = show_percent;
|
1999-02-22 03:50:37 +08:00
|
|
|
|
1999-12-02 21:00:18 +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 =
|
1999-12-02 21:00:18 +08:00
|
|
|
gtk_menu_item_new_with_label
|
|
|
|
(gimp_unit_menu_build_string (format, UNIT_PERCENT));
|
1999-04-06 20:13:54 +08:00
|
|
|
gtk_menu_append (GTK_MENU (menu), menuitem);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
|
1999-12-02 21:00:18 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimp_unit_menu_callback),
|
|
|
|
gum);
|
|
|
|
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu",
|
|
|
|
(gpointer) UNIT_PERCENT);
|
1999-04-06 20:13:54 +08:00
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
}
|
1999-12-02 21:00:18 +08:00
|
|
|
|
1999-04-06 20:13:54 +08:00
|
|
|
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",
|
1999-12-02 21:00:18 +08:00
|
|
|
GTK_SIGNAL_FUNC (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",
|
1999-12-02 21:00:18 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimp_unit_menu_callback),
|
|
|
|
gum);
|
|
|
|
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu",
|
|
|
|
(gpointer) unit);
|
1999-12-04 02:30:35 +08:00
|
|
|
gtk_widget_show (menuitem);
|
1999-03-17 04:14:07 +08:00
|
|
|
}
|
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",
|
1999-12-02 21:00:18 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimp_unit_menu_callback),
|
|
|
|
gum);
|
1999-03-26 07:14:36 +08:00
|
|
|
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu",
|
1999-04-06 20:13:54 +08:00
|
|
|
(gpointer) (UNIT_PERCENT + 1));
|
1999-12-04 02:30:35 +08:00
|
|
|
gtk_widget_show (menuitem);
|
1999-03-26 07:14:36 +08:00
|
|
|
}
|
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);
|
1999-12-04 02:30:35 +08:00
|
|
|
gtk_widget_show (menuitem);
|
1999-03-17 04:14:07 +08:00
|
|
|
|
|
|
|
menuitem =
|
1999-12-02 21:00:18 +08:00
|
|
|
gtk_menu_item_new_with_label (gimp_unit_menu_build_string (gum->format,
|
|
|
|
unit));
|
1999-03-17 04:14:07 +08:00
|
|
|
gtk_menu_append (GTK_MENU (GTK_OPTION_MENU (gum)->menu), menuitem);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
|
1999-12-02 21:00:18 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimp_unit_menu_callback),
|
|
|
|
gum);
|
|
|
|
gtk_object_set_data (GTK_OBJECT (menuitem), "gimp_unit_menu",
|
|
|
|
(gpointer) unit);
|
1999-03-17 04:14:07 +08:00
|
|
|
gtk_menu_reorder_child (GTK_MENU (GTK_OPTION_MENU (gum)->menu),
|
|
|
|
menuitem, user_unit);
|
1999-12-04 02:30:35 +08:00
|
|
|
gtk_widget_show (menuitem);
|
1999-03-17 04:14:07 +08:00
|
|
|
}
|
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-12-02 21:00:18 +08:00
|
|
|
static gint
|
|
|
|
print (gchar *buf,
|
|
|
|
gint len,
|
|
|
|
gint start,
|
|
|
|
const gchar *fmt,
|
|
|
|
...)
|
1999-02-22 03:50:37 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
1999-12-02 21:00:18 +08:00
|
|
|
gint printed;
|
1999-02-22 03:50:37 +08:00
|
|
|
|
|
|
|
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-12-02 21:00:18 +08:00
|
|
|
static const gchar *
|
|
|
|
gimp_unit_menu_build_string (gchar *format,
|
|
|
|
GUnit unit)
|
1999-02-22 03:50:37 +08:00
|
|
|
{
|
1999-12-04 02:30:35 +08:00
|
|
|
static gchar buffer[64];
|
1999-12-02 21:00:18 +08:00
|
|
|
gint i = 0;
|
1999-02-22 03:50:37 +08:00
|
|
|
|
1999-12-04 02:30:35 +08:00
|
|
|
while (i < (sizeof (buffer) - 1) && *format)
|
1999-02-22 03:50:37 +08:00
|
|
|
{
|
|
|
|
switch (*format)
|
|
|
|
{
|
|
|
|
case '%':
|
|
|
|
format++;
|
|
|
|
switch (*format)
|
|
|
|
{
|
|
|
|
case 0:
|
1999-11-23 06:38:02 +08:00
|
|
|
g_warning ("unit-menu-format string ended within %%-sequence");
|
1999-02-22 03:50:37 +08:00
|
|
|
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-12-04 02:30:35 +08:00
|
|
|
i += print (buffer, sizeof (buffer), 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) */
|
1999-12-04 02:30:35 +08:00
|
|
|
i += print (buffer, sizeof (buffer), i, "%s",
|
1999-02-22 03:50:37 +08:00
|
|
|
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 */
|
1999-12-04 02:30:35 +08:00
|
|
|
i += print (buffer, sizeof (buffer), i, "%s",
|
1999-02-22 03:50:37 +08:00
|
|
|
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 */
|
1999-12-04 02:30:35 +08:00
|
|
|
i += print (buffer, sizeof (buffer), i, "%s",
|
1999-02-22 03:50:37 +08:00
|
|
|
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 */
|
1999-12-04 02:30:35 +08:00
|
|
|
i += print (buffer, sizeof (buffer), i, "%s",
|
1999-02-22 03:50:37 +08:00
|
|
|
gimp_unit_get_plural (unit));
|
|
|
|
break;
|
1999-03-26 07:14:36 +08:00
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
default:
|
1999-11-23 06:38:02 +08:00
|
|
|
g_warning ("unit-menu-format contains unknown format sequence '%%%c'", *format);
|
1999-02-22 03:50:37 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1999-03-26 07:14:36 +08:00
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
default:
|
|
|
|
buffer[i++] = *format;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
format++;
|
|
|
|
}
|
1999-12-02 21:00:18 +08:00
|
|
|
|
1999-12-04 02:30:35 +08:00
|
|
|
buffer[MIN (i, sizeof (buffer) - 1)] = 0;
|
1999-12-02 21:00:18 +08:00
|
|
|
|
1999-02-22 03:50:37 +08:00
|
|
|
return buffer;
|
1999-06-18 03:13:08 +08:00
|
|
|
}
|
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-12-02 21:00:18 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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),
|
1999-12-04 02:30:35 +08:00
|
|
|
(gint) (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-12-04 02:30:35 +08:00
|
|
|
|
1999-12-02 21:00:18 +08:00
|
|
|
gimp_unit_menu_selection_close_callback (NULL, gum);
|
1999-03-17 04:14:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 *hbbox;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *scrolled_win;
|
|
|
|
GtkWidget *button;
|
1999-12-02 21:00:18 +08:00
|
|
|
gchar *titles[2];
|
1999-03-17 04:14:07 +08:00
|
|
|
gchar *row[2];
|
|
|
|
GUnit unit;
|
|
|
|
gint num_units;
|
1999-12-04 02:30:35 +08:00
|
|
|
gint unit_width;
|
|
|
|
gint factor_width;
|
1999-03-17 04:14:07 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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-12-04 02:30:35 +08:00
|
|
|
/* the main vbox */
|
|
|
|
vbox = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (gum->selection)->vbox), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
/* the selection list */
|
1999-03-17 04:14:07 +08:00
|
|
|
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
|
1999-12-02 21:00:18 +08:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
|
1999-12-04 02:30:35 +08:00
|
|
|
GTK_POLICY_NEVER,
|
1999-12-02 21:00:18 +08:00
|
|
|
GTK_POLICY_ALWAYS);
|
1999-12-04 02:30:35 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), scrolled_win);
|
|
|
|
gtk_widget_show (scrolled_win);
|
1999-12-02 21:00:18 +08:00
|
|
|
|
|
|
|
titles[0] = _("Unit");
|
|
|
|
titles[1] = _("Factor");
|
|
|
|
gum->clist = gtk_clist_new_with_titles (2, titles);
|
1999-03-17 04:14:07 +08:00
|
|
|
gtk_clist_set_shadow_type (GTK_CLIST (gum->clist), GTK_SHADOW_IN);
|
|
|
|
gtk_clist_set_selection_mode (GTK_CLIST (gum->clist), GTK_SELECTION_BROWSE);
|
1999-12-02 21:00:18 +08:00
|
|
|
gtk_clist_column_titles_passive (GTK_CLIST (gum->clist));
|
1999-03-17 04:14:07 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_win), gum->clist);
|
1999-12-02 21:00:18 +08:00
|
|
|
gtk_widget_show (gum->clist);
|
1999-03-17 04:14:07 +08:00
|
|
|
|
1999-12-02 21:00:18 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (gum->selection), "destroy",
|
|
|
|
GTK_SIGNAL_FUNC (gtk_widget_destroyed),
|
|
|
|
&gum->selection);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (gum->clist), "destroy",
|
|
|
|
GTK_SIGNAL_FUNC (gtk_widget_destroyed),
|
|
|
|
&gum->clist);
|
1999-03-17 04:14:07 +08:00
|
|
|
|
1999-12-04 02:30:35 +08:00
|
|
|
/* 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);
|
1999-12-04 02:30:35 +08:00
|
|
|
|
1999-03-17 04:14:07 +08:00
|
|
|
hbbox = gtk_hbutton_box_new ();
|
|
|
|
gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbbox), 4);
|
1999-12-02 21:00:18 +08:00
|
|
|
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);
|
1999-12-04 02:30:35 +08:00
|
|
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
|
|
|
gtk_widget_grab_default (button);
|
1999-03-17 04:14:07 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
1999-12-02 21:00:18 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimp_unit_menu_selection_select_callback),
|
1999-03-17 04:14:07 +08:00
|
|
|
gum);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label (_("Close"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
|
1999-12-04 02:30:35 +08:00
|
|
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
1999-03-17 04:14:07 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
1999-12-02 21:00:18 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimp_unit_menu_selection_close_callback),
|
1999-03-17 04:14:07 +08:00
|
|
|
gum);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
1999-12-04 02:30:35 +08:00
|
|
|
/* 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),
|
1999-12-02 21:00:18 +08:00
|
|
|
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-12-04 02:30:35 +08:00
|
|
|
unit_width = gtk_clist_optimal_column_width (GTK_CLIST (gum->clist), 0);
|
|
|
|
factor_width = gtk_clist_optimal_column_width (GTK_CLIST (gum->clist), 1);
|
|
|
|
|
|
|
|
gtk_clist_set_column_width (GTK_CLIST (gum->clist), 0, unit_width);
|
|
|
|
gtk_clist_set_column_width (GTK_CLIST (gum->clist), 1, factor_width);
|
|
|
|
|
|
|
|
gtk_widget_set_usize (gum->clist, -1, 150);
|
|
|
|
|
1999-04-05 20:48:48 +08:00
|
|
|
/* now show the dialog */
|
1999-12-04 02:30:35 +08:00
|
|
|
gtk_widget_show (vbox);
|
|
|
|
gtk_widget_show (gum->selection);
|
1999-03-17 04:14:07 +08:00
|
|
|
|
1999-12-02 21:00:18 +08:00
|
|
|
if (gum->unit >= UNIT_END)
|
1999-03-17 04:14:07 +08:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|