Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
styledialog.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/* Authors:
6 * Kamalpreet Kaur Grewal
7 * Tavmjong Bah
8 * Jabiertxof
9 *
10 * Copyright (C) Kamalpreet Kaur Grewal 2016 <grewalkamal005@gmail.com>
11 * Copyright (C) Tavmjong Bah 2017 <tavmjong@free.fr>
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
16#ifndef SEEN_UI_DIALOG_STYLEDIALOG_H
17#define SEEN_UI_DIALOG_STYLEDIALOG_H
18
19#include <gtkmm/scrolledwindow.h>
20#include <gtkmm/treepath.h>
21
23
24namespace Gtk {
25class Adjustment;
26class CellEditable;
27class Dialog;
28class Entry;
29class TreeStore;
30class TreeView;
31class TreeViewColumn;
32} // namespace Gtk
33
34struct SPStyleEnum;
35
36class SPObject;
37
38namespace Inkscape {
39
40class Selection;
41
42namespace XML {
43class Node;
44class NodeObserver;
45} // namespace XML
46
47namespace UI::Dialog {
48
49// for selectorsdialog.cpp
50XML::Node *get_first_style_text_node(XML::Node *root, bool create_if_missing);
51
63class StyleDialog final : public DialogBase
64{
65public:
67 ~StyleDialog() final;
68
69 void documentReplaced() final;
71
72 void setCurrentSelector(Glib::ustring current_selector);
73 Gtk::TreeView *_current_css_tree;
74 Gtk::TreeViewColumn *_current_value_col;
75 Gtk::TreeModel::Path _current_path;
76 bool _deletion{false};
77 void readStyleElement();
78
79 private:
80 using AttrProp = std::map<Glib::ustring, Glib::ustring>;
81
82 // Monitor <style> element for changes.
83 class NodeObserver;
84 // Monitor all objects for addition/removal/attribute change
85 class NodeWatcher;
89 void removeObservers();
90
91 // Data structure
92 class ModelColumns : public Gtk::TreeModel::ColumnRecord {
93 public:
95 {
96 add(_colActive);
97 add(_colName);
98 add(_colValue);
99 add(_colStrike);
100 add(_colSelector);
101 add(_colSelectorPos);
102 add(_colOwner);
103 add(_colLinked);
104 add(_colHref);
105 }
106 Gtk::TreeModelColumn<bool> _colActive; // Active or inactive property
107 Gtk::TreeModelColumn<Glib::ustring> _colName; // Name of the property.
108 Gtk::TreeModelColumn<Glib::ustring> _colValue; // Value of the property.
109 Gtk::TreeModelColumn<bool> _colStrike; // Property not used, overloaded
110 Gtk::TreeModelColumn<Glib::ustring> _colSelector; // Style or matching object id.
111 Gtk::TreeModelColumn<int> _colSelectorPos; // Position of the selector to handle dup selectors
112 Gtk::TreeModelColumn<Glib::ustring> _colOwner; // Store the owner of the property for popup
113 Gtk::TreeModelColumn<bool> _colLinked; // Other object linked
114 Gtk::TreeModelColumn<SPObject *> _colHref; // Is going to another object
115 };
117
118 class CSSData : public Gtk::TreeModel::ColumnRecord {
119 public:
121 Gtk::TreeModelColumn<Glib::ustring> _colCSSData; // Name of the property.
122 };
124
125 unsigned _deleted_pos{0};
126
127 // Widgets
128 Gtk::ScrolledWindow _scrolledWindow;
129 Glib::RefPtr<Gtk::Adjustment> _vadj;
130 Gtk::Box _mainBox;
131 Gtk::Box _styleBox;
132
133 // Reading and writing the style element.
134
135 Inkscape::XML::Node *_getStyleTextNode(bool create_if_missing = false);
136
137 void _writeStyleElement(Glib::RefPtr<Gtk::TreeStore> const &store,
138 Glib::ustring selector, Glib::ustring const &new_selector = {});
139
140 void _activeToggled(const Glib::ustring &path, Glib::RefPtr<Gtk::TreeStore> const &store);
141
142 void _addRow(Glib::RefPtr<Gtk::TreeStore> const &store, Gtk::TreeView *css_tree,
143 Glib::ustring const &selector, int pos);
144
145 void _onPropDelete(Glib::ustring const &path, Glib::RefPtr<Gtk::TreeStore> const &store);
146
147 void _nameEdited(const Glib::ustring &path, const Glib::ustring &name, Glib::RefPtr<Gtk::TreeStore> store,
148 Gtk::TreeView *css_tree);
149
150 Gtk::Entry *_editingEntry = nullptr;
151 void _addTreeViewHandlers(Gtk::TreeView &treeview);
152 void _setEditingEntry(Gtk::Entry *entry, Glib::ustring endChars);
153 void _onTreeViewKeyReleased(unsigned keyval, unsigned keycode, Gdk::ModifierType state);
155
156 void _onLinkObj(Glib::ustring const &path, Glib::RefPtr<Gtk::TreeStore> const &store);
157
158 void _valueEdited(const Glib::ustring &path, const Glib::ustring &value, Glib::RefPtr<Gtk::TreeStore> store);
159 void _startNameEdit(Gtk::CellEditable *cell, const Glib::ustring &path);
160 void _startValueEdit(Gtk::CellEditable *cell, const Glib::ustring &path, Glib::RefPtr<Gtk::TreeStore> store);
161
162 void _setAutocompletion(Gtk::Entry *entry, SPStyleEnum const cssenum[]);
163 void _setAutocompletion(Gtk::Entry *entry, Glib::ustring name);
164 bool _on_foreach_iter(const Gtk::TreeModel::iterator &iter);
165 void _reload();
166 void _vscroll();
167
169 double _scrollpos{0};
170 Glib::ustring _current_selector;
171
172 // Update watchers
173 std::unique_ptr<XML::NodeObserver> const m_nodewatcher;
174 std::unique_ptr<XML::NodeObserver> const m_styletextwatcher;
175
176 // Manipulate Tree
177 std::vector<SPObject *> _getObjVec(Glib::ustring selector);
178 AttrProp parseStyle(Glib::ustring style_string);
180 void _addOwnerStyle(Glib::ustring name, Glib::ustring selector);
181
182 // Variables
184 Inkscape::XML::Node *_textNode{nullptr}; // Track so we know when to add a NodeObserver.
185 bool _updating{false}; // Prevent cyclic actions: read <-> write, select via dialog <-> via desktop
186
187 void _closeDialog(Gtk::Dialog *textDialogPtr);
188};
189
190} // namespace UI::Dialog
191
192} // namespace Inkscape
193
194#endif // SEEN_UI_DIALOG_STYLEDIALOG_H
195
196/*
197 Local Variables:
198 mode:c++
199 c-file-style:"stroustrup"
200 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
201 indent-tabs-mode:nil
202 fill-column:99
203 End:
204*/
205// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Fragment store
Definition canvas.cpp:155
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
DialogBase is the base class for the dialog system.
Definition dialog-base.h:40
Gtk::TreeModelColumn< Glib::ustring > _colCSSData
Gtk::TreeModelColumn< SPObject * > _colHref
Gtk::TreeModelColumn< Glib::ustring > _colOwner
Gtk::TreeModelColumn< int > _colSelectorPos
Gtk::TreeModelColumn< Glib::ustring > _colSelector
Gtk::TreeModelColumn< Glib::ustring > _colValue
Gtk::TreeModelColumn< Glib::ustring > _colName
The StyleDialog class A list of CSS selectors will show up in this dialog.
Definition styledialog.h:64
Inkscape::XML::Node * _textNode
Gtk::TreeModel::Path _current_path
Definition styledialog.h:75
Inkscape::XML::Node * _getStyleTextNode(bool create_if_missing=false)
void _startValueEdit(Gtk::CellEditable *cell, const Glib::ustring &path, Glib::RefPtr< Gtk::TreeStore > store)
void _startNameEdit(Gtk::CellEditable *cell, const Glib::ustring &path)
void _setEditingEntry(Gtk::Entry *entry, Glib::ustring endChars)
std::unique_ptr< XML::NodeObserver > const m_nodewatcher
void _onTreeViewKeyReleased(unsigned keyval, unsigned keycode, Gdk::ModifierType state)
void documentReplaced() final
Handle document replaced.
void _writeStyleElement(Glib::RefPtr< Gtk::TreeStore > const &store, Glib::ustring selector, Glib::ustring const &new_selector={})
Update the content of the style element as selectors (or objects) are added/removed.
void readStyleElement()
Fill the Gtk::TreeStore from the svg:style element.
void _activeToggled(const Glib::ustring &path, Glib::RefPtr< Gtk::TreeStore > const &store)
StyleDialog()
Constructor A treeview and a set of two buttons are added to the dialog.
void _nameEdited(const Glib::ustring &path, const Glib::ustring &name, Glib::RefPtr< Gtk::TreeStore > store, Gtk::TreeView *css_tree)
StyleDialog::nameEdited.
void _setAutocompletion(Gtk::Entry *entry, SPStyleEnum const cssenum[])
void _nodeChanged(Inkscape::XML::Node &repr)
AttrProp parseStyle(Glib::ustring style_string)
StyleDialog::parseStyle.
Inkscape::XML::Node * m_root
Glib::RefPtr< Gtk::Adjustment > _vadj
void _onPropDelete(Glib::ustring const &path, Glib::RefPtr< Gtk::TreeStore > const &store)
StyleDialog::_onPropDelete.
void _closeDialog(Gtk::Dialog *textDialogPtr)
void setCurrentSelector(Glib::ustring current_selector)
void selectionChanged(Selection *selection) final
std::map< Glib::ustring, Glib::ustring > AttrProp
Definition styledialog.h:80
std::vector< SPObject * > _getObjVec(Glib::ustring selector)
void _valueEdited(const Glib::ustring &path, const Glib::ustring &value, Glib::RefPtr< Gtk::TreeStore > store)
StyleDialog::valueEdited.
Gtk::TreeViewColumn * _current_value_col
Definition styledialog.h:74
std::unique_ptr< XML::NodeObserver > const m_styletextwatcher
Gtk::ScrolledWindow _scrolledWindow
void _nodeAdded(Inkscape::XML::Node &repr)
void _onLinkObj(Glib::ustring const &path, Glib::RefPtr< Gtk::TreeStore > const &store)
bool _on_foreach_iter(const Gtk::TreeModel::iterator &iter)
void _nodeRemoved(Inkscape::XML::Node &repr)
void _addRow(Glib::RefPtr< Gtk::TreeStore > const &store, Gtk::TreeView *css_tree, Glib::ustring const &selector, int pos)
void _addTreeViewHandlers(Gtk::TreeView &treeview)
void _addOwnerStyle(Glib::ustring name, Glib::ustring selector)
Interface for refcounted XML nodes.
Definition node.h:80
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
RootCluster root
A base class for all dialogs.
Definition desktop.h:50
XML::Node * get_first_style_text_node(XML::Node *root, bool create_if_missing)
Get the first <style> element's first text node.
Helper class to stream background task notifications as a series of messages.
Glib::ustring name
Definition toolbars.cpp:55