diff options
| author | John Smith <john.smith7545@yahoo.com> | 2012-02-16 05:38:08 +0000 |
|---|---|---|
| committer | John Smith <removethis.john.q.public@bigmail.com> | 2012-02-16 05:38:08 +0000 |
| commit | 9a48c58cd01c6ab3909fc0fa4b883d2fd15e48ee (patch) | |
| tree | fe4b71445f19cdb3a421eb079464eba6454eaccc /src | |
| parent | Prevent false gtk deprecation warnings in canvas-grid and tidy headers (diff) | |
| download | inkscape-9a48c58cd01c6ab3909fc0fa4b883d2fd15e48ee.tar.gz inkscape-9a48c58cd01c6ab3909fc0fa4b883d2fd15e48ee.zip | |
Fix for 930535 : Convert Font and Text dialog to a dockable dialog
(bzr r10989)
Diffstat (limited to 'src')
| -rw-r--r-- | src/dialogs/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/dialogs/text-edit.cpp | 1032 | ||||
| -rw-r--r-- | src/dialogs/text-edit.h | 31 | ||||
| -rw-r--r-- | src/ui/context-menu.cpp | 3 | ||||
| -rw-r--r-- | src/ui/dialog/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/ui/dialog/dialog-manager.cpp | 3 | ||||
| -rw-r--r-- | src/ui/dialog/text-edit.cpp | 703 | ||||
| -rw-r--r-- | src/ui/dialog/text-edit.h | 160 | ||||
| -rw-r--r-- | src/verbs.cpp | 3 | ||||
| -rw-r--r-- | src/widgets/font-selector.cpp | 1 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 3 |
11 files changed, 872 insertions, 1071 deletions
diff --git a/src/dialogs/Makefile_insert b/src/dialogs/Makefile_insert index 342eba137..6a3d33f07 100644 --- a/src/dialogs/Makefile_insert +++ b/src/dialogs/Makefile_insert @@ -11,7 +11,5 @@ ink_common_sources += \ dialogs/find.h \ dialogs/spellcheck.cpp \ dialogs/spellcheck.h \ - dialogs/text-edit.cpp \ - dialogs/text-edit.h \ dialogs/xml-tree.cpp \ dialogs/xml-tree.h diff --git a/src/dialogs/text-edit.cpp b/src/dialogs/text-edit.cpp deleted file mode 100644 index a9a7d7a31..000000000 --- a/src/dialogs/text-edit.cpp +++ /dev/null @@ -1,1032 +0,0 @@ -/** - * @file - * Text editing dialog. - */ -/* Authors: - * Lauris Kaplinski <lauris@ximian.com> - * bulia byak <buliabyak@users.sf.net> - * Johan Engelen <goejendaagh@zonnet.nl> - * Abhishek Sharma - * - * Copyright (C) 1999-2007 Authors - * Copyright (C) 2000-2001 Ximian, Inc. - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <libnrtype/font-instance.h> -#include <gtk/gtk.h> - -#ifdef WITH_GTKSPELL -extern "C" { -# include <gtkspell/gtkspell.h> -} -#endif - -#include "macros.h" -#include <glibmm/i18n.h> -#include "helper/window.h" -#include "../widgets/font-selector.h" -#include "../inkscape.h" -#include "../document.h" -#include "../document-undo.h" -#include "../desktop-style.h" -#include "../desktop-handles.h" -#include "../selection.h" -#include "../style.h" -#include "../sp-text.h" -#include "../sp-flowtext.h" -#include "../text-editing.h" -#include "../ui/icon-names.h" -#include <libnrtype/font-style-to-pos.h> - -#include "dialog-events.h" -#include "../preferences.h" -#include "../verbs.h" -#include "../interface.h" -#include "svg/css-ostringstream.h" -#include "widgets/icon.h" -#include <xml/repr.h> -#include "util/ege-appear-time-tracker.h" - -using Inkscape::DocumentUndo; -using ege::AppearTimeTracker; - -#define VB_MARGIN 4 -#define MIN_ONSCREEN_DISTANCE 50 - -static void sp_text_edit_dialog_selection_modified (Inkscape::Application *inkscape, Inkscape::Selection *sel, guint flags, GtkWidget *dlg); -static void sp_text_edit_dialog_selection_changed (Inkscape::Application *inkscape, Inkscape::Selection *sel, GtkWidget *dlg); -static void sp_text_edit_dialog_subselection_changed ( Inkscape::Application *inkscape, SPDesktop *desktop, GtkWidget *dlg); - -static void sp_text_edit_dialog_set_default (GtkButton *button, GtkWidget *dlg); -static void sp_text_edit_dialog_apply (GtkButton *button, GtkWidget *dlg); -static void sp_text_edit_dialog_close (GtkButton *button, GtkWidget *dlg); - -static void sp_text_edit_dialog_read_selection (GtkWidget *dlg, gboolean style, gboolean content); - -static void sp_text_edit_dialog_text_changed (GtkTextBuffer *tb, GtkWidget *dlg); -static void sp_text_edit_dialog_font_changed (SPFontSelector *fontsel, font_instance *font, GtkWidget *dlg); -static void sp_text_edit_dialog_any_toggled (GtkToggleButton *tb, GtkWidget *dlg); -static void sp_text_edit_dialog_line_spacing_changed (GtkEditable *editable, GtkWidget *dlg); - -static SPItem *sp_ted_get_selected_text_item (void); -static unsigned sp_ted_get_selected_text_count (void); - - -static const gchar *spacings[] = {"50%", "80%", "90%", "100%", "110%", "120%", "130%", "140%", "150%", "200%", "300%", NULL}; - -static GtkWidget *dlg = NULL; -static win_data wd; -// impossible original values to make sure they are read from prefs -static gint x = -1000, y = -1000, w = 0, h = 0; -static Glib::ustring const prefs_path = "/dialogs/textandfont/"; - - - - -static void -sp_text_edit_dialog_destroy( GtkObject */*object*/, gpointer /*data*/ ) -{ - sp_signal_disconnect_by_data (INKSCAPE, dlg); - wd.win = dlg = NULL; - wd.stop = 0; -} - - - -static gboolean -sp_text_edit_dialog_delete( GtkObject */*object*/, GdkEvent */*event*/, gpointer /*data*/ ) -{ - gtk_window_get_position ((GtkWindow *) dlg, &x, &y); - gtk_window_get_size ((GtkWindow *) dlg, &w, &h); - - if (x<0) x=0; - if (y<0) y=0; - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(prefs_path + "x", x); - prefs->setInt(prefs_path + "y", y); - prefs->setInt(prefs_path + "w", w); - prefs->setInt(prefs_path + "h", h); - - return FALSE; // which means, go ahead and destroy it -} - - -/** - These callbacks set the eatkeys flag when the text editor is entered and cancel it when it's left. - This flag is used to prevent passing keys from the dialog to canvas, so that the text editor - can handle keys like Esc and Ctrl+Z itself. - */ -gboolean -text_view_focus_in( GtkWidget */*w*/, GdkEventKey */*event*/, gpointer data ) -{ - GObject *dlg = (GObject *) data; - g_object_set_data (dlg, "eatkeys", GINT_TO_POINTER (TRUE)); - return FALSE; -} - -gboolean -text_view_focus_out (GtkWidget */*w*/, GdkEventKey */*event*/, gpointer data) -{ - GObject *dlg = (GObject *) data; - g_object_set_data (dlg, "eatkeys", GINT_TO_POINTER (FALSE)); - return FALSE; -} - - -void -sp_text_edit_dialog (void) -{ - bool wantTiming = Inkscape::Preferences::get()->getBool("/dialogs/debug/trackAppear", false); - GTimer *timer = wantTiming ? g_timer_new() : 0; - - if (!dlg) { - - gchar title[500]; - sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_TEXT), title); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - dlg = sp_window_new (title, TRUE); - if (x == -1000 || y == -1000) { - x = prefs->getInt(prefs_path + "x", -1000); - y = prefs->getInt(prefs_path + "y", -1000); - } - if (w ==0 || h == 0) { - w = prefs->getInt(prefs_path + "w", 0); - h = prefs->getInt(prefs_path + "h", 0); - } - -// if (x<0) x=0; -// if (y<0) y=0; - - if (w && h) - gtk_window_resize ((GtkWindow *) dlg, w, h); - if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) { - gtk_window_move ((GtkWindow *) dlg, x, y); - } else { - gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER); - } - - - sp_transientize (dlg); - wd.win = dlg; - wd.stop = 0; - g_signal_connect ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd ); - - g_signal_connect ( G_OBJECT (dlg), "event", G_CALLBACK (sp_dialog_event_handler), dlg ); - - g_signal_connect ( G_OBJECT (dlg), "destroy", G_CALLBACK (sp_text_edit_dialog_destroy), dlg ); - g_signal_connect ( G_OBJECT (dlg), "delete_event", G_CALLBACK (sp_text_edit_dialog_delete), dlg ); - g_signal_connect ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (sp_text_edit_dialog_delete), dlg ); - - g_signal_connect ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg ); - g_signal_connect ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg ); - - // box containing the notebook and the bottom buttons - GtkWidget *mainvb = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (dlg), mainvb); - - // notebook - GtkWidget *nb = gtk_notebook_new (); - gtk_box_pack_start (GTK_BOX (mainvb), nb, TRUE, TRUE, 0); - g_object_set_data (G_OBJECT (dlg), "notebook", nb); - - - - // Font tab - { - GtkWidget *l = gtk_label_new_with_mnemonic (_("_Font")); - GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN); - gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN); - gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l); - - /* HBox containing font selection and layout */ - GtkWidget *hb = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vb), hb, TRUE, TRUE, 0); - - // font and style selector - GtkWidget *fontsel = sp_font_selector_new (); - g_signal_connect ( G_OBJECT (fontsel), "font_set", G_CALLBACK (sp_text_edit_dialog_font_changed), dlg ); - - g_signal_connect_swapped ( G_OBJECT (g_object_get_data (G_OBJECT(fontsel), "family-treeview")), - "row-activated", - G_CALLBACK (gtk_window_activate_default), - dlg); - - gtk_box_pack_start (GTK_BOX (hb), fontsel, TRUE, TRUE, 0); - g_object_set_data (G_OBJECT (dlg), "fontsel", fontsel); - - // Layout - { - GtkWidget *f = gtk_frame_new (_("Layout")); - gtk_box_pack_start (GTK_BOX (hb), f, FALSE, FALSE, 4); - GtkWidget *l_vb = gtk_vbox_new (FALSE, VB_MARGIN); - gtk_container_add (GTK_CONTAINER (f), l_vb); - - { - GtkWidget *row = gtk_hbox_new (FALSE, VB_MARGIN); - GtkWidget *group; - - // align left - { - // TODO - replace with Inkscape-specific call - GtkWidget *px = gtk_image_new_from_stock ( GTK_STOCK_JUSTIFY_LEFT, GTK_ICON_SIZE_LARGE_TOOLBAR ); - GtkWidget *b = group = gtk_radio_button_new (NULL); - gtk_widget_set_tooltip_text (b, _("Align lines left")); - gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE); - g_signal_connect ( G_OBJECT (b), "toggled", G_CALLBACK (sp_text_edit_dialog_any_toggled), dlg); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (b), FALSE ); - gtk_container_add (GTK_CONTAINER (b), px); - gtk_box_pack_start (GTK_BOX (row), b, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (dlg), "text_anchor_start", b); - } - - // align center - { - // TODO - replace with Inkscape-specific call - GtkWidget *px = gtk_image_new_from_stock ( GTK_STOCK_JUSTIFY_CENTER, GTK_ICON_SIZE_LARGE_TOOLBAR ); - GtkWidget *b = gtk_radio_button_new (gtk_radio_button_get_group (GTK_RADIO_BUTTON (group))); - /* TRANSLATORS: `Center' here is a verb. */ - gtk_widget_set_tooltip_text (b, _("Center lines")); - gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE); - g_signal_connect ( G_OBJECT (b), "toggled", G_CALLBACK (sp_text_edit_dialog_any_toggled), dlg ); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (b), FALSE); - gtk_container_add (GTK_CONTAINER (b), px); - gtk_box_pack_start (GTK_BOX (row), b, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (dlg), "text_anchor_middle", b); - } - - // align right - { - // TODO - replace with Inkscape-specific call - GtkWidget *px = gtk_image_new_from_stock ( GTK_STOCK_JUSTIFY_RIGHT, GTK_ICON_SIZE_LARGE_TOOLBAR ); - GtkWidget *b = gtk_radio_button_new (gtk_radio_button_get_group (GTK_RADIO_BUTTON (group))); - gtk_widget_set_tooltip_text (b, _("Align lines right")); - gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE); - g_signal_connect ( G_OBJECT (b), "toggled", G_CALLBACK (sp_text_edit_dialog_any_toggled), dlg ); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (b), FALSE); - gtk_container_add (GTK_CONTAINER (b), px); - gtk_box_pack_start (GTK_BOX (row), b, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (dlg), "text_anchor_end", b); - } - - // align justify - { - // TODO - replace with Inkscape-specific call - GtkWidget *px = gtk_image_new_from_stock ( GTK_STOCK_JUSTIFY_FILL, GTK_ICON_SIZE_LARGE_TOOLBAR ); - GtkWidget *b = gtk_radio_button_new (gtk_radio_button_get_group (GTK_RADIO_BUTTON (group))); - gtk_widget_set_tooltip_text (b, _("Justify lines")); - gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE); - g_signal_connect ( G_OBJECT (b), "toggled", G_CALLBACK (sp_text_edit_dialog_any_toggled), dlg ); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (b), FALSE); - gtk_container_add (GTK_CONTAINER (b), px); - gtk_box_pack_start (GTK_BOX (row), b, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (dlg), "text_anchor_justify", b); - } - - gtk_box_pack_start (GTK_BOX (l_vb), row, FALSE, FALSE, 0); - } - - - { - GtkWidget *row = gtk_hbox_new (FALSE, VB_MARGIN); - GtkWidget *group; - - // horizontal - { - GtkWidget *px = sp_icon_new( Inkscape::ICON_SIZE_LARGE_TOOLBAR, - INKSCAPE_ICON("format-text-direction-horizontal") ); - GtkWidget *b = group = gtk_radio_button_new (NULL); - gtk_widget_set_tooltip_text (b, _("Horizontal text")); - gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE); - g_signal_connect ( G_OBJECT (b), "toggled", G_CALLBACK (sp_text_edit_dialog_any_toggled), dlg ); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (b), FALSE); - gtk_container_add (GTK_CONTAINER (b), px); - gtk_box_pack_start (GTK_BOX (row), b, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (dlg), INKSCAPE_ICON("format-text-direction-horizontal"), b); - } - - // vertical - { - GtkWidget *px = sp_icon_new( Inkscape::ICON_SIZE_LARGE_TOOLBAR, - INKSCAPE_ICON("format-text-direction-vertical") ); - GtkWidget *b = gtk_radio_button_new (gtk_radio_button_get_group (GTK_RADIO_BUTTON (group))); - gtk_widget_set_tooltip_text (b, _("Vertical text")); - gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE); - g_signal_connect ( G_OBJECT (b), "toggled", G_CALLBACK (sp_text_edit_dialog_any_toggled), dlg ); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (b), FALSE); - gtk_container_add (GTK_CONTAINER (b), px); - gtk_box_pack_start (GTK_BOX (row), b, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (dlg), INKSCAPE_ICON("format-text-direction-vertical"), b); - } - - gtk_box_pack_start (GTK_BOX (l_vb), row, FALSE, FALSE, 0); - } - - { - GtkWidget *row = gtk_hbox_new (FALSE, VB_MARGIN); - - l = gtk_label_new (_("Line spacing:")); - gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5); - gtk_box_pack_start (GTK_BOX (row), l, FALSE, FALSE, VB_MARGIN); - - gtk_box_pack_start (GTK_BOX (l_vb), row, FALSE, FALSE, 0); - } - - { - GtkWidget *row = gtk_hbox_new (FALSE, VB_MARGIN); - -//This would introduce dependency on gtk version 2.24 which is currently not available in -// Trisquel GNU/Linux 4.5.1 (released on May 25th, 2011) -//This conditional and its #else block can be deleted in the future. -#if GTK_CHECK_VERSION(2, 24,0) - GtkWidget *c = gtk_combo_box_text_new_with_entry (); -#else - GtkWidget *c = gtk_combo_box_entry_new_text (); -#endif - gtk_widget_set_size_request (c, 90, -1); - - { /* Setup strings */ - for (int i = 0; spacings[i]; i++) { -//This would introduce dependency on gtk version 2.24 which is currently not available in -// Trisquel GNU/Linux 4.5.1 (released on May 25th, 2011) -//This conditional and its #else block can be deleted in the future. -#if GTK_CHECK_VERSION(2, 24,0) - gtk_combo_box_text_append_text((GtkComboBoxText *) c, spacings[i]); -#else - gtk_combo_box_append_text((GtkComboBox *) c, spacings[i]); -#endif - } - } - - g_signal_connect ( (GObject *) c, - "changed", - (GCallback) sp_text_edit_dialog_line_spacing_changed, - dlg ); - gtk_box_pack_start (GTK_BOX (row), c, FALSE, FALSE, VB_MARGIN); - g_object_set_data (G_OBJECT (dlg), "line_spacing", c); - - gtk_box_pack_start (GTK_BOX (l_vb), row, FALSE, FALSE, VB_MARGIN); - } - } - - /* Font preview */ - GtkLabel *preview = (GtkLabel*) gtk_label_new(NULL); - gtk_label_set_ellipsize(preview, PANGO_ELLIPSIZE_END); - gtk_label_set_justify(preview, GTK_JUSTIFY_CENTER); - gtk_label_set_line_wrap(preview, FALSE); - gtk_box_pack_start (GTK_BOX (vb), (GtkWidget*) preview, TRUE, TRUE, 4); - g_object_set_data (G_OBJECT (dlg), "preview", preview); - } - - - // Text tab - { - GtkWidget *l = gtk_label_new_with_mnemonic (_("_Text")); - GtkWidget *vb = gtk_vbox_new (FALSE, VB_MARGIN); - gtk_container_set_border_width (GTK_CONTAINER (vb), VB_MARGIN); - gtk_notebook_append_page (GTK_NOTEBOOK (nb), vb, l); - - GtkWidget *scroller = gtk_scrolled_window_new ( NULL, NULL ); - gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW (scroller), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC ); - gtk_scrolled_window_set_shadow_type ( GTK_SCROLLED_WINDOW(scroller), GTK_SHADOW_IN ); - gtk_widget_show (scroller); - - GtkTextBuffer *tb = gtk_text_buffer_new (NULL); - GtkWidget *txt = gtk_text_view_new_with_buffer (tb); - gtk_text_view_set_wrap_mode ((GtkTextView *) txt, GTK_WRAP_WORD); -#ifdef WITH_GTKSPELL - GError *error = NULL; - char *errortext = NULL; - /* todo: Use computed xml:lang attribute of relevant element, if present, to specify the - language (either as 2nd arg of gtkspell_new_attach, or with explicit - gtkspell_set_language call in; see advanced.c example in gtkspell docs). - sp_text_edit_dialog_read_selection looks like a suitable place. */ - if (gtkspell_new_attach(GTK_TEXT_VIEW(txt), NULL, &error) == NULL) { - g_print("gtkspell error: %s\n", error->message); - errortext = g_strdup_printf("GtkSpell was unable to initialize.\n" - "%s", error->message); - g_error_free(error); - } -#endif - gtk_widget_set_size_request (txt, -1, 64); - gtk_text_view_set_editable (GTK_TEXT_VIEW (txt), TRUE); - gtk_container_add (GTK_CONTAINER (scroller), txt); - gtk_box_pack_start (GTK_BOX (vb), scroller, TRUE, TRUE, 0); - g_signal_connect ( G_OBJECT (tb), "changed", - G_CALLBACK (sp_text_edit_dialog_text_changed), dlg ); - g_signal_connect (G_OBJECT (txt), "focus-in-event", G_CALLBACK (text_view_focus_in), dlg); - g_signal_connect (G_OBJECT (txt), "focus-out-event", G_CALLBACK (text_view_focus_out), dlg); - g_object_set_data (G_OBJECT (dlg), "text", tb); - g_object_set_data (G_OBJECT (dlg), "textw", txt); - } - - /* Buttons */ - GtkWidget *hb = gtk_hbox_new (FALSE, VB_MARGIN); - gtk_container_set_border_width (GTK_CONTAINER (hb), 4); - gtk_box_pack_start (GTK_BOX (mainvb), hb, FALSE, FALSE, 0); - - { - GtkWidget *b = gtk_button_new_with_mnemonic (_("Set as _default")); - g_signal_connect ( G_OBJECT (b), "clicked", - G_CALLBACK (sp_text_edit_dialog_set_default), - dlg ); - gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (dlg), "default", b); - } - - { - GtkWidget *b = gtk_button_new_from_stock (GTK_STOCK_CLOSE); - g_signal_connect ( G_OBJECT (b), "clicked", - G_CALLBACK (sp_text_edit_dialog_close), dlg ); - gtk_box_pack_end (GTK_BOX (hb), b, FALSE, FALSE, 0); - } - - { - GtkWidget *b = gtk_button_new_from_stock (GTK_STOCK_APPLY); - g_signal_connect ( G_OBJECT (b), "clicked", - G_CALLBACK (sp_text_edit_dialog_apply), dlg ); - gtk_box_pack_end ( GTK_BOX (hb), b, FALSE, FALSE, 0 ); - gtk_widget_set_can_default (b, TRUE); - gtk_widget_grab_default (b); - g_object_set_data (G_OBJECT (dlg), "apply", b); - } - - g_signal_connect ( G_OBJECT (INKSCAPE), "modify_selection", - G_CALLBACK (sp_text_edit_dialog_selection_modified), dlg); - g_signal_connect ( G_OBJECT (INKSCAPE), "change_selection", - G_CALLBACK (sp_text_edit_dialog_selection_changed), dlg); - g_signal_connect (INKSCAPE, "change_subselection", G_CALLBACK (sp_text_edit_dialog_subselection_changed), dlg); - - gtk_widget_show_all (dlg); - - sp_text_edit_dialog_read_selection (dlg, TRUE, TRUE); - } - - if ( wantTiming ) { - // Time tracker takes ownership of the timer. - AppearTimeTracker *tracker = new AppearTimeTracker(timer, GTK_WIDGET(dlg), "DialogText"); - tracker->setAutodelete(true); - timer = 0; - } - - gtk_window_present ((GtkWindow *) dlg); - -} // end of sp_text_edit_dialog() - - - -static void -sp_text_edit_dialog_selection_modified( Inkscape::Application */*inkscape*/, - Inkscape::Selection */*sel*/, - guint flags, - GtkWidget *dlg ) -{ - gboolean style, content; - - style = - ((flags & ( SP_OBJECT_CHILD_MODIFIED_FLAG | - SP_OBJECT_STYLE_MODIFIED_FLAG )) != 0 ); - - content = - ((flags & ( SP_OBJECT_CHILD_MODIFIED_FLAG | - SP_TEXT_CONTENT_MODIFIED_FLAG )) != 0 ); - - sp_text_edit_dialog_read_selection (dlg, style, content); - -} - - - -static void -sp_text_edit_dialog_selection_changed( Inkscape::Application */*inkscape*/, - Inkscape::Selection */*sel*/, - GtkWidget *dlg ) -{ - sp_text_edit_dialog_read_selection (dlg, TRUE, TRUE); -} - -static void sp_text_edit_dialog_subselection_changed( Inkscape::Application */*inkscape*/, SPDesktop */*desktop*/, GtkWidget *dlg ) -{ - sp_text_edit_dialog_read_selection (dlg, TRUE, FALSE); -} - -static void -sp_text_edit_dialog_update_object_text ( SPItem *text ) -{ - GtkTextBuffer *tb; - GtkTextIter start, end; - gchar *str; - - tb = (GtkTextBuffer*)g_object_get_data (G_OBJECT (dlg), "text"); - - /* write text */ - if (gtk_text_buffer_get_modified (tb)) { - gtk_text_buffer_get_bounds (tb, &start, &end); - str = gtk_text_buffer_get_text (tb, &start, &end, TRUE); - sp_te_set_repr_text_multiline (text, str); - g_free (str); - gtk_text_buffer_set_modified (tb, FALSE); - } -} - -SPCSSAttr * -sp_get_text_dialog_style () -{ - GtkWidget *fontsel = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "fontsel"); - - SPCSSAttr *css = sp_repr_css_attr_new (); - - /* font */ - font_instance *font = sp_font_selector_get_font (SP_FONT_SELECTOR (fontsel)); - - if ( font ) { - Glib::ustring fontName = font_factory::Default()->ConstructFontSpecification(font); - sp_repr_css_set_property (css, "-inkscape-font-specification", fontName.c_str()); - - gchar c[256]; - - font->Family(c, 256); - sp_repr_css_set_property (css, "font-family", c); - - font->Attribute( "weight", c, 256); - sp_repr_css_set_property (css, "font-weight", c); - - font->Attribute("style", c, 256); - sp_repr_css_set_property (css, "font-style", c); - - font->Attribute("stretch", c, 256); - sp_repr_css_set_property (css, "font-stretch", c); - - font->Attribute("variant", c, 256); - sp_repr_css_set_property (css, "font-variant", c); - - Inkscape::CSSOStringStream os; - os << sp_font_selector_get_size (SP_FONT_SELECTOR (fontsel)) << "px"; // must specify px, see inkscape bug 1221626 and 1610103 - sp_repr_css_set_property (css, "font-size", os.str().c_str()); - - font->Unref(); - font=NULL; - } - - /* Layout */ - GtkWidget *b = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "text_anchor_start"); - - // Align Left - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))) { - sp_repr_css_set_property (css, "text-anchor", "start"); - sp_repr_css_set_property (css, "text-align", "start"); - } else { - // Align Center - b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), - "text_anchor_middle"); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))) { - sp_repr_css_set_property (css, "text-anchor", "middle"); - sp_repr_css_set_property (css, "text-align", "center"); - } else { - // Align Right - b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), - "text_anchor_end"); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))) { - sp_repr_css_set_property (css, "text-anchor", "end"); - sp_repr_css_set_property (css, "text-align", "end"); - } else { - // Align Justify - sp_repr_css_set_property (css, "text-anchor", "start"); - sp_repr_css_set_property (css, "text-align", "justify"); - } - } - } - - b = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), INKSCAPE_ICON("format-text-direction-horizontal") ); - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (b))) { - sp_repr_css_set_property (css, "writing-mode", "lr"); - } else { - sp_repr_css_set_property (css, "writing-mode", "tb"); - } - - // Note that CSS 1.1 does not support line-height; we set it for consistency, but also set - // sodipodi:linespacing for backwards compatibility; in 1.2 we use line-height for flowtext - GtkWidget *combo = (GtkWidget*)g_object_get_data ((GObject *) dlg, "line_spacing"); - -//This would introduce dependency on gtk version 2.24 which is currently not available in -// Trisquel GNU/Linux 4.5.1 (released on May 25th, 2011) -//This conditional and its #else block can be deleted in the future. -#if GTK_CHECK_VERSION(2, 24,0) - const gchar *sstr = gtk_combo_box_text_get_active_text ((GtkComboBoxText *) combo); -#else - const gchar *sstr = gtk_entry_get_text ((GtkEntry *) (gtk_bin_get_child (GTK_BIN (combo)))); -#endif - sp_repr_css_set_property (css, "line-height", sstr); - - return css; -} - - -static void -sp_text_edit_dialog_set_default( GtkButton */*button*/, GtkWidget *dlg ) -{ - GtkWidget *def = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "default"); - - SPCSSAttr *css = sp_get_text_dialog_style (); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - g_object_set_data (G_OBJECT (dlg), "blocked", GINT_TO_POINTER (TRUE)); - prefs->mergeStyle("/tools/text/style", css); - g_object_set_data (G_OBJECT (dlg), "blocked", GINT_TO_POINTER (FALSE)); - - sp_repr_css_attr_unref (css); - - gtk_widget_set_sensitive (def, FALSE); -} - - - -static void -sp_text_edit_dialog_apply( GtkButton */*button*/, GtkWidget *dlg ) -{ - g_object_set_data (G_OBJECT (dlg), "blocked", GINT_TO_POINTER (TRUE)); - - GtkWidget *apply = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "apply"); - GtkWidget *def = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "default"); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - - unsigned items = 0; - const GSList *item_list = sp_desktop_selection(desktop)->itemList(); - SPCSSAttr *css = sp_get_text_dialog_style (); - sp_desktop_set_style(desktop, css, true); - - for (; item_list != NULL; item_list = item_list->next) { - // apply style to the reprs of all text objects in the selection - if (SP_IS_TEXT (item_list->data)) { - - // backwards compatibility: - reinterpret_cast<SPObject*>(item_list->data)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); - - ++items; - } - else if (SP_IS_FLOWTEXT (item_list->data)) - // no need to set sodipodi:linespacing, because Inkscape never supported it on flowtext - ++items; - } - - if (items == 0) { - // no text objects; apply style to prefs for new objects - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->mergeStyle("/tools/text/style", css); - gtk_widget_set_sensitive (def, FALSE); - } else if (items == 1) { - /* exactly one text object; now set its text, too */ - SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); - if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT(item)) { - sp_text_edit_dialog_update_object_text (item); - } - } - - // complete the transaction - DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT, - _("Set text style")); - gtk_widget_set_sensitive (apply, FALSE); - sp_repr_css_attr_unref (css); - g_object_set_data (G_OBJECT (dlg), "blocked", GINT_TO_POINTER (FALSE)); -} - -static void -sp_text_edit_dialog_close( GtkButton */*button*/, GtkWidget *dlg ) -{ - gtk_widget_destroy (GTK_WIDGET (dlg)); -} - -static void -sp_text_edit_dialog_read_selection ( GtkWidget *dlg, - gboolean dostyle, - gboolean docontent ) -{ - if (g_object_get_data (G_OBJECT (dlg), "blocked")) - return; - - g_object_set_data (G_OBJECT (dlg), "blocked", GINT_TO_POINTER (TRUE)); - - //GtkWidget *notebook = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "notebook"); - GtkWidget *textw = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "textw"); - GtkWidget *fontsel = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "fontsel"); - GtkWidget *preview = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "preview"); - GtkWidget *apply = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "apply"); - GtkWidget *def = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "default"); - - GtkTextBuffer *tb = (GtkTextBuffer*)g_object_get_data (G_OBJECT (dlg), "text"); - - SPItem *text = sp_ted_get_selected_text_item (); - - /* TRANSLATORS: Test string used in text and font dialog (when no - * text has been entered) to get a preview of the font. Choose - * some representative characters that users of your locale will be - * interested in. */ - gchar *phrase = g_strdup(_("AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()")); - - if (text) - { - guint items = sp_ted_get_selected_text_count (); - if (items == 1) { - gtk_widget_set_sensitive (textw, TRUE); - } else { - gtk_widget_set_sensitive (textw, FALSE); - } - gtk_widget_set_sensitive (apply, FALSE); - gtk_widget_set_sensitive (def, TRUE); - - if (docontent) { - gchar *str; - str = sp_te_get_string_multiline (text); - - if (str) { - if (items == 1) { - gtk_text_buffer_set_text (tb, str, strlen (str)); - gtk_text_buffer_set_modified (tb, FALSE); - } - g_free(phrase); - phrase = str; - - } else { - gtk_text_buffer_set_text (tb, "", 0); - } - } // end of if (docontent) - text->getRepr(); // was being called but result ignored. Check this. - } else { - gtk_widget_set_sensitive (textw, FALSE); - gtk_widget_set_sensitive (apply, FALSE); - gtk_widget_set_sensitive (def, FALSE); - } - - if (dostyle) { - - // create temporary style - SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); - // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection - //int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); - int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); - int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); - int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); - - // If querying returned nothing, read the style from the text tool prefs (default style for new texts) - // (Ok to not get a font specification - must just rely on the family and style in that case) - if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING - || result_numbers == QUERY_STYLE_NOTHING) { - sp_style_read_from_prefs(query, "/tools/text"); - } - - // FIXME: process result_family/style == QUERY_STYLE_MULTIPLE_DIFFERENT by showing "Many" in the lists - - // Get a font_instance using the font-specification attribute stored in SPStyle if available - font_instance *font = font_factory::Default()->FaceFromStyle(query); - - - if (font) { - // the font is oversized, so we need to pass the true size separately - sp_font_selector_set_font (SP_FONT_SELECTOR (fontsel), font, query->font_size.computed); - char *desc = pango_font_description_to_string(font->descr); - double size = sp_font_selector_get_size(SP_FONT_SELECTOR(fontsel)); - gchar *markup = g_strdup_printf("<span font=\"%s\" size=\"%d\">%s</span>", - desc, (int) size * PANGO_SCALE, phrase); - gtk_label_set_markup(GTK_LABEL(preview), markup); - g_free(desc); - g_free(markup); - font->Unref(); - font=NULL; - } - - GtkWidget *b; - if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) { - if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) { - b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), "text_anchor_justify" ); - } else { - b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), "text_anchor_start" ); - } - } else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) { - b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), "text_anchor_middle" ); - } else { - b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), "text_anchor_end" ); - } - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (b), TRUE); - - if (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB) { - b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), INKSCAPE_ICON("format-text-direction-horizontal") ); - } else { - b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), INKSCAPE_ICON("format-text-direction-vertical") ); - } - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (b), TRUE); - - GtkWidget *combo = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg), "line_spacing" ); - double height; - if (query->line_height.normal) height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL; - else if (query->line_height.unit == SP_CSS_UNIT_PERCENT) - height = query->line_height.value; - else height = query->line_height.computed; - gchar *sstr = g_strdup_printf ("%d%%", (int) floor(height * 100 + 0.5)); - - gtk_entry_set_text ((GtkEntry *) gtk_bin_get_child ((GtkBin *) (combo)), sstr); - g_free(sstr); - - sp_style_unref(query); - } - g_free(phrase); - g_object_set_data (G_OBJECT (dlg), "blocked", NULL); -} - - -static void -sp_text_edit_dialog_text_changed (GtkTextBuffer *tb, GtkWidget *dlg) -{ - if (g_object_get_data (G_OBJECT (dlg), "blocked")) { - return; - } - - SPItem *text = sp_ted_get_selected_text_item(); - - //GtkWidget *textw = reinterpret_cast<GtkWidget*>(g_object_get_data(G_OBJECT (dlg), "textw")); - GtkWidget *preview = reinterpret_cast<GtkWidget*>(g_object_get_data(G_OBJECT (dlg), "preview")); - GtkWidget *apply = reinterpret_cast<GtkWidget*>(g_object_get_data(G_OBJECT (dlg), "apply")); - GtkWidget *def = reinterpret_cast<GtkWidget*>(g_object_get_data(G_OBJECT (dlg), "default")); - GtkWidget *fontsel = reinterpret_cast<GtkWidget*>(g_object_get_data(G_OBJECT (dlg), "fontsel")); - - GtkTextIter start; - GtkTextIter end; - gtk_text_buffer_get_bounds (tb, &start, &end); - gchar *str = gtk_text_buffer_get_text(tb, &start, &end, TRUE); - font_instance *font = sp_font_selector_get_font(SP_FONT_SELECTOR(fontsel)); - - if (font) { - gchar *phrase = str && *str ? str : _("AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()"); - char *desc = pango_font_description_to_string(font->descr); - double size = sp_font_selector_get_size(SP_FONT_SELECTOR(fontsel)); - gchar *markup = g_strdup_printf("<span font=\"%s\" size=\"%d\">%s</span>", - desc, (int) size * PANGO_SCALE, phrase); - gtk_label_set_markup(GTK_LABEL(preview), markup); - g_free(desc); - g_free(markup); - } else { - gtk_label_set_markup(GTK_LABEL(preview), NULL); - } - g_free (str); - - if (text) { - gtk_widget_set_sensitive (apply, TRUE); - } - gtk_widget_set_sensitive (def, TRUE); - -} // end of sp_text_edit_dialog_text_changed() - -void -sp_text_edit_dialog_default_set_insensitive () -{ - if (!dlg) return; - gpointer data = g_object_get_data (G_OBJECT (dlg), "default"); - if (!data) return; - gtk_widget_set_sensitive (GTK_WIDGET (data), FALSE); -} - -static void -sp_text_edit_dialog_font_changed ( SPFontSelector * /*fsel*/, - font_instance *font, - GtkWidget *dlg ) -{ - GtkWidget *preview, *apply, *def, *fontsel; - GtkTextIter start, end; - gchar *str; - - if (g_object_get_data (G_OBJECT (dlg), "blocked")) - return; - - SPItem *text = sp_ted_get_selected_text_item (); - - preview = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "preview"); - apply = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "apply"); - def = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "default"); - fontsel = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "fontsel"); - - GtkTextBuffer *tb = (GtkTextBuffer*)g_object_get_data (G_OBJECT (dlg), "text"); - gtk_text_buffer_get_bounds (tb, &start, &end); - str = gtk_text_buffer_get_text (tb, &start, &end, TRUE); - - if (font) { - gchar *phrase = str && *str ? str : _("AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()"); - char *desc = pango_font_description_to_string(font->descr); - double size = sp_font_selector_get_size(SP_FONT_SELECTOR(fontsel)); - gchar *markup = g_strdup_printf("<span font=\"%s\" size=\"%d\">%s</span>", - desc, (int) size * PANGO_SCALE, phrase); - gtk_label_set_markup(GTK_LABEL(preview), markup); - g_free(desc); - g_free(markup); - } else { - gtk_label_set_markup(GTK_LABEL(preview), NULL); - } - g_free(str); - - if (text) { - gtk_widget_set_sensitive (apply, TRUE); - } - gtk_widget_set_sensitive (def, TRUE); - -} // end of sp_text_edit_dialog_font_changed() - - - -static void -sp_text_edit_dialog_any_toggled( GtkToggleButton */*tb*/, GtkWidget *dlg ) -{ - GtkWidget *apply, *def; - - if (g_object_get_data (G_OBJECT (dlg), "blocked")) - return; - - SPItem *text = sp_ted_get_selected_text_item (); - - apply = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "apply"); - def = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "default"); - - if (text) { - gtk_widget_set_sensitive (apply, TRUE); - } - gtk_widget_set_sensitive (def, TRUE); -} - - - -static void -sp_text_edit_dialog_line_spacing_changed( GtkEditable */*editable*/, GtkWidget *dlg ) -{ - GtkWidget *apply, *def; - - if (g_object_get_data ((GObject *) dlg, "blocked")) - return; - - SPItem *text = sp_ted_get_selected_text_item (); - - apply = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "apply"); - def = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), "default"); - - if (text) { - gtk_widget_set_sensitive (apply, TRUE); - } - gtk_widget_set_sensitive (def, TRUE); -} - - - -static SPItem * -sp_ted_get_selected_text_item (void) -{ - if (!SP_ACTIVE_DESKTOP) - return NULL; - - for (const GSList *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); - item != NULL; - item = item->next) - { - if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) - return SP_ITEM (item->data); - } - - return NULL; -} - - - -static unsigned -sp_ted_get_selected_text_count (void) -{ - if (!SP_ACTIVE_DESKTOP) - return 0; - - unsigned int items = 0; - - for (const GSList *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); - item != NULL; - item = item->next) - { - if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) - ++items; - } - - return items; -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/dialogs/text-edit.h b/src/dialogs/text-edit.h deleted file mode 100644 index 84f914728..000000000 --- a/src/dialogs/text-edit.h +++ /dev/null @@ -1,31 +0,0 @@ -/** @file - * @brief Text-edit - */ -/* Authors: - * Lauris Kaplinski <lauris@ximian.com> - * bulia byak <buliabyak@users.sf.net> - * Johan Engelen <goejendaagh@zonnet.nl> - * - * Copyright (C) 1999-2007 Authors - * Copyright (C) 2000-2001 Ximian, Inc. - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ -#ifndef SEEN_DIALOGS_TEXT_EDIT_H -#define SEEN_DIALOGS_TEXT_EDIT_H - -void sp_text_edit_dialog (void); -void sp_text_edit_dialog_default_set_insensitive (); //FIXME: Replace trough a verb - -#endif - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/context-menu.cpp b/src/ui/context-menu.cpp index 8824ad914..4cfc01cdc 100644 --- a/src/ui/context-menu.cpp +++ b/src/ui/context-menu.cpp @@ -55,7 +55,6 @@ void sp_object_menu(SPObject *object, SPDesktop *desktop, GtkMenu *menu) #include "sp-path.h" #include "sp-text.h" #include "desktop-handles.h" -#include "dialogs/text-edit.h" #include "dialogs/spellcheck.h" #include "ui/dialog/object-attributes.h" #include "ui/dialog/object-properties.h" @@ -534,7 +533,7 @@ static void sp_text_settings(GtkMenuItem *menuitem, SPItem *item) sp_desktop_selection(desktop)->set(item); } - sp_text_edit_dialog(); + desktop->_dlg_mgr->showDialog("TextFont"); } /* Spellcheck entry */ diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert index c8fa60d4a..c2a200d53 100644 --- a/src/ui/dialog/Makefile_insert +++ b/src/ui/dialog/Makefile_insert @@ -79,6 +79,8 @@ ink_common_sources += \ ui/dialog/svg-fonts-dialog.h \ ui/dialog/swatches.cpp \ ui/dialog/swatches.h \ + ui/dialog/text-edit.cpp \ + ui/dialog/text-edit.h \ ui/dialog/tile.cpp \ ui/dialog/tile.h \ ui/dialog/tracedialog.cpp \ diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index 4781e55ba..308a1247c 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -47,6 +47,7 @@ #include "preferences.h" #include "ui/dialog/object-attributes.h" #include "ui/dialog/object-properties.h" +#include "ui/dialog/text-edit.h" #ifdef ENABLE_SVG_FONTS @@ -122,6 +123,7 @@ DialogManager::DialogManager() { registerFactory("Transformation", &create<Transformation, FloatingBehavior>); registerFactory("UndoHistory", &create<UndoHistory, FloatingBehavior>); registerFactory("InputDevices", &create<InputDialog, FloatingBehavior>); + registerFactory("TextFont", &create<TextEdit, FloatingBehavior>); } else { @@ -152,6 +154,7 @@ DialogManager::DialogManager() { registerFactory("Transformation", &create<Transformation, DockBehavior>); registerFactory("UndoHistory", &create<UndoHistory, DockBehavior>); registerFactory("InputDevices", &create<InputDialog, DockBehavior>); + registerFactory("TextFont", &create<TextEdit, DockBehavior>); } } diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp new file mode 100644 index 000000000..046d0e513 --- /dev/null +++ b/src/ui/dialog/text-edit.cpp @@ -0,0 +1,703 @@ +/** + * @file + * Text editing dialog. + */ +/* Authors: + * Lauris Kaplinski <lauris@ximian.com> + * bulia byak <buliabyak@users.sf.net> + * Johan Engelen <goejendaagh@zonnet.nl> + * Abhishek Sharma + * + * Copyright (C) 1999-2007 Authors + * Copyright (C) 2000-2001 Ximian, Inc. + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <libnrtype/font-instance.h> +#include <gtk/gtk.h> + +#ifdef WITH_GTKSPELL +extern "C" { +# include <gtkspell/gtkspell.h> +} +#endif + +#include <gtkmm/stock.h> +#include <libnrtype/font-instance.h> +#include <libnrtype/font-style-to-pos.h> +#include <xml/repr.h> + +#include "text-edit.h" +#include "macros.h" +#include "helper/window.h" +#include "inkscape.h" +#include "document.h" +#include "desktop.h" +#include "desktop-style.h" +#include "desktop-handles.h" +#include "document-undo.h" +#include "selection.h" +#include "style.h" +#include "sp-text.h" +#include "sp-flowtext.h" +#include "text-editing.h" +#include "ui/icon-names.h" +#include "preferences.h" +#include "verbs.h" +#include "interface.h" +#include "svg/css-ostringstream.h" +#include "widgets/icon.h" + + +namespace Inkscape { +namespace UI { +namespace Dialog { + +TextEdit::TextEdit() + : UI::Widget::Panel("", "/dialogs/textandfont", SP_VERB_DIALOG_TEXT), + font_label(_("_Font"), true), + layout_frame(_("Layout")), + text_label(_("_Text"), true), + setasdefault_button(_("Set as _default")), + close_button(Gtk::Stock::CLOSE), + apply_button(Gtk::Stock::APPLY), + desktop(NULL), + deskTrack(), + selectChangedConn(), + subselChangedConn(), + selectModifiedConn(), + /* + TRANSLATORS: Test string used in text and font dialog (when no + * text has been entered) to get a preview of the font. Choose + * some representative characters that users of your locale will be + * interested in.*/ + blocked(false), + samplephrase(_("AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()")) +{ + + /* Font selector */ + GtkWidget *fontsel = sp_font_selector_new (); + gtk_widget_set_size_request (fontsel, 0, 150); + fsel = SP_FONT_SELECTOR(fontsel); + fontsel_hbox.pack_start(*Gtk::manage(Glib::wrap(fontsel)), true, true); + + /* Align buttons */ + styleButton(&align_left, _("Align left"), GTK_STOCK_JUSTIFY_LEFT, NULL); + styleButton(&align_center, _("Align center"), GTK_STOCK_JUSTIFY_CENTER, &align_left); + styleButton(&align_right, _("Align right"), GTK_STOCK_JUSTIFY_RIGHT, &align_left); + styleButton(&align_justify, _("Justify (only flowed text)"), GTK_STOCK_JUSTIFY_FILL, &align_left); + layout_hbox.pack_start(align_sep, false, false, 10); + + /* Direction buttons */ + styleButton(&text_horizontal, _("Horizontal text"), INKSCAPE_ICON("format-text-direction-horizontal"), NULL); + styleButton(&text_vertical, _("Vertical text"), INKSCAPE_ICON("format-text-direction-vertical"), &text_horizontal); + layout_hbox.pack_start(text_sep, false, false, 10); + + /* Line Spacing */ + GtkWidget *px = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("text_line_spacing") ); + layout_hbox.pack_start(*Gtk::manage(Glib::wrap(px)), false, false); + +/** +This would introduce dependency on gtk version 2.24 which is currently not available in +Trisquel GNU/Linux 4.5.1 (released on May 25th, 2011) +This conditional and its #else block can be deleted in the future. +*/ +#if GTK_CHECK_VERSION(2, 24,0) + spacing_combo = gtk_combo_box_text_new_with_entry (); +#else + spacing_combo = gtk_combo_box_entry_new_text (); +#endif + gtk_widget_set_size_request (spacing_combo, 90, -1); + + const gchar *spacings[] = {"50%", "80%", "90%", "100%", "110%", "120%", "130%", "140%", "150%", "200%", "300%", NULL}; + for (int i = 0; spacings[i]; i++) { +/** +This would introduce dependency on gtk version 2.24 which is currently not available in +Trisquel GNU/Linux 4.5.1 (released on May 25th, 2011) +This conditional and its #else block can be deleted in the future. +*/ +#if GTK_CHECK_VERSION(2, 24,0) + gtk_combo_box_text_append_text((GtkComboBoxText *) spacing_combo, spacings[i]); +#else + gtk_combo_box_append_text((GtkComboBox *) spacing_combo, spacings[i]); +#endif + } + + gtk_widget_set_tooltip_text (px, _("Spacing between lines (percent of font size)")); + gtk_widget_set_tooltip_text (spacing_combo, _("Spacing between lines (percent of font size)")); + layout_hbox.pack_start(*Gtk::manage(Glib::wrap(spacing_combo)), false, false); + layout_frame.add(layout_hbox); + + /* Font preview */ + preview_label.set_ellipsize(Pango::ELLIPSIZE_END); + preview_label.set_justify(Gtk::JUSTIFY_CENTER); + preview_label.set_line_wrap(FALSE); + + font_vbox.pack_start(fontsel_hbox, true, true); + font_vbox.pack_start(layout_frame, false, false, VB_MARGIN); + font_vbox.pack_start(preview_label, true, true, VB_MARGIN); + + /* Text tab */ + scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC ); + scroller.set_shadow_type(Gtk::SHADOW_IN); + + text_buffer = gtk_text_buffer_new (NULL); + text_view = gtk_text_view_new_with_buffer (text_buffer); + gtk_text_view_set_wrap_mode ((GtkTextView *) text_view, GTK_WRAP_WORD); + +#ifdef WITH_GTKSPELL + GError *error = NULL; + +/* + TODO: Use computed xml:lang attribute of relevant element, if present, to specify the + language (either as 2nd arg of gtkspell_new_attach, or with explicit + gtkspell_set_language call in; see advanced.c example in gtkspell docs). + onReadSelection looks like a suitable place. +*/ + if (gtkspell_new_attach(GTK_TEXT_VIEW(text_view), NULL, &error) == NULL) { + g_print("gtkspell error: %s\n", error->message); + g_error_free(error); + } +#endif + + gtk_widget_set_size_request (text_view, -1, 64); + gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), TRUE); + scroller.add(*Gtk::manage(Glib::wrap(text_view))); + text_vbox.pack_start(scroller, true, true, 0); + + notebook.append_page(font_vbox, font_label); + notebook.append_page(text_vbox, text_label); + + /* Buttons */ + setasdefault_button.set_use_underline(true); + apply_button.set_flags(Gtk::CAN_DEFAULT); + //apply_button.grab_default(); + button_row.pack_start(setasdefault_button, false, false, 0); + button_row.pack_end(close_button, false, false, VB_MARGIN); + button_row.pack_end(apply_button, false, false, VB_MARGIN); + + Gtk::Box *contents = _getContents(); + contents->set_spacing(4); + contents->pack_start(notebook, true, true); + contents->pack_start(button_row, false, false, VB_MARGIN); + + /* Signal handlers */ + g_signal_connect ( G_OBJECT (fontsel), "font_set", G_CALLBACK (onFontChange), this ); + g_signal_connect ( G_OBJECT (spacing_combo), "changed", G_CALLBACK (onLineSpacingChange), this ); + g_signal_connect ( G_OBJECT (text_buffer), "changed", G_CALLBACK (onTextChange), this ); + setasdefault_button.signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onSetDefault)); + apply_button.signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onApply)); + close_button.signal_clicked().connect(sigc::bind(_signal_response.make_slot(), GTK_RESPONSE_CLOSE)); + + desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &TextEdit::setTargetDesktop) ); + deskTrack.connect(GTK_WIDGET(gobj())); + + show_all_children(); +} + +TextEdit::~TextEdit() +{ + selectModifiedConn.disconnect(); + subselChangedConn.disconnect(); + selectChangedConn.disconnect(); + desktopChangeConn.disconnect(); + deskTrack.disconnect(); +} + +/* + * Function to style the radio buttons with tooltips and icons + */ +void TextEdit::styleButton(Gtk::RadioButton *button, gchar const *tooltip, gchar const *icon_name, Gtk::RadioButton *group_button ) +{ + GtkWidget *icon = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, icon_name ); + if (!GTK_IS_IMAGE(icon)) { + icon = gtk_image_new_from_stock ( icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR ); + } + + if (group_button) { + Gtk::RadioButton::Group group = group_button->get_group(); + button->set_group(group); + } + + button->add(*Gtk::manage(Glib::wrap(icon))); + button->set_tooltip_text(tooltip); + button->set_relief(Gtk::RELIEF_NONE); + button->set_mode(false); + button->signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onToggle)); + + layout_hbox.pack_start(*button, false, false); +} + +void TextEdit::onSelectionModified(guint flags ) +{ + gboolean style, content; + + style = ((flags & ( SP_OBJECT_CHILD_MODIFIED_FLAG | + SP_OBJECT_STYLE_MODIFIED_FLAG )) != 0 ); + + content = ((flags & ( SP_OBJECT_CHILD_MODIFIED_FLAG | + SP_TEXT_CONTENT_MODIFIED_FLAG )) != 0 ); + + onReadSelection (style, content); +} +/** + * Called whenever something 'changes' on canvas + * Gets the currently selected item from the canvas and sets all the controls in this dialog to the correct state + */ +void TextEdit::onReadSelection ( gboolean dostyle, gboolean docontent ) +{ + if (blocked) + return; + + if (!desktop || SP_ACTIVE_DESKTOP != desktop) + { + return; + } + + blocked = true; + + SPItem *text = getSelectedTextItem (); + + Glib::ustring phrase = samplephrase; + + if (text) + { + guint items = getSelectedTextCount (); + if (items == 1) { + gtk_widget_set_sensitive (text_view, TRUE); + } else { + gtk_widget_set_sensitive (text_view, FALSE); + } + apply_button.set_sensitive ( false ); + setasdefault_button.set_sensitive ( true ); + + //if (docontent) { // When would we NOT want to show the content ? + gchar *str; + str = sp_te_get_string_multiline (text); + if (str) { + if (items == 1) { + gtk_text_buffer_set_text (text_buffer, str, strlen (str)); + gtk_text_buffer_set_modified (text_buffer, FALSE); + } + phrase = str; + + } else { + gtk_text_buffer_set_text (text_buffer, "", 0); + } + //} // end of if (docontent) + text->getRepr(); // was being called but result ignored. Check this. + } else { + gtk_widget_set_sensitive (text_view, FALSE); + apply_button.set_sensitive ( false ); + setasdefault_button.set_sensitive ( false ); + } + + if (dostyle) { + // create temporary style + SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection + //int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); + int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); + int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); + int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + + // If querying returned nothing, read the style from the text tool prefs (default style for new texts) + // (Ok to not get a font specification - must just rely on the family and style in that case) + if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING + || result_numbers == QUERY_STYLE_NOTHING) { + sp_style_read_from_prefs(query, "/tools/text"); + } + + // FIXME: process result_family/style == QUERY_STYLE_MULTIPLE_DIFFERENT by showing "Many" in the lists + + // Get a font_instance using the font-specification attribute stored in SPStyle if available + font_instance *font = font_factory::Default()->FaceFromStyle(query); + + if (font) { + sp_font_selector_set_font (fsel, font, query->font_size.computed); + setPreviewText(font, phrase); + font->Unref(); + font=NULL; + } + + if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) { + if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) { + align_justify.set_active(); + } else { + align_left.set_active(); + } + } else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) { + align_center.set_active(); + } else { + align_right.set_active(); + } + + if (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB) { + text_horizontal.set_active(); + } else { + text_vertical.set_active(); + } + + double height; + if (query->line_height.normal) height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL; + else if (query->line_height.unit == SP_CSS_UNIT_PERCENT) + height = query->line_height.value; + else height = query->line_height.computed; + gchar *sstr = g_strdup_printf ("%d%%", (int) floor(height * 100 + 0.5)); + + gtk_entry_set_text ((GtkEntry *) gtk_bin_get_child ((GtkBin *) spacing_combo), sstr); + g_free(sstr); + + sp_style_unref(query); + } + blocked = false; +} + +void TextEdit::setPreviewText (font_instance *font, Glib::ustring phrase) +{ + if (!font) { + return; + } + + char *desc = pango_font_description_to_string(font->descr); + double size = sp_font_selector_get_size(fsel); + + gchar *const phrase_escaped = g_markup_escape_text(phrase.c_str(), -1); + + gchar *markup = g_strdup_printf("<span font=\"%s\" size=\"%d\">%s</span>", + desc, (int) (size * PANGO_SCALE), phrase_escaped); + + + preview_label.set_markup(markup); + + g_free(desc); + g_free(phrase_escaped); + g_free(markup); +} + +SPItem *TextEdit::getSelectedTextItem (void) +{ + if (!SP_ACTIVE_DESKTOP) + return NULL; + + for (const GSList *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); + item != NULL; + item = item->next) + { + if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) + return SP_ITEM (item->data); + } + + return NULL; +} + + +unsigned TextEdit::getSelectedTextCount (void) +{ + if (!SP_ACTIVE_DESKTOP) + return 0; + + unsigned int items = 0; + + for (const GSList *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); + item != NULL; + item = item->next) + { + if (SP_IS_TEXT(item->data) || SP_IS_FLOWTEXT(item->data)) + ++items; + } + + return items; +} + +void TextEdit::onSelectionChange() +{ + onReadSelection (TRUE, TRUE); +} + +void TextEdit::updateObjectText ( SPItem *text ) +{ + GtkTextIter start, end; + gchar *str; + + // write text + if (gtk_text_buffer_get_modified (text_buffer)) { + gtk_text_buffer_get_bounds (text_buffer, &start, &end); + str = gtk_text_buffer_get_text (text_buffer, &start, &end, TRUE); + sp_te_set_repr_text_multiline (text, str); + g_free (str); + gtk_text_buffer_set_modified (text_buffer, FALSE); + } +} + +SPCSSAttr *TextEdit::getTextStyle () +{ + SPCSSAttr *css = sp_repr_css_attr_new (); + + // font + font_instance *font = sp_font_selector_get_font (fsel); + + if ( font ) { + Glib::ustring fontName = font_factory::Default()->ConstructFontSpecification(font); + sp_repr_css_set_property (css, "-inkscape-font-specification", fontName.c_str()); + + gchar c[256]; + + font->Family(c, 256); + sp_repr_css_set_property (css, "font-family", c); + + font->Attribute( "weight", c, 256); + sp_repr_css_set_property (css, "font-weight", c); + + font->Attribute("style", c, 256); + sp_repr_css_set_property (css, "font-style", c); + + font->Attribute("stretch", c, 256); + sp_repr_css_set_property (css, "font-stretch", c); + + font->Attribute("variant", c, 256); + sp_repr_css_set_property (css, "font-variant", c); + + Inkscape::CSSOStringStream os; + os << sp_font_selector_get_size (fsel) << "px"; // must specify px, see inkscape bug 1221626 and 1610103 + sp_repr_css_set_property (css, "font-size", os.str().c_str()); + + font->Unref(); + font=NULL; + } + + // Layout + if ( align_left.get_active() ) { + sp_repr_css_set_property (css, "text-anchor", "start"); + sp_repr_css_set_property (css, "text-align", "start"); + } else if ( align_center.get_active() ) { + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "text-align", "center"); + } else if ( align_right.get_active() ){ + sp_repr_css_set_property (css, "text-anchor", "end"); + sp_repr_css_set_property (css, "text-align", "end"); + } else { + // Align Justify + sp_repr_css_set_property (css, "text-anchor", "start"); + sp_repr_css_set_property (css, "text-align", "justify"); + } + + if (text_horizontal.get_active()) { + sp_repr_css_set_property (css, "writing-mode", "lr"); + } else { + sp_repr_css_set_property (css, "writing-mode", "tb"); + } + + // Note that CSS 1.1 does not support line-height; we set it for consistency, but also set + // sodipodi:linespacing for backwards compatibility; in 1.2 we use line-height for flowtext + +/** +This would introduce dependency on gtk version 2.24 which is currently not available in +Trisquel GNU/Linux 4.5.1 (released on May 25th, 2011) +This conditional and its #else block can be deleted in the future. +*/ +#if GTK_CHECK_VERSION(2, 24,0) + const gchar *sstr = gtk_combo_box_text_get_active_text ((GtkComboBoxText *) spacing_combo); +#else + const gchar *sstr = gtk_entry_get_text ((GtkEntry *) (gtk_bin_get_child (GTK_BIN (combo)))); +#endif + sp_repr_css_set_property (css, "line-height", sstr); + + return css; +} + +void TextEdit::onSetDefault() +{ + SPCSSAttr *css = getTextStyle (); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + blocked = true; + prefs->mergeStyle("/tools/text/style", css); + blocked = false; + + sp_repr_css_attr_unref (css); + + setasdefault_button.set_sensitive ( false ); +} + +void TextEdit::onApply() +{ + blocked = true; + + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + + unsigned items = 0; + const GSList *item_list = sp_desktop_selection(desktop)->itemList(); + SPCSSAttr *css = getTextStyle (); + sp_desktop_set_style(desktop, css, true); + + for (; item_list != NULL; item_list = item_list->next) { + // apply style to the reprs of all text objects in the selection + if (SP_IS_TEXT (item_list->data)) { + + // backwards compatibility: + reinterpret_cast<SPObject*>(item_list->data)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); + + ++items; + } + else if (SP_IS_FLOWTEXT (item_list->data)) + // no need to set sodipodi:linespacing, because Inkscape never supported it on flowtext + ++items; + } + + if (items == 0) { + // no text objects; apply style to prefs for new objects + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->mergeStyle("/tools/text/style", css); + setasdefault_button.set_sensitive ( false ); + + } else if (items == 1) { + // exactly one text object; now set its text, too + SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT(item)) { + updateObjectText (item); + } + } + + // complete the transaction + DocumentUndo::done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT, + _("Set text style")); + apply_button.set_sensitive ( false ); + + sp_repr_css_attr_unref (css); + blocked = false; +} + +void TextEdit::onTextChange (GtkTextBuffer *text_buffer, TextEdit *self) +{ + if (!self || self->blocked) { + return; + } + + SPItem *text = self->getSelectedTextItem(); + + GtkTextIter start; + GtkTextIter end; + gtk_text_buffer_get_bounds (text_buffer, &start, &end); + gchar *str = gtk_text_buffer_get_text(text_buffer, &start, &end, TRUE); + font_instance *font = sp_font_selector_get_font(self->fsel); + + if (font) { + const gchar *phrase = str && *str ? str : self->samplephrase.c_str(); + self->setPreviewText(font, phrase); + } else { + self->preview_label.set_markup(""); + } + g_free (str); + + if (text) { + self->apply_button.set_sensitive ( true ); + //self->onApply(); + } + self->setasdefault_button.set_sensitive ( true); +} + +void TextEdit::onFontChange(SPFontSelector * /*fontsel*/, font_instance * font, TextEdit *self) +{ + GtkTextIter start, end; + gchar *str; + + if (!self || self->blocked) + return; + + SPItem *text = self->getSelectedTextItem (); + + gtk_text_buffer_get_bounds (self->text_buffer, &start, &end); + str = gtk_text_buffer_get_text (self->text_buffer, &start, &end, TRUE); + + if (font) { + const gchar *phrase = str && *str ? str : self->samplephrase.c_str(); + self->setPreviewText(font, phrase); + } else { + self->preview_label.set_markup(""); + } + g_free(str); + + if (text) { + self->apply_button.set_sensitive ( true ); + //self->onApply(); + } + self->setasdefault_button.set_sensitive ( true ); + +} + +void TextEdit::onToggle() +{ + if (blocked) + return; + + SPItem *text = getSelectedTextItem (); + + if (text) { + apply_button.set_sensitive ( true ); + //onApply(); + } + setasdefault_button.set_sensitive ( true ); + +} + + +void TextEdit::onLineSpacingChange(GtkComboBox* widget, gpointer data) +{ + TextEdit *self = (TextEdit *)data; + if (!self || self->blocked) + return; + + SPItem *text = self->getSelectedTextItem (); + + if (text) { + self->apply_button.set_sensitive ( true ); + //self->onApply(); + } + self->setasdefault_button.set_sensitive ( true ); +} + +void TextEdit::setDesktop(SPDesktop *desktop) +{ + Panel::setDesktop(desktop); + deskTrack.setBase(desktop); +} + +void TextEdit::setTargetDesktop(SPDesktop *desktop) +{ + if (this->desktop != desktop) { + if (this->desktop) { + selectModifiedConn.disconnect(); + subselChangedConn.disconnect(); + selectChangedConn.disconnect(); + } + this->desktop = desktop; + if (desktop && desktop->selection) { + selectChangedConn = desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(*this, &TextEdit::onSelectionChange))); + subselChangedConn = desktop->connectToolSubselectionChanged(sigc::hide(sigc::mem_fun(*this, &TextEdit::onSelectionChange))); + selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &TextEdit::onSelectionModified))); + } + //widget_setup(); + onReadSelection (TRUE, TRUE); + } +} + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/dialog/text-edit.h b/src/ui/dialog/text-edit.h new file mode 100644 index 000000000..7d599a32c --- /dev/null +++ b/src/ui/dialog/text-edit.h @@ -0,0 +1,160 @@ +/** @file + * @brief Text-edit + */ +/* Authors: + * Lauris Kaplinski <lauris@ximian.com> + * bulia byak <buliabyak@users.sf.net> + * Johan Engelen <goejendaagh@zonnet.nl> + * + * Copyright (C) 1999-2007 Authors + * Copyright (C) 2000-2001 Ximian, Inc. + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_UI_DIALOG_TEXT_EDIT_H +#define INKSCAPE_UI_DIALOG_TEXT_EDIT_H + +#include <gtk/gtk.h> + +#include <gtkmm/box.h> +#include <gtkmm/textview.h> +#include <gtkmm/notebook.h> +#include <gtkmm/button.h> +#include <gtkmm/frame.h> +#include <gtkmm/scrolledwindow.h> +#include <gtkmm/separator.h> + +#include <glibmm/i18n.h> + +#include "ui/widget/panel.h" +#include "dialogs/dialog-events.h" +#include "widgets/font-selector.h" +#include "ui/dialog/desktop-tracker.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +#define VB_MARGIN 4 + +class TextEdit : public UI::Widget::Panel { +public: + TextEdit(); + virtual ~TextEdit(); + + static TextEdit &getInstance() { return *new TextEdit(); } + +protected: + + /** + * Callbacks for button presses and change handlers + */ + void onSetDefault (); + void onApply (); + void onSelectionChange (); + void onSelectionModified (guint flags); + void onReadSelection (gboolean style, gboolean content); + void onToggle (); + static void onLineSpacingChange (GtkComboBox* widget, gpointer data); + static void onTextChange (GtkTextBuffer *text_buffer, TextEdit *self); + static void onFontChange (SPFontSelector *fontsel, font_instance *font, TextEdit *self); + + /** + * Functions to get the selected text off the main canvas + */ + SPItem *getSelectedTextItem (void); + unsigned getSelectedTextCount (void); + + /** + * Helper function to create markup from a font definition and display in the preview label + */ + void setPreviewText (font_instance *font, Glib::ustring phrase); + + void updateObjectText ( SPItem *text ); + SPCSSAttr *getTextStyle (); + + /** + * Helper function to style radio buttons with icons, tooltips + */ + void styleButton(Gtk::RadioButton *button, gchar const *tooltip, gchar const *iconname, Gtk::RadioButton *group_button ); + + /** + * Can be invoked for setting the desktop. Currently not used. + */ + void setDesktop(SPDesktop *desktop); + + /** + * Is invoked by the desktop tracker when the desktop changes. + */ + void setTargetDesktop(SPDesktop *desktop); + + + +private: + + /** + * All the dialogs widgets + */ + Gtk::Notebook notebook; + + Gtk::VBox font_vbox; + Gtk::Label font_label; + Gtk::HBox fontsel_hbox; + SPFontSelector *fsel; + + Gtk::Frame layout_frame; + Gtk::HBox layout_hbox; + Gtk::RadioButton align_left; + Gtk::RadioButton align_center; + Gtk::RadioButton align_right; + Gtk::RadioButton align_justify; + Gtk::VSeparator align_sep; + Gtk::RadioButton text_vertical; + Gtk::RadioButton text_horizontal; + Gtk::VSeparator text_sep; + GtkWidget *spacing_combo; + + Gtk::Label preview_label; + + Gtk::Label text_label; + Gtk::VBox text_vbox; + Gtk::ScrolledWindow scroller; + GtkWidget *text_view; // TODO - Convert this to a Gtk::TextView, but GtkSpell doesn't seem to work with it + GtkTextBuffer *text_buffer; + + Gtk::HBox button_row; + Gtk::Button setasdefault_button; + Gtk::Button close_button; + Gtk::Button apply_button; + + SPDesktop *desktop; + DesktopTracker deskTrack; + sigc::connection desktopChangeConn; + sigc::connection selectChangedConn; + sigc::connection subselChangedConn; + sigc::connection selectModifiedConn; + + bool blocked; + const Glib::ustring samplephrase; + TextEdit(TextEdit const &d); + TextEdit operator=(TextEdit const &d); +}; + + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + +#endif // INKSCAPE_UI_DIALOG_TEXT_EDIT_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/verbs.cpp b/src/verbs.cpp index f62b35751..afdeb665a 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -42,7 +42,6 @@ #include "dialogs/clonetiler.h" #include "dialogs/find.h" #include "dialogs/spellcheck.h" -#include "dialogs/text-edit.h" #include "dialogs/xml-tree.h" #include "display/curve.h" #include "document.h" @@ -1817,7 +1816,7 @@ void DialogVerb::perform(SPAction *action, void *data) dt->_dlg_mgr->showDialog("SprayOptionClass"); break; case SP_VERB_DIALOG_TEXT: - sp_text_edit_dialog(); + dt->_dlg_mgr->showDialog("TextFont"); break; case SP_VERB_DIALOG_XML_EDITOR: sp_xml_tree_dialog(); diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index 4515f3f97..08f98a49f 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -205,6 +205,7 @@ static void sp_font_selector_init(SPFontSelector *fsel) gtk_box_pack_start(GTK_BOX(vb), hb, FALSE, FALSE, 0); fsel->size = gtk_combo_box_entry_new_text (); + gtk_widget_set_tooltip_text (fsel->size, _("Font size (px)")); gtk_widget_set_size_request(fsel->size, 90, -1); g_signal_connect (G_OBJECT(fsel->size), "changed", G_CALLBACK (sp_font_selector_size_changed), fsel); gtk_box_pack_end (GTK_BOX(hb), fsel->size, FALSE, FALSE, 0); diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 8be528b53..171fc8332 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -46,7 +46,6 @@ #include "../desktop-handles.h" #include "../desktop-style.h" #include "../dialogs/dialog-events.h" -#include "../dialogs/text-edit.h" #include "../document-private.h" #include "../ege-adjustment-action.h" #include "../ege-output-action.h" @@ -6632,7 +6631,7 @@ static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GOb { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->mergeStyle("/tools/text/style", css); - sp_text_edit_dialog_default_set_insensitive (); //FIXME: Replace through a verb + //sp_text_edit_dialog_default_set_insensitive (); //FIXME: Replace through a verb } else { |
