Code

first set of updates to headers for clean gcc 4.3 builds
[inkscape.git] / src / selcue.cpp
1 #define __SELCUE_C__
3 /*
4  * Helper object for showing selected items
5  *
6  * Authors:
7  *   bulia byak <bulia@users.sf.net>
8  *   Carl Hetherington <inkscape@carlh.net>
9  *
10  * Copyright (C) 2004 Authors
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include <string.h>
17 #include "desktop-handles.h"
18 #include "selection.h"
19 #include "display/sp-canvas-util.h"
20 #include "display/sodipodi-ctrl.h"
21 #include "display/sodipodi-ctrlrect.h"
22 #include "libnrtype/Layout-TNG.h"
23 #include "text-editing.h"
24 #include "sp-text.h"
25 #include "sp-flowtext.h"
26 #include "prefs-utils.h"
27 #include "selcue.h"
29 Inkscape::SelCue::SelCue(SPDesktop *desktop)
30     : _desktop(desktop)
31 {
32     _selection = sp_desktop_selection(_desktop);
34     _sel_changed_connection = _selection->connectChanged(
35         sigc::hide(sigc::mem_fun(*this, &Inkscape::SelCue::_updateItemBboxes))
36         );
38     _sel_modified_connection = _selection->connectModified(
39         sigc::hide(sigc::hide(sigc::mem_fun(*this, &Inkscape::SelCue::_updateItemBboxes)))
40         );
42     _updateItemBboxes();
43 }
45 Inkscape::SelCue::~SelCue()
46 {
47     _sel_changed_connection.disconnect();
48     _sel_modified_connection.disconnect();
50     for (std::list<SPCanvasItem*>::iterator i = _item_bboxes.begin(); i != _item_bboxes.end(); i++) {
51         gtk_object_destroy(*i);
52     }
53     _item_bboxes.clear();
55     for (std::list<SPCanvasItem*>::iterator i = _text_baselines.begin(); i != _text_baselines.end(); i++) {
56         gtk_object_destroy(*i);
57     }
58     _text_baselines.clear();
59 }
61 void Inkscape::SelCue::_updateItemBboxes()
62 {
63     for (std::list<SPCanvasItem*>::iterator i = _item_bboxes.begin(); i != _item_bboxes.end(); i++) {
64         gtk_object_destroy(*i);
65     }
66     _item_bboxes.clear();
68     for (std::list<SPCanvasItem*>::iterator i = _text_baselines.begin(); i != _text_baselines.end(); i++) {
69         gtk_object_destroy(*i);
70     }
71     _text_baselines.clear();
73     gint mode = prefs_get_int_attribute ("options.selcue", "value", MARK);
74     if (mode == NONE) {
75         return;
76     }
78     g_return_if_fail(_selection != NULL);
80         gchar const *prefs_bbox = prefs_get_string_attribute("tools", "bounding_box");
81     SPItem::BBoxType bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;
82     
83     for (GSList const *l = _selection->itemList(); l != NULL; l = l->next) {
84         SPItem *item = (SPItem *) l->data;
86         NR::Maybe<NR::Rect> const b = sp_item_bbox_desktop(item, bbox_type);
88         SPCanvasItem* box = NULL;
90         if (b) {
91             if (mode == MARK) {
92                 box = sp_canvas_item_new(sp_desktop_controls(_desktop),
93                                          SP_TYPE_CTRL,
94                                          "mode", SP_CTRL_MODE_XOR,
95                                          "shape", SP_CTRL_SHAPE_DIAMOND,
96                                          "size", 5.0,
97                                          "filled", TRUE,
98                                          "fill_color", 0x000000ff,
99                                          "stroked", FALSE,
100                                          "stroke_color", 0x000000ff,
101                                          NULL);
102                 sp_canvas_item_show(box);
103                 SP_CTRL(box)->moveto(NR::Point(b->min()[NR::X], b->max()[NR::Y]));
105                 sp_canvas_item_move_to_z(box, 0); // just low enough to not get in the way of other draggable knots
107             } else if (mode == BBOX) {
108                 box = sp_canvas_item_new(sp_desktop_controls(_desktop),
109                                          SP_TYPE_CTRLRECT,
110                                          NULL);
112                 SP_CTRLRECT(box)->setRectangle(*b);
113                 SP_CTRLRECT(box)->setColor(0x000000a0, 0, 0);
114                 SP_CTRLRECT(box)->setDashed(true);
116                 sp_canvas_item_move_to_z(box, 0);
117             }
118         }
120         if (box) {
121             _item_bboxes.push_back(box);
122         }
124         SPCanvasItem* baseline_point = NULL;
125         if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { // visualize baseline
126             Inkscape::Text::Layout const *layout = te_get_layout(item);
127             if (layout != NULL) {
128                 NR::Point a = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(item);
129                 baseline_point = sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRL,
130                                                     "mode", SP_CTRL_MODE_XOR,
131                                                     "size", 4.0,
132                                                     "filled", 0,
133                                                     "stroked", 1,
134                                                     "stroke_color", 0x000000ff,
135                                                     NULL);
137                 sp_canvas_item_show(baseline_point);
138                 SP_CTRL(baseline_point)->moveto(a);
139                 sp_canvas_item_move_to_z(baseline_point, 0);
140             }
141         }
143         if (baseline_point) {
144                _text_baselines.push_back(baseline_point);
145         }
146     }
149 /*
150   Local Variables:
151   mode:c++
152   c-file-style:"stroustrup"
153   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
154   indent-tabs-mode:nil
155   fill-column:99
156   End:
157 */
158 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :