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