Commit ebdd4fb7 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

app/widgets/Makefile.am app/widgets/widgets-types.h

2004-05-08  Sven Neumann  <sven@gimp.org>

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpunitcombobox.[ch]
	* app/widgets/gimpunitstore.[ch]: added a prototype of a unit menu
	based on GtkComboBox. Will move this to libgimpwidgets later...

	* app/display/gimpstatusbar.[ch]: use the new GimpUnitComboBox and
	GimpUnitStore.

	* themes/Default/gtkrc
	* themes/Small/gtkrc: hardcode the appearance of the
	GimpUnitComboBox. It uses a hack that doesn't work in list mode.
parent 8e6d919c
2004-05-08 Sven Neumann <sven@gimp.org>
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpunitcombobox.[ch]
* app/widgets/gimpunitstore.[ch]: added a prototype of a unit menu
based on GtkComboBox. Will move this to libgimpwidgets later...
* app/display/gimpstatusbar.[ch]: use the new GimpUnitComboBox and
GimpUnitStore.
* themes/Default/gtkrc
* themes/Small/gtkrc: hardcode the appearance of the
GimpUnitComboBox. It uses a hack that doesn't work in list mode.
2004-05-07 Sven Neumann <sven@gimp.org>
* app/core/gimpimage-colormap.[ch]: added a const qualifier.
......
......@@ -25,6 +25,9 @@
#include "core/gimpimage.h"
#include "core/gimpimage-unit.h"
#include "widgets/gimpunitstore.h"
#include "widgets/gimpunitcombobox.h"
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
#include "gimpstatusbar.h"
......@@ -38,12 +41,17 @@
#define CURSOR_STR_LENGTH 256
static void gimp_statusbar_class_init (GimpStatusbarClass *klass);
static void gimp_statusbar_init (GimpStatusbar *statusbar);
static void gimp_statusbar_class_init (GimpStatusbarClass *klass);
static void gimp_statusbar_init (GimpStatusbar *statusbar);
static void gimp_statusbar_update (GtkStatusbar *gtk_statusbar,
guint context_id,
const gchar *text);
static void gimp_statusbar_update (GtkStatusbar *gtk_statusbar,
guint context_id,
const gchar *text);
static void gimp_statusbar_set_cursor (GimpStatusbar *statusbar,
gdouble x,
gdouble y);
static void gimp_statusbar_unit_changed (GtkWidget *combo,
GimpStatusbar *statusbar);
static GtkStatusbarClass *parent_class = NULL;
......@@ -95,6 +103,7 @@ gimp_statusbar_init (GimpStatusbar *statusbar)
{
GtkStatusbar *gtk_statusbar;
GtkBox *box;
GimpUnitStore *store;
GtkShadowType shadow_type;
gtk_statusbar = GTK_STATUSBAR (statusbar);
......@@ -122,6 +131,17 @@ gimp_statusbar_init (GimpStatusbar *statusbar)
statusbar->cursor_label);
gtk_widget_show (statusbar->cursor_label);
store = gimp_unit_store_new (2);
statusbar->combo = gimp_unit_combo_box_new_with_model (store);
g_object_unref (store);
gtk_box_pack_start (box, statusbar->combo, FALSE, FALSE, 0);
gtk_widget_show (statusbar->combo);
g_signal_connect (statusbar->combo, "changed",
G_CALLBACK (gimp_statusbar_unit_changed),
statusbar);
statusbar->progressbar = gtk_progress_bar_new ();
gtk_box_pack_start (box, statusbar->progressbar, TRUE, TRUE, 0);
gtk_widget_show (statusbar->progressbar);
......@@ -264,31 +284,7 @@ gimp_statusbar_update_cursor (GimpStatusbar *statusbar,
}
else
{
GimpImage *gimage;
gchar buffer[CURSOR_STR_LENGTH];
gimage = statusbar->shell->gdisp->gimage;
if (gimage->unit == GIMP_UNIT_PIXEL)
{
g_snprintf (buffer, sizeof (buffer), statusbar->cursor_format_str,
"",
ROUND (x),
", ",
ROUND (y));
}
else /* show real world units */
{
gdouble unit_factor = gimp_image_unit_get_factor (gimage);
g_snprintf (buffer, sizeof (buffer), statusbar->cursor_format_str,
"",
x * unit_factor / gimage->xresolution,
", ",
y * unit_factor / gimage->yresolution);
}
gtk_label_set_text (GTK_LABEL (statusbar->cursor_label), buffer);
gimp_statusbar_set_cursor (statusbar, x, y);
}
}
......@@ -299,48 +295,50 @@ gimp_statusbar_resize_cursor (GimpStatusbar *statusbar)
GimpDisplayShell *shell;
GimpImage *gimage;
gchar buffer[CURSOR_STR_LENGTH];
GtkTreeModel *model;
const gchar *text;
gint cursor_label_width;
gint label_frame_size_difference;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
shell = statusbar->shell;
shell = statusbar->shell;
gimage = shell->gdisp->gimage;
model = gtk_combo_box_get_model (GTK_COMBO_BOX (statusbar->combo));
gimp_unit_store_set_resolutions (GIMP_UNIT_STORE (model),
gimage->xresolution, gimage->yresolution);
g_signal_handlers_block_by_func (statusbar->combo,
gimp_statusbar_unit_changed, statusbar);
gtk_combo_box_set_active (GTK_COMBO_BOX (statusbar->combo), gimage->unit);
g_signal_handlers_unblock_by_func (statusbar->combo,
gimp_statusbar_unit_changed, statusbar);
if (gimage->unit == GIMP_UNIT_PIXEL)
{
g_snprintf (statusbar->cursor_format_str,
sizeof (statusbar->cursor_format_str),
"%%s%%d%%s%%d");
g_snprintf (buffer, sizeof (buffer), statusbar->cursor_format_str,
"", shell->gdisp->gimage->width,
", ", shell->gdisp->gimage->height);
}
else /* show real world units */
{
gdouble unit_factor = gimp_image_unit_get_factor (gimage);
g_snprintf (statusbar->cursor_format_str,
sizeof (statusbar->cursor_format_str),
"%%s%%.%df%%s%%.%df %s",
gimp_image_unit_get_digits (gimage),
gimp_image_unit_get_digits (gimage),
gimp_image_unit_get_symbol (gimage));
g_snprintf (buffer, sizeof (buffer), statusbar->cursor_format_str,
"",
(gdouble) gimage->width * unit_factor / gimage->xresolution,
", ",
(gdouble) gimage->height * unit_factor / gimage->yresolution);
"%%s%%.%df%%s%%.%df",
gimp_image_unit_get_digits (gimage),
gimp_image_unit_get_digits (gimage));
}
gimp_statusbar_set_cursor (statusbar, gimage->width, gimage->height);
text = gtk_label_get_text (GTK_LABEL (statusbar->cursor_label));
/* one static layout for all displays should be fine */
if (! layout)
layout = gtk_widget_create_pango_layout (statusbar->cursor_label, buffer);
layout = gtk_widget_create_pango_layout (statusbar->cursor_label, text);
else
pango_layout_set_text (layout, buffer, -1);
pango_layout_set_text (layout, text, -1);
pango_layout_get_pixel_size (layout, &cursor_label_width, NULL);
......@@ -359,3 +357,43 @@ gimp_statusbar_resize_cursor (GimpStatusbar *statusbar)
label_frame_size_difference,
-1);
}
static void
gimp_statusbar_set_cursor (GimpStatusbar *statusbar,
gdouble x,
gdouble y)
{
GimpImage *image = statusbar->shell->gdisp->gimage;
GtkTreeModel *model;
GimpUnitStore *store;
gchar buffer[CURSOR_STR_LENGTH];
model = gtk_combo_box_get_model (GTK_COMBO_BOX (statusbar->combo));
store = GIMP_UNIT_STORE (model);
gimp_unit_store_set_pixel_values (store, x, y);
if (image->unit == GIMP_UNIT_PIXEL)
{
g_snprintf (buffer, sizeof (buffer), statusbar->cursor_format_str,
"", ROUND (x), ", ", ROUND (y));
}
else /* show real world units */
{
gimp_unit_store_get_values (store, image->unit, &x, &y);
g_snprintf (buffer, sizeof (buffer), statusbar->cursor_format_str,
"", x, ", ", y);
}
gtk_label_set_text (GTK_LABEL (statusbar->cursor_label), buffer);
}
static void
gimp_statusbar_unit_changed (GtkWidget *combo,
GimpStatusbar *statusbar)
{
gimp_image_set_unit (statusbar->shell->gdisp->gimage,
gtk_combo_box_get_active (GTK_COMBO_BOX (combo)));
}
......@@ -47,6 +47,7 @@ struct _GimpStatusbar
GtkWidget *cursor_frame;
GtkWidget *cursor_label;
gchar cursor_format_str[CURSOR_FORMAT_LENGTH];
GtkWidget *combo;
GtkWidget *progressbar;
guint progressid;
......
......@@ -206,6 +206,10 @@ libappwidgets_a_sources = \
gimpuimanager.h \
gimpundoeditor.c \
gimpundoeditor.h \
gimpunitcombobox.c \
gimpunitcombobox.h \
gimpunitstore.c \
gimpunitstore.h \
gimpvectorstreeview.c \
gimpvectorstreeview.h \
gimpviewablebutton.c \
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpunitcombobox.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* 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.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "widgets-types.h"
#include "gimpunitcombobox.h"
#include "gimpunitstore.h"
static void gimp_unit_combo_box_init (GimpUnitComboBox *combo);
GType
gimp_unit_combo_box_get_type (void)
{
static GType combo_box_type = 0;
if (!combo_box_type)
{
static const GTypeInfo combo_box_info =
{
sizeof (GimpUnitComboBoxClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpUnitComboBox),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_unit_combo_box_init
};
combo_box_type = g_type_register_static (GTK_TYPE_COMBO_BOX,
"GimpUnitComboBox",
&combo_box_info, 0);
}
return combo_box_type;
}
static void
gimp_unit_combo_box_init (GimpUnitComboBox *combo)
{
GtkCellLayout *layout = GTK_CELL_LAYOUT (combo);
GtkCellRenderer *cell;
cell = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (layout, cell, TRUE);
gtk_cell_layout_set_attributes (layout, cell,
"text", GIMP_UNIT_STORE_UNIT_PLURAL,
NULL);
/* hackedehack ... */
layout = GTK_CELL_LAYOUT (GTK_BIN (combo)->child);
gtk_cell_layout_clear (layout);
cell = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (layout, cell, TRUE);
gtk_cell_layout_set_attributes (layout, cell,
"text", GIMP_UNIT_STORE_UNIT_ABBREVIATION,
NULL);
}
/**
* gimp_unit_combo_box_new:
*
* Return value: a new #GimpUnitComboBox.
**/
GtkWidget *
gimp_unit_combo_box_new (void)
{
GtkWidget *combo_box;
GimpUnitStore *store;
store = gimp_unit_store_new (0);
combo_box = g_object_new (GIMP_TYPE_UNIT_COMBO_BOX,
"model", store,
NULL);
g_object_unref (store);
return combo_box;
}
/**
* gimp_unit_combo_box_new_with_model:
* @model: a GimpUnitStore
*
* Return value: a new #GimpUnitComboBox.
**/
GtkWidget *
gimp_unit_combo_box_new_with_model (GimpUnitStore *model)
{
return g_object_new (GIMP_TYPE_UNIT_COMBO_BOX,
"model", model,
NULL);
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpunitcombobox.h
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* 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.
*/
#ifndef __GIMP_UNIT_COMBO_BOX_H__
#define __GIMP_UNIT_COMBO_BOX_H__
#include <gtk/gtkcombobox.h>
#define GIMP_TYPE_UNIT_COMBO_BOX (gimp_unit_combo_box_get_type ())
#define GIMP_UNIT_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_UNIT_COMBO_BOX, GimpUnitComboBox))
#define GIMP_UNIT_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_UNIT_COMBO_BOX, GimpUnitComboBoxClass))
#define GIMP_IS_UNIT_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_UNIT_COMBO_BOX))
#define GIMP_IS_UNIT_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_UNIT_COMBO_BOX))
#define GIMP_UNIT_COMBO_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_UNIT_COMBO_BOX, GimpUnitComboBoxClass))
typedef struct _GimpUnitComboBoxClass GimpUnitComboBoxClass;
struct _GimpUnitComboBoxClass
{
GtkComboBoxClass parent_instance;
};
struct _GimpUnitComboBox
{
GtkComboBox parent_instance;
};
GType gimp_unit_combo_box_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_unit_combo_box_new (void);
GtkWidget * gimp_unit_combo_box_new_with_model (GimpUnitStore *model);
#endif /* __GIMP_UNIT_COMBO_BOX_H__ */
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpunitstore.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* 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.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "config/gimpconfig-types.h"
#include "gimpunitstore.h"
enum
{
PROP_0,
PROP_NUM_VALUES
};
static GType column_types[GIMP_UNIT_STORE_UNIT_COLUMNS] =
{
G_TYPE_INVALID,
G_TYPE_DOUBLE,
G_TYPE_INT,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING
};
static void gimp_unit_store_class_init (GimpUnitStoreClass *klass);
static void gimp_unit_store_tree_model_init (GtkTreeModelIface *iface);
static void gimp_unit_store_finalize (GObject *object);
static void gimp_unit_store_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_unit_store_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static GtkTreeModelFlags gimp_unit_store_get_flags (GtkTreeModel *tree_model);
static gint gimp_unit_store_get_n_columns (GtkTreeModel *tree_model);
static GType gimp_unit_store_get_column_type (GtkTreeModel *tree_model,
gint index);
static gboolean gimp_unit_store_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreePath *path);
static GtkTreePath *gimp_unit_store_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static void gimp_unit_store_tree_model_get_value (GtkTreeModel *tree_model,
GtkTreeIter *iter,
gint column,
GValue *value);
static gboolean gimp_unit_store_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean gimp_unit_store_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent);
static gboolean gimp_unit_store_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gint gimp_unit_store_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean gimp_unit_store_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent,
gint n);
static gboolean gimp_unit_store_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child);
static GObjectClass *parent_class = NULL;
GType
gimp_unit_store_get_type (void)
{
static GType store_type = 0;
if (!store_type)
{
static const GTypeInfo store_info =
{
sizeof (GimpUnitStoreClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gimp_unit_store_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpUnitStore),
0, /* n_preallocs */
NULL /* instance_init */
};
static const GInterfaceInfo tree_model_info =
{
(GInterfaceInitFunc) gimp_unit_store_tree_model_init,
NULL,
NULL
};
store_type = g_type_register_static (G_TYPE_OBJECT,
"GimpUnitStore",
&store_info, 0);
g_type_add_interface_static (store_type,
GTK_TYPE_TREE_MODEL,
&tree_model_info);
}
return store_type;
}
static void
gimp_unit_store_class_init (GimpUnitStoreClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
column_types[GIMP_UNIT_STORE_UNIT] = GIMP_TYPE_UNIT;
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_unit_store_finalize;
object_class->set_property = gimp_unit_store_set_property;
object_class->get_property = gimp_unit_store_get_property;
g_object_class_install_property (object_class, PROP_NUM_VALUES,
g_param_spec_int ("num-values",
NULL, NULL,
0, G_MAXINT, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
};
static void
gimp_unit_store_tree_model_init (GtkTreeModelIface *iface)
{
iface->get_flags = gimp_unit_store_get_flags;
iface->get_n_columns = gimp_unit_store_get_n_columns;
iface->get_column_type = gimp_unit_store_get_column_type;
iface->get_iter = gimp_unit_store_get_iter;
iface->get_path = gimp_unit_store_get_path;
iface->get_value = gimp_unit_store_tree_model_get_value;
iface->iter_next = gimp_unit_store_iter_next;
iface->iter_children = gimp_unit_store_iter_children;
iface->iter_has_child = gimp_unit_store_iter_has_child;
iface->iter_n_children = gimp_unit_store_iter_n_children;
iface->iter_nth_child = gimp_unit_store_iter_nth_child;
iface->iter_parent = gimp_unit_store_iter_parent;
}
static void
gimp_unit_store_finalize (GObject *object)
{
GimpUnitStore *store = GIMP_UNIT_STORE (object);
if (store->num_values > 0)
{
g_free (store->values);
g_free (store->resolutions);
store->num_values = 0;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_unit_store_set_property (GObject *object,