Fix some FTBFS issues when compiling with GCC 4.3
[synfig.git] / synfig-studio / trunk / src / gtkmm / canvasproperties.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file canvasproperties.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 "canvasproperties.h"
33 #include <gtkmm/frame.h>
34 #include <gtkmm/table.h>
35 #include <gtkmm/label.h>
36 #include <gtkmm/alignment.h>
37 #include <synfigapp/canvasinterface.h>
38 #include "metadatatreestore.h"
39 #include <gtkmm/treeview.h>
40 #include <gtkmm/scrolledwindow.h>
41 #include "app.h"
42
43 #include "general.h"
44
45 #endif
46
47 /* === U S I N G =========================================================== */
48
49 using namespace std;
50 using namespace etl;
51 using namespace synfig;
52 using namespace studio;
53
54 /* === M A C R O S ========================================================= */
55
56 /* === G L O B A L S ======================================================= */
57
58 /* === P R O C E D U R E S ================================================= */
59
60 /* === M E T H O D S ======================================================= */
61
62 CanvasProperties::CanvasProperties(Gtk::Window& parent,etl::handle<synfigapp::CanvasInterface> canvas_interface):
63         Gtk::Dialog(_("Canvas Properties"),parent,false,true),
64         canvas_interface_(canvas_interface)
65 {
66         widget_rend_desc.show();
67         widget_rend_desc.signal_changed().connect(sigc::mem_fun(*this,&studio::CanvasProperties::on_rend_desc_changed));
68
69         Gtk::Alignment *dialogPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
70         dialogPadding->set_padding(12, 12, 12, 12);
71         get_vbox()->pack_start(*dialogPadding, false, false, 0);
72
73         Gtk::VBox *dialogBox = manage(new Gtk::VBox(false, 12));
74         dialogPadding->add(*dialogBox);
75
76         Gtk::Frame *info_frame=manage(new Gtk::Frame(_("Canvas Info")));
77         info_frame->set_shadow_type(Gtk::SHADOW_NONE);
78         ((Gtk::Label *) info_frame->get_label_widget())->set_markup(_("<b>Canvas Info</b>"));
79         dialogBox->pack_start(*info_frame, false, false, 0);
80
81         Gtk::Alignment *infoPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
82         infoPadding->set_padding(6, 0, 24, 0);
83         info_frame->add(*infoPadding);
84
85         Gtk::Table *info_table=manage(new Gtk::Table(2,2,false));
86         info_table->set_row_spacings(6);
87         info_table->set_col_spacings(12);
88         infoPadding->add(*info_table);
89
90         // The root canvas doesn't have an ID, so don't
91         // display it if this is a root canvas.
92         if(!canvas_interface_->get_canvas()->is_root())
93         {
94                 Gtk::Label *idLabel = manage(new Gtk::Label(_("_ID"), true));
95                 idLabel->set_alignment(0, 0.5);
96                 idLabel->set_mnemonic_widget(entry_id);
97                 info_table->attach(*idLabel, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
98                 info_table->attach(entry_id, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
99         }
100         Gtk::Label *nameLabel = manage(new Gtk::Label(_("_Name"), true));
101         nameLabel->set_alignment(0, 0.5);
102         nameLabel->set_mnemonic_widget(entry_name);
103         Gtk::Label *descriptionLabel = manage(new Gtk::Label(_("_Description"), true));
104         descriptionLabel->set_alignment(0, 0.5);
105         descriptionLabel->set_mnemonic_widget(entry_description);
106         info_table->attach(*nameLabel, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
107         info_table->attach(*descriptionLabel, 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
108         info_table->attach(entry_name, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
109         info_table->attach(entry_description, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
110
111         dialogBox->pack_start(widget_rend_desc, false, false, 0);
112
113         canvas_interface_->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&studio::CanvasProperties::refresh));
114
115         Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
116         ok_button->show();
117         add_action_widget(*ok_button,2);
118         ok_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_ok_pressed));
119
120         Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
121         apply_button->show();
122         add_action_widget(*apply_button,1);
123         apply_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_apply_pressed));
124
125         Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
126         cancel_button->show();
127         add_action_widget(*cancel_button,0);
128         cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_cancel_pressed));
129
130         //set_default_response(1);
131
132         get_vbox()->show_all();
133         refresh();
134
135         update_title();
136 }
137
138 Gtk::Widget&
139 CanvasProperties::create_meta_data_view()
140 {
141         MetaDataTreeStore::Model model;
142         meta_data_tree_view=(manage(new class Gtk::TreeView()));
143
144         meta_data_tree_view->append_column(_("Key"),model.key);
145         meta_data_tree_view->append_column_editable(_("Data"),model.data);
146         meta_data_tree_view->set_model(MetaDataTreeStore::create(canvas_interface_));
147         meta_data_tree_view->set_rules_hint();
148         meta_data_tree_view->show();
149
150         Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
151         scrolledwindow->set_flags(Gtk::CAN_FOCUS);
152         scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
153         scrolledwindow->add(*meta_data_tree_view);
154         scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
155         scrolledwindow->show();
156
157
158
159         Gtk::Table *table=manage(new Gtk::Table());
160         table->attach(*scrolledwindow, 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
161
162         Gtk::Button* button_add(manage(new Gtk::Button(Gtk::StockID("gtk-add"))));
163         button_add->show();
164         button_add->signal_clicked().connect(sigc::mem_fun(*this,&CanvasProperties::on_button_meta_data_add));
165         table->attach(*button_add, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
166
167         Gtk::Button* button_delete(manage(new Gtk::Button(Gtk::StockID("gtk-delete"))));
168         button_delete->show();
169         button_delete->signal_clicked().connect(sigc::mem_fun(*this,&CanvasProperties::on_button_meta_data_delete));
170         table->attach(*button_delete, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
171
172         table->show();
173         return *table;
174 }
175
176 void
177 CanvasProperties::on_button_meta_data_add()
178 {
179         synfig::String key;
180         if(App::dialog_entry(_("New MetaData Entry"), _("Please enter the name of the key"),key) && !key.empty())
181         {
182                 canvas_interface_->set_meta_data(key," ");
183         }
184
185 }
186
187 void
188 CanvasProperties::on_button_meta_data_delete()
189 {
190 }
191
192 void
193 CanvasProperties::update_title()
194 {
195         set_title(_("Properties")+String(" - ")+canvas_interface_->get_canvas()->get_name());
196 }
197
198 void
199 CanvasProperties::refresh()
200 {
201         widget_rend_desc.set_rend_desc(canvas_interface_->get_canvas()->rend_desc());
202         entry_id.set_text(canvas_interface_->get_canvas()->get_id());
203         entry_name.set_text(canvas_interface_->get_canvas()->get_name());
204         entry_description.set_text(canvas_interface_->get_canvas()->get_description());
205
206         dirty_rend_desc=false;
207
208         update_title();
209 }
210
211 CanvasProperties::~CanvasProperties()
212 {
213 }
214
215 void
216 CanvasProperties::on_rend_desc_changed()
217 {
218         dirty_rend_desc=true;
219 }
220
221 void
222 CanvasProperties::on_apply_pressed()
223 {
224         if(entry_id.get_text()!=canvas_interface_->get_canvas()->get_id())
225                 canvas_interface_->set_id(entry_id.get_text());
226         if(entry_name.get_text()!=canvas_interface_->get_canvas()->get_name())
227                 canvas_interface_->set_name(entry_name.get_text());
228         if(entry_description.get_text()!=canvas_interface_->get_canvas()->get_description())
229                 canvas_interface_->set_description(entry_description.get_text());
230         if(dirty_rend_desc)                     // do this last, because it causes the dialog to be refreshed with currently set values
231                 canvas_interface_->set_rend_desc(widget_rend_desc.get_rend_desc());
232
233         dirty_rend_desc=false;
234 }
235
236 void
237 CanvasProperties::on_ok_pressed()
238 {
239         on_apply_pressed();
240         hide();
241 }
242
243 void
244 CanvasProperties::on_cancel_pressed()
245 {
246         refresh();
247         hide();
248 }