Code

Simple tracking of time to display dialogs and main window.
[inkscape.git] / src / dialogs / text-edit.cpp
index 279c5b5e714bb4c14b6b3d2e24c0edfaef7698f3..d741e2de096a98bda3b7b5a9d3254cd7f3bae644 100644 (file)
@@ -1,12 +1,11 @@
-#define __SP_TEXT_EDIT_C__
-
-/**
- * \brief Text editing dialog
- *
- * Authors:
+/** @file
+ * @brief 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.
@@ -19,7 +18,6 @@
 #endif
 
 #include <libnrtype/font-instance.h>
-
 #include <gtk/gtk.h>
 
 #ifdef WITH_GTKSPELL
@@ -41,16 +39,20 @@ extern "C" {
 #include "../sp-text.h"
 #include "../sp-flowtext.h"
 #include "../text-editing.h"
-#include "../inkscape-stock.h"
+#include "../ui/icon-names.h"
 #include <libnrtype/font-style-to-pos.h>
 
 #include "dialog-events.h"
-#include "../prefs-utils.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
@@ -80,7 +82,7 @@ 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 gchar const *prefs_path = "dialogs.textandfont";
+static Glib::ustring const prefs_path = "/dialogs/textandfont/";
 
 
 
@@ -104,10 +106,11 @@ sp_text_edit_dialog_delete( GtkObject */*object*/, GdkEvent */*event*/, gpointer
     if (x<0) x=0;
     if (y<0) y=0;
 
-    prefs_set_int_attribute (prefs_path, "x", x);
-    prefs_set_int_attribute (prefs_path, "y", y);
-    prefs_set_int_attribute (prefs_path, "w", w);
-    prefs_set_int_attribute (prefs_path, "h", h);
+    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
 }
@@ -138,20 +141,23 @@ text_view_focus_out (GtkWidget */*w*/, GdkEventKey */*event*/, gpointer data)
 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_get_int_attribute (prefs_path, "x", -1000);
-            y = prefs_get_int_attribute (prefs_path, "y", -1000);
+            x = prefs->getInt(prefs_path + "x", -1000);
+            y = prefs->getInt(prefs_path + "y", -1000);
         }
-
         if (w ==0 || h == 0) {
-            w = prefs_get_int_attribute (prefs_path, "w", 0);
-            h = prefs_get_int_attribute (prefs_path, "h", 0);
+            w = prefs->getInt(prefs_path + "w", 0);
+            h = prefs->getInt(prefs_path + "h", 0);
         }
 
 //        if (x<0) x=0;
@@ -297,7 +303,7 @@ sp_text_edit_dialog (void)
                     // horizontal
                     {
                         GtkWidget *px = sp_icon_new( Inkscape::ICON_SIZE_LARGE_TOOLBAR,
-                                                      INKSCAPE_STOCK_WRITING_MODE_LR );
+                                                      INKSCAPE_ICON_FORMAT_TEXT_DIRECTION_HORIZONTAL );
                         GtkWidget *b = group = gtk_radio_button_new (NULL);
                         gtk_tooltips_set_tip (tt, b, _("Horizontal text"), NULL);
                         gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE);
@@ -305,13 +311,13 @@ sp_text_edit_dialog (void)
                         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_STOCK_WRITING_MODE_LR, b);
+                        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_STOCK_WRITING_MODE_TB );
+                                                      INKSCAPE_ICON_FORMAT_TEXT_DIRECTION_VERTICAL );
                         GtkWidget *b = gtk_radio_button_new (gtk_radio_button_group (GTK_RADIO_BUTTON (group)));
                         gtk_tooltips_set_tip (tt, b, _("Vertical text"), NULL);
                         gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE);
@@ -319,7 +325,7 @@ sp_text_edit_dialog (void)
                         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_STOCK_WRITING_MODE_TB, b);
+                        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);
@@ -456,6 +462,13 @@ sp_text_edit_dialog (void)
         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()
@@ -526,30 +539,34 @@ sp_get_text_dialog_style ()
         /* font */
         font_instance *font = sp_font_selector_get_font (SP_FONT_SELECTOR (fontsel));
 
-                               if ( font ) {
-                                       gchar c[256];
-                                       font->Family(c, 256);
-                                       sp_repr_css_set_property (css, "font-family", c);
+        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->Attribute( "weight", c, 256);
-                                       sp_repr_css_set_property (css, "font-weight", c);
+            font->Family(c, 256);
+            sp_repr_css_set_property (css, "font-family", c);
 
-                                       font->Attribute("style", c, 256);
-                                       sp_repr_css_set_property (css, "font-style", c);
+            font->Attribute( "weight", c, 256);
+            sp_repr_css_set_property (css, "font-weight", c);
 
-                                       font->Attribute("stretch", c, 256);
-                                       sp_repr_css_set_property (css, "font-stretch", c);
+            font->Attribute("style", c, 256);
+            sp_repr_css_set_property (css, "font-style", c);
 
-                                       font->Attribute("variant", c, 256);
-                                       sp_repr_css_set_property (css, "font-variant", c);
+            font->Attribute("stretch", c, 256);
+            sp_repr_css_set_property (css, "font-stretch", 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->Attribute("variant", c, 256);
+            sp_repr_css_set_property (css, "font-variant", c);
 
-                                       font->Unref();
-                                       font=NULL;
-                               }
+            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");
@@ -567,7 +584,7 @@ sp_get_text_dialog_style ()
                 sp_repr_css_set_property (css, "text-align", "center");
             } else {
                 // Align Right
-               b = (GtkWidget*)g_object_get_data ( G_OBJECT (dlg),
+                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");
@@ -580,7 +597,7 @@ sp_get_text_dialog_style ()
             }
         }
 
-        b = (GtkWidget*)g_object_get_data (G_OBJECT (dlg), INKSCAPE_STOCK_WRITING_MODE_LR );
+        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");
@@ -604,9 +621,10 @@ 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));
-    sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style");
+    prefs->mergeStyle("/tools/text/style", css);
     g_object_set_data (G_OBJECT (dlg), "blocked", GINT_TO_POINTER (FALSE));
 
     sp_repr_css_attr_unref (css);
@@ -635,7 +653,7 @@ sp_text_edit_dialog_apply( GtkButton */*button*/, GtkWidget *dlg )
         if (SP_IS_TEXT (item_list->data)) {
 
             // backwards compatibility:
-            SP_OBJECT_REPR(item_list->data)->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL));
+            reinterpret_cast<SPObject*>(item_list->data)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL));
 
             ++items;
         }
@@ -646,7 +664,8 @@ sp_text_edit_dialog_apply( GtkButton */*button*/, GtkWidget *dlg )
 
     if (items == 0) {
         // no text objects; apply style to prefs for new objects
-        sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style");
+        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 */
@@ -657,8 +676,8 @@ sp_text_edit_dialog_apply( GtkButton */*button*/, GtkWidget *dlg )
     }
 
     // complete the transaction
-    sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT,
-                      _("Set text style"));
+    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));
@@ -723,7 +742,7 @@ sp_text_edit_dialog_read_selection ( GtkWidget *dlg,
                 sp_font_preview_set_phrase (SP_FONT_PREVIEW (preview), NULL);
             }
         } // end of if (docontent)
-        repr = SP_OBJECT_REPR (text);
+        repr = text->getRepr();
 
     } else {
         gtk_widget_set_sensitive (textw, FALSE);
@@ -736,29 +755,30 @@ sp_text_edit_dialog_read_selection ( GtkWidget *dlg,
         // 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)
-        if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING || result_numbers == QUERY_STYLE_NOTHING) {
-            repr = inkscape_get_repr (INKSCAPE, "tools.text");
-            if (repr) {
-                gtk_widget_set_sensitive (notebook, TRUE);
-                sp_style_read_from_repr (query, repr);
-            } else {
-                gtk_widget_set_sensitive (notebook, FALSE);
-            }
+        // (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
-        font_instance *font = (font_factory::Default())->Face ( query->text->font_family.value, font_style_to_pos(*query) );
+
+        // 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);
             sp_font_preview_set_font (SP_FONT_PREVIEW (preview), font, SP_FONT_SELECTOR(fontsel));
-                                               font->Unref();
-                                               font=NULL;
+            font->Unref();
+            font=NULL;
         }
 
         GtkWidget *b;
@@ -776,9 +796,9 @@ sp_text_edit_dialog_read_selection ( GtkWidget *dlg,
         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_STOCK_WRITING_MODE_LR );
+            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_STOCK_WRITING_MODE_TB );
+            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);
 
@@ -959,4 +979,4 @@ sp_ted_get_selected_text_count (void)
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :