Code

Inkscape::XML::Document -> Inkscape::XML::DocumentTree (more refactoring ...)
[inkscape.git] / src / verbs.h
1 #ifndef SEEN_SP_VERBS_H
2 #define SEEN_SP_VERBS_H
4 /** \file
5  * \brief Frontend to actions
6  *
7  * Author:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *   Ted Gould <ted@gould.cx>
10  *   David Yip <yipdw@rose-hulman.edu>
11  *
12  *  Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
13  *  Copyright (C) (date unspecified) Authors
15  * This code is in public domain if done by Lauris
16  * This code is GPL if done by Ted or David
17  */
19 #include <cstring>
20 #include <string>
21 #include <string.h>
22 #include "config.h"
23 #include "require-config.h"   /* HAVE_GTK_WINDOW_FULLSCREEN */
24 #include "helper/helper-forward.h"
25 #include "forward.h"
26 #include <glibmm/ustring.h>
28 /** \brief This anonymous enum is used to provide a list of the Verbs
29            which are defined staticly in the verb files.  There may be
30            other verbs which are defined dynamically also. */
31 enum {
32     /* Header */
33     SP_VERB_INVALID,               /**< A dummy verb to represent doing something wrong. */
34     SP_VERB_NONE,                  /**< A dummy verb to represent not having a verb. */
35     /* File */
36     SP_VERB_FILE_NEW,              /**< A new file in a new window. */
37     SP_VERB_FILE_OPEN,             /**< Open a file. */
38     SP_VERB_FILE_REVERT,           /**< Revert this file to its original state. */
39     SP_VERB_FILE_SAVE,             /**< Save the current file with its saved filename */
40     SP_VERB_FILE_SAVE_AS,          /**< Save the current file with a new filename */
41     SP_VERB_FILE_SAVE_A_COPY,      /**< Save a copy of the current file */
42     SP_VERB_FILE_PRINT,
43     SP_VERB_FILE_VACUUM,
44     SP_VERB_FILE_PRINT_PREVIEW,
45     SP_VERB_FILE_IMPORT,
46     SP_VERB_FILE_EXPORT,
47     SP_VERB_FILE_IMPORT_FROM_OCAL, /**< Import the file from Open Clip Art Library */
48     SP_VERB_FILE_EXPORT_TO_OCAL, /**< Export the file to Open Clip Art  Library */
49     SP_VERB_FILE_NEXT_DESKTOP,
50     SP_VERB_FILE_PREV_DESKTOP,
51     SP_VERB_FILE_CLOSE_VIEW,
52     SP_VERB_FILE_QUIT,
53     /* Edit */
54     SP_VERB_EDIT_UNDO,
55     SP_VERB_EDIT_REDO,
56     SP_VERB_EDIT_CUT,
57     SP_VERB_EDIT_COPY,
58     SP_VERB_EDIT_PASTE,
59     SP_VERB_EDIT_PASTE_STYLE,
60     SP_VERB_EDIT_PASTE_SIZE,
61     SP_VERB_EDIT_PASTE_SIZE_X,
62     SP_VERB_EDIT_PASTE_SIZE_Y,
63     SP_VERB_EDIT_PASTE_SIZE_SEPARATELY,
64     SP_VERB_EDIT_PASTE_SIZE_SEPARATELY_X,
65     SP_VERB_EDIT_PASTE_SIZE_SEPARATELY_Y,
66     SP_VERB_EDIT_PASTE_IN_PLACE,
67     SP_VERB_EDIT_PASTE_LIVEPATHEFFECT,
68     SP_VERB_EDIT_REMOVE_LIVEPATHEFFECT,
69     SP_VERB_EDIT_REMOVE_FILTER,
70     SP_VERB_EDIT_DELETE,
71     SP_VERB_EDIT_DUPLICATE,
72     SP_VERB_EDIT_CLONE,
73     SP_VERB_EDIT_UNLINK_CLONE,
74     SP_VERB_EDIT_RELINK_CLONE,
75     SP_VERB_EDIT_CLONE_SELECT_ORIGINAL,
76     SP_VERB_EDIT_SELECTION_2_MARKER,
77     SP_VERB_EDIT_SELECTION_2_GUIDES,
78     SP_VERB_EDIT_TILE,
79     SP_VERB_EDIT_UNTILE,
80     SP_VERB_EDIT_CLEAR_ALL,
81     SP_VERB_EDIT_SELECT_ALL,
82     SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS,
83     SP_VERB_EDIT_INVERT,
84     SP_VERB_EDIT_INVERT_IN_ALL_LAYERS,
85     SP_VERB_EDIT_SELECT_NEXT,
86     SP_VERB_EDIT_SELECT_PREV,
87     SP_VERB_EDIT_DESELECT,
88     SP_VERB_EDIT_GUIDES_AROUND_PAGE,
89     SP_VERB_EDIT_NEXT_PATHEFFECT_PARAMETER,
90     /* Selection */
91     SP_VERB_SELECTION_TO_FRONT,
92     SP_VERB_SELECTION_TO_BACK,
93     SP_VERB_SELECTION_RAISE,
94     SP_VERB_SELECTION_LOWER,
95     SP_VERB_SELECTION_GROUP,
96     SP_VERB_SELECTION_UNGROUP,
97     SP_VERB_SELECTION_TEXTTOPATH,
98     SP_VERB_SELECTION_TEXTFROMPATH,
99     SP_VERB_SELECTION_REMOVE_KERNS,
100     SP_VERB_SELECTION_UNION,
101     SP_VERB_SELECTION_INTERSECT,
102     SP_VERB_SELECTION_DIFF,
103     SP_VERB_SELECTION_SYMDIFF,
104     SP_VERB_SELECTION_CUT,
105     SP_VERB_SELECTION_SLICE,
106     SP_VERB_SELECTION_OFFSET,
107     SP_VERB_SELECTION_OFFSET_SCREEN,
108     SP_VERB_SELECTION_OFFSET_SCREEN_10,
109     SP_VERB_SELECTION_INSET,
110     SP_VERB_SELECTION_INSET_SCREEN,
111     SP_VERB_SELECTION_INSET_SCREEN_10,
112     SP_VERB_SELECTION_DYNAMIC_OFFSET,
113     SP_VERB_SELECTION_LINKED_OFFSET,
114     SP_VERB_SELECTION_OUTLINE,
115     SP_VERB_SELECTION_SIMPLIFY,
116     SP_VERB_SELECTION_REVERSE,
117     SP_VERB_SELECTION_TRACE,
118     SP_VERB_SELECTION_CREATE_BITMAP,
119     SP_VERB_SELECTION_COMBINE,
120     SP_VERB_SELECTION_BREAK_APART,
121     SP_VERB_SELECTION_GRIDTILE,
122     /* Layer */
123     SP_VERB_LAYER_NEW,
124     SP_VERB_LAYER_RENAME,
125     SP_VERB_LAYER_NEXT,
126     SP_VERB_LAYER_PREV,
127     SP_VERB_LAYER_MOVE_TO_NEXT,
128     SP_VERB_LAYER_MOVE_TO_PREV,
129     SP_VERB_LAYER_TO_TOP,
130     SP_VERB_LAYER_TO_BOTTOM,
131     SP_VERB_LAYER_RAISE,
132     SP_VERB_LAYER_LOWER,
133     SP_VERB_LAYER_DUPLICATE,
134     SP_VERB_LAYER_DELETE,
135     SP_VERB_LAYER_SOLO,
136     /* Object */
137     SP_VERB_OBJECT_ROTATE_90_CW,
138     SP_VERB_OBJECT_ROTATE_90_CCW,
139     SP_VERB_OBJECT_FLATTEN,
140     SP_VERB_OBJECT_TO_CURVE,
141     SP_VERB_OBJECT_FLOW_TEXT,
142     SP_VERB_OBJECT_UNFLOW_TEXT,
143     SP_VERB_OBJECT_FLOWTEXT_TO_TEXT,
144     SP_VERB_OBJECT_FLIP_HORIZONTAL,
145     SP_VERB_OBJECT_FLIP_VERTICAL,
146     SP_VERB_OBJECT_SET_MASK,
147     SP_VERB_OBJECT_EDIT_MASK,
148     SP_VERB_OBJECT_UNSET_MASK,
149     SP_VERB_OBJECT_SET_CLIPPATH,
150     SP_VERB_OBJECT_EDIT_CLIPPATH,
151     SP_VERB_OBJECT_UNSET_CLIPPATH,
152     /* Tools */
153     SP_VERB_CONTEXT_SELECT,
154     SP_VERB_CONTEXT_NODE,
155     SP_VERB_CONTEXT_TWEAK,
156     SP_VERB_CONTEXT_RECT,
157     SP_VERB_CONTEXT_3DBOX,
158     SP_VERB_CONTEXT_ARC,
159     SP_VERB_CONTEXT_STAR,
160     SP_VERB_CONTEXT_SPIRAL,
161     SP_VERB_CONTEXT_PENCIL,
162     SP_VERB_CONTEXT_PEN,
163     SP_VERB_CONTEXT_CALLIGRAPHIC,
164     SP_VERB_CONTEXT_TEXT,
165     SP_VERB_CONTEXT_GRADIENT,
166     SP_VERB_CONTEXT_ZOOM,
167     SP_VERB_CONTEXT_DROPPER,
168     SP_VERB_CONTEXT_CONNECTOR,
169     SP_VERB_CONTEXT_PAINTBUCKET,
170     SP_VERB_CONTEXT_LPE, /* not really a tool but used for editing LPE parameters on-canvas for example */
171     SP_VERB_CONTEXT_ERASER,
172     SP_VERB_CONTEXT_LPETOOL, /* note that this is very different from SP_VERB_CONTEXT_LPE above! */
173     /* Tool preferences */
174     SP_VERB_CONTEXT_SELECT_PREFS,
175     SP_VERB_CONTEXT_NODE_PREFS,
176     SP_VERB_CONTEXT_TWEAK_PREFS,
177     SP_VERB_CONTEXT_RECT_PREFS,
178     SP_VERB_CONTEXT_3DBOX_PREFS,
179     SP_VERB_CONTEXT_ARC_PREFS,
180     SP_VERB_CONTEXT_STAR_PREFS,
181     SP_VERB_CONTEXT_SPIRAL_PREFS,
182     SP_VERB_CONTEXT_PENCIL_PREFS,
183     SP_VERB_CONTEXT_PEN_PREFS,
184     SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS,
185     SP_VERB_CONTEXT_TEXT_PREFS,
186     SP_VERB_CONTEXT_GRADIENT_PREFS,
187     SP_VERB_CONTEXT_ZOOM_PREFS,
188     SP_VERB_CONTEXT_DROPPER_PREFS,
189     SP_VERB_CONTEXT_CONNECTOR_PREFS,
190     SP_VERB_CONTEXT_PAINTBUCKET_PREFS,
191     SP_VERB_CONTEXT_ERASER_PREFS,
192     SP_VERB_CONTEXT_LPETOOL_PREFS,
193     /* Zooming and desktop settings */
194     SP_VERB_ZOOM_IN,
195     SP_VERB_ZOOM_OUT,
196     SP_VERB_TOGGLE_RULERS,
197     SP_VERB_TOGGLE_SCROLLBARS,
198     SP_VERB_TOGGLE_GRID,
199     SP_VERB_TOGGLE_GUIDES,
200     SP_VERB_TOGGLE_SNAPPING,
201     SP_VERB_ZOOM_NEXT,
202     SP_VERB_ZOOM_PREV,
203     SP_VERB_ZOOM_1_1,
204     SP_VERB_ZOOM_1_2,
205     SP_VERB_ZOOM_2_1,
206 #ifdef HAVE_GTK_WINDOW_FULLSCREEN
207     SP_VERB_FULLSCREEN,
208 #endif /* HAVE_GTK_WINDOW_FULLSCREEN */
209     SP_VERB_FOCUSTOGGLE,
210     SP_VERB_VIEW_NEW,
211     SP_VERB_VIEW_NEW_PREVIEW,
212     SP_VERB_VIEW_MODE_NORMAL,
213     SP_VERB_VIEW_MODE_NO_FILTERS,
214     SP_VERB_VIEW_MODE_OUTLINE,
215     SP_VERB_VIEW_MODE_TOGGLE,
216     SP_VERB_VIEW_CMS_TOGGLE,
217     SP_VERB_VIEW_ICON_PREVIEW,
218     SP_VERB_ZOOM_PAGE,
219     SP_VERB_ZOOM_PAGE_WIDTH,
220     SP_VERB_ZOOM_DRAWING,
221     SP_VERB_ZOOM_SELECTION,
222     /* Dialogs */
223     SP_VERB_DIALOG_DISPLAY,
224     SP_VERB_DIALOG_NAMEDVIEW,
225     SP_VERB_DIALOG_METADATA,
226     SP_VERB_DIALOG_FILL_STROKE,
227     SP_VERB_DIALOG_SWATCHES,
228     SP_VERB_DIALOG_TRANSFORM,
229     SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
230     SP_VERB_DIALOG_UNDO_HISTORY,
231     SP_VERB_DIALOG_TEXT,
232     SP_VERB_DIALOG_XML_EDITOR,
233     SP_VERB_DIALOG_FIND,
234     SP_VERB_DIALOG_FINDREPLACE,
235     SP_VERB_DIALOG_SPELLCHECK,
236     SP_VERB_DIALOG_DEBUG,
237     SP_VERB_DIALOG_SCRIPT,
238     SP_VERB_DIALOG_TOGGLE,
239     SP_VERB_DIALOG_CLONETILER,
240     SP_VERB_DIALOG_ITEM,
241 #ifdef WITH_INKBOARD
242     SP_VERB_XMPP_CLIENT,
243 #endif
244     SP_VERB_DIALOG_INPUT,
245     SP_VERB_DIALOG_INPUT2,
246     SP_VERB_DIALOG_EXTENSIONEDITOR,
247     SP_VERB_DIALOG_LAYERS,
248     SP_VERB_DIALOG_LIVE_PATH_EFFECT,
249     SP_VERB_DIALOG_FILTER_EFFECTS,
250     SP_VERB_DIALOG_SVG_FONTS,
251     /* Help */
252     SP_VERB_HELP_ABOUT_EXTENSIONS,
253     SP_VERB_HELP_MEMORY,
254     SP_VERB_HELP_ABOUT,
255     //SP_VERB_SHOW_LICENSE,
256     /* Tutorials */
257     SP_VERB_TUTORIAL_BASIC,
258     SP_VERB_TUTORIAL_SHAPES,
259     SP_VERB_TUTORIAL_ADVANCED,
260     SP_VERB_TUTORIAL_TRACING,
261     SP_VERB_TUTORIAL_CALLIGRAPHY,
262     SP_VERB_TUTORIAL_DESIGN,
263     SP_VERB_TUTORIAL_TIPS,
264     /* Effects */
265     SP_VERB_EFFECT_LAST,
266     SP_VERB_EFFECT_LAST_PREF,
267     /* Fit Canvas */
268     SP_VERB_FIT_CANVAS_TO_SELECTION,
269     SP_VERB_FIT_CANVAS_TO_DRAWING,
270     SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING,
271     /* LockAndHide */
272     SP_VERB_UNLOCK_ALL,
273     SP_VERB_UNLOCK_ALL_IN_ALL_LAYERS,
274     SP_VERB_UNHIDE_ALL,
275     SP_VERB_UNHIDE_ALL_IN_ALL_LAYERS,
276     /* Color management */
277     SP_VERB_EDIT_LINK_COLOR_PROFILE,
278     SP_VERB_EDIT_REMOVE_COLOR_PROFILE,
279     /*Scripting*/
280     SP_VERB_EDIT_ADD_EXTERNAL_SCRIPT,
281     SP_VERB_EDIT_REMOVE_EXTERNAL_SCRIPT,
282     /* Footer */
283     SP_VERB_LAST
284 };
286 gchar *sp_action_get_title (const SPAction *action);
288 #include <map>
290 namespace Inkscape {
292 /** \brief A class to represent things the user can do.  In many ways
293            these are 'action factories' as they are used to create
294            individual actions that are based on a given view.
295 */
296 class Verb {
297 private:
298     /** \brief An easy to use defition of the table of verbs by code. */
299     typedef std::map<unsigned int, Inkscape::Verb *> VerbTable;
300     /** \brief A table of all the dynamically created verbs. */
301     static VerbTable _verbs;
302     /** \brief The table of statically created verbs which are mostly
303                'base verbs'. */
304     static Verb * _base_verbs[SP_VERB_LAST + 1];
305     /* Plus one because there is an entry for SP_VERB_LAST */
306     /** A string comparison function to be used in the Verb ID lookup
307         to find the different verbs in the hash map. */
308     struct ltstr {
309         bool operator()(const char* s1, const char* s2) const {
310             if ( (s1 == NULL) && (s2 != NULL) ) {
311                 return true;
312             } else if (s1 == NULL || s2 == NULL) {
313                 return false;
314             } else {
315                 return strcmp(s1, s2) < 0;
316             }
317         }
318     };
319     /** \brief An easy to use definition of the table of verbs by ID. */
320     typedef std::map<gchar const *, Verb *, ltstr> VerbIDTable;
321     /** \brief Quick lookup of verbs by ID */
322     static VerbIDTable _verb_ids;
324     /** \brief A simple typedef to make using the action table easier. */
325     typedef std::map<Inkscape::UI::View::View *, SPAction *> ActionTable;
326     /** \brief A list of all the actions that have been created for this
327                verb.  It is referenced by the view that they are created for. */
328     ActionTable * _actions;
330     /** \brief A unique textual ID for the verb. */
331     gchar const * _id;
332     /** \brief The full name of the verb.  (shown on menu entries) */
333     gchar const * _name;
334     /** \brief Tooltip for the verb. */
335     gchar const * _tip;
336     /** \brief Name of the image that represents the verb. */
337     gchar const * _image;
338     /** \brief Unique numerical representation of the verb.  In most cases
339                it is a value from the anonymous enum at the top of this
340                file. */
341     unsigned int  _code;
343     /** \brief Whether this verb is set to default to sensitive or
344                insensitive when new actions are created. */
345     bool _default_sensitive;
346 protected:
347     /** \brief Allows for preliminary setting of the \c _default_sensitive
348                value without effecting existing actions
349         \param in_val New value
351         This function is mostly used at initialization where there are
352         not actions to effect.  I can't think of another case where it
353         should be used.
354     */
355     bool set_default_sensitive (bool in_val) { return _default_sensitive = in_val; }
356 public:
357     /** \brief Accessor to get the \c _default_sensitive value */
358     bool get_default_sensitive (void) { return _default_sensitive; }
360 public:
361     /** \brief Accessor to get the internal variable. */
362     unsigned int get_code (void) { return _code; }
363     /** \brief Accessor to get the internal variable. */
364     gchar const * get_id (void) { return _id; }
365     /** \brief Accessor to get the internal variable. */
366     gchar const * get_name (void) { return _name; }
367     /** \brief Accessor to get the internal variable. */
368     gchar const * get_tip (void) ;
369     /** \brief Accessor to get the internal variable. */
370     gchar const * get_image (void) { return _image; }
372     /** \brief Set the name after initialization. */
373     gchar const * set_name (gchar const * name) { _name = name; return _name; }
374     /** \brief Set the tooltip after initialization. */
375     gchar const * set_tip (gchar const * tip) { _tip = tip; return _tip; }
377 protected:
378     SPAction * make_action_helper (Inkscape::UI::View::View * view, SPActionEventVector * vector, void * in_pntr = NULL);
379     virtual SPAction * make_action (Inkscape::UI::View::View * view);
381 public:
382     /** \brief Inititalizes the Verb with the parameters
383         \param code  Goes to \c _code
384         \param id    Goes to \c _id
385         \param name  Goes to \c _name
386         \param tip   Goes to \c _tip
387         \param image Goes to \c _image
389         This function also sets \c _actions to NULL.
391         \warning NO DATA IS COPIED BY CALLING THIS FUNCTION.
393         In many respects this is very bad object oriented design, but it
394         is done for a reason.  All verbs today are of two types: 1) static
395         or 2) created for extension.  In the static case all of the
396         strings are constants in the code, and thus don't really need to
397         be copied.  In the extensions case the strings are identical to
398         the ones already created in the extension object, copying them
399         would be a waste of memory.
400     */
401     Verb(const unsigned int code,
402          gchar const * id,
403          gchar const * name,
404          gchar const * tip,
405          gchar const * image) :
406         _actions(NULL), _id(id), _name(name), _tip(tip), _image(image), _code(code), _default_sensitive(true) {
407         _verbs.insert(VerbTable::value_type(_code, this));
408         _verb_ids.insert(VerbIDTable::value_type(_id, this));
409     }
410     Verb (gchar const * id, gchar const * name, gchar const * tip, gchar const * image);
411     virtual ~Verb (void);
413     SPAction * get_action(Inkscape::UI::View::View * view);
415 private:
416     static Verb * get_search (unsigned int code);
417 public:
418     /** \brief A function to turn a code into a verb.
419         \param  code  The code to be translated
420         \return A pointer to a verb object or a NULL if not found.
422         This is an inline function to translate the codes which are
423         static quickly.  This should optimize into very quick code
424         everywhere which hard coded \c codes are used.  In the case
425         where the \c code is not static the \c get_search function
426         is used.
427     */
428     static Verb * get (unsigned int code) {
429         if (code <= SP_VERB_LAST) {
430             return _base_verbs[code];
431         } else {
432             return get_search(code);
433         }
434     }
435     static Verb * getbyid (gchar const * id);
437     static void delete_all_view (Inkscape::UI::View::View * view);
438     void delete_view (Inkscape::UI::View::View * view);
440     void sensitive (Inkscape::XML::DocumentTree * in_doc = NULL, bool in_sensitive = true);
441     void name (Inkscape::XML::DocumentTree * in_doc = NULL, Glib::ustring in_name = "");
443 // Yes, multiple public, protected and private sections are bad. We'll clean that up later
444 protected:
445     /** \brief Returns the size of the internal base verb array.
446         \return The size in elements of the internal base array.
448         This is an inline function intended for testing. This should normally not be used.
449         For testing, a subclass that returns this value can be created to verify that the
450         length matches the enum values, etc.
451     */
452     static int _getBaseListSize(void) {return G_N_ELEMENTS(_base_verbs);}
454 public:
455     static void list (void);
456 }; /* Verb class */
459 }  /* Inkscape namespace */
461 #endif // SEEN_SP_VERBS_H
463 /*
464   Local Variables:
465   mode:c++
466   c-file-style:"stroustrup"
467   c-file-offsets:((innamespace . 0)(inline-open . 0))
468   indent-tabs-mode:nil
469   fill-column:99
470   End:
471 */
472 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :