index de7b27c579e6210ba1e209117ffa2589c2a9141d..146853c2258d10716a08fbe89703cc75757a9db4 100644 (file)
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
#include "document-private.h"
#include "desktop-style.h"
#include "../libnrtype/font-lister.h"
+#include "../connection-pool.h"
#include "mod360.h"
static GtkWidget *sp_dropper_toolbox_new(SPDesktop *desktop);
static GtkWidget *sp_empty_toolbox_new(SPDesktop *desktop);
static GtkWidget *sp_connector_toolbox_new(SPDesktop *desktop);
-static GtkWidget *sp_text_toolbox_new (SPDesktop *desktop);
+
+namespace { GtkWidget *sp_text_toolbox_new (SPDesktop *desktop); }
static struct {
//Call back for letter rotation spinbutton
}*/
-static void
-sp_text_toolbox_selection_changed (Inkscape::Selection *selection, GObject *tbl)
-{
- GtkWidget *cbox = GTK_WIDGET(g_object_get_data (G_OBJECT(tbl), "combo-box-family"));
+namespace {
+
+ void
+ sp_text_toolbox_selection_changed (Inkscape::Selection *selection, GObject *tbl)
+ {
+ GtkComboBox *cbox = 0;
+
+ SPStyle *query =
+ sp_style_new ();
+
+ 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);
- // create temporary style
- SPStyle *query = sp_style_new ();
- // 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_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);
+ 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)
+ {
+ Inkscape::XML::Node *repr = inkscape_get_repr (INKSCAPE, "tools.text");
+
+ if (repr)
+ {
+ sp_style_read_from_repr (query, repr);
+ }
+ else
+ {
+ return;
+ }
+ }
- // 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)
+ if (result_numbers == QUERY_STYLE_MULTIPLE_DIFFERENT)
+ {
+ static char* cboxes[] = { "combo-box-family", "combo-box-style" };
+
+ for (unsigned n = 0 ; n < G_N_ELEMENTS(cboxes); ++n)
+ {
+ cbox = GTK_COMBO_BOX(g_object_get_data (G_OBJECT(tbl), cboxes[n]));
+ g_object_set_data (G_OBJECT (cbox), "block", GINT_TO_POINTER(1));
+ gtk_combo_box_set_active (GTK_COMBO_BOX (cbox), -1);
+ g_object_set_data (G_OBJECT (cbox), "block", GINT_TO_POINTER(0));
+ }
+ gtk_widget_hide (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image")));
+ return;
+ }
+
+ if (query->text)
+ {
+ if (query->text->font_family.value)
+ {
+ Gtk::TreePath path;
+ try {
+ path = Inkscape::FontLister::get_instance()->get_row_for_font (query->text->font_family.value);
+ } catch (...) {
+ return;
+ }
+
+ cbox = GTK_COMBO_BOX(g_object_get_data (G_OBJECT(tbl), "combo-box-family"));
+ 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]);
+ g_object_set_data (G_OBJECT (cbox), "block", GINT_TO_POINTER(0));
+ }
+
+ //Style
+ cbox = GTK_COMBO_BOX(g_object_get_data (G_OBJECT(tbl), "combo-box-style"));
+ g_object_set_data (G_OBJECT (cbox), "block", GINT_TO_POINTER(1));
+ gtk_combo_box_set_active (GTK_COMBO_BOX (cbox), gint(query->font_style.value));
+ g_object_set_data (G_OBJECT (cbox), "block", GINT_TO_POINTER(0));
+
+ gtk_widget_hide (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image")));
+ }
+ }
+
+ void
+ sp_text_toolbox_selection_modified (Inkscape::Selection *selection, guint flags, GObject *tbl)
{
- return;
+ sp_text_toolbox_selection_changed (selection, tbl);
}
- if (result_numbers == QUERY_STYLE_MULTIPLE_DIFFERENT)
+ void
+ sp_text_toolbox_subselection_changed (gpointer dragger, GObject *tbl)
{
- g_object_set_data (G_OBJECT (cbox), "block", GINT_TO_POINTER(1));
- gtk_combo_box_set_active (GTK_COMBO_BOX (cbox), -1);
- g_object_set_data (G_OBJECT (cbox), "block", GINT_TO_POINTER(0));
- return;
+ sp_text_toolbox_selection_changed (NULL, tbl);
+ }
+
+ void
+ sp_text_toolbox_family_changed (GtkComboBox *cbox,
+ GtkWidget *tbl)
+ {
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+
+ if (GPOINTER_TO_INT(g_object_get_data (G_OBJECT (cbox), "block")) != 0) return;
+
+ if (gtk_combo_box_get_active (cbox) < 0) return;
+
+ 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, true);
+ sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP));
+ sp_repr_css_attr_unref (css);
+
+ gtk_widget_hide (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image")));
}
- if (query->text && query->text->font_family.value)
+ void
+ sp_text_toolbox_family_entry_activate (GtkEntry *entry,
+ GtkWidget *tbl)
{
- Gtk::TreePath path;
- try {
- path = Inkscape::FontLister::get_instance()->get_row_for_font (query->text->font_family.value);
+ const char* family = gtk_entry_get_text (entry);
+
+ try {
+ Gtk::TreePath path = Inkscape::FontLister::get_instance()->get_row_for_font (family);
+ GtkComboBox *cbox = GTK_COMBO_BOX(g_object_get_data (G_OBJECT(tbl), "combo-box-family"));
+ gtk_combo_box_set_active (cbox, gtk_tree_path_get_indices (path.gobj())[0]);
+ gtk_widget_hide (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image")));
} catch (...) {
- return;
+ //XXX: Accept it anyway and show the warning
+ if (family && strlen (family)) gtk_widget_show_all (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image")));
}
- 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]);
- g_object_set_data (G_OBJECT (cbox), "block", GINT_TO_POINTER(0));
}
-}
-static void
-sp_text_toolbox_family_changed (GtkComboBox *cbox,
- GtkWidget *tbl)
-{
- SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ void
+ sp_text_toolbox_style_changed (GtkComboBox *cbox,
+ GtkWidget *tbl)
+ {
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- if (GPOINTER_TO_INT(g_object_get_data (G_OBJECT (cbox), "block")) != 0) return;
+ if (GPOINTER_TO_INT(g_object_get_data (G_OBJECT (cbox), "block")) != 0) return;
+
+ static char* styles[] = { "normal", "italic" , "oblique" };
- 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, true);
- sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP));
- sp_repr_css_attr_unref (css);
-}
+ SPCSSAttr *css = sp_repr_css_attr_new ();
+ sp_repr_css_set_property (css, "font-style", styles[gtk_combo_box_get_active (cbox)]);
+ sp_desktop_set_style (desktop, css, true, true);
+ sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP));
+ sp_repr_css_attr_unref (css);
+ }
+
+}//<unnamed> namespace
#if 0
static void cell_data_func (GtkCellLayout *cell_layout,
}
#endif
-static GtkWidget*
-sp_text_toolbox_new (SPDesktop *desktop)
+namespace
{
- GtkWidget *tbl = gtk_hbox_new (FALSE, 0);
+ GtkWidget*
+ sp_text_toolbox_new (SPDesktop *desktop)
+ {
+ GtkWidget *tbl = gtk_hbox_new (FALSE, 0);
#if 0
GtkWidget *us = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(tbl), "units"));
GtkWidget *group;
#endif
- //Font Family
- GtkWidget *cbox = gtk_combo_box_entry_new_text ();
- Glib::RefPtr<Gtk::ListStore> 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);
+ //Font Family
+ GtkWidget *cbox = gtk_combo_box_entry_new_text ();
+ Glib::RefPtr<Gtk::ListStore> 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);
+ GtkEntryCompletion *completion = gtk_entry_completion_new ();
+ gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (Glib::unwrap(store)));
+ gtk_entry_completion_set_text_column (completion, 0);
+ gtk_entry_completion_set_minimum_key_length (completion, 3); //3 characters minimum sounds reasonable
+ g_object_set (G_OBJECT(completion), "inline-completion", TRUE, "popup-completion", TRUE, NULL);
#if 0
- gtk_cell_layout_set_cell_data_func
+ gtk_cell_layout_set_cell_data_func
(GTK_CELL_LAYOUT (cbox),
cell,
GtkCellLayoutDataFunc (cell_data_func),
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);
- g_object_set_data (G_OBJECT (tbl), "combo-box-family", cbox);
- g_signal_connect (G_OBJECT (cbox), "changed", G_CALLBACK (sp_text_toolbox_family_changed), tbl);
-
-#if 0
- //Font Style
- GtkWidget *cbox = gtk_combo_box_new_text ();
- gtk_widget_set_size_request (cbox, 144, -1);
- aux_toolbox_space (tbl, 1);
- gtk_box_pack_start (GTK_BOX (tbl), cbox, FALSE, FALSE, 0);
- g_object_set_data (G_OBJECT (tbl), "combo-box-style", cbox);
-#endif
-
- sigc::connection *connection =
- new sigc::connection( sp_desktop_selection (desktop)->connectChanged (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_changed), (GObject*)tbl)));
- g_signal_connect(G_OBJECT(tbl), "destroy", G_CALLBACK(delete_connection), connection);
+ 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);
+ g_object_set_data (G_OBJECT (tbl), "combo-box-family", cbox);
+ g_signal_connect (G_OBJECT (cbox), "changed", G_CALLBACK (sp_text_toolbox_family_changed), tbl);
+ g_signal_connect (G_OBJECT (GTK_BIN(cbox)->child), "activate", G_CALLBACK (sp_text_toolbox_family_entry_activate), tbl);
+ gtk_entry_set_completion (GTK_ENTRY(GTK_BIN(cbox)->child), completion);
+
+ GtkWidget *image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
+ aux_toolbox_space (tbl, 1);
+ GtkWidget *box = gtk_event_box_new ();
+ gtk_container_add (GTK_CONTAINER (box), image);
+ gtk_box_pack_start (GTK_BOX (tbl), box, FALSE, FALSE, 4);
+ g_object_set_data (G_OBJECT (tbl), "warning-image", box);
+ GtkTooltips *tooltips = gtk_tooltips_new ();
+ gtk_tooltips_set_tip (tooltips, box, _("This font is currently not installed on your system. Inkscape will use the default font instead."), "");
+ gtk_widget_hide (GTK_WIDGET (box));
+
+ //Font Style
+ cbox = gtk_combo_box_new_text ();
+ gtk_combo_box_append_text (GTK_COMBO_BOX (cbox), _("Normal"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (cbox), _("Italic"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (cbox), _("Oblique"));
+ gtk_widget_set_size_request (cbox, 144, -1);
+ aux_toolbox_space (tbl, 1);
+ gtk_box_pack_start (GTK_BOX (tbl), cbox, FALSE, FALSE, 0);
+ g_object_set_data (G_OBJECT (tbl), "combo-box-style", cbox);
+ g_signal_connect (G_OBJECT (cbox), "changed", G_CALLBACK (sp_text_toolbox_style_changed), tbl);
+
+ Inkscape::ConnectionPool* pool = Inkscape::ConnectionPool::new_connection_pool ("ISTextToolbox");
+
+ sigc::connection *c_selection_changed =
+ new sigc::connection (sp_desktop_selection (desktop)->connectChanged
+ (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_changed), (GObject*)tbl)));
+ pool->add_connection ("selection-changed", c_selection_changed);
+
+ sigc::connection *c_selection_modified =
+ new sigc::connection (sp_desktop_selection (desktop)->connectModified
+ (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_modified), (GObject*)tbl)));
+ pool->add_connection ("selection-modified", c_selection_modified);
+
+ sigc::connection *c_subselection_changed =
+ new sigc::connection (desktop->connectToolSubselectionChanged
+ (sigc::bind (sigc::ptr_fun (sp_text_toolbox_subselection_changed), (GObject*)tbl)));
+ pool->add_connection ("tool-subselection-changed", c_subselection_changed);
+
+ Inkscape::ConnectionPool::connect_destroy (G_OBJECT (tbl), pool);
#if 0
//Font Size
}
#endif
- Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL);
- swatch->setWatchedTool ("tools.text", true);
- GtkWidget *swatch_ = GTK_WIDGET(swatch->gobj());
- gtk_box_pack_end (GTK_BOX(tbl), swatch_, FALSE, FALSE, 0);
- gtk_widget_show_all (tbl);
+ Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL);
+ swatch->setWatchedTool ("tools.text", true);
+ GtkWidget *swatch_ = GTK_WIDGET(swatch->gobj());
+ gtk_box_pack_end (GTK_BOX(tbl), swatch_, FALSE, FALSE, 0);
+ gtk_widget_show_all (tbl);
- return tbl;
+ return tbl;
+
+ } // end of sp_text_toolbox_new()
-} // end of sp_text_toolbox_new()
+}//<unnamed> namespace
//#########################