From 65109d24faf88afd631db022297dc9fbb0c0743b Mon Sep 17 00:00:00 2001 From: mderezynski Date: Thu, 18 May 2006 14:56:08 +0000 Subject: [PATCH] * Properly deal with setting the style using the text toolbar --- src/verbs.cpp | 58 ++++++++++++++++++++++++++++++- src/verbs.h | 8 +++++ src/widgets/toolbox.cpp | 75 +++++++++++++++++++---------------------- 3 files changed, 99 insertions(+), 42 deletions(-) diff --git a/src/verbs.cpp b/src/verbs.cpp index a046372fc..bec08fe55 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -333,6 +333,24 @@ public: { } }; /* TutorialVerb class */ +/** \brief A class to encompass all of the verbs which deal with + text operations. */ +class TextVerb : public Verb { +private: + static void perform(SPAction *action, void *mydata, void *otherdata); + static SPActionEventVector vector; +protected: + virtual SPAction *make_action(Inkscape::UI::View::View *view); +public: + /** \brief Use the Verb initializer with the same parameters. */ + TextVerb(unsigned int const code, + gchar const *id, + gchar const *name, + gchar const *tip, + gchar const *image) : + Verb(code, id, name, tip, image) + { } +}; //TextVerb : public Verb Verb::VerbTable Verb::_verbs; Verb::VerbIDTable Verb::_verb_ids; @@ -509,6 +527,18 @@ TutorialVerb::make_action(Inkscape::UI::View::View *view) return make_action_helper(view, &vector); } +/** \brief Create an action for a \c TextVerb + \param view Which view the action should be created for + \return The built action. + + Calls \c make_action_helper with the \c vector. +*/ +SPAction * +TextVerb::make_action(Inkscape::UI::View::View *view) +{ + return make_action_helper(view, &vector); +} + /** \brief A quick little convience function to make building actions a little bit easier. \param view Which view the action should be created for. @@ -1367,6 +1397,18 @@ ContextVerb::perform(SPAction *action, void *data, void *pdata) } // end of sp_verb_action_ctx_perform() +/** \brief Decode the verb code and take appropriate action */ +void +TextVerb::perform(SPAction *action, void *data, void *pdata) +{ + SPDesktop *dt = static_cast(sp_action_get_view(action)); + if (!dt) + return; + + SPDocument *doc = sp_desktop_document(dt); + Inkscape::XML::Node *repr = SP_OBJECT_REPR(dt->namedview); +} + /** \brief Decode the verb code and take appropriate action */ void ZoomVerb::perform(SPAction *action, void *data, void *pdata) @@ -1783,6 +1825,14 @@ SPActionEventVector HelpVerb::vector = SPActionEventVector TutorialVerb::vector = {{NULL},TutorialVerb::perform, NULL, NULL, NULL}; +/** + * Action vector to define functions called if a staticly defined tutorial verb + * is called + */ +SPActionEventVector TextVerb::vector = + {{NULL},TextVerb::perform, NULL, NULL, NULL}; + + /* *********** Effect Last ********** */ /** \brief A class to represent the last effect issued */ @@ -2359,7 +2409,13 @@ Verb *Verb::_base_verbs[] = { N_("Fit the canvas to the drawing"), NULL), new FitCanvasVerb(SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING, "FitCanvasToSelectionOrDrawing", N_("Fit Canvas to Selection or Drawing"), N_("Fit the canvas to the current selection or the drawing if there is no selection"), NULL), - + +#if 0 + //Text + new FitCanvasVerb(SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING, "FitCanvasToSelectionOrDrawing", N_("Fit Canvas to Selection or Drawing"), + N_("Fit the canvas to the current selection or the drawing if there is no selection"), NULL), +#endif + /* Footer */ new Verb(SP_VERB_LAST, " '\"invalid id", NULL, NULL, NULL) }; diff --git a/src/verbs.h b/src/verbs.h index 5d364c53b..4ed1c6bc9 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -229,6 +229,14 @@ enum { SP_VERB_FIT_CANVAS_TO_SELECTION, SP_VERB_FIT_CANVAS_TO_DRAWING, SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING, + +#if 0 + /* Text */ + SP_VERB_TEXT_BOLD, + SP_VERB_TEXT_ITALIC, + SP_VERB_TEXT_UNDERLINE, +#endif + /* Footer */ SP_VERB_LAST }; diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 0a4065e80..cc76f080e 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -2788,7 +2788,6 @@ sp_text_toolbox_selection_changed (Inkscape::Selection *selection, GObject *tbl) { GtkWidget *cbox = GTK_WIDGET(g_object_get_data (G_OBJECT(tbl), "combo-box-family")); Inkscape::XML::Node *repr = 0; -// Inkscape::XML::Node *oldrepr = 0; SPStyle *style = 0; bool multiple = false; const GSList *items = selection->itemList(); @@ -2824,25 +2823,10 @@ sp_text_toolbox_selection_changed (Inkscape::Selection *selection, GObject *tbl) g_object_set_data (G_OBJECT (cbox), "block", GINT_TO_POINTER(1)); gtk_combo_box_set_active (GTK_COMBO_BOX (cbox), gtk_tree_path_get_indices (path.gobj())[0]); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; SPCSSAttr *css = sp_repr_css_attr_new (); - items = sp_desktop_selection(desktop)->itemList(); - sp_repr_css_set_property (css, "font-family", gtk_combo_box_get_active_text (GTK_COMBO_BOX(cbox))); sp_desktop_set_style (desktop, css, true); - - for (; items != NULL; items = items->next) - { - // apply style to the reprs of all text objects in the selection - if (SP_IS_TEXT (items->data)) - { - // backwards compatibility: - SP_OBJECT_REPR(items->data)->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); - } - } - - // complete the transaction sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP)); sp_repr_css_attr_unref (css); @@ -2855,36 +2839,30 @@ sp_text_toolbox_family_changed (GtkComboBox *cbox, { SPDesktop *desktop = SP_ACTIVE_DESKTOP; unsigned items = 0; - const GSList *item_list = sp_desktop_selection(desktop)->itemList(); - SPCSSAttr *css = sp_repr_css_attr_new (); if (GPOINTER_TO_INT(g_object_get_data (G_OBJECT (cbox), "block")) != 0) return; + const GSList *item_list = sp_desktop_selection(desktop)->itemList(); + SPCSSAttr *css = sp_repr_css_attr_new (); sp_repr_css_set_property (css, "font-family", gtk_combo_box_get_active_text (cbox)); 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: - SP_OBJECT_REPR(item_list->data)->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; - } - - sp_repr_css_change (inkscape_get_repr (INKSCAPE, "tools.text"), css, "style"); - - // complete the transaction sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP)); sp_repr_css_attr_unref (css); } +#if 0 +static void cell_data_func (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + GtkTreeModel *tree_model, + GtkTreeIter *iter, + gpointer data) +{ + char *text; + gtk_tree_model_get (tree_model, iter, 0, &text, -1); + g_object_set (G_OBJECT (cell), "family", text, NULL); +} +#endif + static GtkWidget* sp_text_toolbox_new (SPDesktop *desktop) { @@ -2900,7 +2878,22 @@ sp_text_toolbox_new (SPDesktop *desktop) { GtkWidget *cbox = gtk_combo_box_entry_new_text (); Glib::RefPtr store = Inkscape::FontLister::get_instance()->get_font_list(); + gtk_cell_layout_clear (GTK_CELL_LAYOUT (cbox)); + GtkCellRenderer *cell = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbox), cell, FALSE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbox), cell, "text", 0, NULL); + +#if 0 + gtk_cell_layout_set_cell_data_func + (GTK_CELL_LAYOUT (cbox), + cell, + GtkCellLayoutDataFunc (cell_data_func), + tbl, + NULL); +#endif + gtk_combo_box_set_model (GTK_COMBO_BOX (cbox), GTK_TREE_MODEL (Glib::unwrap(store))); + gtk_widget_set_size_request (cbox, 250, -1); aux_toolbox_space (tbl, 1); gtk_box_pack_start (GTK_BOX (tbl), cbox, FALSE, FALSE, 0); @@ -2933,9 +2926,9 @@ sp_text_toolbox_new (SPDesktop *desktop) gtk_box_pack_start (GTK_BOX (tbl), c, FALSE, FALSE, 0); } - aux_toolbox_space(tbl, AUX_BETWEEN_BUTTON_GROUPS); - //Bold - { + aux_toolbox_space(tbl, AUX_BETWEEN_BUTTON_GROUPS); + //Bold + { GtkWidget *px = gtk_image_new_from_stock(GTK_STOCK_BOLD, Inkscape::ICON_SIZE_SMALL_TOOLBAR); GtkWidget *button = gtk_toggle_button_new (); gtk_container_add (GTK_CONTAINER (button), px); @@ -2944,7 +2937,7 @@ sp_text_toolbox_new (SPDesktop *desktop) gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); gtk_widget_set_sensitive(button, TRUE); gtk_box_pack_start (GTK_BOX (tbl), button, FALSE, FALSE, 0); - } + } //Italic -- 2.30.2