Code

Applying fixes for gcc 4.3 build issues (closes LP: #169115)
[inkscape.git] / src / tools-switch.cpp
1 /*
2  * Utility functions for switching tools (= contexts)
3  *
4  * Authors:
5  *   bulia byak <buliabyak@users.sf.net>
6  *   Josh Andler <scislac@users.sf.net>
7  *
8  * Copyright (C) 2003-2007 authors
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
18 #include <cstring>
19 #include <string>
21 #include "inkscape-private.h"
22 #include "desktop.h"
23 #include "desktop-handles.h"
24 #include <glibmm/i18n.h>
26 #include <xml/repr.h>
28 #include "select-context.h"
29 #include "node-context.h"
30 #include "tweak-context.h"
31 #include "sp-path.h"
32 #include "rect-context.h"
33 #include "sp-rect.h"
34 #include "box3d-context.h"
35 #include "box3d.h"
36 #include "arc-context.h"
37 #include "sp-ellipse.h"
38 #include "star-context.h"
39 #include "sp-star.h"
40 #include "spiral-context.h"
41 #include "sp-spiral.h"
42 #include "dyna-draw-context.h"
43 #include "pen-context.h"
44 #include "pencil-context.h"
45 #include "text-context.h"
46 #include "sp-text.h"
47 #include "sp-flowtext.h"
48 #include "gradient-context.h"
49 #include "zoom-context.h"
50 #include "dropper-context.h"
51 #include "connector-context.h"
52 #include "flood-context.h"
53 #include "sp-offset.h"
54 #include "message-context.h"
56 #include "tools-switch.h"
58 static char const *const tool_names[] = {
59     NULL,
60     "tools.select",
61     "tools.nodes",
62     "tools.tweak",
63     "tools.shapes.rect",
64     "tools.shapes.3dbox",
65     "tools.shapes.arc",
66     "tools.shapes.star",
67     "tools.shapes.spiral",
68     "tools.freehand.pencil",
69     "tools.freehand.pen",
70     "tools.calligraphic",
71     "tools.text",
72     "tools.gradient",
73     "tools.zoom",
74     "tools.dropper",
75     "tools.connector",
76     "tools.paintbucket",
77     NULL
78 };
80 static char const *const tool_ids[] = {
81     NULL,
82     "select",
83     "nodes",
84     "tweak",
85     "rect",
86     "3dbox",
87     "arc",
88     "star",
89     "spiral",
90     "pencil",
91     "pen",
92     "calligraphic",
93     "text",
94     "gradient",
95     "zoom",
96     "dropper",
97     "connector",
98     "paintbucket",
99     NULL
100 };
102 static int
103 tools_id2num(char const *id)
105     int i = 1;
106     while (tool_ids[i]) {
107         if (strcmp(tool_ids[i], id) == 0)
108             return i;
109         else i++;
110     }
111     g_assert( 0 == TOOLS_INVALID );
112     return 0; //nothing found
115 int
116 tools_isactive(SPDesktop *dt, unsigned num)
118     g_assert( num < G_N_ELEMENTS(tool_ids) );
119     if (SP_IS_EVENT_CONTEXT(dt->event_context))
120         return (!strcmp(dt->event_context->prefs_repr->attribute("id"), tool_ids[num]));
121     else return FALSE;
124 int
125 tools_active(SPDesktop *dt)
127     return (tools_id2num(dt->event_context->prefs_repr->attribute("id")));
130 void
131 tools_switch(SPDesktop *dt, int num)
133     if (dt) {
134         dt->_tool_changed.emit(num);
135     }
137     switch (num) {
138         case TOOLS_SELECT:
139             dt->set_event_context(SP_TYPE_SELECT_CONTEXT, tool_names[num]);
140             /* fixme: This is really ugly hack. We should bind and unbind class methods */
141             dt->activate_guides(true);
142             inkscape_eventcontext_set(sp_desktop_event_context(dt));
143             break;
144         case TOOLS_NODES:
145             dt->set_event_context(SP_TYPE_NODE_CONTEXT, tool_names[num]);
146             dt->activate_guides(true);
147             inkscape_eventcontext_set(sp_desktop_event_context(dt));
148             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("To edit a path, <b>click</b>, <b>Shift+click</b>, or <b>drag around</b> nodes to select them, then <b>drag</b> nodes and handles. <b>Click</b> on an object to select."));
149             break;
150         case TOOLS_TWEAK:
151             dt->set_event_context(SP_TYPE_TWEAK_CONTEXT, tool_names[num]);
152             dt->activate_guides(true);
153             inkscape_eventcontext_set(sp_desktop_event_context(dt));
154             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("To tweak a path by pushing, select it and drag over it."));
155             break;
156         case TOOLS_SHAPES_RECT:
157             dt->set_event_context(SP_TYPE_RECT_CONTEXT, tool_names[num]);
158             dt->activate_guides(false);
159             inkscape_eventcontext_set(sp_desktop_event_context(dt));
160             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a rectangle. <b>Drag controls</b> to round corners and resize. <b>Click</b> to select."));
161             break;
162         case TOOLS_SHAPES_3DBOX:
163             dt->set_event_context(SP_TYPE_BOX3D_CONTEXT, tool_names[num]);
164             dt->activate_guides(false);
165             inkscape_eventcontext_set(sp_desktop_event_context(dt));
166             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a 3D box. <b>Drag controls</b> to resize in perspective. <b>Click</b> to select (with <b>Ctrl+Alt</b> for single faces)."));
167             break;
168         case TOOLS_SHAPES_ARC:
169             dt->set_event_context(SP_TYPE_ARC_CONTEXT, tool_names[num]);
170             dt->activate_guides(false);
171             inkscape_eventcontext_set(sp_desktop_event_context(dt));
172             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create an ellipse. <b>Drag controls</b> to make an arc or segment. <b>Click</b> to select."));
173             break;
174         case TOOLS_SHAPES_STAR:
175             dt->set_event_context(SP_TYPE_STAR_CONTEXT, tool_names[num]);
176             dt->activate_guides(false);
177             inkscape_eventcontext_set(sp_desktop_event_context(dt));
178             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a star. <b>Drag controls</b> to edit the star shape. <b>Click</b> to select."));
179             break;
180         case TOOLS_SHAPES_SPIRAL:
181             dt->set_event_context(SP_TYPE_SPIRAL_CONTEXT, tool_names[num]);
182             dt->activate_guides(false);
183             inkscape_eventcontext_set(sp_desktop_event_context(dt));
184             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a spiral. <b>Drag controls</b> to edit the spiral shape. <b>Click</b> to select."));
185             break;
186         case TOOLS_FREEHAND_PENCIL:
187             dt->set_event_context(SP_TYPE_PENCIL_CONTEXT, tool_names[num]);
188             dt->activate_guides(false);
189             inkscape_eventcontext_set(sp_desktop_event_context(dt));
190             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a freehand line. Start drawing with <b>Shift</b> to append to selected path. <b>Ctrl+click</b> to create single dots."));
191             break;
192         case TOOLS_FREEHAND_PEN:
193             dt->set_event_context(SP_TYPE_PEN_CONTEXT, tool_names[num]);
194             dt->activate_guides(false);
195             inkscape_eventcontext_set(sp_desktop_event_context(dt));
196             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to start a path; with <b>Shift</b> to append to selected path. <b>Ctrl+click</b> to create single dots."));
197             break;
198         case TOOLS_CALLIGRAPHIC:
199             dt->set_event_context(SP_TYPE_DYNA_DRAW_CONTEXT, tool_names[num]);
200             dt->activate_guides(false);
201             inkscape_eventcontext_set(sp_desktop_event_context(dt));
202             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to draw a calligraphic stroke; with <b>Ctrl</b> to track a guide, with <b>Alt</b> to thin/thicken. <b>Arrow keys</b> adjust width (left/right) and angle (up/down)."));
203             break;
204         case TOOLS_TEXT:
205             dt->set_event_context(SP_TYPE_TEXT_CONTEXT, tool_names[num]);
206             dt->activate_guides(false);
207             inkscape_eventcontext_set(sp_desktop_event_context(dt));
208             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to select or create text, <b>drag</b> to create flowed text; then type."));
209             break;
210         case TOOLS_GRADIENT:
211             dt->set_event_context(SP_TYPE_GRADIENT_CONTEXT, tool_names[num]);
212             dt->activate_guides(false);
213             inkscape_eventcontext_set(sp_desktop_event_context(dt));
214             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> or <b>double click</b> to create a gradient on selected objects, <b>drag handles</b> to adjust gradients."));
215             break;
216         case TOOLS_ZOOM:
217             dt->set_event_context(SP_TYPE_ZOOM_CONTEXT, tool_names[num]);
218             dt->activate_guides(false);
219             inkscape_eventcontext_set(sp_desktop_event_context(dt));
220             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>drag around an area</b> to zoom in, <b>Shift+click</b> to zoom out."));
221             break;
222         case TOOLS_DROPPER:
223             dt->set_event_context(SP_TYPE_DROPPER_CONTEXT, tool_names[num]);
224             dt->activate_guides(false);
225             inkscape_eventcontext_set(sp_desktop_event_context(dt));
226             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to set fill, <b>Shift+click</b> to set stroke; <b>drag</b> to average color in area; with <b>Alt</b> to pick inverse color; <b>Ctrl+C</b> to copy the color under mouse to clipboard"));
227             break;
228         case TOOLS_CONNECTOR:
229             dt->set_event_context(SP_TYPE_CONNECTOR_CONTEXT, tool_names[num]);
230             dt->activate_guides(false);
231             inkscape_eventcontext_set(sp_desktop_event_context(dt));
232             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click and drag</b> between shapes to create a connector."));
233             break;
234         case TOOLS_PAINTBUCKET:
235             dt->set_event_context(SP_TYPE_FLOOD_CONTEXT, tool_names[num]);
236             dt->activate_guides(false);
237             inkscape_eventcontext_set(sp_desktop_event_context(dt));
238             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to paint a bounded area, <b>Shift+click</b> to union the new fill with the current selection, <b>Ctrl+click</b> to change the clicked object's fill and stroke to the current setting."));
239             break;
240     }
243 void
244 tools_switch_current(int num)
246     SPDesktop *dt = SP_ACTIVE_DESKTOP;
247     if (dt) tools_switch(dt, num);
250 void tools_switch_by_item(SPDesktop *dt, SPItem *item)
252     if (SP_IS_RECT(item)) {
253         tools_switch(dt, TOOLS_SHAPES_RECT);
254     } else if (SP_IS_BOX3D(item)) {
255         tools_switch(dt, TOOLS_SHAPES_3DBOX);
256     } else if (SP_IS_GENERICELLIPSE(item)) {
257         tools_switch(dt, TOOLS_SHAPES_ARC);
258     } else if (SP_IS_STAR(item)) {
259         tools_switch(dt, TOOLS_SHAPES_STAR);
260     } else if (SP_IS_SPIRAL(item)) {
261         tools_switch(dt, TOOLS_SHAPES_SPIRAL);
262     } else if (SP_IS_PATH(item)) {
263         if (cc_item_is_connector(item)) {
264             tools_switch(dt, TOOLS_CONNECTOR);
265         }
266         else {
267             tools_switch(dt, TOOLS_NODES);
268         }
269     } else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item))  {
270         tools_switch(dt, TOOLS_TEXT);
271     } else if (SP_IS_OFFSET(item))  {
272         tools_switch(dt, TOOLS_NODES);
273     }
276 /*
277   Local Variables:
278   mode:c++
279   c-file-style:"stroustrup"
280   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
281   indent-tabs-mode:nil
282   fill-column:99
283   End:
284 */
285 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :