Code

r10814@tres: ted | 2006-01-29 14:02:54 -0800
[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  * 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     /* Tools */
119     SP_VERB_CONTEXT_SELECT,
120     SP_VERB_CONTEXT_NODE,
121     SP_VERB_CONTEXT_RECT,
122     SP_VERB_CONTEXT_ARC,
123     SP_VERB_CONTEXT_STAR,
124     SP_VERB_CONTEXT_SPIRAL,
125     SP_VERB_CONTEXT_PENCIL,
126     SP_VERB_CONTEXT_PEN,
127     SP_VERB_CONTEXT_CALLIGRAPHIC,
128     SP_VERB_CONTEXT_TEXT,
129     SP_VERB_CONTEXT_GRADIENT,
130     SP_VERB_CONTEXT_ZOOM,
131     SP_VERB_CONTEXT_DROPPER,
132     SP_VERB_CONTEXT_CONNECTOR,
133     /* Tool preferences */
134     SP_VERB_CONTEXT_SELECT_PREFS,
135     SP_VERB_CONTEXT_NODE_PREFS,
136     SP_VERB_CONTEXT_RECT_PREFS,
137     SP_VERB_CONTEXT_ARC_PREFS,
138     SP_VERB_CONTEXT_STAR_PREFS,
139     SP_VERB_CONTEXT_SPIRAL_PREFS,
140     SP_VERB_CONTEXT_PENCIL_PREFS,
141     SP_VERB_CONTEXT_PEN_PREFS,
142     SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS,
143     SP_VERB_CONTEXT_TEXT_PREFS,
144     SP_VERB_CONTEXT_GRADIENT_PREFS,
145     SP_VERB_CONTEXT_ZOOM_PREFS,
146     SP_VERB_CONTEXT_DROPPER_PREFS,
147     SP_VERB_CONTEXT_CONNECTOR_PREFS,
148     /* Zooming and desktop settings */
149     SP_VERB_ZOOM_IN,
150     SP_VERB_ZOOM_OUT,
151     SP_VERB_TOGGLE_RULERS,
152     SP_VERB_TOGGLE_SCROLLBARS,
153     SP_VERB_TOGGLE_GRID,
154     SP_VERB_TOGGLE_GUIDES,
155     SP_VERB_ZOOM_NEXT,
156     SP_VERB_ZOOM_PREV,
157     SP_VERB_ZOOM_1_1,
158     SP_VERB_ZOOM_1_2,
159     SP_VERB_ZOOM_2_1,
160 #ifdef HAVE_GTK_WINDOW_FULLSCREEN
161     SP_VERB_FULLSCREEN,
162 #endif /* HAVE_GTK_WINDOW_FULLSCREEN */
163     SP_VERB_VIEW_NEW,
164     SP_VERB_VIEW_NEW_PREVIEW,
165     SP_VERB_VIEW_MODE_NORMAL,
166     SP_VERB_VIEW_MODE_OUTLINE,
167     SP_VERB_VIEW_ICON_PREVIEW,
168     SP_VERB_ZOOM_PAGE,
169     SP_VERB_ZOOM_PAGE_WIDTH,
170     SP_VERB_ZOOM_DRAWING,
171     SP_VERB_ZOOM_SELECTION,
172     /* Dialogs */
173     SP_VERB_DIALOG_DISPLAY,
174     SP_VERB_DIALOG_NAMEDVIEW,
175     SP_VERB_DIALOG_METADATA,
176     SP_VERB_DIALOG_FILL_STROKE,
177     SP_VERB_DIALOG_SWATCHES,
178     SP_VERB_DIALOG_TRANSFORM,
179     SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
180     SP_VERB_DIALOG_TEXT,
181     SP_VERB_DIALOG_XML_EDITOR,
182     SP_VERB_DIALOG_FIND,
183     SP_VERB_DIALOG_DEBUG,
184     SP_VERB_DIALOG_SCRIPT,
185     SP_VERB_DIALOG_TOGGLE,
186     SP_VERB_DIALOG_CLONETILER,
187     SP_VERB_DIALOG_ITEM,
188 #ifdef WITH_INKBOARD
189         SP_VERB_DIALOG_WHITEBOARD_CONNECT,
190         SP_VERB_DIALOG_WHITEBOARD_SHAREWITHUSER,
191         SP_VERB_DIALOG_WHITEBOARD_SHAREWITHCHAT,
192         SP_VERB_DIALOG_WHITEBOARD_DUMPXMLTRACKER,
193         SP_VERB_DIALOG_WHITEBOARD_OPENSESSIONFILE,
194         SP_VERB_DIALOG_WHITEBOARD_SESSIONPLAYBACK,
195         SP_VERB_DIALOG_WHITEBOARD_DISCONNECT_FROM_SESSION,
196         SP_VERB_DIALOG_WHITEBOARD_DISCONNECT_FROM_SERVER,
197 #endif
198     SP_VERB_DIALOG_INPUT,
199     /* Help */
200     SP_VERB_HELP_KEYS,
201     SP_VERB_HELP_ABOUT_EXTENSIONS,
202     SP_VERB_HELP_MEMORY,
203     SP_VERB_HELP_ABOUT,
204     SP_VERB_SHOW_LICENSE,
205     /* Tutorials */
206     SP_VERB_TUTORIAL_BASIC,
207     SP_VERB_TUTORIAL_SHAPES,
208     SP_VERB_TUTORIAL_ADVANCED,
209     SP_VERB_TUTORIAL_TRACING,
210     SP_VERB_TUTORIAL_CALLIGRAPHY,
211     SP_VERB_TUTORIAL_DESIGN,
212     SP_VERB_TUTORIAL_TIPS,
213     /* Effects */
214     SP_VERB_EFFECT_LAST,
215     SP_VERB_EFFECT_LAST_PREF,
216     /* Footer */
217     SP_VERB_LAST
218 };
220 gchar *sp_action_get_title (const SPAction *action);
222 #include <map>
224 namespace Inkscape {
226 /** \brief A class to represent things the user can do.  In many ways
227            these are 'action factories' as they are used to create
228            individual actions that are based on a given view.
229 */
230 class Verb {
231 private:
232     /** \brief An easy to use defition of the table of verbs by code. */
233     typedef std::map<unsigned int, Inkscape::Verb *> VerbTable;
234     /** \brief A table of all the dynamically created verbs. */
235     static VerbTable _verbs;
236     /** \brief The table of statically created verbs which are mostly
237                'base verbs'. */
238     static Verb * _base_verbs[SP_VERB_LAST + 1];
239     /* Plus one because there is an entry for SP_VERB_LAST */
240     /** A string comparison function to be used in the Verb ID lookup
241         to find the different verbs in the hash map. */
242     struct ltstr {
243         bool operator()(const char* s1, const char* s2) const {
244             if (s1 == NULL || s2 == NULL) return true;
245             return strcmp(s1, s2) < 0;
246         }
247     };
248     /** \brief An easy to use definition of the table of verbs by ID. */
249     typedef std::map<gchar const *, Verb *, ltstr> VerbIDTable;
250     /** \brief Quick lookup of verbs by ID */
251     static VerbIDTable _verb_ids;
253     /** \brief A simple typedef to make using the action table easier. */
254     typedef std::map<Inkscape::UI::View::View *, SPAction *> ActionTable;
255     /** \brief A list of all the actions that have been created for this
256                verb.  It is referenced by the view that they are created for. */
257     ActionTable * _actions;
259     /** \brief A unique textual ID for the verb. */
260     gchar const * _id;
261     /** \brief The full name of the verb.  (shown on menu entries) */
262     gchar const * _name;
263     /** \brief Tooltip for the verb. */
264     gchar const * _tip;
265     /** \brief Name of the image that represents the verb. */
266     gchar const * _image;
267     /** \brief Unique numerical representation of the verb.  In most cases
268                it is a value from the anonymous enum at the top of this
269                file. */
270     unsigned int  _code;
272     /** \brief Whether this verb is set to default to sensitive or
273                insensitive when new actions are created. */
274     bool _default_sensitive;
275 protected:
276     /** \brief Allows for preliminary setting of the \c _default_sensitive
277                value without effecting existing actions
278         \param in_val New value
280         This function is mostly used at initialization where there are
281         not actions to effect.  I can't think of another case where it
282         should be used.
283     */
284     bool set_default_sensitive (bool in_val) { return _default_sensitive = in_val; }
285 public:
286     /** \brief Accessor to get the \c _default_sensitive value */
287     bool get_default_sensitive (void) { return _default_sensitive; }
289 public:
290     /** \brief Accessor to get the internal variable. */
291     unsigned int get_code (void) { return _code; }
292     /** \brief Accessor to get the internal variable. */
293     gchar const * get_id (void) { return _id; }
294     /** \brief Accessor to get the internal variable. */
295     gchar const * get_name (void) { return _name; }
297 protected:
298     SPAction * make_action_helper (Inkscape::UI::View::View * view, SPActionEventVector * vector, void * in_pntr = NULL);
299     virtual SPAction * make_action (Inkscape::UI::View::View * view);
301 public:
302     /** \brief Inititalizes the Verb with the parameters
303         \param code  Goes to \c _code
304         \param id    Goes to \c _id
305         \param name  Goes to \c _name
306         \param tip   Goes to \c _tip
307         \param image Goes to \c _image
309         This function also sets \c _actions to NULL.
311         \warning NO DATA IS COPIED BY CALLING THIS FUNCTION.
313         In many respects this is very bad object oriented design, but it
314         is done for a reason.  All verbs today are of two types: 1) static
315         or 2) created for extension.  In the static case all of the
316         strings are constants in the code, and thus don't really need to
317         be copied.  In the extensions case the strings are identical to
318         the ones already created in the extension object, copying them
319         would be a waste of memory.
320     */
321     Verb(const unsigned int code,
322          gchar const * id,
323          gchar const * name,
324          gchar const * tip,
325          gchar const * image) :
326         _actions(NULL), _id(id), _name(name), _tip(tip), _image(image), _code(code), _default_sensitive(true) {
327         _verbs.insert(VerbTable::value_type(_code, this));
328         _verb_ids.insert(VerbIDTable::value_type(_id, this));
329     }
330     Verb (gchar const * id, gchar const * name, gchar const * tip, gchar const * image);
331     virtual ~Verb (void);
333     SPAction * get_action(Inkscape::UI::View::View * view);
335 private:
336     static Verb * get_search (unsigned int code);
337 public:
338     /** \brief A function to turn a code into a verb.
339         \param  code  The code to be translated
340         \return A pointer to a verb object or a NULL if not found.
342         This is an inline function to translate the codes which are
343         static quickly.  This should optimize into very quick code
344         everywhere which hard coded \c codes are used.  In the case
345         where the \c code is not static the \c get_search function
346         is used.
347     */
348     static Verb * get (unsigned int code) {
349         if (code <= SP_VERB_LAST) {
350             return _base_verbs[code];
351         } else {
352             return get_search(code);
353         }
354     }
355     static Verb * getbyid (gchar const * id);
357     static void delete_all_view (Inkscape::UI::View::View * view);
358     void delete_view (Inkscape::UI::View::View * view);
360     void sensitive (SPDocument * in_doc = NULL, bool in_sensitive = true);
361 }; /* Verb class */
364 }  /* Inkscape namespace */
366 #endif // SEEN_SP_VERBS_H
368 /*
369   Local Variables:
370   mode:c++
371   c-file-style:"stroustrup"
372   c-file-offsets:((innamespace . 0)(inline-open . 0))
373   indent-tabs-mode:nil
374   fill-column:99
375   End:
376 */
377 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :