1 // SPDX-License-Identifier: GPL-2.0-or-later 2 #ifndef __INKSCAPE_H__ 3 #define __INKSCAPE_H__ 4 5 /* 6 * Interface to main application 7 * 8 * Authors: 9 * Lauris Kaplinski <lauris@kaplinski.com> 10 * Liam P. White <inkscapebrony@gmail.com> 11 * 12 * Copyright (C) 1999-2014 Authors 13 * 14 * Released under GNU GPL v2+, read the file 'COPYING' for more information. 15 */ 16 17 #include "layer-model.h" 18 #include "selection.h" 19 #include <glib-object.h> 20 #include <glib.h> 21 #include <gtkmm/cssprovider.h> 22 #include <map> 23 #include <sigc++/signal.h> 24 #include <vector> 25 26 class SPDesktop; 27 class SPDocument; 28 struct SPColor; 29 30 namespace Inkscape { 31 32 class Application; 33 namespace UI { 34 namespace Tools { 35 36 class ToolBase; 37 38 } // namespace Tools 39 } // namespace UI 40 41 class ActionContext; 42 43 namespace XML { 44 class Node; 45 struct Document; 46 } // namespace XML 47 48 } // namespace Inkscape 49 50 void inkscape_ref (Inkscape::Application & in); 51 void inkscape_unref(Inkscape::Application & in); 52 53 #define INKSCAPE (Inkscape::Application::instance()) 54 #define SP_ACTIVE_EVENTCONTEXT (INKSCAPE.active_event_context()) 55 #define SP_ACTIVE_DOCUMENT (INKSCAPE.active_document()) 56 #define SP_ACTIVE_DESKTOP (INKSCAPE.active_desktop()) 57 58 class AppSelectionModel { 59 Inkscape::LayerModel _layer_model; 60 Inkscape::Selection *_selection; 61 62 public: AppSelectionModel(SPDocument * doc)63 AppSelectionModel(SPDocument *doc) { 64 _layer_model.setDocument(doc); 65 // TODO: is this really how we should manage the lifetime of the selection? 66 // I just copied this from the initialization of the Selection in SPDesktop. 67 // When and how is it actually released? 68 _selection = Inkscape::GC::release(new Inkscape::Selection(&_layer_model, nullptr)); 69 } 70 getSelection()71 Inkscape::Selection *getSelection() const { return _selection; } 72 }; 73 74 namespace Inkscape { 75 76 class Application { 77 public: 78 static Application& instance(); 79 static bool exists(); 80 static void create(bool use_gui); 81 82 // returns the mask of the keyboard modifier to map to Alt, zero if no mapping 83 // Needs to be a guint because gdktypes.h does not define a 'no-modifier' value mapalt()84 guint mapalt() const { return _mapalt; } 85 86 // Sets the keyboard modifier to map to Alt. Zero switches off mapping, as does '1', which is the default 87 void mapalt(guint maskvalue); 88 trackalt()89 guint trackalt() const { return _trackalt; } trackalt(guint trackvalue)90 void trackalt(guint trackvalue) { _trackalt = trackvalue; } 91 use_gui()92 bool use_gui() const { return _use_gui; } use_gui(gboolean guival)93 void use_gui(gboolean guival) { _use_gui = guival; } 94 95 // no setter for this -- only we can control this variable isCrashing()96 static bool isCrashing() { return _crashIsHappening; } 97 98 // useful functions 99 void application_init (gboolean use_gui); 100 void load_config (const gchar *filename, Inkscape::XML::Document *config, const gchar *skeleton, 101 unsigned int skel_size, const gchar *e_notreg, const gchar *e_notxml, 102 const gchar *e_notsp, const gchar *warn); 103 104 bool load_menus(); 105 Inkscape::XML::Node * get_menus(); 106 107 Inkscape::UI::Tools::ToolBase * active_event_context(); 108 SPDocument * active_document(); 109 SPDesktop * active_desktop(); 110 Glib::RefPtr<Gtk::CssProvider> styleprovider; 111 Glib::RefPtr<Gtk::CssProvider> themeprovider; 112 Glib::RefPtr<Gtk::CssProvider> contrastthemeprovider; 113 Glib::RefPtr<Gtk::CssProvider> colorizeprovider; 114 // Use this function to get selection model etc for a document 115 Inkscape::ActionContext action_context_for_document(SPDocument *doc); 116 Inkscape::ActionContext active_action_context(); 117 118 bool sole_desktop_for_document(SPDesktop const &desktop); 119 120 // Inkscape desktop stuff 121 void add_desktop(SPDesktop * desktop); 122 void remove_desktop(SPDesktop* desktop); 123 void activate_desktop (SPDesktop * desktop); 124 void switch_desktops_next (); 125 void switch_desktops_prev (); 126 void get_all_desktops (std::list< SPDesktop* >& listbuf); 127 void reactivate_desktop (SPDesktop * desktop); 128 SPDesktop * find_desktop_by_dkey (unsigned int dkey); 129 unsigned int maximum_dkey(); 130 SPDesktop * next_desktop (); 131 SPDesktop * prev_desktop (); 132 133 void external_change (); 134 void selection_modified (Inkscape::Selection *selection, guint flags); 135 void selection_changed (Inkscape::Selection * selection); 136 void subselection_changed (SPDesktop *desktop); 137 void selection_set (Inkscape::Selection * selection); 138 Glib::ustring get_symbolic_colors(); 139 void eventcontext_set (Inkscape::UI::Tools::ToolBase * eventcontext); 140 141 // Moved document add/remove functions into public inkscape.h as they are used 142 // (rightly or wrongly) by console-mode functions 143 void add_document (SPDocument *document); 144 bool remove_document (SPDocument *document); 145 146 // fixme: This has to be rethought 147 void refresh_display (); 148 149 // fixme: This also 150 void exit (); 151 152 static void crash_handler(int signum); 153 154 // nobody should be accessing our reference count, so it's made private. 155 friend void ::inkscape_ref (Application & in); 156 friend void ::inkscape_unref(Application & in); 157 158 // signals 159 160 // one of selections changed 161 sigc::signal<void, Inkscape::Selection *> signal_selection_changed; 162 // one of subselections (text selection, gradient handle, etc) changed 163 sigc::signal<void, SPDesktop *> signal_subselection_changed; 164 // one of selections modified 165 sigc::signal<void, Inkscape::Selection *, guint /*flags*/> signal_selection_modified; 166 // one of selections set 167 sigc::signal<void, Inkscape::Selection *> signal_selection_set; 168 // tool switched 169 sigc::signal<void, Inkscape::UI::Tools::ToolBase * /*eventcontext*/> signal_eventcontext_set; 170 // some desktop got focus 171 sigc::signal<void, SPDesktop *> signal_activate_desktop; 172 // some desktop lost focus 173 sigc::signal<void, SPDesktop *> signal_deactivate_desktop; 174 // user change theme 175 sigc::signal<void> signal_change_theme; 176 // these are orphaned signals (nothing emits them and nothing connects to them) 177 sigc::signal<void, SPDocument *> signal_destroy_document; 178 sigc::signal<void, SPColor *, double /*opacity*/> signal_color_set; 179 180 // inkscape is quitting 181 sigc::signal<void> signal_shut_down; 182 // a document was changed by some external means (undo or XML editor); this 183 // may not be reflected by a selection change and thus needs a separate signal 184 sigc::signal<void> signal_external_change; 185 set_pdf_poppler(bool p)186 void set_pdf_poppler(bool p) { 187 _pdf_poppler = p; 188 } get_pdf_poppler()189 bool get_pdf_poppler() { 190 return _pdf_poppler; 191 } set_pdf_page(gint page)192 void set_pdf_page(gint page) { 193 _pdf_page = page; 194 } get_pdf_page()195 gint get_pdf_page() { 196 return _pdf_page; 197 } 198 199 void add_gtk_css(bool only_providers); 200 void add_icon_theme(); 201 202 private: 203 static Inkscape::Application * _S_inst; 204 205 Application(bool use_gui); 206 ~Application(); 207 208 Application(Application const&); // no copy 209 Application& operator=(Application const&); // no assign 210 Application* operator&() const; // no pointer access 211 212 Inkscape::XML::Document *_menus = nullptr; 213 std::map<SPDocument *, int> _document_set; 214 std::map<SPDocument *, AppSelectionModel *> _selection_models; 215 std::vector<SPDesktop *> *_desktops = nullptr; 216 217 unsigned refCount = 1; 218 guint _mapalt = GDK_MOD1_MASK; 219 guint _trackalt = false; 220 static bool _crashIsHappening; 221 bool _use_gui = false; 222 gint _pdf_page = 1; 223 bool _pdf_poppler = false; 224 }; 225 226 } // namespace Inkscape 227 228 #endif 229 230 /* 231 Local Variables: 232 mode:c++ 233 c-file-style:"stroustrup" 234 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 235 indent-tabs-mode:nil 236 fill-column:99 237 End: 238 */ 239 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 240