Build rectanglular blines in the same handedness as all the other shapes.
[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 **      Copyright (c) 2007, 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "canvasproperties.h"
34 #include <gtkmm/frame.h>
35 #include <gtkmm/table.h>
36 #include <gtkmm/label.h>
37 #include <gtkmm/alignment.h>
38 #include <synfigapp/canvasinterface.h>
39 #include "metadatatreestore.h"
40 #include <gtkmm/treeview.h>
41 #include <gtkmm/scrolledwindow.h>
42 #include "app.h"
43
44 #include "general.h"
45
46 #endif
47
48 /* === U S I N G =========================================================== */
49
50 using namespace std;
51 using namespace etl;
52 using namespace synfig;
53 using namespace studio;
54
55 /* === M A C R O S ========================================================= */
56
57 /* === G L O B A L S ======================================================= */
58
59 /* === P R O C E D U R E S ================================================= */
60
61 /* === M E T H O D S ======================================================= */
62
63 CanvasProperties::CanvasProperties(Gtk::Window& parent,etl::handle<synfigapp::CanvasInterface> canvas_interface):
64         Gtk::Dialog(_("Canvas Properties"),parent,false,true),
65         canvas_interface_(canvas_interface)
66 {
67         widget_rend_desc.show();
68         widget_rend_desc.signal_changed().connect(sigc::mem_fun(*this,&studio::CanvasProperties::on_rend_desc_changed));
69
70         Gtk::Alignment *dialogPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
71         dialogPadding->set_padding(12, 12, 12, 12);
72         get_vbox()->pack_start(*dialogPadding, false, false, 0);
73
74         Gtk::VBox *dialogBox = manage(new Gtk::VBox(false, 12));
75         dialogPadding->add(*dialogBox);
76
77         Gtk::Frame *info_frame=manage(new Gtk::Frame(_("Canvas Info")));
78         info_frame->set_shadow_type(Gtk::SHADOW_NONE);
79         ((Gtk::Label *) info_frame->get_label_widget())->set_markup(_("<b>Canvas Info</b>"));
80         dialogBox->pack_start(*info_frame, false, false, 0);
81
82         Gtk::Alignment *infoPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
83         infoPadding->set_padding(6, 0, 24, 0);
84         info_frame->add(*infoPadding);
85
86         Gtk::Table *info_table=manage(new Gtk::Table(2,2,false));
87         info_table->set_row_spacings(6);
88         info_table->set_col_spacings(12);
89         infoPadding->add(*info_table);
90
91         // The root canvas doesn't have an ID, so don't
92         // display it if this is a root canvas.
93         if(!canvas_interface_->get_canvas()->is_root())
94         {
95                 Gtk::Label *idLabel = manage(new Gtk::Label(_("_ID"), true));
96                 idLabel->set_alignment(0, 0.5);
97                 idLabel->set_mnemonic_widget(entry_id);
98                 info_table->attach(*idLabel, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
99                 info_table->attach(entry_id, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
100         }
101         Gtk::Label *nameLabel = manage(new Gtk::Label(_("_Name"), true));
102         nameLabel->set_alignment(0, 0.5);
103         nameLabel->set_mnemonic_widget(entry_name);
104         Gtk::Label *descriptionLabel = manage(new Gtk::Label(_("_Description"), true));
105         descriptionLabel->set_alignment(0, 0.5);
106         descriptionLabel->set_mnemonic_widget(entry_description);
107         info_table->attach(*nameLabel, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
108         info_table->attach(*descriptionLabel, 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
109         info_table->attach(entry_name, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
110         info_table->attach(entry_description, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
111
112         dialogBox->pack_start(widget_rend_desc, false, false, 0);
113
114         canvas_interface_->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&studio::CanvasProperties::refresh));
115         canvas_interface_->signal_id_changed().connect(sigc::mem_fun(*this,&studio::CanvasProperties::refresh));
116
117         Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
118         ok_button->show();
119         add_action_widget(*ok_button,2);
120         ok_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_ok_pressed));
121
122         Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
123         apply_button->show();
124         add_action_widget(*apply_button,1);
125         apply_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_apply_pressed));
126
127         Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
128         cancel_button->show();
129         add_action_widget(*cancel_button,0);
130         cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_cancel_pressed));
131
132         //set_default_response(1);
133
134         get_vbox()->show_all();
135         refresh();
136
137         update_title();
138 }
139
140 Gtk::Widget&
141 CanvasProperties::create_meta_data_view()
142 {
143         MetaDataTreeStore::Model model;
144         meta_data_tree_view=(manage(new class Gtk::TreeView()));
145
146         meta_data_tree_view->append_column(_("Key"),model.key);
147         meta_data_tree_view->append_column_editable(_("Data"),model.data);
148         meta_data_tree_view->set_model(MetaDataTreeStore::create(canvas_interface_));
149         meta_data_tree_view->set_rules_hint();
150         meta_data_tree_view->show();
151
152         Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
153         scrolledwindow->set_flags(Gtk::CAN_FOCUS);
154         scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
155         scrolledwindow->add(*meta_data_tree_view);
156         scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
157         scrolledwindow->show();
158
159
160
161         Gtk::Table *table=manage(new Gtk::Table());
162         table->attach(*scrolledwindow, 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
163
164         Gtk::Button* button_add(manage(new Gtk::Button(Gtk::StockID("gtk-add"))));
165         button_add->show();
166         button_add->signal_clicked().connect(sigc::mem_fun(*this,&CanvasProperties::on_button_meta_data_add));
167         table->attach(*button_add, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
168
169         Gtk::Button* button_delete(manage(new Gtk::Button(Gtk::StockID("gtk-delete"))));
170         button_delete->show();
171         button_delete->signal_clicked().connect(sigc::mem_fun(*this,&CanvasProperties::on_button_meta_data_delete));
172         table->attach(*button_delete, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
173
174         table->show();
175         return *table;
176 }
177
178 void
179 CanvasProperties::on_button_meta_data_add()
180 {
181         synfig::String key;
182         if(App::dialog_entry(_("New MetaData Entry"), _("Please enter the name of the key"),key) && !key.empty())
183         {
184                 canvas_interface_->set_meta_data(key," ");
185         }
186
187 }
188
189 void
190 CanvasProperties::on_button_meta_data_delete()
191 {
192 }
193
194 void
195 CanvasProperties::update_title()
196 {
197         set_title(_("Properties")+String(" - ")+canvas_interface_->get_canvas()->get_name());
198 }
199
200 void
201 CanvasProperties::refresh()
202 {
203         widget_rend_desc.set_rend_desc(canvas_interface_->get_canvas()->rend_desc());
204         entry_id.set_text(canvas_interface_->get_canvas()->get_id());
205         entry_name.set_text(canvas_interface_->get_canvas()->get_name());
206         entry_description.set_text(canvas_interface_->get_canvas()->get_description());
207
208         dirty_rend_desc=false;
209
210         update_title();
211 }
212
213 CanvasProperties::~CanvasProperties()
214 {
215 }
216
217 void
218 CanvasProperties::on_rend_desc_changed()
219 {
220         dirty_rend_desc=true;
221 }
222
223 void
224 CanvasProperties::on_apply_pressed()
225 {
226         synfigapp::Action::PassiveGrouper group(canvas_interface_->get_instance().get(),_("Edit Canvas Properties"));
227
228         // fetch these three values first, because each set_() method refreshes the dialog with currently set values
229         String id = entry_id.get_text();
230         String name = entry_name.get_text();
231         String description = entry_description.get_text();
232
233         // do this first, because the other three cause the dialog to be refreshed with currently set values
234         if (dirty_rend_desc) canvas_interface_->set_rend_desc(widget_rend_desc.get_rend_desc());
235
236         if (id != canvas_interface_->get_canvas()->get_id() && !id.empty())             canvas_interface_->set_id(id);
237         if (name != canvas_interface_->get_canvas()->get_name())                                canvas_interface_->set_name(name);
238         if (description != canvas_interface_->get_canvas()->get_description())  canvas_interface_->set_description(description);
239
240         dirty_rend_desc=false;
241 }
242
243 void
244 CanvasProperties::on_ok_pressed()
245 {
246         on_apply_pressed();
247         hide();
248 }
249
250 void
251 CanvasProperties::on_cancel_pressed()
252 {
253         refresh();
254         hide();
255 }