Code

Renaming sp-marker.* to marker.*
[inkscape.git] / src / dialogs / guidelinedialog.cpp
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), SP_VERB_NONE, 
77                      _("Set guide properties"));
78 }
80 void GuidelinePropertiesDialog::_onOK()
81 {
82     _onApply();
83 }
85 void GuidelinePropertiesDialog::_onDelete()
86 {
87     SPDocument *doc = SP_OBJECT_DOCUMENT(_guide);
88     sp_guide_remove(_guide);
89     sp_document_done(doc, SP_VERB_NONE, 
90                      _("Delete guide"));
91 }
93 void GuidelinePropertiesDialog::_response(gint response)
94 {
95     switch (response) {
96         case Gtk::RESPONSE_OK:
97             _onOK();
98             break;
99         case -12:
100             _onDelete();
101             break;
102         case Gtk::RESPONSE_CLOSE:
103             break;
104         case Gtk::RESPONSE_DELETE_EVENT:
105             break;
106 /*      case GTK_RESPONSE_APPLY:
107         _onApply();
108         break;
109 */
110         default:
111             g_assert_not_reached();
112     }
115 void GuidelinePropertiesDialog::_setup() {
116     set_title(_("Guideline"));
117     add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
118     add_button(Gtk::Stock::DELETE, -12);
119     add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
121     Gtk::VBox *mainVBox = get_vbox();
123     _layout_table.set_spacings(4);
124     _layout_table.resize (3, 4);
126     mainVBox->pack_start(_layout_table, false, false, 0);
128     _label_descr.set_label("foo1");
129     _layout_table.attach(_label_descr,
130                          0, 3, 0, 1, Gtk::FILL, Gtk::FILL);
131     _label_descr.set_alignment(0, 0.5);
133     _layout_table.attach(_label_move,
134                          0, 2, 1, 2, Gtk::FILL, Gtk::FILL);
135     _label_move.set_alignment(0, 0.5);
136     _modeChanged();
138     // indent
139     _layout_table.attach(*manage(new Gtk::Label(" ")),
140                          0, 1, 2, 3, Gtk::FILL, Gtk::FILL, 10);
142     // mode radio button
143     _layout_table.attach(_relative_toggle,
144                          1, 3, 3, 4, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
145     _relative_toggle.signal_toggled().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_modeChanged));
147     // unitmenu
148     /* fixme: We should allow percents here too, as percents of the canvas size */
149     GtkWidget *unit_selector = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE);
150     sp_unit_selector_set_unit(SP_UNIT_SELECTOR(unit_selector), _desktop->namedview->doc_units);
151     _unit_selector = Gtk::manage(Glib::wrap(unit_selector));
153     // spinbutton
154     sp_unit_selector_add_adjustment(SP_UNIT_SELECTOR(unit_selector), GTK_ADJUSTMENT(_adjustment.gobj()));
155     _spin_button.configure(_adjustment, 1.0 , 2);
156     _spin_button.set_numeric(TRUE);
157     _layout_table.attach(_spin_button,
158                          1, 2, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::FILL);
159     gtk_signal_connect_object(GTK_OBJECT(_spin_button.gobj()), "activate",
160                               GTK_SIGNAL_FUNC(gtk_window_activate_default),
161                               gobj());
163     _layout_table.attach(*_unit_selector,
164                          2, 3, 2, 3, Gtk::FILL, Gtk::FILL);
167     // dialog
168     set_default_response(Gtk::RESPONSE_OK);
169     signal_response().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_response));
171     // initialize dialog
172     _oldpos = _guide->position;
173     {
174         gchar *guide_description = sp_guide_description(_guide);
175         Inkscape::XML::Node *repr = SP_OBJECT_REPR (_guide);
176         const gchar *guide_id = repr->attribute("id");
177         gchar *label = g_strdup_printf(_("Moving %s %s"), guide_description, guide_id);
178         g_free(guide_description);
179         _label_descr.set_label(label);
180         g_free(label);
181     }
183     SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unit_selector));
184     gdouble const val = sp_pixels_get_units(_oldpos, unit);
185     _spin_button.set_value(val);
186     _spin_button.grab_focus();
187     _spin_button.select_region(0, 20);
188     set_position(Gtk::WIN_POS_MOUSE);
190     show_all_children();
191     set_modal(true);
192     _desktop->setWindowTransient (gobj());
193     property_destroy_with_parent() = true;
200 /*
201   Local Variables:
202   mode:c++
203   c-file-style:"stroustrup"
204   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
205   indent-tabs-mode:nil
206   fill-column:99
207   End:
208 */
209 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :