Commit a93e91f3 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

themes/Default/images/Makefile.am

2003-03-31  Sven Neumann  <sven@gimp.org>

	* themes/Default/images/Makefile.am
	* themes/Default/images/stock-text-dir-ltr-24.png
	* themes/Default/images/stock-text-dir-rtl-24.png: placeholders
	for new icons.

	* libgimpwidgets/gimpstock.[ch]: register the new icons.

	* themes/Default/gtkrc: tweak GtkDialog in "gimp-default-style".

	* app/text/text-enums.[ch]
	* app/text/gimptext.[ch]
	* app/text/gimptextlayout.c: added new enum GimpTextDirection and
	use it instead of PangoDirection.

	* app/widgets/widgets-types.h
	* app/widgets/gimptexteditor.[ch]: made GimpTextEditor a real widget
	and added buttons to switch the text direction.

	* app/tools/gimptextoptions.[ch]
	* app/tools/gimptexttool.c: moved creation of the text editor to the
	text tool options, take care of GimpText::base-direction here.
parent 056f5ce5
2003-03-31 Sven Neumann <sven@gimp.org>
* themes/Default/images/Makefile.am
* themes/Default/images/stock-text-dir-ltr-24.png
* themes/Default/images/stock-text-dir-rtl-24.png: placeholders
for new icons.
* libgimpwidgets/gimpstock.[ch]: register the new icons.
* themes/Default/gtkrc: tweak GtkDialog in "gimp-default-style".
* app/text/text-enums.[ch]
* app/text/gimptext.[ch]
* app/text/gimptextlayout.c: added new enum GimpTextDirection and
use it instead of PangoDirection.
* app/widgets/widgets-types.h
* app/widgets/gimptexteditor.[ch]: made GimpTextEditor a real widget
and added buttons to switch the text direction.
* app/tools/gimptextoptions.[ch]
* app/tools/gimptexttool.c: moved creation of the text editor to the
text tool options, take care of GimpText::base-direction here.
2003-03-31 Jakub Steiner <jimmac@ximian.com>
* themes/Default/images/stock-list-16.png:
......@@ -173,8 +173,8 @@ gimp_text_class_init (GimpTextClass *klass)
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_BASE_DIR,
"base-direction",
NULL,
PANGO_TYPE_DIRECTION,
PANGO_DIRECTION_LTR,
GIMP_TYPE_TEXT_DIRECTION,
GIMP_TEXT_DIRECTION_LTR,
0);
GIMP_CONFIG_INSTALL_PROP_COLOR (object_class, PROP_COLOR,
"color", NULL,
......
......@@ -44,7 +44,7 @@ struct _GimpText
gboolean autohint;
gboolean antialias;
gchar *language;
gint base_dir; /* actually a PangoDirection */
GimpTextDirection base_dir;
GimpRGB color;
GimpTextJustification justify;
gdouble indent;
......
......@@ -375,7 +375,15 @@ gimp_text_get_pango_context (GimpText *text,
pango_context_set_language (context,
pango_language_from_string (text->language));
pango_context_set_base_dir (context, text->base_dir);
switch (text->base_dir)
{
case GIMP_TEXT_DIRECTION_LTR:
pango_context_set_base_dir (context, PANGO_DIRECTION_LTR);
break;
case GIMP_TEXT_DIRECTION_RTL:
pango_context_set_base_dir (context, PANGO_DIRECTION_RTL);
break;
}
return context;
}
......@@ -8,6 +8,25 @@
/* enumerations from "./text-enums.h" */
static const GEnumValue gimp_text_direction_enum_values[] =
{
{ GIMP_TEXT_DIRECTION_LTR, N_("From Left to Right"), "ltr" },
{ GIMP_TEXT_DIRECTION_RTL, N_("From Right to Left"), "rtl" },
{ 0, NULL, NULL }
};
GType
gimp_text_direction_get_type (void)
{
static GType enum_type = 0;
if (!enum_type)
enum_type = g_enum_register_static ("GimpTextDirection", gimp_text_direction_enum_values);
return enum_type;
}
static const GEnumValue gimp_text_justification_enum_values[] =
{
{ GIMP_TEXT_JUSTIFY_LEFT, N_("Left Justified"), "left" },
......
......@@ -20,6 +20,17 @@
#define __TEXT_ENUMS_H__
#define GIMP_TYPE_TEXT_DIRECTION (gimp_text_direction_get_type ())
GType gimp_text_direction_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_TEXT_DIRECTION_LTR, /*< desc="From Left to Right" >*/
GIMP_TEXT_DIRECTION_RTL /*< desc="From Right to Left" >*/
} GimpTextDirection;
#define GIMP_TYPE_TEXT_JUSTIFICATION (gimp_text_justification_get_type ())
GType gimp_text_justification_get_type (void) G_GNUC_CONST;
......
......@@ -316,6 +316,54 @@ gimp_text_options_gui (GimpToolOptions *tool_options)
return vbox;
}
static void
gimp_text_options_dir_changed (GimpTextEditor *editor,
GimpText *text)
{
g_object_set (text,
"base-direction", editor->base_dir,
NULL);
}
static void
gimp_text_options_notify_dir (GimpText *text,
GParamSpec *pspec,
GimpTextEditor *editor)
{
GimpTextDirection dir;
g_object_get (text,
"base-direction", &dir,
NULL);
gimp_text_editor_set_direction (editor, dir);
}
GtkWidget *
gimp_text_options_editor_new (GimpTextOptions *options,
const gchar *title)
{
GtkWidget *editor;
g_return_val_if_fail (GIMP_IS_TEXT_OPTIONS (options), NULL);
editor = gimp_text_editor_new (title, options->buffer);
gimp_text_editor_set_direction (GIMP_TEXT_EDITOR (editor),
options->text->base_dir);
g_signal_connect_object (editor, "dir_changed",
G_CALLBACK (gimp_text_options_dir_changed),
options->text, 0);
g_signal_connect_object (options->text, "notify::base-direction",
G_CALLBACK (gimp_text_options_notify_dir),
editor, 0);
return editor;
}
static void
gimp_text_options_font_clicked (GtkWidget *widget,
GimpContext *context)
......
......@@ -43,9 +43,12 @@ struct _GimpTextOptions
};
GType gimp_text_options_get_type (void) G_GNUC_CONST;
GType gimp_text_options_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_text_options_gui (GimpToolOptions *tool_options);
GtkWidget * gimp_text_options_gui (GimpToolOptions *tool_options);
GtkWidget * gimp_text_options_editor_new (GimpTextOptions *options,
const gchar *title);
#endif /* __GIMP_TEXT_OPTIONS_H__ */
......@@ -44,7 +44,6 @@
#include "widgets/gimpfontselection.h"
#include "widgets/gimppropwidgets.h"
#include "widgets/gimptexteditor.h"
#include "widgets/gimpwidgets-utils.h"
#include "display/gimpdisplay.h"
......@@ -366,8 +365,8 @@ gimp_text_tool_editor (GimpTextTool *text_tool)
options = GIMP_TEXT_OPTIONS (GIMP_TOOL (text_tool)->tool_info->tool_options);
text_tool->editor = gimp_text_editor_new (_("GIMP Text Editor"),
options->buffer);
text_tool->editor = gimp_text_options_editor_new (options,
_("GIMP Text Editor"));
g_object_add_weak_pointer (G_OBJECT (text_tool->editor),
(gpointer *) &text_tool->editor);
......
......@@ -30,77 +30,201 @@
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets/gimptexteditor.h"
#include "widgets-types.h"
#include "gimp-intl.h"
#include "core/gimpmarshal.h"
#include "gimpenummenu.h"
#include "gimptexteditor.h"
#include "gimp-intl.h"
typedef struct _TextEditorData TextEditorData;
struct _TextEditorData
enum
{
GtkTextBuffer *buffer;
GtkWidget *editor;
GtkWidget *filesel;
DIR_CHANGED,
LAST_SIGNAL
};
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);
static void gimp_text_editor_class_init (GimpTextEditorClass *klass);
static void gimp_text_editor_init (GimpTextEditor *editor);
static void gimp_text_editor_dispose (GObject *object);
static void gimp_text_editor_dir_changed (GtkWidget *widget,
GimpTextEditor *editor);
static void gimp_text_editor_load (GtkWidget *widget,
GimpTextEditor *editor);
static void gimp_text_editor_load_ok (GimpTextEditor *editor);
static gboolean gimp_text_editor_load_file (GtkTextBuffer *buffer,
const gchar *filename);
static void gimp_text_editor_clear (GtkWidget *widget,
GimpTextEditor *editor);
static GimpDialogClass *parent_class = NULL;
static guint text_editor_signals[LAST_SIGNAL] = { 0 };
GType
gimp_text_editor_get_type (void)
{
static GType type = 0;
if (! type)
{
static const GTypeInfo info =
{
sizeof (GimpTextEditorClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gimp_text_editor_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpTextEditor),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_text_editor_init,
};
type = g_type_register_static (GIMP_TYPE_DIALOG,
"GimpTextEditor",
&info, 0);
}
return type;
}
static void
gimp_text_editor_class_init (GimpTextEditorClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
text_editor_signals[DIR_CHANGED] =
g_signal_new ("dir_changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpTextEditorClass, dir_changed),
NULL, NULL,
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->dispose = gimp_text_editor_dispose;
klass->dir_changed = NULL;
}
static void
gimp_text_editor_init (GimpTextEditor *editor)
{
editor->buffer = NULL;
editor->view = NULL;
editor->group = NULL;
editor->filesel = NULL;
switch (gtk_widget_get_default_direction ())
{
case GTK_TEXT_DIR_NONE:
case GTK_TEXT_DIR_LTR:
editor->base_dir = GIMP_TEXT_DIRECTION_LTR;
break;
case GTK_TEXT_DIR_RTL:
editor->base_dir = GIMP_TEXT_DIRECTION_RTL;
break;
}
}
static void
gimp_text_editor_dispose (GObject *object)
{
GimpTextEditor *editor = GIMP_TEXT_EDITOR (object);
if (editor->buffer)
{
g_object_unref (editor->buffer);
editor->buffer = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
GtkWidget *
gimp_text_editor_new (const gchar *title,
GtkTextBuffer *buffer)
{
GtkWidget *editor;
GtkWidget *toolbar;
GimpTextEditor *editor;
GtkToolbar *toolbar;
GtkWidget *scrolled_window;
GtkWidget *text_view;
TextEditorData *data;
GtkWidget *box;
GtkWidget *button;
GList *children;
GList *list;
g_return_val_if_fail (title != NULL, NULL);
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
editor = gimp_dialog_new (title, "text_editor",
gimp_standard_help_func,
"dialogs/text_editor.html",
GTK_WIN_POS_NONE,
FALSE, TRUE, FALSE,
GTK_STOCK_CLOSE, gtk_widget_destroy,
NULL, 1, NULL, TRUE, TRUE,
NULL);
data = g_new0 (TextEditorData, 1);
editor = g_object_new (GIMP_TYPE_TEXT_EDITOR,
"title", title,
NULL);
data->buffer = buffer;
data->editor = editor;
gtk_window_set_wmclass (GTK_WINDOW (editor), "text_editor", "Gimp");
gimp_help_connect (GTK_WIDGET (editor),
gimp_standard_help_func, "dialogs/text_editor.html");
g_object_weak_ref (G_OBJECT (editor), (GWeakNotify) g_free, data);
gimp_dialog_create_action_area (GIMP_DIALOG (editor),
GTK_STOCK_CLOSE, gtk_widget_destroy,
NULL, 1, NULL, TRUE, TRUE,
NULL);
gtk_dialog_set_has_separator (GTK_DIALOG (editor), FALSE);
toolbar = gtk_toolbar_new ();
toolbar = GTK_TOOLBAR (gtk_toolbar_new ());
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (editor)->vbox),
toolbar, FALSE, FALSE, 0);
gtk_widget_show (toolbar);
GTK_WIDGET (toolbar), FALSE, FALSE, 0);
gtk_widget_show (GTK_WIDGET (toolbar));
gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar), GTK_STOCK_OPEN,
gtk_toolbar_insert_stock (toolbar, GTK_STOCK_OPEN,
_("Load Text from File"), NULL,
G_CALLBACK (gimp_text_editor_load), data,
G_CALLBACK (gimp_text_editor_load), editor,
0);
gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar), GTK_STOCK_CLEAR,
gtk_toolbar_insert_stock (toolbar, GTK_STOCK_CLEAR,
_("Clear all Text"), NULL,
G_CALLBACK (gimp_text_editor_clear), data,
G_CALLBACK (gimp_text_editor_clear), editor,
1);
gtk_toolbar_append_space (toolbar);
box = gimp_enum_stock_box_new (GIMP_TYPE_TEXT_DIRECTION,
"gimp-text-dir",
gtk_toolbar_get_icon_size (toolbar),
G_CALLBACK (gimp_text_editor_dir_changed),
editor,
&editor->group);
gimp_radio_group_set_active (GTK_RADIO_BUTTON (editor->group),
GINT_TO_POINTER (editor->base_dir));
children = gtk_container_get_children (GTK_CONTAINER (box));
for (list = children; list; list = g_list_next (list))
{
button = GTK_WIDGET (list->data);
g_object_ref (button);
gtk_container_remove (GTK_CONTAINER (box), button);
gtk_toolbar_append_widget (toolbar, button, NULL, NULL);
}
g_list_free (children);
gtk_widget_destroy (box);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
......@@ -110,24 +234,82 @@ gimp_text_editor_new (const gchar *title,
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);
editor->buffer = g_object_ref (buffer);
editor->view = gtk_text_view_new_with_buffer (buffer);
gtk_container_add (GTK_CONTAINER (scrolled_window), editor->view);
gtk_widget_show (editor->view);
switch (editor->base_dir)
{
case GIMP_TEXT_DIRECTION_LTR:
gtk_widget_set_direction (editor->view, GTK_TEXT_DIR_LTR);
break;
case GIMP_TEXT_DIRECTION_RTL:
gtk_widget_set_direction (editor->view, GTK_TEXT_DIR_RTL);
break;
}
gtk_widget_set_size_request (editor->view, 128, 64);
return GTK_WIDGET (editor);
}
void
gimp_text_editor_set_direction (GimpTextEditor *editor,
GimpTextDirection base_dir)
{
g_return_if_fail (GIMP_IS_TEXT_EDITOR (editor));
if (editor->base_dir == base_dir)
return;
editor->base_dir = base_dir;
g_signal_handlers_block_by_func (editor->group,
G_CALLBACK (gimp_text_editor_dir_changed),
editor);
gimp_radio_group_set_active (GTK_RADIO_BUTTON (editor->group),
GINT_TO_POINTER (base_dir));
gtk_widget_set_size_request (text_view, 128, 64);
g_signal_handlers_unblock_by_func (editor->group,
G_CALLBACK (gimp_text_editor_dir_changed),
editor);
switch (editor->base_dir)
{
case GIMP_TEXT_DIRECTION_LTR:
gtk_widget_set_direction (editor->view, GTK_TEXT_DIR_LTR);
break;
case GIMP_TEXT_DIRECTION_RTL:
gtk_widget_set_direction (editor->view, GTK_TEXT_DIR_RTL);
break;
}
g_signal_emit (editor, text_editor_signals[DIR_CHANGED], 0);
}
static void
gimp_text_editor_dir_changed (GtkWidget *widget,
GimpTextEditor *editor)
{
GimpTextDirection dir;
dir = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
"gimp-item-data"));
return editor;
gimp_text_editor_set_direction (editor, dir);
}
static void
gimp_text_editor_load (GtkWidget *widget,
TextEditorData *data)
GimpTextEditor *editor)
{
GtkFileSelection *filesel;
if (data->filesel)
if (editor->filesel)
{
gtk_window_present (GTK_WINDOW (data->filesel));
gtk_window_present (GTK_WINDOW (editor->filesel));
return;
}
......@@ -140,32 +322,32 @@ gimp_text_editor_load (GtkWidget *widget,
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_transient_for (GTK_WINDOW (filesel), GTK_WINDOW (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);
editor);
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);
editor->filesel = GTK_WIDGET (filesel);
g_object_add_weak_pointer (G_OBJECT (filesel), (gpointer) &editor->filesel);
gtk_widget_show (GTK_WIDGET (filesel));
}
static void
gimp_text_editor_load_ok (TextEditorData *data)
gimp_text_editor_load_ok (GimpTextEditor *editor)
{
const gchar *filename;
filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (data->filesel));
filename =
gtk_file_selection_get_filename (GTK_FILE_SELECTION (editor->filesel));
if (gimp_text_editor_load_file (data->buffer, filename))
gtk_widget_destroy (data->filesel);
if (gimp_text_editor_load_file (editor->buffer, filename))
gtk_widget_destroy (editor->filesel);
}
static gboolean
......@@ -217,7 +399,7 @@ gimp_text_editor_load_file (GtkTextBuffer *buffer,
static void
gimp_text_editor_clear (GtkWidget *widget,
TextEditorData *data)
GimpTextEditor *editor)
{
gtk_text_buffer_set_text (data->buffer, "", 0);
gtk_text_buffer_set_text (editor->buffer, "", 0);
}
......@@ -23,8 +23,39 @@
#define __GIMP_TEXT_EDITOR_H__
GtkWidget * gimp_text_editor_new (const gchar *title,
GtkTextBuffer *buffer);
#define GIMP_TYPE_TEXT_EDITOR (gimp_text_editor_get_type ())
#define GIMP_TEXT_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TEXT_EDITOR, GimpTextEditor))
#define GIMP_IS_TEXT_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TEXT_EDITOR))
typedef struct _GimpTextEditorClass GimpTextEditorClass;
struct _GimpTextEditor
{
GimpDialog parent_instance;
GimpTextDirection base_dir;
/*< private >*/
GtkTextBuffer *buffer;
GtkWidget *group;
GtkWidget *view;
GtkWidget *filesel;
};
struct _GimpTextEditorClass
{
GimpDialogClass parent_class;
void (* dir_changed) (GimpTextEditor *editor);
};
GType gimp_text_editor_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_text_editor_new (const gchar *title,
GtkTextBuffer *buffer);
void gimp_text_editor_set_direction (GimpTextEditor *editor,
GimpTextDirection base_dir);
#endif /* __GIMP_TEXT_EDITOR_H__ */
......@@ -103,6 +103,8 @@ typedef struct _GimpFontSelectionDialog GimpFontSelectionDialog;
typedef struct _GimpHistogramView GimpHistogramView;
typedef struct _GimpHistogramBox GimpHistogramBox;
typedef struct _GimpTextEditor GimpTextEditor;
/* structs */
......
......@@ -141,6 +141,8 @@ static GtkStockItem gimp_stock_items[] =
{ GIMP_STOCK_CHAR_PICKER, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_LETTER_SPACING, N_("L_etter Spacing"), 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_LINE_SPACING, N_("L_ine Spacing"), 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_TEXT_DIR_LTR, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_TEXT_DIR_RTL, NULL, 0, 0, LIBGIMP_DOMAIN },