minor fix
[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: canvasoptions.cpp,v 1.1.1.1 2005/01/07 03:34:35 darco Exp $
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 "canvasview.h"
38 #include "workarea.h"
39
40 #endif
41
42 /* === U S I N G =========================================================== */
43
44 using namespace std;
45 using namespace etl;
46 using namespace synfig;
47 using namespace studio;
48
49 /* === M A C R O S ========================================================= */
50
51 /* === G L O B A L S ======================================================= */
52
53 /* === P R O C E D U R E S ================================================= */
54
55 /* === M E T H O D S ======================================================= */
56
57 CanvasOptions::CanvasOptions(loose_handle<studio::CanvasView> canvas_view):
58         Gtk::Dialog(_("Canvas Options"),*canvas_view,false,true),
59         canvas_view_(canvas_view),
60         toggle_grid_snap(_("Grid Snap")),
61         toggle_grid_show(_("Grid Show")),
62         toggle_time_snap(_("Snap-To-Frame"))
63 {
64         vector_grid_size.set_canvas(canvas_view->get_canvas());
65         
66         Gtk::Notebook *notebook=manage(new class Gtk::Notebook());
67
68         toggle_grid_snap.signal_toggled().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_grid_snap_toggle));
69         toggle_grid_show.signal_toggled().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_grid_show_toggle));
70
71         Gtk::Table *grid_page=manage(new class Gtk::Table(2,2,false));
72         notebook->append_page(*grid_page,_("Grids"));
73         grid_page->attach(vector_grid_size, 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);    
74         grid_page->attach(toggle_grid_snap, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);    
75         grid_page->attach(toggle_grid_show, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);    
76         
77         Gtk::Table *time_page=manage(new class Gtk::Table(2,2,false));
78         notebook->append_page(*time_page,_("Time"));
79         time_page->attach(toggle_time_snap, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);    
80         
81         Gtk::Table *unit_page=manage(new class Gtk::Table(2,2,false));
82         notebook->append_page(*unit_page,_("Units"));
83         unit_page->attach(*manage(new Gtk::Label(_("Not yet implemented"))), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);   
84         
85         
86         Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
87         ok_button->show();
88         add_action_widget(*ok_button,2);
89         ok_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_ok_pressed));
90
91         Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
92         apply_button->show();
93         add_action_widget(*apply_button,1);
94         apply_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_apply_pressed));
95
96         Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
97         cancel_button->show();
98         add_action_widget(*cancel_button,0);
99         cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasOptions::on_cancel_pressed));
100
101         //set_default_response(1);
102         
103         
104         get_vbox()->pack_start(*notebook);
105         notebook->show_all();
106         
107         signal_show().connect(sigc::mem_fun(*this, &studio::CanvasOptions::refresh));
108
109         vector_grid_size.set_digits(5);
110         
111         update_title();
112 }
113
114 CanvasOptions::~CanvasOptions()
115 {
116 }
117
118 void
119 CanvasOptions::update_title()
120 {
121         set_title(_("Options")+String(" - ")+canvas_view_->get_canvas()->get_name());
122 }
123
124 void
125 CanvasOptions::refresh()
126 {
127         if(canvas_view_->work_area->grid_status())
128                 toggle_grid_show.set_active(true);
129         else
130                 toggle_grid_show.set_active(false);
131                 
132         if(canvas_view_->work_area->get_grid_snap())
133                 toggle_grid_snap.set_active(true);
134         else
135                 toggle_grid_snap.set_active(false);
136         
137         vector_grid_size.set_value(canvas_view_->work_area->get_grid_size());
138         
139         tooltips.set_tip(toggle_time_snap,_("Not yet implemented"));
140         toggle_time_snap.set_sensitive(false);
141
142         update_title();
143 }
144
145 void
146 CanvasOptions::on_grid_snap_toggle()
147 {
148 }
149
150 void
151 CanvasOptions::on_grid_show_toggle()
152 {
153 }
154
155 void
156 CanvasOptions::on_apply_pressed()
157 {
158         if(toggle_grid_snap.get_active())
159                 canvas_view_->work_area->enable_grid_snap();
160         else
161                 canvas_view_->work_area->disable_grid_snap();
162                 
163         if(toggle_grid_show.get_active())
164                 canvas_view_->work_area->enable_grid();
165         else
166                 canvas_view_->work_area->disable_grid();
167
168         canvas_view_->work_area->set_grid_size(vector_grid_size.get_value());
169 }
170
171 void
172 CanvasOptions::on_ok_pressed()
173 {
174         on_apply_pressed();
175         hide();
176 }
177
178 void
179 CanvasOptions::on_cancel_pressed()
180 {
181         refresh();
182         hide();
183 }