Code

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