Commit 47f2a7f8 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

app/config/gimpconfig.[ch] added a reset method to GimpConfigInterface.

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

	* app/config/gimpconfig.[ch]
	* app/config/gimpconfig-utils.[ch]: added a reset method to
	GimpConfigInterface. Added the new function gimp_config_reset()

	* app/text/gimptext.c: added a GimpConfigInterface to GimpText.

	* app/widgets/Makefile.am
	* app/widgets/gimptexteditor.[ch]: new files that hold the simple
	text editor dialog used by the text tool.

	* app/widgets/gimppropwidgets.[ch]: added new widget constructor
	gimp_prop_scale_entry_new().

	* app/tools/gimptexttool.[ch]: replaced old-style ToolOptions with
	a GimpText object. Connect text layers to the text tool by means
	of their GimpText objects. Still work in progress ...
parent bc288a6f
2003-02-01 Sven Neumann <sven@gimp.org>
* app/config/gimpconfig.[ch]
* app/config/gimpconfig-utils.[ch]: added a reset method to
GimpConfigInterface. Added the new function gimp_config_reset()
* app/text/gimptext.c: added a GimpConfigInterface to GimpText.
* app/widgets/Makefile.am
* app/widgets/gimptexteditor.[ch]: new files that hold the simple
text editor dialog used by the text tool.
* app/widgets/gimppropwidgets.[ch]: added new widget constructor
gimp_prop_scale_entry_new().
* app/tools/gimptexttool.[ch]: replaced old-style ToolOptions with
a GimpText object. Connect text layers to the text tool by means
of their GimpText objects. Still work in progress ...
2003-02-01 Sven Neumann <sven@gimp.org>
 
* app/text/gimptextlayer.c (gimp_text_layer_position_layout):
......
......@@ -96,25 +96,67 @@ gimp_config_copy_properties (GObject *src,
for (i = 0; i < n_property_specs; i++)
{
GParamSpec *prop_spec;
GValue value = { 0, };
GParamSpec *prop_spec;
prop_spec = property_specs[i];
if (! (prop_spec->flags & G_PARAM_READWRITE))
continue;
if (prop_spec->flags & G_PARAM_READABLE &&
prop_spec->flags & G_PARAM_WRITABLE)
{
GValue value = { 0, };
g_value_init (&value, prop_spec->value_type);
g_value_init (&value, prop_spec->value_type);
g_object_get_property (src, prop_spec->name, &value);
g_object_set_property (dest, prop_spec->name, &value);
g_object_get_property (src, prop_spec->name, &value);
g_object_set_property (dest, prop_spec->name, &value);
g_value_unset (&value);
}
}
g_free (property_specs);
}
void
gimp_config_reset_properties (GObject *object)
{
GObjectClass *klass;
GParamSpec **property_specs;
guint n_property_specs;
guint i;
g_return_if_fail (G_IS_OBJECT (object));
klass = G_OBJECT_GET_CLASS (object);
g_value_unset (&value);
property_specs = g_object_class_list_properties (klass, &n_property_specs);
if (!property_specs)
return;
for (i = 0; i < n_property_specs; i++)
{
GParamSpec *prop_spec;
prop_spec = property_specs[i];
if (prop_spec->flags & G_PARAM_WRITABLE)
{
GValue value = { 0, };
g_value_init (&value, prop_spec->value_type);
g_param_value_set_default (prop_spec, &value);
g_object_set_property (object, prop_spec->name, &value);
g_value_unset (&value);
}
}
g_free (property_specs);
}
gchar *
gimp_config_build_data_path (const gchar *name)
{
......
......@@ -28,6 +28,7 @@ GList * gimp_config_diff (GObject *a,
GParamFlags flags);
void gimp_config_copy_properties (GObject *src,
GObject *dest);
void gimp_config_reset_properties (GObject *object);
gchar * gimp_config_build_data_path (const gchar *name);
gchar * gimp_config_build_plug_in_path (const gchar *name);
......
......@@ -65,6 +65,7 @@ static gboolean gimp_config_iface_deserialize (GObject *object,
static GObject *gimp_config_iface_duplicate (GObject *object);
static gboolean gimp_config_iface_equal (GObject *a,
GObject *b);
static void gimp_config_iface_reset (GObject *object);
GType
......@@ -101,6 +102,7 @@ gimp_config_iface_init (GimpConfigInterface *gimp_config_iface)
gimp_config_iface->deserialize_property = NULL;
gimp_config_iface->duplicate = gimp_config_iface_duplicate;
gimp_config_iface->equal = gimp_config_iface_equal;
gimp_config_iface->reset = gimp_config_iface_reset;
}
static gboolean
......@@ -173,6 +175,12 @@ gimp_config_iface_equal (GObject *a,
return equal;
}
static void
gimp_config_iface_reset (GObject *object)
{
gimp_config_reset_properties (object);
}
/**
* gimp_config_serialize:
* @object: a #GObject that implements the #GimpConfigInterface.
......@@ -415,7 +423,6 @@ gimp_config_duplicate (GObject *object)
return gimp_config_iface->duplicate (object);
}
/**
* gimp_config_is_equal_to:
* @a: a #GObject that implements the #GimpConfigInterface.
......@@ -446,6 +453,28 @@ gimp_config_is_equal_to (GObject *a,
return gimp_config_iface->equal (a, b);
}
/**
* gimp_config_reset:
* @object: a #GObject that implements the #GimpConfigInterface.
*
* Resets the object to its default state. The default implementation of the
* #GimpConfigInterface only works for objects that are completely defined by
* their properties.
**/
void
gimp_config_reset (GObject *object)
{
GimpConfigInterface *gimp_config_iface;
g_return_if_fail (G_IS_OBJECT (object));
gimp_config_iface = GIMP_GET_CONFIG_INTERFACE (object);
g_return_if_fail (gimp_config_iface != NULL);
return gimp_config_iface->reset (object);
}
/*
* Code to store and lookup unknown tokens (string key/value pairs).
......
......@@ -62,6 +62,7 @@ struct _GimpConfigInterface
GObject * (* duplicate) (GObject *object);
gboolean (* equal) (GObject *a,
GObject *b);
void (* reset) (GObject *object);
};
typedef void (* GimpConfigForeachFunc) (const gchar *key,
......@@ -89,6 +90,7 @@ gboolean gimp_config_deserialize_return (GScanner *scanner,
GObject * gimp_config_duplicate (GObject *object);
gboolean gimp_config_is_equal_to (GObject *a,
GObject *b);
void gimp_config_reset (GObject *object);
void gimp_config_add_unknown_token (GObject *object,
const gchar *key,
......
......@@ -28,6 +28,7 @@
#include "text/text-types.h"
#include "config/gimpconfig.h"
#include "config/gimpconfig-params.h"
#include "gimptext.h"
......@@ -81,9 +82,19 @@ gimp_text_get_type (void)
0, /* n_preallocs */
NULL /* instance_init */
};
static const GInterfaceInfo text_iface_info =
{
NULL, /* iface_init */
NULL, /* iface_finalize */
NULL /* iface_data */
};
text_type = g_type_register_static (G_TYPE_OBJECT,
"GimpText", &text_info, 0);
g_type_add_interface_static (text_type,
GIMP_TYPE_CONFIG_INTERFACE,
&text_iface_info);
}
return text_type;
......@@ -108,7 +119,7 @@ gimp_text_class_init (GimpTextClass *klass)
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_TEXT,
"text", NULL,
NULL,
"GIMP",
0);
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_FONT,
"font", NULL,
......@@ -116,7 +127,7 @@ gimp_text_class_init (GimpTextClass *klass)
0);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_FONT_SIZE,
"font-size", NULL,
0.0, G_MAXFLOAT, 18.0,
0.0, 1024.0, 18.0,
0);
GIMP_CONFIG_INSTALL_PROP_UNIT (object_class, PROP_FONT_SIZE_UNIT,
"font-size-unit", NULL,
......
......@@ -381,8 +381,8 @@ gimp_text_layer_position_layout (GimpTextLayer *layer,
pos->height += 2 * text->border;
}
pos->x = - ink.x;
pos->y = - ink.y;
pos->x = 0;
pos->y = 0;
if (!fixed)
return TRUE;
......
This diff is collapsed.
......@@ -41,9 +41,7 @@ struct _GimpTextTool
GimpDisplay *gdisp;
GimpText *text;
GtkTextBuffer *buffer;
GtkWidget *editor;
GtkWidget *filesel;
};
struct _GimpTextToolClass
......
......@@ -141,6 +141,8 @@ libappwidgets_a_sources = \
gimppropwidgets.h \
gimpselectioneditor.c \
gimpselectioneditor.h \
gimptexteditor.c \
gimptexteditor.h \
gimptoolbox.c \
gimptoolbox.h \
gimptoolbox-color-area.c \
......
......@@ -382,6 +382,53 @@ gimp_prop_spin_button_new (GObject *config,
return spinbutton;
}
void
gimp_prop_scale_entry_new (GObject *config,
const gchar *property_name,
GtkTable *table,
gint column,
gint row,
const gchar *text,
gdouble step_increment,
gdouble page_increment,
gint digits)
{
GtkWidget *label;
GtkWidget *scale;
GtkWidget *spinbutton;
GtkAdjustment *adj;
label = gtk_label_new_with_mnemonic (text);
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label,
column, column + 1, row, row + 1,
GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (label);
spinbutton = gimp_prop_spin_button_new (config, property_name,
step_increment, page_increment,
digits);
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 4 + digits);
gtk_table_attach (GTK_TABLE (table), spinbutton,
column + 2, column + 3, row, row + 1,
GTK_SHRINK, GTK_SHRINK, 0, 0);
gtk_widget_show (spinbutton);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spinbutton));
scale = gtk_hscale_new (adj);
gtk_scale_set_digits (GTK_SCALE (scale), digits);
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
gtk_table_attach (GTK_TABLE (table), scale,
column + 1, column + 2, row, row + 1,
GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
gtk_widget_show (scale);
}
static void
gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
GObject *config)
......
......@@ -49,6 +49,15 @@ GtkWidget * gimp_prop_spin_button_new (GObject *config,
gdouble step_increment,
gdouble page_increment,
gint digits);
void gimp_prop_scale_entry_new (GObject *config,
const gchar *property_name,
GtkTable *table,
gint column,
gint row,
const gchar *text,
gdouble step_increment,
gdouble page_increment,
gint digits);
/* GimpParamMemsize */
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpTextEditor
* Copyright (C) 2002-2003 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets/gimptexteditor.h"
#include "libgimp/gimpintl.h"
typedef struct _TextEditorData TextEditorData;
struct _TextEditorData
{
GtkTextBuffer *buffer;
GtkWidget *editor;
GtkWidget *filesel;
GimpTextEditorCallback callback;
gpointer callback_data;
};
static void gimp_text_editor_ok (TextEditorData *data);
static void gimp_text_editor_cancel (TextEditorData *data);
static void gimp_text_editor_load (GtkWidget *widget,
TextEditorData *data);
static void gimp_text_editor_load_ok (TextEditorData *data);
static gboolean gimp_text_editor_load_file (GtkTextBuffer *buffer,
const gchar *filename);
static void gimp_text_editor_clear (GtkWidget *widget,
TextEditorData *data);
GtkWidget *
gimp_text_editor_new (GtkTextBuffer *buffer,
const gchar *title,
GimpTextEditorCallback callback,
gpointer callback_data)
{
GtkWidget *editor;
GtkWidget *toolbar;
GtkWidget *scrolled_window;
GtkWidget *text_view;
TextEditorData *data;
data = g_new0 (TextEditorData, 1);
editor = gimp_dialog_new (title, "text_editor",
gimp_standard_help_func,
"dialogs/text_editor.html",
GTK_WIN_POS_NONE,
FALSE, TRUE, FALSE,
GTK_STOCK_CANCEL, gimp_text_editor_cancel,
NULL, data, NULL, TRUE, TRUE,
GTK_STOCK_OK, gimp_text_editor_ok,
NULL, data, NULL, TRUE, TRUE,
NULL);
data->buffer = buffer;
data->editor = editor;
data->callback = callback;
data->callback_data = callback_data;
g_object_weak_ref (G_OBJECT (editor), (GWeakNotify) g_free, data);
gtk_dialog_set_has_separator (GTK_DIALOG (editor), FALSE);
toolbar = gtk_toolbar_new ();
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (editor)->vbox),
toolbar, FALSE, FALSE, 0);
gtk_widget_show (toolbar);
gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar), GTK_STOCK_OPEN,
_("Load Text from File"), NULL,
G_CALLBACK (gimp_text_editor_load), data,
0);
gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar), GTK_STOCK_CLEAR,
_("Clear all Text"), NULL,
G_CALLBACK (gimp_text_editor_clear), data,
1);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 4);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (editor)->vbox),
scrolled_window, TRUE, TRUE, 0);
gtk_widget_show (scrolled_window);
text_view = gtk_text_view_new_with_buffer (buffer);
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
gtk_widget_show (text_view);
return editor;
}
static void
gimp_text_editor_response (TextEditorData *data,
GtkResponseType response)
{
if (data->callback)
data->callback (data->editor, response, data->callback_data);
}
static void
gimp_text_editor_ok (TextEditorData *data)
{
gimp_text_editor_response (data, GTK_RESPONSE_OK);
}
static void
gimp_text_editor_cancel (TextEditorData *data)
{
gimp_text_editor_response (data, GTK_RESPONSE_CANCEL);
}
static void
gimp_text_editor_load (GtkWidget *widget,
TextEditorData *data)
{
GtkFileSelection *filesel;
if (data->filesel)
{
gtk_window_present (GTK_WINDOW (data->filesel));
return;
}
filesel =
GTK_FILE_SELECTION (gtk_file_selection_new (_("Open Text File (UTF-8)")));
gtk_window_set_wmclass (GTK_WINDOW (filesel), "gimp-text-load-file", "Gimp");
gtk_window_set_position (GTK_WINDOW (filesel), GTK_WIN_POS_MOUSE);
gtk_container_set_border_width (GTK_CONTAINER (filesel), 2);
gtk_container_set_border_width (GTK_CONTAINER (filesel->button_area), 2);
gtk_window_set_transient_for (GTK_WINDOW (filesel),
GTK_WINDOW (data->editor));
gtk_window_set_destroy_with_parent (GTK_WINDOW (filesel), TRUE);
g_signal_connect_swapped (filesel->ok_button, "clicked",
G_CALLBACK (gimp_text_editor_load_ok),
data);
g_signal_connect_swapped (filesel->cancel_button, "clicked",
G_CALLBACK (gtk_widget_destroy),
filesel);
data->filesel = GTK_WIDGET (filesel);
g_object_add_weak_pointer (G_OBJECT (filesel), (gpointer) &data->filesel);
gtk_widget_show (GTK_WIDGET (filesel));
}
static void
gimp_text_editor_load_ok (TextEditorData *data)
{
const gchar *filename;
filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (data->filesel));
if (gimp_text_editor_load_file (data->buffer, filename))
gtk_widget_destroy (data->filesel);
}
static gboolean
gimp_text_editor_load_file (GtkTextBuffer *buffer,
const gchar *filename)
{
FILE *file;
gchar buf[2048];
gint remaining = 0;
GtkTextIter iter;
file = fopen (filename, "r");
if (!file)
{
g_message (_("Error opening file '%s': %s"),
filename, g_strerror (errno));
return FALSE;
}
gtk_text_buffer_set_text (buffer, "", 0);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
while (!feof (file))
{
const char *leftover;
gint count;
gint to_read = sizeof (buf) - remaining - 1;
count = fread (buf + remaining, 1, to_read, file);
buf[count + remaining] = '\0';
g_utf8_validate (buf, count + remaining, &leftover);
gtk_text_buffer_insert (buffer, &iter, buf, leftover - buf);
remaining = (buf + remaining + count) - leftover;
g_memmove (buf, leftover, remaining);
if (remaining > 6 || count < to_read)
break;
}
if (remaining)
g_message (_("Invalid UTF-8 data in file '%s'."), filename);
return TRUE;
}
static void
gimp_text_editor_clear (GtkWidget *widget,
TextEditorData *data)
{
gtk_text_buffer_set_text (data->buffer, "", 0);
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpTextEditor
* Copyright (C) 2002-2003 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_TEXT_EDITOR_H__
#define __GIMP_TEXT_EDITOR_H__
typedef void (* GimpTextEditorCallback) (GtkWidget *editor,
GtkResponseType response,
gpointer data);
GtkWidget * gimp_text_editor_new (GtkTextBuffer *buffer,
const gchar *title,