glyphs.cpp revision 50875492099cda448c2aa399dfcaab4e608ea1e5
a37d24d06e3d85017b59997302b89bc2017b0970jvergara/**
a37d24d06e3d85017b59997302b89bc2017b0970jvergara * Glyph selector dialog.
a37d24d06e3d85017b59997302b89bc2017b0970jvergara */
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara/* Authors:
a37d24d06e3d85017b59997302b89bc2017b0970jvergara * Jon A. Cruz
a37d24d06e3d85017b59997302b89bc2017b0970jvergara *
a37d24d06e3d85017b59997302b89bc2017b0970jvergara * Copyright (C) 2010 Jon A. Cruz
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac * Released under GNU GPL, read the file 'COPYING' for more information
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac */
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara#include <vector>
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara#include <gtkmm/entry.h>
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac#include <gtkmm/iconview.h>
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac#include <gtkmm/label.h>
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac#include <gtkmm/liststore.h>
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac#include <gtkmm/scrolledwindow.h>
a37d24d06e3d85017b59997302b89bc2017b0970jvergara#include <gtkmm/table.h>
a37d24d06e3d85017b59997302b89bc2017b0970jvergara#include <gtkmm/treemodelcolumn.h>
a37d24d06e3d85017b59997302b89bc2017b0970jvergara#include <gtkmm/widget.h>
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara#include <gtk/gtkbutton.h>
37867092eb9f5796a0dabbb51ff918585421eb01jvergara#include <gtk/gtkstock.h>
a5b9f8fb834b1b2208e59a2fa76714bd91a5f147violette
a37d24d06e3d85017b59997302b89bc2017b0970jvergara#include "glyphs.h"
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara#include "verbs.h"
a37d24d06e3d85017b59997302b89bc2017b0970jvergara#include "widgets/font-selector.h"
a37d24d06e3d85017b59997302b89bc2017b0970jvergara#include "libnrtype/font-instance.h"
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergaranamespace Inkscape {
a37d24d06e3d85017b59997302b89bc2017b0970jvergaranamespace UI {
a37d24d06e3d85017b59997302b89bc2017b0970jvergaranamespace Dialogs {
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergaraGlyphsPanel &GlyphsPanel::getInstance()
a37d24d06e3d85017b59997302b89bc2017b0970jvergara{
b138eb36479de1170a91322a845ad9e977c3af56ludovicp return *new GlyphsPanel();
a37d24d06e3d85017b59997302b89bc2017b0970jvergara}
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
e2ad5d496df9ae6a822b25aed4cef9e3746a1658jvergaraclass GlyphColumns : public Gtk::TreeModel::ColumnRecord
a37d24d06e3d85017b59997302b89bc2017b0970jvergara{
92bd137769a071d6992c3a01c14c0b2bf044b293ludovicppublic:
a37d24d06e3d85017b59997302b89bc2017b0970jvergara Gtk::TreeModelColumn<gunichar> code;
6af3eb301687826075597a054f455ce76f5349eejvergara Gtk::TreeModelColumn<Glib::ustring> name;
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara GlyphColumns()
a37d24d06e3d85017b59997302b89bc2017b0970jvergara {
a37d24d06e3d85017b59997302b89bc2017b0970jvergara add(code);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara add(name);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara }
a37d24d06e3d85017b59997302b89bc2017b0970jvergara};
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergaraGlyphColumns *GlyphsPanel::getColumns()
a37d24d06e3d85017b59997302b89bc2017b0970jvergara{
a37d24d06e3d85017b59997302b89bc2017b0970jvergara static GlyphColumns *columns = new GlyphColumns();
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara return columns;
a37d24d06e3d85017b59997302b89bc2017b0970jvergara}
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
b26e36d8a08a1c775531659c04abc3d4ed504139jvergara/**
a37d24d06e3d85017b59997302b89bc2017b0970jvergara * Constructor
a37d24d06e3d85017b59997302b89bc2017b0970jvergara */
b26e36d8a08a1c775531659c04abc3d4ed504139jvergaraGlyphsPanel::GlyphsPanel(gchar const *prefsPath) :
a37d24d06e3d85017b59997302b89bc2017b0970jvergara Inkscape::UI::Widget::Panel("", prefsPath, SP_VERB_DIALOG_GLYPHS, "", false),
a37d24d06e3d85017b59997302b89bc2017b0970jvergara store(Gtk::ListStore::create(*getColumns())),
a37d24d06e3d85017b59997302b89bc2017b0970jvergara iconView(0),
a37d24d06e3d85017b59997302b89bc2017b0970jvergara entry(0),
cdc00d2b7899dbd1d090f7f68d562b43fc944a90jvergara label(0)
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara{
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara Gtk::Table *table = new Gtk::Table(3, 1, false);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara _getContents()->pack_start(*Gtk::manage(table), Gtk::PACK_EXPAND_WIDGET);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara guint row = 0;
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara// -------------------------------
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
95c63d5c79b97d5f353c7512e6193c4dba66a6fcjvergara GtkWidget *fontsel = sp_font_selector_new();
a37d24d06e3d85017b59997302b89bc2017b0970jvergara g_signal_connect( G_OBJECT(fontsel), "font_set", G_CALLBACK(fontChangeCB), this );
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara table->attach(*Gtk::manage(Glib::wrap(fontsel)),
a37d24d06e3d85017b59997302b89bc2017b0970jvergara 0, 1, row, row + 1,
d25372dc8e65a9ed019a88fdf659ca61313f1b31jcduff Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara row++;
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara// -------------------------------
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
665c725aa5d38e054c9816f9edf5c8253f3f093ejvergara GlyphColumns *columns = getColumns();
665c725aa5d38e054c9816f9edf5c8253f3f093ejvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara iconView = new Gtk::IconView(store);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara iconView->set_text_column(columns->name);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara //iconView->set_columns(16);
ddafbeb2ae1c18db9aea2af918290d3b06097f1fjvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara iconView->signal_item_activated().connect(sigc::mem_fun(*this, &GlyphsPanel::glyphActivated));
a37d24d06e3d85017b59997302b89bc2017b0970jvergara iconView->signal_selection_changed().connect(sigc::mem_fun(*this, &GlyphsPanel::glyphSelectionChanged));
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
b138eb36479de1170a91322a845ad9e977c3af56ludovicp Gtk::ScrolledWindow *scroller = new Gtk::ScrolledWindow();
a201fb0f51e2e2d392d60b2dd96a21e16a324b88violette scroller->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara scroller->add(*Gtk::manage(iconView));
a37d24d06e3d85017b59997302b89bc2017b0970jvergara table->attach(*Gtk::manage(scroller),
a37d24d06e3d85017b59997302b89bc2017b0970jvergara 0, 1, row, row + 1,
a37d24d06e3d85017b59997302b89bc2017b0970jvergara Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara row++;
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara// -------------------------------
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara Gtk::HBox *box = new Gtk::HBox();
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara entry = new Gtk::Entry();
a37d24d06e3d85017b59997302b89bc2017b0970jvergara box->pack_start(*Gtk::manage(entry));
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara label = new Gtk::Label(" ");
a37d24d06e3d85017b59997302b89bc2017b0970jvergara box->pack_start(*Gtk::manage(label), Gtk::PACK_EXPAND_PADDING);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara GtkWidget *applyBtn = gtk_button_new_from_stock(GTK_STOCK_APPLY);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara GTK_WIDGET_SET_FLAGS(applyBtn, GTK_CAN_DEFAULT | GTK_HAS_DEFAULT);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara gtk_widget_set_sensitive(applyBtn, FALSE);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara box->pack_end(*Gtk::manage(Glib::wrap(applyBtn)), Gtk::PACK_SHRINK);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
7855b07c34797e1650c83f4038ced2dade3a8109jvergara table->attach( *Gtk::manage(box),
a37d24d06e3d85017b59997302b89bc2017b0970jvergara 0, 1, row, row + 1,
a37d24d06e3d85017b59997302b89bc2017b0970jvergara Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara row++;
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara// -------------------------------
b26e36d8a08a1c775531659c04abc3d4ed504139jvergara
7855b07c34797e1650c83f4038ced2dade3a8109jvergara
b26e36d8a08a1c775531659c04abc3d4ed504139jvergara show_all_children();
b26e36d8a08a1c775531659c04abc3d4ed504139jvergara
b26e36d8a08a1c775531659c04abc3d4ed504139jvergara restorePanelPrefs();
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara}
b26e36d8a08a1c775531659c04abc3d4ed504139jvergara
b26e36d8a08a1c775531659c04abc3d4ed504139jvergaraGlyphsPanel::~GlyphsPanel()
a37d24d06e3d85017b59997302b89bc2017b0970jvergara{
a37d24d06e3d85017b59997302b89bc2017b0970jvergara}
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergaravoid GlyphsPanel::glyphActivated(Gtk::TreeModel::Path const & path)
a37d24d06e3d85017b59997302b89bc2017b0970jvergara{
a37d24d06e3d85017b59997302b89bc2017b0970jvergara Gtk::ListStore::iterator row = store->get_iter(path);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara gunichar ch = (*row)[getColumns()->code];
a37d24d06e3d85017b59997302b89bc2017b0970jvergara Glib::ustring tmp;
a37d24d06e3d85017b59997302b89bc2017b0970jvergara tmp += ch;
7855b07c34797e1650c83f4038ced2dade3a8109jvergara
fbbcdae277f66a56a2e5450858b249f82470dc56jvergara int startPos = 0;
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara int endPos = 0;
a37d24d06e3d85017b59997302b89bc2017b0970jvergara if (entry->get_selection_bounds(startPos, endPos)) {
a37d24d06e3d85017b59997302b89bc2017b0970jvergara // there was something selected.
a37d24d06e3d85017b59997302b89bc2017b0970jvergara entry->delete_text(startPos, endPos);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara }
7855b07c34797e1650c83f4038ced2dade3a8109jvergara startPos = entry->get_position();
a37d24d06e3d85017b59997302b89bc2017b0970jvergara entry->insert_text(tmp, -1, startPos);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara entry->set_position(startPos);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara}
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergaravoid GlyphsPanel::glyphSelectionChanged()
a37d24d06e3d85017b59997302b89bc2017b0970jvergara{
ea01fb5b2270d39e0b705a30a5d633336e25faa0jvergara Gtk::IconView::ArrayHandle_TreePaths itemArray = iconView->get_selected_items();
7855b07c34797e1650c83f4038ced2dade3a8109jvergara if (itemArray.empty()) {
ea01fb5b2270d39e0b705a30a5d633336e25faa0jvergara label->set_text(" ");
ea01fb5b2270d39e0b705a30a5d633336e25faa0jvergara } else {
ea01fb5b2270d39e0b705a30a5d633336e25faa0jvergara Gtk::TreeModel::Path const & path = *itemArray.begin();
ea01fb5b2270d39e0b705a30a5d633336e25faa0jvergara Gtk::ListStore::iterator row = store->get_iter(path);
ea01fb5b2270d39e0b705a30a5d633336e25faa0jvergara gunichar ch = (*row)[getColumns()->code];
7855b07c34797e1650c83f4038ced2dade3a8109jvergara
7855b07c34797e1650c83f4038ced2dade3a8109jvergara gchar * tmp = g_strdup_printf("U+%04X", ch);
cdc00d2b7899dbd1d090f7f68d562b43fc944a90jvergara label->set_text(tmp);
cdc00d2b7899dbd1d090f7f68d562b43fc944a90jvergara }
cdc00d2b7899dbd1d090f7f68d562b43fc944a90jvergara}
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara
7855b07c34797e1650c83f4038ced2dade3a8109jvergaravoid GlyphsPanel::fontChangeCB(SPFontSelector *fontsel, font_instance *font, GlyphsPanel *self)
7855b07c34797e1650c83f4038ced2dade3a8109jvergara{
7855b07c34797e1650c83f4038ced2dade3a8109jvergara if (self) {
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara self->handleFontChange(fontsel, font);
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara }
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara}
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara
7855b07c34797e1650c83f4038ced2dade3a8109jvergaravoid GlyphsPanel::handleFontChange(SPFontSelector * /*fontsel*/, font_instance *font)
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara{
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara if (font) {
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara gunichar maxUni = 0;
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara std::vector<gunichar> present;
a37d24d06e3d85017b59997302b89bc2017b0970jvergara for (gunichar ch = 0; ch < 65536; ch++) {
7855b07c34797e1650c83f4038ced2dade3a8109jvergara int glyphId = font->MapUnicodeChar(ch);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara if (glyphId > 0) {
fbbcdae277f66a56a2e5450858b249f82470dc56jvergara maxUni = std::max(maxUni, ch);
244d81e51f8c022982d4941603f72f3a3475175fmatthew present.push_back(ch);
a37d24d06e3d85017b59997302b89bc2017b0970jvergara }
a37d24d06e3d85017b59997302b89bc2017b0970jvergara }
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara GlyphColumns *columns = getColumns();
7855b07c34797e1650c83f4038ced2dade3a8109jvergara store->clear();
a37d24d06e3d85017b59997302b89bc2017b0970jvergara for (std::vector<gunichar>::iterator it = present.begin(); it != present.end(); ++it)
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara {
a37d24d06e3d85017b59997302b89bc2017b0970jvergara Gtk::ListStore::iterator row = store->append();
a37d24d06e3d85017b59997302b89bc2017b0970jvergara Glib::ustring tmp;
a37d24d06e3d85017b59997302b89bc2017b0970jvergara tmp += *it;
7855b07c34797e1650c83f4038ced2dade3a8109jvergara (*row)[columns->code] = *it;
a37d24d06e3d85017b59997302b89bc2017b0970jvergara (*row)[columns->name] = tmp;
fbbcdae277f66a56a2e5450858b249f82470dc56jvergara }
bf7236c96ba10b04b60169ee7c84327b4998ffc9jvergara }
a37d24d06e3d85017b59997302b89bc2017b0970jvergara}
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
a37d24d06e3d85017b59997302b89bc2017b0970jvergara
665c725aa5d38e054c9816f9edf5c8253f3f093ejvergara} // namespace Dialogs
7855b07c34797e1650c83f4038ced2dade3a8109jvergara} // namespace UI
fbbcdae277f66a56a2e5450858b249f82470dc56jvergara} // namespace Inkscape
665c725aa5d38e054c9816f9edf5c8253f3f093ejvergara
665c725aa5d38e054c9816f9edf5c8253f3f093ejvergara/*
665c725aa5d38e054c9816f9edf5c8253f3f093ejvergara Local Variables:
665c725aa5d38e054c9816f9edf5c8253f3f093ejvergara mode:c++
7855b07c34797e1650c83f4038ced2dade3a8109jvergara c-file-style:"stroustrup"
fbbcdae277f66a56a2e5450858b249f82470dc56jvergara c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
665c725aa5d38e054c9816f9edf5c8253f3f093ejvergara indent-tabs-mode:nil
665c725aa5d38e054c9816f9edf5c8253f3f093ejvergara fill-column:99
665c725aa5d38e054c9816f9edf5c8253f3f093ejvergara End:
a37d24d06e3d85017b59997302b89bc2017b0970jvergara*/
7855b07c34797e1650c83f4038ced2dade3a8109jvergara// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
fbbcdae277f66a56a2e5450858b249f82470dc56jvergara