text-edit.cpp revision 3478d2cd051e123df40b5dfef79f2cb254f26f6f
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos/**
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * @file
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Text editing dialog.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos/* Authors:
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Lauris Kaplinski <lauris@ximian.com>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * bulia byak <buliabyak@users.sf.net>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Johan Engelen <goejendaagh@zonnet.nl>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Abhishek Sharma
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * John Smith
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Tavmjong Bah
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos *
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Copyright (C) 1999-2013 Authors
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Copyright (C) 2000-2001 Ximian, Inc.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos *
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Released under GNU GPL, read the file 'COPYING' for more information
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#ifdef HAVE_CONFIG_H
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos# include "config.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#endif
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "text-edit.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include <libnrtype/font-instance.h>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include <gtk/gtk.h>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#ifdef WITH_GTKSPELL
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosextern "C" {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos# include <gtkspell/gtkspell.h>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#endif
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include <gtkmm/stock.h>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include <libnrtype/font-instance.h>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include <libnrtype/font-lister.h>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include <xml/repr.h>
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "macros.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "helper/window.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "inkscape.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "document.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "desktop.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "desktop-style.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "document-undo.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "selection.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "style.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "sp-text.h"
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek#include "sp-flowtext.h"
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek#include "text-editing.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "ui/icon-names.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "preferences.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "verbs.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "ui/interface.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "svg/css-ostringstream.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "widgets/icon.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "widgets/font-selector.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include <glibmm/i18n.h>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include <glibmm/markup.h>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "util/units.h"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#include "sp-textpath.h"
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosnamespace Inkscape {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosnamespace UI {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosnamespace Dialog {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej KosTextEdit::TextEdit()
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos : UI::Widget::Panel("", "/dialogs/textandfont", SP_VERB_DIALOG_TEXT),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos font_label(_("_Font"), true),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_frame(),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos text_label(_("_Text"), true),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos vari_label(_("_Variants"), true),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos setasdefault_button(_("Set as _default")),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos close_button(Gtk::Stock::CLOSE),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos apply_button(Gtk::Stock::APPLY),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos desktop(NULL),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos deskTrack(),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos selectChangedConn(),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos subselChangedConn(),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos selectModifiedConn(),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /*
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos TRANSLATORS: Test string used in text and font dialog (when no
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * text has been entered) to get a preview of the font. Choose
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * some representative characters that users of your locale will be
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * interested in.*/
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos blocked(false),
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos samplephrase(_("AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()"))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos{
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Font selector */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos GtkWidget *fontsel = sp_font_selector_new ();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_size_request (fontsel, 0, 150);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos fsel = SP_FONT_SELECTOR(fontsel);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos fontsel_hbox.pack_start(*Gtk::manage(Glib::wrap(fontsel)), true, true);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Align buttons */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos styleButton(&align_left, _("Align left"), INKSCAPE_ICON("format-justify-left"), NULL);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos styleButton(&align_center, _("Align center"), INKSCAPE_ICON("format-justify-center"), &align_left);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos styleButton(&align_right, _("Align right"), INKSCAPE_ICON("format-justify-right"), &align_left);
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov styleButton(&align_justify, _("Justify (only flowed text)"), INKSCAPE_ICON("format-justify-fill"), &align_left);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#if WITH_GTKMM_3_0
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos align_sep.set_orientation(Gtk::ORIENTATION_VERTICAL);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#endif
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(align_sep, false, false, 10);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Direction buttons */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos styleButton(&text_horizontal, _("Horizontal text"), INKSCAPE_ICON("format-text-direction-horizontal"), NULL);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos styleButton(&text_vertical, _("Vertical text"), INKSCAPE_ICON("format-text-direction-vertical"), &text_horizontal);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#if WITH_GTKMM_3_0
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos text_sep.set_orientation(Gtk::ORIENTATION_VERTICAL);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#endif
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(text_sep, false, false, 10);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Line Spacing */
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov GtkWidget *px = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, INKSCAPE_ICON("text_line_spacing") );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(*Gtk::manage(Glib::wrap(px)), false, false);
a5f79cce8abc74beec0c27c477c046bb6cbe7101Simo Sorce
a5f79cce8abc74beec0c27c477c046bb6cbe7101Simo Sorce spacing_combo = gtk_combo_box_text_new_with_entry ();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_size_request (spacing_combo, 90, -1);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos const gchar *spacings[] = {"50%", "80%", "90%", "100%", "110%", "120%", "130%", "140%", "150%", "200%", "300%", NULL};
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos for (int i = 0; spacings[i]; i++) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_combo_box_text_append_text((GtkComboBoxText *) spacing_combo, spacings[i]);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_tooltip_text (px, _("Spacing between lines (percent of font size)"));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_tooltip_text (spacing_combo, _("Spacing between lines (percent of font size)"));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(*Gtk::manage(Glib::wrap(spacing_combo)), false, false);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_frame.set_padding(4,4,4,4);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_frame.add(layout_hbox);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // Text start Offset
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos startOffset = gtk_combo_box_text_new_with_entry ();
a5f79cce8abc74beec0c27c477c046bb6cbe7101Simo Sorce gtk_widget_set_size_request(startOffset, 90, -1);
a5f79cce8abc74beec0c27c477c046bb6cbe7101Simo Sorce
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov const gchar *spacings[] = {"0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%", NULL};
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos for (int i = 0; spacings[i]; i++) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_combo_box_text_append_text(reinterpret_cast<GtkComboBoxText *>(startOffset), spacings[i]);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_entry_set_text(reinterpret_cast<GtkEntry *>(gtk_bin_get_child(reinterpret_cast<GtkBin *>(startOffset))), "0%");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_tooltip_text(startOffset, _("Text path offset"));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#if WITH_GTKMM_3_0
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Gtk::Separator *sep = Gtk::manage(new Gtk::Separator());
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sep->set_orientation(Gtk::ORIENTATION_VERTICAL);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#else
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Gtk::VSeparator *sep = Gtk::manage(new Gtk::VSeparator);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#endif
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(*sep, false, false, 10);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(*Gtk::manage(Glib::wrap(startOffset)), false, false);
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Font preview */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos preview_label.set_ellipsize(Pango::ELLIPSIZE_END);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos preview_label.set_justify(Gtk::JUSTIFY_CENTER);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos preview_label.set_line_wrap(FALSE);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos font_vbox.pack_start(fontsel_hbox, true, true);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos font_vbox.pack_start(layout_frame, false, false, VB_MARGIN);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos font_vbox.pack_start(preview_label, true, true, VB_MARGIN);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Text tab */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos scroller.set_shadow_type(Gtk::SHADOW_IN);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos text_buffer = gtk_text_buffer_new (NULL);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos text_view = gtk_text_view_new_with_buffer (text_buffer);
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov gtk_text_view_set_wrap_mode ((GtkTextView *) text_view, GTK_WRAP_WORD);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#ifdef WITH_GTKSPELL
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos GError *error = NULL;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos/*
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos TODO: Use computed xml:lang attribute of relevant element, if present, to specify the
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos language (either as 2nd arg of gtkspell_new_attach, or with explicit
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtkspell_set_language call in; see advanced.c example in gtkspell docs).
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos onReadSelection looks like a suitable place.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos*/
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (gtkspell_new_attach(GTK_TEXT_VIEW(text_view), NULL, &error) == NULL) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos g_print("gtkspell error: %s\n", error->message);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos g_error_free(error);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#endif
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_size_request (text_view, -1, 64);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), TRUE);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos scroller.add(*Gtk::manage(Glib::wrap(text_view)));
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov text_vbox.pack_start(scroller, true, true, 0);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos notebook.append_page(font_vbox, font_label);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos notebook.append_page(text_vbox, text_label);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos notebook.append_page(vari_vbox, vari_label);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos /* Buttons */
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos setasdefault_button.set_use_underline(true);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos apply_button.set_can_default();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button_row.pack_start(setasdefault_button, false, false, 0);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button_row.pack_end(close_button, false, false, VB_MARGIN);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button_row.pack_end(apply_button, false, false, VB_MARGIN);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek Gtk::Box *contents = _getContents();
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek contents->set_spacing(4);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos contents->pack_start(notebook, true, true);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos contents->pack_start(button_row, false, false, VB_MARGIN);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek /* Signal handlers */
e27c0ecef59272d4723f904a17061b4e59f0a6dbMichal Židek g_signal_connect ( G_OBJECT (fontsel), "font_set", G_CALLBACK (onFontChange), this );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek g_signal_connect ( G_OBJECT (spacing_combo), "changed", G_CALLBACK (onLineSpacingChange), this );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek g_signal_connect ( G_OBJECT (text_buffer), "changed", G_CALLBACK (onTextChange), this );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek g_signal_connect(startOffset, "changed", G_CALLBACK(onStartOffsetChange), this);
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek setasdefault_button.signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onSetDefault));
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek apply_button.signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onApply));
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek close_button.signal_clicked().connect(sigc::bind(_signal_response.make_slot(), GTK_RESPONSE_CLOSE));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &TextEdit::setTargetDesktop) );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos deskTrack.connect(GTK_WIDGET(gobj()));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos show_all_children();
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej KosTextEdit::~TextEdit()
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos{
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos selectModifiedConn.disconnect();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos subselChangedConn.disconnect();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos selectChangedConn.disconnect();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos desktopChangeConn.disconnect();
f322968cb3e9187eb5ddc9d575fa77027b71bb3bJakub Hrozek deskTrack.disconnect();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosvoid TextEdit::styleButton(Gtk::RadioButton *button, gchar const *tooltip, gchar const *icon_name, Gtk::RadioButton *group_button )
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos{
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov GtkWidget *icon = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, icon_name );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (!GTK_IS_IMAGE(icon)) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos icon = gtk_image_new_from_icon_name ( icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if (group_button) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Gtk::RadioButton::Group group = group_button->get_group();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button->set_group(group);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button->add(*Gtk::manage(Glib::wrap(icon)));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button->set_tooltip_text(tooltip);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button->set_relief(Gtk::RELIEF_NONE);
2f6b38151c6dd21cbe0cf2579c20f8c5a358d956Ondrej Kos button->set_mode(false);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos button->signal_clicked().connect(sigc::mem_fun(*this, &TextEdit::onToggle));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos layout_hbox.pack_start(*button, false, false);
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek}
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židekvoid TextEdit::onSelectionModified(guint flags )
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek{
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek gboolean style, content;
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek style = ((flags & ( SP_OBJECT_CHILD_MODIFIED_FLAG |
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek SP_OBJECT_STYLE_MODIFIED_FLAG )) != 0 );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek content = ((flags & ( SP_OBJECT_CHILD_MODIFIED_FLAG |
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek SP_TEXT_CONTENT_MODIFIED_FLAG )) != 0 );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek onReadSelection (style, content);
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek}
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židekvoid TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ )
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek{
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek if (blocked)
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek return;
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek if (!desktop || SP_ACTIVE_DESKTOP != desktop)
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek {
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek return;
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek }
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek blocked = true;
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek SPItem *text = getSelectedTextItem ();
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek Glib::ustring phrase = samplephrase;
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek if (text)
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek {
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek guint items = getSelectedTextCount ();
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek if (items == 1) {
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek gtk_widget_set_sensitive (text_view, TRUE);
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek gtk_widget_set_sensitive( startOffset, SP_IS_TEXT_TEXTPATH(text) );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek if (SP_IS_TEXT_TEXTPATH(text)) {
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek SPTextPath *tp = SP_TEXTPATH(text->firstChild());
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek if (tp->getAttribute("startOffset")) {
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek gtk_entry_set_text(reinterpret_cast<GtkEntry *>(gtk_bin_get_child(reinterpret_cast<GtkBin *>(startOffset))), tp->getAttribute("startOffset"));
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek }
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek }
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek } else {
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek gtk_widget_set_sensitive (text_view, FALSE);
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek gtk_widget_set_sensitive( startOffset, FALSE );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek }
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek apply_button.set_sensitive ( false );
cca497b4cbbbf05c4f9181b7d8113cde81754831Michal Židek setasdefault_button.set_sensitive ( true );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos //if (docontent) { // When would we NOT want to show the content ?
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov gchar *str;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos str = sp_te_get_string_multiline (text);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (str) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (items == 1) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_text_buffer_set_text (text_buffer, str, strlen (str));
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_text_buffer_set_modified (text_buffer, FALSE);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos phrase = str;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos } else {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_text_buffer_set_text (text_buffer, "", 0);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov //} // end of if (docontent)
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov text->getRepr(); // was being called but result ignored. Check this.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos } else {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_sensitive (text_view, FALSE);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_widget_set_sensitive( startOffset, FALSE );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos apply_button.set_sensitive ( false );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos setasdefault_button.set_sensitive ( false );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (dostyle) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // create temporary style
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos SPStyle query(SP_ACTIVE_DOCUMENT);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos //int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTFAMILY);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTSTYLE);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // If querying returned nothing, read the style from the text tool prefs (default style for new texts)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // (Ok to not get a font specification - must just rely on the family and style in that case)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos || result_numbers == QUERY_STYLE_NOTHING) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos query.readFromPrefs("/tools/text");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // FIXME: process result_family/style == QUERY_STYLE_MULTIPLE_DIFFERENT by showing "Many" in the lists
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // This is normally done for us by text-toolbar but only when we are in text editing context
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos fontlister->update_font_list(this->desktop->getDocument());
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos fontlister->selection_update();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Glib::ustring fontspec = fontlister->get_fontspec();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos double size = sp_style_css_size_px_to_units(query.font_size.computed, unit);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_font_selector_set_fontspec(fsel, fontspec, size );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos setPreviewText (fontspec, phrase);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (query.text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos align_justify.set_active();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos } else {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos align_left.set_active();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos } else if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) {
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov align_center.set_active();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos } else {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos align_right.set_active();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (query.writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos text_horizontal.set_active();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos } else {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos text_vertical.set_active();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos double height;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (query.line_height.normal) height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos else if (query.line_height.unit == SP_CSS_UNIT_PERCENT)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos height = query.line_height.value;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos else height = query.line_height.computed;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gchar *sstr = g_strdup_printf ("%d%%", (int) floor(height * 100 + 0.5));
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_entry_set_text ((GtkEntry *) gtk_bin_get_child ((GtkBin *) spacing_combo), sstr);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos g_free(sstr);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // Update font variant widget
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos //int result_variants =
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTVARIANTS);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos vari_vbox.update( query.font_variant_ligatures.computed, query.font_variant_ligatures.value );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos blocked = false;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosvoid TextEdit::setPreviewText (Glib::ustring font_spec, Glib::ustring phrase)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos{
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (font_spec.empty()) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos return;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Glib::ustring phrase_escaped = Glib::Markup::escape_text( phrase );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos double pt_size = Inkscape::Util::Quantity::convert(sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit), "px", "pt");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // Pango font size is in 1024ths of a point
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // C++11: Glib::ustring size = std::to_string( int(pt_size * PANGO_SCALE) );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos std::ostringstream size_st;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos size_st << int(pt_size * PANGO_SCALE); // Markup code expects integers
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Glib::ustring markup = "<span font=\'" + font_spec +
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos "\' size=\'" + size_st.str() + "\'>" + phrase_escaped + "</span>";
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos preview_label.set_markup(markup.c_str());
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej KosSPItem *TextEdit::getSelectedTextItem (void)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos{
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (!SP_ACTIVE_DESKTOP)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos return NULL;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos std::vector<SPItem*> tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos return *i;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos return NULL;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosunsigned TextEdit::getSelectedTextCount (void)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos{
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (!SP_ACTIVE_DESKTOP)
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov return 0;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos unsigned int items = 0;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos std::vector<SPItem*> tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos ++items;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos return items;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosvoid TextEdit::onSelectionChange()
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos{
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos onReadSelection (TRUE, TRUE);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosvoid TextEdit::updateObjectText ( SPItem *text )
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos{
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos GtkTextIter start, end;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // write text
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (gtk_text_buffer_get_modified (text_buffer)) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_text_buffer_get_bounds (text_buffer, &start, &end);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gchar *str = gtk_text_buffer_get_text (text_buffer, &start, &end, TRUE);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov sp_te_set_repr_text_multiline (text, str);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos g_free (str);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos gtk_text_buffer_set_modified (text_buffer, FALSE);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej KosSPCSSAttr *TextEdit::fillTextStyle ()
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos{
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos SPCSSAttr *css = sp_repr_css_attr_new ();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov Glib::ustring fontspec = sp_font_selector_get_fontspec (fsel);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if( !fontspec.empty() ) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos fontlister->fill_css( css, fontspec );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik // TODO, possibly move this to FontLister::set_css to be shared.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::CSSOStringStream os;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (prefs->getBool("/options/font/textOutputPx", true)) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos os << sp_style_css_size_units_to_px(sp_font_selector_get_size (fsel), unit) << sp_style_get_css_unit_string(SP_CSS_UNIT_PX);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos } else {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos os << sp_font_selector_get_size (fsel) << sp_style_get_css_unit_string(unit);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "font-size", os.str().c_str());
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // Layout
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if ( align_left.get_active() ) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-anchor", "start");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-align", "start");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos } else if ( align_center.get_active() ) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-anchor", "middle");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-align", "center");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos } else if ( align_right.get_active() ){
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-anchor", "end");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-align", "end");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos } else {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // Align Justify
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-anchor", "start");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "text-align", "justify");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos if (text_horizontal.get_active()) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "writing-mode", "lr");
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik } else {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "writing-mode", "tb");
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos }
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // Note that CSS 1.1 does not support line-height; we set it for consistency, but also set
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos // sodipodi:linespacing for backwards compatibility; in 1.2 we use line-height for flowtext
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos const gchar *sstr = gtk_combo_box_text_get_active_text ((GtkComboBoxText *) spacing_combo);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_set_property (css, "line-height", sstr);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos return css;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosvoid TextEdit::onSetDefault()
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos{
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos SPCSSAttr *css = fillTextStyle ();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Inkscape::Preferences *prefs = Inkscape::Preferences::get();
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos blocked = true;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos prefs->mergeStyle("/tools/text/style", css);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos blocked = false;
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos sp_repr_css_attr_unref (css);
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos setasdefault_button.set_sensitive ( false );
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosvoid TextEdit::onApply()
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos{
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos blocked = true;
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek SPDesktop *desktop = SP_ACTIVE_DESKTOP;
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek unsigned items = 0;
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek const std::vector<SPItem*> item_list = desktop->getSelection()->itemList();
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek SPCSSAttr *css = fillTextStyle ();
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek sp_desktop_set_style(desktop, css, true);
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek for(std::vector<SPItem*>::const_iterator i=item_list.begin();i!=item_list.end();i++){
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // apply style to the reprs of all text objects in the selection
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek if (SP_IS_TEXT (*i)) {
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // backwards compatibility:
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek (*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL));
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek ++items;
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek }
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek else if (SP_IS_FLOWTEXT (*i))
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // no need to set sodipodi:linespacing, because Inkscape never supported it on flowtext
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek ++items;
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek }
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek if (items == 0) {
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // no text objects; apply style to prefs for new objects
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek Inkscape::Preferences *prefs = Inkscape::Preferences::get();
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek prefs->mergeStyle("/tools/text/style", css);
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek setasdefault_button.set_sensitive ( false );
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek } else if (items == 1) {
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // exactly one text object; now set its text, too
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek SPItem *item = SP_ACTIVE_DESKTOP->getSelection()->singleItem();
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT(item)) {
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek updateObjectText (item);
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek }
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek }
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // Update FontLister
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek Glib::ustring fontspec = sp_font_selector_get_fontspec (fsel);
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek if( !fontspec.empty() ) {
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance();
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek fontlister->set_fontspec( fontspec, false );
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek }
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek // complete the transaction
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_CONTEXT_TEXT,
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek _("Set text style"));
8b2a31634764168183506925a4b9f461afdba6f3Michal Židek 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);
Glib::ustring fontspec = sp_font_selector_get_fontspec(self->fsel);
if( !fontspec.empty() ) {
const gchar *phrase = str && *str ? str : self->samplephrase.c_str();
self->setPreviewText(fontspec, 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*/, gchar* fontspec, 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 (fontspec) {
const gchar *phrase = str && *str ? str : self->samplephrase.c_str();
self->setPreviewText(fontspec, 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::onStartOffsetChange(GtkTextBuffer * /*text_buffer*/, TextEdit *self)
{
SPItem *text = self->getSelectedTextItem();
if (text && SP_IS_TEXT_TEXTPATH(text))
{
SPTextPath *tp = SP_TEXTPATH(text->firstChild());
const gchar *sstr = gtk_combo_box_text_get_active_text(reinterpret_cast<GtkComboBoxText *>(self->startOffset));
tp->setAttribute("startOffset", sstr);
DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "startOffset", SP_VERB_CONTEXT_TEXT, _("Set text style"));
}
}
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 = static_cast<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 :