Code

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