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