Commit 8f7f7a21 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

libgimpwidgets/Makefile.am made GimpMemsizeEntry a widget which doesn't

2003-01-05  Sven Neumann  <sven@gimp.org>

	* libgimpwidgets/Makefile.am
	* libgimpwidgets/gimpmemsizeentry.[ch]: made GimpMemsizeEntry a
	widget which doesn't use a GtkAdjustment to store the value.  The
	latter caused problems on 64bit machines since a gdouble doesn't
	provide enough precision for G_MAXULONG.

	* libgimpwidgets/gimpwidgets.[ch]
	* libgimpwidgets/gimpwidgetstypes.h
	* app/widgets/gimppropwidgets.c: changed accordingly.
parent 5dcf8da0
2003-01-05 Sven Neumann <sven@gimp.org>
* libgimpwidgets/Makefile.am
* libgimpwidgets/gimpmemsizeentry.[ch]: made GimpMemsizeEntry a
widget which doesn't use a GtkAdjustment to store the value. The
latter caused problems on 64bit machines since a gdouble doesn't
provide enough precision for G_MAXULONG.
* libgimpwidgets/gimpwidgets.[ch]
* libgimpwidgets/gimpwidgetstypes.h
* app/widgets/gimppropwidgets.c: changed accordingly.
2003-01-05 Sven Neumann <sven@gimp.org>
 
* app/core/gimpimage-merge.c (gimp_image_merge_layers): redid the
......
......@@ -442,46 +442,6 @@ gimp_prop_spin_button_new (GObject *config,
return spinbutton;
}
GtkWidget *
gimp_prop_memsize_entry_new (GObject *config,
const gchar *property_name)
{
GParamSpec *param_spec;
GParamSpecULong *ulong_spec;
GtkObject *adjustment;
GtkWidget *entry;
guint value;
param_spec = check_param_spec (config, property_name,
GIMP_TYPE_PARAM_MEMSIZE, G_STRLOC);
if (! param_spec)
return NULL;
g_object_get (config,
property_name, &value,
NULL);
ulong_spec = G_PARAM_SPEC_ULONG (param_spec);
adjustment = gtk_adjustment_new (value,
ulong_spec->minimum,
ulong_spec->maximum,
1, 64, 0);
entry = gimp_memsize_entry_new (GTK_ADJUSTMENT (adjustment));
set_param_spec (G_OBJECT (adjustment), param_spec);
g_signal_connect (G_OBJECT (adjustment), "value_changed",
G_CALLBACK (gimp_prop_adjustment_callback),
config);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_adjustment_notify),
adjustment);
return entry;
}
static void
gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
GObject *config)
......@@ -597,6 +557,99 @@ gimp_prop_adjustment_notify (GObject *config,
}
/*************/
/* memsize */
/*************/
static void gimp_prop_memsize_callback (GimpMemsizeEntry *entry,
GObject *config);
static void gimp_prop_memsize_notify (GObject *config,
GParamSpec *param_spec,
GimpMemsizeEntry *entry);
GtkWidget *
gimp_prop_memsize_entry_new (GObject *config,
const gchar *property_name)
{
GParamSpec *param_spec;
GParamSpecULong *ulong_spec;
GtkWidget *entry;
gulong value;
param_spec = check_param_spec (config, property_name,
GIMP_TYPE_PARAM_MEMSIZE, G_STRLOC);
if (! param_spec)
return NULL;
g_object_get (config,
property_name, &value,
NULL);
ulong_spec = G_PARAM_SPEC_ULONG (param_spec);
entry = gimp_memsize_entry_new (value,
ulong_spec->minimum,
ulong_spec->maximum);
set_param_spec (G_OBJECT (entry), param_spec);
g_signal_connect (G_OBJECT (entry), "value_changed",
G_CALLBACK (gimp_prop_memsize_callback),
config);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_memsize_notify),
entry);
return entry;
}
static void
gimp_prop_memsize_callback (GimpMemsizeEntry *entry,
GObject *config)
{
GParamSpec *param_spec;
param_spec = get_param_spec (G_OBJECT (entry));
if (! param_spec)
return;
g_return_if_fail (G_IS_PARAM_SPEC_ULONG (param_spec));
g_object_set (config,
param_spec->name, gimp_memsize_entry_get_value (entry),
NULL);
}
static void
gimp_prop_memsize_notify (GObject *config,
GParamSpec *param_spec,
GimpMemsizeEntry *entry)
{
gulong value;
g_return_if_fail (G_IS_PARAM_SPEC_ULONG (param_spec));
g_object_get (config,
param_spec->name, &value,
NULL);
if (entry->value != value)
{
g_signal_handlers_block_by_func (G_OBJECT (entry),
gimp_prop_memsize_callback,
config);
gimp_memsize_entry_set_value (entry, value);
g_signal_handlers_unblock_by_func (G_OBJECT (entry),
gimp_prop_memsize_callback,
config);
}
}
/***********/
/* entry */
/***********/
......
2003-01-05 Sven Neumann <sven@gimp.org>
* libgimpwidgets/libgimpwidgets-docs.sgml
* libgimpwidgets/libgimpwidgets-sections.txt
* libgimpwidgets/libgimpwidgets.types
* libgimpwidgets/tmpl/gimpmemsizeentry.sgml
* libgimpwidgets/tmpl/gimpwidgets.sgml: added a new file that
documents GimpMemsizeEntry and changed the others accordingly.
2003-01-02 Michael Natterer <mitch@gimp.org>
* libgimpmodule/libgimpmodule-sections.txt
......
......@@ -12,6 +12,7 @@
<!entity GimpDialog SYSTEM "sgml/gimpdialog.sgml">
<!entity GimpFileSelection SYSTEM "sgml/gimpfileselection.sgml">
<!entity GimpHelpUI SYSTEM "sgml/gimphelpui.sgml">
<!entity GimpMemsizeEntry SYSTEM "sgml/gimpmemsizeentry.sgml">
<!entity GimpPathEditor SYSTEM "sgml/gimppatheditor.sgml">
<!entity GimpPickButton SYSTEM "sgml/gimppickbutton.sgml">
<!entity GimpPixmap SYSTEM "sgml/gimppixmap.sgml">
......@@ -34,6 +35,7 @@
&GimpColorButton;
&GimpColorScale;
&GimpFileSelection;
&GimpMemsizeEntry;
&GimpPathEditor;
&GimpPickButton;
&GimpPixmap;
......
......@@ -111,6 +111,23 @@ GIMP_IS_PIXMAP_CLASS
GIMP_PIXMAP_GET_CLASS
</SECTION>
<SECTION>
<FILE>gimpmemsizeentry</FILE>
<TITLE>GimpMemsizeEntry</TITLE>
GimpMemsizeEntry
gimp_memsize_entry_new
gimp_memsize_entry_set_value
gimp_memsize_entry_get_value
<SUBSECTION Standard>
GIMP_MEMSIZE_ENTRY
GIMP_IS_MEMSIZE_ENTRY
GIMP_TYPE_MEMSIZE_ENTRY
gimp_memsize_entry_get_type
GIMP_MEMSIZE_ENTRY_CLASS
GIMP_IS_MEMSIZE_ENTRY_CLASS
GIMP_MEMSIZE_ENTRY_GET_CLASS
</SECTION>
<SECTION>
<FILE>gimpsizeentry</FILE>
<TITLE>GimpSizeEntry</TITLE>
......@@ -369,10 +386,6 @@ GIMP_RANDOM_SEED_SPINBUTTON_ADJ
gimp_random_seed_new
GIMP_COORDINATES_CHAINBUTTON
gimp_coordinates_new
GIMP_MEMSIZE_ENTRY_SPINBUTTON
GIMP_MEMSIZE_ENTRY_SPINBUTTON_ADJ
GIMP_MEMSIZE_ENTRY_OPTIONMENU
gimp_memsize_entry_new
gimp_pixmap_button_new
gimp_toggle_button_sensitive_update
gimp_toggle_button_update
......
......@@ -14,6 +14,7 @@ gimp_color_selector_get_type
gimp_color_select_get_type
gimp_dialog_get_type
gimp_file_selection_get_type
gimp_memsize_entry_get_type
gimp_path_editor_get_type
gimp_pick_button_get_type
gimp_pixmap_get_type
......
<!-- ##### SECTION Title ##### -->
GimpMemsizeEntry
<!-- ##### SECTION Short_Description ##### -->
<!-- ##### SECTION Long_Description ##### -->
<para>
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
</para>
<!-- ##### STRUCT GimpMemsizeEntry ##### -->
<para>
</para>
<!-- ##### FUNCTION gimp_memsize_entry_new ##### -->
<para>
</para>
@value:
@lower:
@upper:
@Returns:
<!-- # Unused Parameters # -->
@adjustment:
<!-- ##### FUNCTION gimp_memsize_entry_set_value ##### -->
<para>
</para>
@entry:
@value:
<!-- ##### FUNCTION gimp_memsize_entry_get_value ##### -->
<para>
</para>
@entry:
@Returns:
<!-- ##### SIGNAL GimpMemsizeEntry::value-changed ##### -->
<para>
</para>
@gimpmemsizeentry: the object which received the signal.
......@@ -412,39 +412,6 @@ Returns the #GimpChainButton which is attached to the #GimpSizeEntry.
@Returns:
<!-- ##### MACRO GIMP_MEMSIZE_ENTRY_SPINBUTTON ##### -->
<para>
</para>
@memsize:
<!-- ##### MACRO GIMP_MEMSIZE_ENTRY_SPINBUTTON_ADJ ##### -->
<para>
</para>
@memsize:
<!-- ##### MACRO GIMP_MEMSIZE_ENTRY_OPTIONMENU ##### -->
<para>
</para>
@memsize:
<!-- ##### FUNCTION gimp_memsize_entry_new ##### -->
<para>
</para>
@adjustment:
@Returns:
<!-- ##### FUNCTION gimp_pixmap_button_new ##### -->
<para>
......
......@@ -86,6 +86,8 @@ libgimpwidgets_1_3_la_sources = \
gimpfileselection.h \
gimphelpui.c \
gimphelpui.h \
gimpmemsizeentry.c \
gimpmemsizeentry.h \
gimpoffsetarea.c \
gimpoffsetarea.h \
gimppatheditor.c \
......
......@@ -87,4 +87,4 @@ gboolean gimp_chain_button_get_active (GimpChainButton *gcb);
G_END_DECLS
#endif /* __CHAIN_BUTTON_H__ */
#endif /* __GIMP_CHAIN_BUTTON_H__ */
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpmemsizeentry.c
* Copyright (C) 2000-2003 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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 Lesser 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.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "gimpwidgetstypes.h"
#include "gimpmemsizeentry.h"
#include "gimpwidgets.h"
#include "libgimp/libgimp-intl.h"
enum
{
VALUE_CHANGED,
LAST_SIGNAL
};
static void gimp_memsize_entry_class_init (GimpMemsizeEntryClass *klass);
static void gimp_memsize_entry_init (GimpMemsizeEntry *entry);
static void gimp_memsize_entry_finalize (GObject *object);
static void gimp_memsize_entry_adj_callback (GtkAdjustment *adj,
GimpMemsizeEntry *entry);
static void gimp_memsize_entry_unit_callback (GtkWidget *widget,
GimpMemsizeEntry *entry);
static guint gimp_memsize_entry_signals[LAST_SIGNAL] = { 0 };
static GtkHBoxClass *parent_class = NULL;
GType
gimp_memsize_entry_get_type (void)
{
static GType entry_type = 0;
if (! entry_type)
{
static const GTypeInfo entry_info =
{
sizeof (GimpMemsizeEntryClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_memsize_entry_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpMemsizeEntry),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_memsize_entry_init,
};
entry_type = g_type_register_static (GTK_TYPE_HBOX, "GimpMemsizeEntry",
&entry_info, 0);
}
return entry_type;
}
static void
gimp_memsize_entry_class_init (GimpMemsizeEntryClass *klass)
{
GObjectClass *object_class;
parent_class = g_type_class_peek_parent (klass);
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gimp_memsize_entry_finalize;
gimp_memsize_entry_signals[VALUE_CHANGED] =
g_signal_new ("value_changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpMemsizeEntryClass, value_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
klass->value_changed = NULL;
}
static void
gimp_memsize_entry_init (GimpMemsizeEntry *entry)
{
entry->value = 0;
entry->lower = 0;
entry->upper = 0;
entry->shift = 0;
entry->adjustment = NULL;
entry->menu = NULL;
}
static void
gimp_memsize_entry_finalize (GObject *object)
{
GimpMemsizeEntry *entry = (GimpMemsizeEntry *) object;
if (entry->adjustment)
{
g_object_unref (entry->adjustment);
entry->adjustment = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/**
* gimp_memsize_entry_new:
* @value: the initial value (in Bytes)
* @lower: the lower limit for the value (in Bytes)
* @upper: the upper limit for the value (in Bytes)
*
* Creates a new #GimpMemsizeEntry which is a #GtkHBox with a #GtkSpinButton
* and a #GtkOptionMenu all setup to allow the user to enter memory sizes.
*
* Returns: Pointer to the new #GimpMemsizeEntry.
**/
GtkWidget *
gimp_memsize_entry_new (gulong value,
gulong lower,
gulong upper)
{
GimpMemsizeEntry *entry;
GtkWidget *spinbutton;
guint shift;
g_return_val_if_fail (value >= lower && value <= upper, NULL);
entry = GIMP_MEMSIZE_ENTRY (g_object_new (GIMP_TYPE_MEMSIZE_ENTRY, NULL));
for (shift = 30; shift > 10; shift -= 10)
{
if (value > (1 << shift) && value % (1 << shift) == 0)
break;
}
entry->value = value;
entry->lower = lower;
entry->upper = upper;
entry->shift = shift;
spinbutton = gimp_spin_button_new ((GtkObject **) &entry->adjustment,
value >> shift,
lower >> shift,
upper >> shift, 1, 8, 0, 1, 0);
g_object_ref (entry->adjustment);
gtk_object_sink (GTK_OBJECT (entry->adjustment));
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 10);
gtk_box_pack_start (GTK_BOX (entry), spinbutton, FALSE, FALSE, 0);
gtk_widget_show (spinbutton);
g_signal_connect (G_OBJECT (entry->adjustment), "value_changed",
G_CALLBACK (gimp_memsize_entry_adj_callback),
entry);
entry->menu =
gimp_option_menu_new2 (FALSE,
G_CALLBACK (gimp_memsize_entry_unit_callback),
entry,
GUINT_TO_POINTER (shift),
_("KiloBytes"), GUINT_TO_POINTER (10), NULL,
_("MegaBytes"), GUINT_TO_POINTER (20), NULL,
_("GigaBytes"), GUINT_TO_POINTER (30), NULL,
NULL);
gtk_box_pack_start (GTK_BOX (entry), entry->menu, FALSE, FALSE, 0);
gtk_widget_show (entry->menu);
return GTK_WIDGET (entry);
}
/**
* gimp_memsize_entry_set_value:
* @entry: a #GimpMemsizeEntry
* @value: the new value (in Bytes)
*
* Sets the @entry's value. Please note that the #GimpMemsizeEntry rounds
* the value to full Kilobytes.
**/
void
gimp_memsize_entry_set_value (GimpMemsizeEntry *entry,
gulong value)
{
guint shift;
g_return_if_fail (GIMP_IS_MEMSIZE_ENTRY (entry));
g_return_if_fail (value >= entry->lower && value <= entry->upper);
for (shift = 30; shift > 10; shift -= 10)
{
if (value > (1 << shift) && value % (1 << shift) == 0)
break;
}
if (shift != entry->shift)
{
entry->shift = shift;
gimp_option_menu_set_history (GTK_OPTION_MENU (entry->menu),
GUINT_TO_POINTER (shift));
}
gtk_adjustment_set_value (entry->adjustment, value >> shift);
}
/**
* gimp_memsize_entry_get_value:
* @entry: a #GimpMemsizeEntry
*
* Retrieves the current value from a #GimpMemsizeEntry.
*
* Returns: the current value of @entry (in Bytes).
**/
gulong
gimp_memsize_entry_get_value (GimpMemsizeEntry *entry)
{
g_return_val_if_fail (GIMP_IS_MEMSIZE_ENTRY (entry), 0);
return entry->value;
}
static void
gimp_memsize_entry_adj_callback (GtkAdjustment *adj,
GimpMemsizeEntry *entry)
{
gulong size;
size = gtk_adjustment_get_value (adj);
entry->value = size << entry->shift;
g_signal_emit (G_OBJECT (entry),
gimp_memsize_entry_signals[VALUE_CHANGED], 0);
}
static void
gimp_memsize_entry_unit_callback (GtkWidget *widget,
GimpMemsizeEntry *entry)
{
guint shift = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget),
"gimp-item-data"));
if (shift != entry->shift)
{
entry->shift = shift;