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