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