1 #define __GUIDELINE_CPP__
3 /*
4 * simple guideline dialog
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * Andrius R. <knutux@gmail.com>
9 *
10 * Copyright (C) 1999-2006 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
18 #include "display/guideline.h"
19 #include "helper/unit-menu.h"
20 #include "helper/units.h"
21 #include "desktop.h"
22 #include "document.h"
23 #include "sp-guide.h"
24 #include "sp-namedview.h"
25 #include "desktop-handles.h"
26 #include "event-context.h"
27 #include "widgets/desktop-widget.h"
28 #include "sp-metrics.h"
29 #include <glibmm/i18n.h>
30 #include "dialogs/dialog-events.h"
31 #include "message-context.h"
32 #include "xml/repr.h"
34 #include "guidelinedialog.h"
36 namespace Inkscape {
37 namespace UI {
38 namespace Dialogs {
40 GuidelinePropertiesDialog::GuidelinePropertiesDialog(SPGuide *guide, SPDesktop *desktop)
41 : _desktop(desktop), _guide(guide),
42 _relative_toggle(_("Rela_tive move"), _("Move guide relative to current position")),
43 _adjustment(0.0, -SP_DESKTOP_SCROLL_LIMIT, SP_DESKTOP_SCROLL_LIMIT, 1.0, 10.0, 10.0),
44 _unit_selector(NULL), _mode(true), _oldpos(0.0)
45 {
46 }
48 GuidelinePropertiesDialog::~GuidelinePropertiesDialog() {
49 }
51 void GuidelinePropertiesDialog::showDialog(SPGuide *guide, SPDesktop *desktop) {
52 GuidelinePropertiesDialog dialog(guide, desktop);
53 dialog._setup();
54 dialog.run();
55 }
57 void GuidelinePropertiesDialog::_modeChanged()
58 {
59 _mode = !_relative_toggle.get_active();
60 if (!_mode) {
61 _label_move.set_label(_("Move by:"));
62 } else {
63 _label_move.set_label(_("Move to:"));
64 }
65 }
67 void GuidelinePropertiesDialog::_onApply()
68 {
69 gdouble const raw_dist = _spin_button.get_value();
70 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(_unit_selector->gobj()));
71 gdouble const points = sp_units_get_pixels(raw_dist, unit);
72 gdouble const newpos = ( _mode
73 ? points
74 : _guide->position + points );
75 sp_guide_moveto(*_guide, newpos, true);
76 sp_document_done(SP_OBJECT_DOCUMENT(_guide));
77 }
79 void GuidelinePropertiesDialog::_onOK()
80 {
81 _onApply();
82 }
84 void GuidelinePropertiesDialog::_onDelete()
85 {
86 SPDocument *doc = SP_OBJECT_DOCUMENT(_guide);
87 sp_guide_remove(_guide);
88 sp_document_done(doc);
89 }
91 void GuidelinePropertiesDialog::_response(gint response)
92 {
93 switch (response) {
94 case Gtk::RESPONSE_OK:
95 _onOK();
96 break;
97 case -12:
98 _onDelete();
99 break;
100 case Gtk::RESPONSE_CLOSE:
101 break;
102 case Gtk::RESPONSE_DELETE_EVENT:
103 break;
104 /* case GTK_RESPONSE_APPLY:
105 _onApply();
106 break;
107 */
108 default:
109 g_assert_not_reached();
110 }
111 }
113 void GuidelinePropertiesDialog::_setup() {
114 set_title(_("Guideline"));
115 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
116 add_button(Gtk::Stock::DELETE, -12);
117 add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
119 Gtk::VBox *mainVBox = get_vbox();
121 _layout_table.set_spacings(4);
122 _layout_table.resize (3, 4);
124 mainVBox->pack_start(_layout_table, false, false, 0);
126 _label_descr.set_label("foo1");
127 _layout_table.attach(_label_descr,
128 0, 3, 0, 1, Gtk::FILL, Gtk::FILL);
129 _label_descr.set_alignment(0, 0.5);
131 _layout_table.attach(_label_move,
132 0, 2, 1, 2, Gtk::FILL, Gtk::FILL);
133 _label_move.set_alignment(0, 0.5);
134 _modeChanged();
136 // indent
137 _layout_table.attach(*manage(new Gtk::Label(" ")),
138 0, 1, 2, 3, Gtk::FILL, Gtk::FILL, 10);
140 // mode radio button
141 _layout_table.attach(_relative_toggle,
142 1, 3, 3, 4, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
143 _relative_toggle.signal_toggled().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_modeChanged));
145 // unitmenu
146 /* fixme: We should allow percents here too, as percents of the canvas size */
147 GtkWidget *unit_selector = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
148 sp_unit_selector_set_unit(SP_UNIT_SELECTOR(unit_selector), _desktop->namedview->doc_units);
149 _unit_selector = Gtk::manage(Glib::wrap(unit_selector));
151 // spinbutton
152 sp_unit_selector_add_adjustment(SP_UNIT_SELECTOR(unit_selector), GTK_ADJUSTMENT(_adjustment.gobj()));
153 _spin_button.configure(_adjustment, 1.0 , 2);
154 _spin_button.set_numeric(TRUE);
155 _layout_table.attach(_spin_button,
156 1, 2, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
157 gtk_signal_connect_object(GTK_OBJECT(_spin_button.gobj()), "activate",
158 GTK_SIGNAL_FUNC(gtk_window_activate_default),
159 gobj());
161 _layout_table.attach(*_unit_selector,
162 2, 3, 2, 3, Gtk::FILL, Gtk::FILL);
165 // dialog
166 set_default_response(Gtk::RESPONSE_OK);
167 signal_response().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_response));
169 // initialize dialog
170 _oldpos = _guide->position;
171 {
172 gchar *guide_description = sp_guide_description(_guide);
173 Inkscape::XML::Node *repr = SP_OBJECT_REPR (_guide);
174 const gchar *guide_id = repr->attribute("id");
175 gchar *label = g_strdup_printf(_("Moving %s %s"), guide_description, guide_id);
176 g_free(guide_description);
177 _label_descr.set_label(label);
178 g_free(label);
179 }
181 SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unit_selector));
182 gdouble const val = sp_pixels_get_units(_oldpos, unit);
183 _spin_button.set_value(val);
184 _spin_button.grab_focus();
185 _spin_button.select_region(0, 20);
186 set_position(Gtk::WIN_POS_MOUSE);
188 show_all_children();
189 set_modal(true);
190 _desktop->setWindowTransient (gobj());
191 property_destroy_with_parent() = true;
192 }
194 }
195 }
196 }
198 /*
199 Local Variables:
200 mode:c++
201 c-file-style:"stroustrup"
202 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
203 indent-tabs-mode:nil
204 fill-column:99
205 End:
206 */
207 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :