~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/tools-switch.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
12
 
 
13
 
 
14
#ifdef HAVE_CONFIG_H
 
15
# include "config.h"
 
16
#endif
 
17
 
 
18
#include <cstring>
 
19
#include <string>
 
20
 
 
21
#include "inkscape-private.h"
 
22
#include "desktop.h"
 
23
#include "desktop-handles.h"
 
24
#include <glibmm/i18n.h>
 
25
 
 
26
#include <xml/repr.h>
 
27
 
 
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 "eraser-context.h"
 
44
#include "pen-context.h"
 
45
#include "pencil-context.h"
 
46
#include "lpe-tool-context.h"
 
47
#include "text-context.h"
 
48
#include "sp-text.h"
 
49
#include "sp-flowtext.h"
 
50
#include "gradient-context.h"
 
51
#include "zoom-context.h"
 
52
#include "dropper-context.h"
 
53
#include "connector-context.h"
 
54
#include "flood-context.h"
 
55
#include "sp-offset.h"
 
56
#include "message-context.h"
 
57
 
 
58
#include "tools-switch.h"
 
59
 
 
60
static char const *const tool_names[] = {
 
61
    NULL,
 
62
    "/tools/select",
 
63
    "/tools/nodes",
 
64
    "/tools/tweak",
 
65
    "/tools/shapes/rect",
 
66
    "/tools/shapes/3dbox",
 
67
    "/tools/shapes/arc",
 
68
    "/tools/shapes/star",
 
69
    "/tools/shapes/spiral",
 
70
    "/tools/freehand/pencil",
 
71
    "/tools/freehand/pen",
 
72
    "/tools/calligraphic",
 
73
    "/tools/text",
 
74
    "/tools/gradient",
 
75
    "/tools/zoom",
 
76
    "/tools/dropper",
 
77
    "/tools/connector",
 
78
    "/tools/paintbucket",
 
79
    "/tools/eraser",
 
80
    "/tools/lpetool",
 
81
    NULL
 
82
};
 
83
 
 
84
static int
 
85
tools_prefpath2num(char const *id)
 
86
{
 
87
    int i = 1;
 
88
    while (tool_names[i]) {
 
89
        if (strcmp(tool_names[i], id) == 0)
 
90
            return i;
 
91
        else i++;
 
92
    }
 
93
    g_assert( 0 == TOOLS_INVALID );
 
94
    return 0; //nothing found
 
95
}
 
96
 
 
97
int
 
98
tools_isactive(SPDesktop *dt, unsigned num)
 
99
{
 
100
    g_assert( num < G_N_ELEMENTS(tool_names) );
 
101
    if (SP_IS_EVENT_CONTEXT(dt->event_context))
 
102
        return dt->event_context->pref_observer->observed_path == tool_names[num];
 
103
    else return FALSE;
 
104
}
 
105
 
 
106
int
 
107
tools_active(SPDesktop *dt)
 
108
{
 
109
    return tools_prefpath2num(dt->event_context->pref_observer->observed_path.data());
 
110
}
 
111
 
 
112
void
 
113
tools_switch(SPDesktop *dt, int num)
 
114
{
 
115
    if (dt) {
 
116
        dt->_tool_changed.emit(num);
 
117
    }
 
118
 
 
119
    switch (num) {
 
120
        case TOOLS_SELECT:
 
121
            dt->set_event_context(SP_TYPE_SELECT_CONTEXT, tool_names[num]);
 
122
            /* fixme: This is really ugly hack. We should bind and unbind class methods */
 
123
            dt->activate_guides(true);
 
124
            inkscape_eventcontext_set(sp_desktop_event_context(dt));
 
125
            break;
 
126
        case TOOLS_NODES:
 
127
            dt->set_event_context(SP_TYPE_NODE_CONTEXT, tool_names[num]);
 
128
            dt->activate_guides(true);
 
129
            inkscape_eventcontext_set(sp_desktop_event_context(dt));
 
130
            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."));
 
131
            break;
 
132
        case TOOLS_TWEAK:
 
133
            dt->set_event_context(SP_TYPE_TWEAK_CONTEXT, tool_names[num]);
 
134
            dt->activate_guides(true);
 
135
            inkscape_eventcontext_set(sp_desktop_event_context(dt));
 
136
            dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("To tweak a path by pushing, select it and drag over it."));
 
137
            break;
 
138
        case TOOLS_SHAPES_RECT:
 
139
            dt->set_event_context(SP_TYPE_RECT_CONTEXT, tool_names[num]);
 
140
            dt->activate_guides(false);
 
141
            inkscape_eventcontext_set(sp_desktop_event_context(dt));
 
142
            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."));
 
143
            break;
 
144
        case TOOLS_SHAPES_3DBOX:
 
145
            dt->set_event_context(SP_TYPE_BOX3D_CONTEXT, tool_names[num]);
 
146
            dt->activate_guides(false);
 
147
            inkscape_eventcontext_set(sp_desktop_event_context(dt));
 
148
            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)."));
 
149
            break;
 
150
        case TOOLS_SHAPES_ARC:
 
151
            dt->set_event_context(SP_TYPE_ARC_CONTEXT, tool_names[num]);
 
152
            dt->activate_guides(false);
 
153
            inkscape_eventcontext_set(sp_desktop_event_context(dt));
 
154
            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."));
 
155
            break;
 
156
        case TOOLS_SHAPES_STAR:
 
157
            dt->set_event_context(SP_TYPE_STAR_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 star. <b>Drag controls</b> to edit the star shape. <b>Click</b> to select."));
 
161
            break;
 
162
        case TOOLS_SHAPES_SPIRAL:
 
163
            dt->set_event_context(SP_TYPE_SPIRAL_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 spiral. <b>Drag controls</b> to edit the spiral shape. <b>Click</b> to select."));
 
167
            break;
 
168
        case TOOLS_FREEHAND_PENCIL:
 
169
            dt->set_event_context(SP_TYPE_PENCIL_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 a freehand line. <b>Shift</b> appends to selected path, <b>Alt</b> activates sketch mode."));
 
173
            break;
 
174
        case TOOLS_FREEHAND_PEN:
 
175
            dt->set_event_context(SP_TYPE_PEN_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>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 (straight line modes only)."));
 
179
            break;
 
180
        case TOOLS_CALLIGRAPHIC:
 
181
            dt->set_event_context(SP_TYPE_DYNA_DRAW_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 draw a calligraphic stroke; with <b>Ctrl</b> to track a guide path. <b>Arrow keys</b> adjust width (left/right) and angle (up/down)."));
 
185
            break;
 
186
        case TOOLS_TEXT:
 
187
            dt->set_event_context(SP_TYPE_TEXT_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>Click</b> to select or create text, <b>drag</b> to create flowed text; then type."));
 
191
            break;
 
192
        case TOOLS_GRADIENT:
 
193
            dt->set_event_context(SP_TYPE_GRADIENT_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>Drag</b> or <b>double click</b> to create a gradient on selected objects, <b>drag handles</b> to adjust gradients."));
 
197
            break;
 
198
        case TOOLS_ZOOM:
 
199
            dt->set_event_context(SP_TYPE_ZOOM_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>Click</b> or <b>drag around an area</b> to zoom in, <b>Shift+click</b> to zoom out."));
 
203
            break;
 
204
        case TOOLS_DROPPER:
 
205
            dt->set_event_context(SP_TYPE_DROPPER_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 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"));
 
209
            break;
 
210
        case TOOLS_CONNECTOR:
 
211
            dt->set_event_context(SP_TYPE_CONNECTOR_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>Click and drag</b> between shapes to create a connector."));
 
215
            break;
 
216
        case TOOLS_PAINTBUCKET:
 
217
            dt->set_event_context(SP_TYPE_FLOOD_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> 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."));
 
221
            break;
 
222
        case TOOLS_ERASER:
 
223
            dt->set_event_context(SP_TYPE_ERASER_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>Drag</b> to erase."));
 
227
            break;
 
228
        case TOOLS_LPETOOL:
 
229
            dt->set_event_context(SP_TYPE_LPETOOL_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, _("Choose a subtool from the toolbar"));
 
233
            break;
 
234
    }
 
235
}
 
236
 
 
237
void tools_switch_by_item(SPDesktop *dt, SPItem *item, Geom::Point const p)
 
238
{
 
239
    if (SP_IS_RECT(item)) {
 
240
        tools_switch(dt, TOOLS_SHAPES_RECT);
 
241
    } else if (SP_IS_BOX3D(item)) {
 
242
        tools_switch(dt, TOOLS_SHAPES_3DBOX);
 
243
    } else if (SP_IS_GENERICELLIPSE(item)) {
 
244
        tools_switch(dt, TOOLS_SHAPES_ARC);
 
245
    } else if (SP_IS_STAR(item)) {
 
246
        tools_switch(dt, TOOLS_SHAPES_STAR);
 
247
    } else if (SP_IS_SPIRAL(item)) {
 
248
        tools_switch(dt, TOOLS_SHAPES_SPIRAL);
 
249
    } else if (SP_IS_PATH(item)) {
 
250
        if (cc_item_is_connector(item)) {
 
251
            tools_switch(dt, TOOLS_CONNECTOR);
 
252
        }
 
253
        else {
 
254
            tools_switch(dt, TOOLS_NODES);
 
255
        }
 
256
    } else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item))  {
 
257
        tools_switch(dt, TOOLS_TEXT);
 
258
        sp_text_context_place_cursor_at (SP_TEXT_CONTEXT(dt->event_context), SP_OBJECT(item), p);
 
259
    } else if (SP_IS_OFFSET(item))  {
 
260
        tools_switch(dt, TOOLS_NODES);
 
261
    }
 
262
}
 
263
 
 
264
/*
 
265
  Local Variables:
 
266
  mode:c++
 
267
  c-file-style:"stroustrup"
 
268
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
269
  indent-tabs-mode:nil
 
270
  fill-column:99
 
271
  End:
 
272
*/
 
273
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :