Code

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