diff --git a/app/tools/gimptexttool-editor.c b/app/tools/gimptexttool-editor.c index 4a4737a711..e4e9fd39ea 100644 --- a/app/tools/gimptexttool-editor.c +++ b/app/tools/gimptexttool-editor.c @@ -30,6 +30,7 @@ #include "tools-types.h" +#include "core/gimp.h" #include "core/gimpimage.h" #include "text/gimptext.h" @@ -160,8 +161,9 @@ gimp_text_tool_editor_start (GimpTextTool *text_tool) if (! text_tool->style_overlay) { - gdouble xres = 1.0; - gdouble yres = 1.0; + Gimp *gimp = GIMP_CONTEXT (options)->gimp; + gdouble xres = 1.0; + gdouble yres = 1.0; text_tool->style_overlay = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (text_tool->style_overlay), @@ -176,7 +178,9 @@ gimp_text_tool_editor_start (GimpTextTool *text_tool) if (text_tool->image) gimp_image_get_resolution (text_tool->image, &xres, &yres); - text_tool->style_editor = gimp_text_style_editor_new (text_tool->buffer, + text_tool->style_editor = gimp_text_style_editor_new (gimp, + text_tool->buffer, + gimp->fonts, xres, yres); gtk_container_add (GTK_CONTAINER (text_tool->style_overlay), text_tool->style_editor); diff --git a/app/widgets/gimptextstyleeditor.c b/app/widgets/gimptextstyleeditor.c index 5c9a116103..27c046ccb3 100644 --- a/app/widgets/gimptextstyleeditor.c +++ b/app/widgets/gimptextstyleeditor.c @@ -24,17 +24,29 @@ #include #include "libgimpbase/gimpbase.h" +#include "libgimpwidgets/gimpwidgets.h" #include "widgets-types.h" +#include "core/gimp.h" +#include "core/gimpcontext.h" + +#include "text/gimpfontlist.h" + +#include "gimpcontainerentry.h" +#include "gimpcontainerview.h" #include "gimptextbuffer.h" #include "gimptextstyleeditor.h" +#include "gimp-intl.h" + enum { PROP_0, + PROP_GIMP, PROP_BUFFER, + PROP_FONTS, PROP_RESOLUTION_X, PROP_RESOLUTION_Y }; @@ -84,6 +96,13 @@ gimp_text_style_editor_class_init (GimpTextStyleEditorClass *klass) object_class->set_property = gimp_text_style_editor_set_property; object_class->get_property = gimp_text_style_editor_get_property; + g_object_class_install_property (object_class, PROP_GIMP, + g_param_spec_object ("gimp", + NULL, NULL, + GIMP_TYPE_GIMP, + GIMP_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_BUFFER, g_param_spec_object ("buffer", NULL, NULL, @@ -91,6 +110,13 @@ gimp_text_style_editor_class_init (GimpTextStyleEditorClass *klass) GIMP_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_FONTS, + g_param_spec_object ("fonts", + NULL, NULL, + GIMP_TYPE_FONT_LIST, + GIMP_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_RESOLUTION_X, g_param_spec_double ("resolution-x", NULL, NULL, @@ -115,11 +141,27 @@ gimp_text_style_editor_init (GimpTextStyleEditor *editor) { GtkWidget *image; + editor->font_entry = gimp_container_entry_new (NULL, NULL, + GIMP_VIEW_SIZE_SMALL, 1); + gtk_box_pack_start (GTK_BOX (editor), editor->font_entry, FALSE, FALSE, 0); + gtk_widget_show (editor->font_entry); + + /* don't let unhandled key events drop through to the text editor */ + g_signal_connect_after (editor->font_entry, "key-press-event", + G_CALLBACK (gtk_true), + NULL); + g_signal_connect_after (editor->font_entry, "key-release-event", + G_CALLBACK (gtk_false), + NULL); + editor->clear_button = gtk_button_new (); gtk_widget_set_can_focus (editor->clear_button, FALSE); gtk_box_pack_start (GTK_BOX (editor), editor->clear_button, FALSE, FALSE, 0); gtk_widget_show (editor->clear_button); + gimp_help_set_help_data (editor->clear_button, + _("Clear style of selected text"), NULL); + g_signal_connect (editor->clear_button, "clicked", G_CALLBACK (gimp_text_style_editor_clear_tags), editor); @@ -146,8 +188,17 @@ gimp_text_style_editor_constructor (GType type, editor = GIMP_TEXT_STYLE_EDITOR (object); + g_assert (GIMP_IS_GIMP (editor->gimp)); + g_assert (GIMP_IS_FONT_LIST (editor->fonts)); g_assert (GIMP_IS_TEXT_BUFFER (editor->buffer)); + editor->context = gimp_context_new (editor->gimp, "text style editor", NULL); + + gimp_container_view_set_container (GIMP_CONTAINER_VIEW (editor->font_entry), + editor->fonts); + gimp_container_view_set_context (GIMP_CONTAINER_VIEW (editor->font_entry), + editor->context); + gimp_text_style_editor_create_toggle (editor, editor->buffer->bold_tag, GTK_STOCK_BOLD); gimp_text_style_editor_create_toggle (editor, editor->buffer->italic_tag, @@ -197,12 +248,24 @@ gimp_text_style_editor_finalize (GObject *object) { GimpTextStyleEditor *editor = GIMP_TEXT_STYLE_EDITOR (object); + if (editor->context) + { + g_object_unref (editor->context); + editor->context = NULL; + } + if (editor->buffer) { g_object_unref (editor->buffer); editor->buffer = NULL; } + if (editor->fonts) + { + g_object_unref (editor->fonts); + editor->fonts = NULL; + } + G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -216,9 +279,15 @@ gimp_text_style_editor_set_property (GObject *object, switch (property_id) { + case PROP_GIMP: + editor->gimp = g_value_get_object (value); /* don't ref */ + break; case PROP_BUFFER: editor->buffer = g_value_dup_object (value); break; + case PROP_FONTS: + editor->fonts = g_value_dup_object (value); + break; case PROP_RESOLUTION_X: editor->resolution_x = g_value_get_double (value); break; @@ -242,9 +311,15 @@ gimp_text_style_editor_get_property (GObject *object, switch (property_id) { + case PROP_GIMP: + g_value_set_object (value, editor->gimp); + break; case PROP_BUFFER: g_value_set_object (value, editor->buffer); break; + case PROP_FONTS: + g_value_set_object (value, editor->fonts); + break; case PROP_RESOLUTION_X: g_value_set_double (value, editor->resolution_x); break; @@ -262,16 +337,21 @@ gimp_text_style_editor_get_property (GObject *object, /* public functions */ GtkWidget * -gimp_text_style_editor_new (GimpTextBuffer *buffer, +gimp_text_style_editor_new (Gimp *gimp, + GimpTextBuffer *buffer, + GimpContainer *fonts, gdouble resolution_x, gdouble resolution_y) { + g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); g_return_val_if_fail (GIMP_IS_TEXT_BUFFER (buffer), NULL); g_return_val_if_fail (resolution_x > 0.0, NULL); g_return_val_if_fail (resolution_y > 0.0, NULL); return g_object_new (GIMP_TYPE_TEXT_STYLE_EDITOR, + "gimp", gimp, "buffer", buffer, + "fonts", fonts, "resolution-x", resolution_x, "resolution-y", resolution_y, NULL); diff --git a/app/widgets/gimptextstyleeditor.h b/app/widgets/gimptextstyleeditor.h index caacf1e137..602007d376 100644 --- a/app/widgets/gimptextstyleeditor.h +++ b/app/widgets/gimptextstyleeditor.h @@ -36,11 +36,16 @@ struct _GimpTextStyleEditor { GtkHBox parent_instance; + Gimp *gimp; + GimpContext *context; + GimpTextBuffer *buffer; + GimpContainer *fonts; gdouble resolution_x; gdouble resolution_y; + GtkWidget *font_entry; GtkWidget *clear_button; GtkWidget *bold_toggle; GtkWidget *italic_toggle; @@ -60,7 +65,9 @@ struct _GimpTextStyleEditorClass GType gimp_text_style_editor_get_type (void) G_GNUC_CONST; -GtkWidget * gimp_text_style_editor_new (GimpTextBuffer *buffer, +GtkWidget * gimp_text_style_editor_new (Gimp *gimp, + GimpTextBuffer *buffer, + GimpContainer *fonts, gdouble resolution_x, gdouble resolution_y);