Fix a crash when running single-threaded and dragging the time slider.
[synfig.git] / synfig-studio / trunk / src / gtkmm / canvasoptions.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file canvasoptions.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "canvasoptions.h"
33 #include <gtkmm/frame.h>
34 #include <gtkmm/table.h>
35 #include <gtkmm/label.h>
36 #include <gtkmm/notebook.h>
37 #include <gtkmm/alignment.h>
38 #include "canvasview.h"
39 #include "workarea.h"
40
41 #endif
42
43 /* === U S I N G =========================================================== */
44
45 using namespace std;
46 using namespace etl;
47 using namespace synfig;
48 using namespace studio;
49
50 /* === M A C R O S ========================================================= */
51
52 /* === G L O B A L S ======================================================= */
53
54 /* === P R O C E D U R E S ================================================= */
55
56 /* === M E T H O D S ======================================================= */
57
58 CanvasOptions::CanvasOptions(loose_handle<studio::CanvasView> canvas_view):
59         Gtk::Dialog(_("Canvas Options"),*canvas_view,false,true),
60         canvas_view_(canvas_view),
61         toggle_grid_snap(_("_Snap to grid"), true),
62         toggle_grid_show(_("S_how grid"), true),
63         toggle_time_snap(_("Snap to _frame"), true)
64 {
65         vector_grid_size.set_canvas(canvas_view->get_canvas());
66
67         Gtk::Alignment *dialogPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
68         dialogPadding->set_padding(12, 12, 12, 12);
69
70         Gtk::Notebook *notebook=manage(new class Gtk::Notebook());
71         dialogPadding->add(*notebook);
72
73         toggle_grid_snap.signal_toggled().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_grid_snap_toggle));
74         toggle_grid_show.signal_toggled().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_grid_show_toggle));
75
76         Gtk::Alignment *gridPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
77         gridPadding->set_padding(12, 12, 12, 12);
78         notebook->append_page(*gridPadding, _("Grid"));
79
80         Gtk::VBox *gridBox = manage(new Gtk::VBox(false, 12));
81         gridPadding->add(*gridBox);
82
83         Gtk::Table *gridTable = manage(new Gtk::Table(3, 2, false));
84         gridTable->set_row_spacings(6);
85         gridTable->set_col_spacings(12);
86         gridBox->pack_start(*gridTable, false, false, 0);
87
88         Gtk::Label *gridSizeLabel = manage(new Gtk::Label(_("_Grid size"), true));
89         gridSizeLabel->set_alignment(0, 0.5);
90         gridSizeLabel->set_mnemonic_widget(vector_grid_size);
91
92         toggle_grid_show.set_alignment(0, 0.5);
93         toggle_grid_snap.set_alignment(0, 0.5);
94
95         gridTable->attach(*gridSizeLabel, 0, 1, 0, 1, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
96         gridTable->attach(vector_grid_size, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
97         gridTable->attach(toggle_grid_show, 0, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
98         gridTable->attach(toggle_grid_snap, 0, 2, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
99
100         Gtk::Alignment *timePadding = manage(new Gtk::Alignment(0, 0, 1, 1));
101         timePadding->set_padding(12, 12, 12, 12);
102         notebook->append_page(*timePadding, _("Time"));
103
104         Gtk::VBox *timeBox = manage(new Gtk::VBox(false, 12));
105         timePadding->add(*timeBox);
106
107         timeBox->pack_start(toggle_time_snap, false, false, 0);
108
109         Gtk::Alignment *unitPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
110         unitPadding->set_padding(12, 12, 12, 12);
111         notebook->append_page(*unitPadding, _("Units"));
112         unitPadding->add(*manage(new Gtk::Label(_("Not yet implemented!"))));
113
114         Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
115         ok_button->show();
116         add_action_widget(*ok_button,2);
117         ok_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_ok_pressed));
118
119         Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
120         apply_button->show();
121         add_action_widget(*apply_button,1);
122         apply_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_apply_pressed));
123
124         Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
125         cancel_button->show();
126         add_action_widget(*cancel_button,0);
127         cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_cancel_pressed));
128
129         //set_default_response(1);
130
131
132         get_vbox()->pack_start(*dialogPadding);
133         get_vbox()->show_all();
134
135         signal_show().connect(sigc::mem_fun(*this, &studio::CanvasOptions::refresh));
136
137         vector_grid_size.set_digits(5);
138
139         update_title();
140 }
141
142 CanvasOptions::~CanvasOptions()
143 {
144 }
145
146 void
147 CanvasOptions::update_title()
148 {
149         set_title(_("Options")+String(" - ")+canvas_view_->get_canvas()->get_name());
150 }
151
152 void
153 CanvasOptions::refresh()
154 {
155         if(canvas_view_->work_area->grid_status())
156                 toggle_grid_show.set_active(true);
157         else
158                 toggle_grid_show.set_active(false);
159
160         if(canvas_view_->work_area->get_grid_snap())
161                 toggle_grid_snap.set_active(true);
162         else
163                 toggle_grid_snap.set_active(false);
164
165         vector_grid_size.set_value(canvas_view_->work_area->get_grid_size());
166
167         tooltips.set_tip(toggle_time_snap,_("Not yet implemented"));
168         toggle_time_snap.set_sensitive(false);
169
170         update_title();
171 }
172
173 void
174 CanvasOptions::on_grid_snap_toggle()
175 {
176 }
177
178 void
179 CanvasOptions::on_grid_show_toggle()
180 {
181 }
182
183 void
184 CanvasOptions::on_apply_pressed()
185 {
186         if(toggle_grid_snap.get_active())
187                 canvas_view_->work_area->enable_grid_snap();
188         else
189                 canvas_view_->work_area->disable_grid_snap();
190
191         if(toggle_grid_show.get_active())
192                 canvas_view_->work_area->enable_grid();
193         else
194                 canvas_view_->work_area->disable_grid();
195
196         canvas_view_->work_area->set_grid_size(vector_grid_size.get_value());
197 }
198
199 void
200 CanvasOptions::on_ok_pressed()
201 {
202         on_apply_pressed();
203         hide();
204 }
205
206 void
207 CanvasOptions::on_cancel_pressed()
208 {
209         refresh();
210         hide();
211 }