Code

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