Fix some FTBFS issues when compiling with GCC 4.3
[synfig.git] / synfig-studio / trunk / src / gtkmm / childrentree.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file childrentree.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 "childrentree.h"
33 #include "cellrenderer_value.h"
34 #include "cellrenderer_timetrack.h"
35 #include <synfigapp/action.h>
36 #include <synfigapp/instance.h>
37 #include <gtkmm/scrolledwindow.h>
38
39 #include "general.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 #ifndef SMALL_BUTTON
53 #define SMALL_BUTTON(button,stockid,tooltip)    \
54         button = manage(new class Gtk::Button());       \
55         icon=manage(new Gtk::Image(Gtk::StockID(stockid),iconsize));    \
56         button->add(*icon);     \
57         tooltips_.set_tip(*button,tooltip);     \
58         icon->set_padding(0,0);\
59         icon->show();   \
60         button->set_relief(Gtk::RELIEF_NONE); \
61         button->show()
62 #endif
63
64 #ifndef NORMAL_BUTTON
65 #define NORMAL_BUTTON(button,stockid,tooltip)   \
66         button = manage(new class Gtk::Button());       \
67         icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::ICON_SIZE_BUTTON));       \
68         button->add(*icon);     \
69         tooltips_.set_tip(*button,tooltip);     \
70         icon->set_padding(0,0);\
71         icon->show();   \
72         /*button->set_relief(Gtk::RELIEF_NONE);*/ \
73         button->show()
74 #endif
75
76 #define NEW_SMALL_BUTTON(x,y,z) Gtk::Button *SMALL_BUTTON(x,y,z)
77
78 #define NOT_IMPLEMENTED_SLOT sigc::mem_fun(*reinterpret_cast<studio::CanvasViewUIInterface*>(get_ui_interface().get()),&studio::CanvasViewUIInterface::not_implemented)
79
80 /* === G L O B A L S ======================================================= */
81
82 /* === P R O C E D U R E S ================================================= */
83
84 /* === M E T H O D S ======================================================= */
85
86 ChildrenTree::ChildrenTree()
87 {
88         const ChildrenTreeStore::Model model;
89
90         {       // --- N A M E --------------------------------------------------------
91                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ID")) );
92
93                 // Set up the icon cell-renderer
94                 Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
95                 column->pack_start(*icon_cellrenderer,false);
96                 column->add_attribute(icon_cellrenderer->property_pixbuf(), model.icon);
97
98                 // Pack the label into the column
99                 column->pack_start(model.label,true);
100
101                 // Finish setting up the column
102                 column->set_reorderable();
103                 column->set_resizable();
104                 column->set_clickable();
105                 column->set_min_width(150);
106                 column->set_sort_column_id(model.label);
107                 tree_view.append_column(*column);
108
109         }
110         {       // --- T Y P E --------------------------------------------------------
111                 int cols_count = tree_view.append_column(_("Type"),model.type);
112                 Gtk::TreeViewColumn* column = tree_view.get_column(cols_count-1);
113                 if(column)
114                 {
115                         column->set_reorderable();
116                         column->set_resizable();
117                         column->set_clickable();
118                         column->set_sort_column_id(model.type);
119                 }
120         }
121         {       // --- V A L U E  -----------------------------------------------------
122                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ValueBase")) );
123
124                 // Set up the value cell-renderer
125                 cellrenderer_value=ChildrenTreeStore::add_cell_renderer_value(column);
126                 cellrenderer_value->signal_edited().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_edited_value));
127                 cellrenderer_value->property_value()=synfig::ValueBase();
128
129                 // Finish setting up the column
130                 tree_view.append_column(*column);
131                 column->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
132                 column->set_min_width(150);
133                 column->set_reorderable();
134                 column->set_resizable();
135                 column->set_clickable(false);
136         }
137         {       // --- T I M E   T R A C K --------------------------------------------
138                 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Time Track")) );
139                 column_time_track=column;
140
141                 // Set up the value-node cell-renderer
142                 cellrenderer_time_track=ChildrenTreeStore::add_cell_renderer_value_node(column);
143                 cellrenderer_time_track->property_mode()=Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
144                 cellrenderer_time_track->signal_waypoint_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_waypoint_clicked) );
145                 column->add_attribute(cellrenderer_time_track->property_value_desc(), model.value_desc);
146                 column->add_attribute(cellrenderer_time_track->property_canvas(), model.canvas);
147
148                 //column->pack_start(*cellrenderer_time_track);
149
150                 // Finish setting up the column
151                 column->set_reorderable();
152                 column->set_resizable();
153                 tree_view.append_column(*column);
154         }
155
156         // This makes things easier to read.
157         tree_view.set_rules_hint();
158
159         // Make us more sensitive to several events
160         tree_view.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK|Gdk::POINTER_MOTION_MASK);
161
162         tree_view.signal_event().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_tree_event));
163
164         // Create a scrolled window for that tree
165         Gtk::ScrolledWindow *scroll_children_tree = manage(new class Gtk::ScrolledWindow());
166         scroll_children_tree->set_flags(Gtk::CAN_FOCUS);
167         scroll_children_tree->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
168         scroll_children_tree->add(tree_view);
169         scroll_children_tree->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
170         scroll_children_tree->show();
171
172         attach(*scroll_children_tree, 0, 3, 0, 1, Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL, 0, 0);
173
174         hbox=manage(new Gtk::HBox());
175
176         attach(*hbox, 0, 1, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 0, 0);
177
178
179
180         tree_view.set_enable_search(true);
181         tree_view.set_search_column(model.label);
182
183
184 /*
185         Gtk::Image *icon;
186         //Gtk::IconSize iconsize(Gtk::IconSize::from_name("synfig-small_icon"));
187         Gtk::IconSize iconsize(Gtk::ICON_SIZE_SMALL_TOOLBAR);
188
189         SMALL_BUTTON(button_raise,"gtk-go-up",_("Raise"));
190         SMALL_BUTTON(button_lower,"gtk-go-down",_("Lower"));
191         SMALL_BUTTON(button_duplicate,"synfig-duplicate",_("Duplicate"));
192         SMALL_BUTTON(button_delete,"gtk-delete",_("Delete"));
193
194         hbox->pack_start(*button_raise,Gtk::PACK_SHRINK);
195         hbox->pack_start(*button_lower,Gtk::PACK_SHRINK);
196         hbox->pack_start(*button_duplicate,Gtk::PACK_SHRINK);
197         hbox->pack_start(*button_delete,Gtk::PACK_SHRINK);
198
199         button_raise->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_raise_pressed));
200         button_lower->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_lower_pressed));
201         button_duplicate->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_duplicate_pressed));
202         button_delete->signal_clicked().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_delete_pressed));
203
204         button_raise->set_sensitive(false);
205         button_lower->set_sensitive(false);
206         button_duplicate->set_sensitive(false);
207         button_delete->set_sensitive(false);
208 */
209
210
211
212         get_selection()->signal_changed().connect(sigc::mem_fun(*this, &studio::ChildrenTree::on_selection_changed));
213
214
215         tree_view.set_reorderable(true);
216
217         hbox->show();
218         tree_view.show();
219
220         tooltips_.enable();
221
222         //get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
223 }
224
225
226 ChildrenTree::~ChildrenTree()
227 {
228 }
229
230 void
231 ChildrenTree::set_show_timetrack(bool x)
232 {
233         column_time_track->set_visible(x);
234 }
235
236 void
237 ChildrenTree::set_model(Glib::RefPtr<ChildrenTreeStore> children_tree_store)
238 {
239         children_tree_store_=children_tree_store;
240         tree_view.set_model(children_tree_store_);
241         children_tree_store_->canvas_interface()->signal_dirty_preview().connect(sigc::mem_fun(*this,&studio::ChildrenTree::on_dirty_preview));
242 }
243
244 void
245 ChildrenTree::set_time_adjustment(Gtk::Adjustment &adjustment)
246 {
247         cellrenderer_time_track->set_adjustment(adjustment);
248 }
249
250 void
251 ChildrenTree::on_dirty_preview()
252 {
253 }
254
255 void
256 ChildrenTree::on_selection_changed()
257 {
258         if(0)
259                 {
260                 button_raise->set_sensitive(false);
261                 button_lower->set_sensitive(false);
262                 button_duplicate->set_sensitive(false);
263                 button_delete->set_sensitive(false);
264                 return;
265         }
266 }
267
268
269 void
270 ChildrenTree::on_edited_value(const Glib::ustring&path_string,synfig::ValueBase value)
271 {
272         Gtk::TreePath path(path_string);
273
274         const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
275
276         row[model.value]=value;
277 //      signal_edited_value()(row[model.value_desc],value);
278 }
279
280 void
281 ChildrenTree::on_waypoint_clicked(const Glib::ustring &path_string, synfig::Waypoint waypoint,int button)
282 {
283         Gtk::TreePath path(path_string);
284
285         const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
286
287         signal_waypoint_clicked()(static_cast<synfigapp::ValueDesc>(row[model.value_desc]),waypoint,button);
288 }
289
290 bool
291 ChildrenTree::on_tree_event(GdkEvent *event)
292 {
293     switch(event->type)
294     {
295         case GDK_BUTTON_PRESS:
296                 {
297                         Gtk::TreeModel::Path path;
298                         Gtk::TreeViewColumn *column;
299                         int cell_x, cell_y;
300                         if(!tree_view.get_path_at_pos(
301                                 int(event->button.x),int(event->button.y),      // x, y
302                                 path, // TreeModel::Path&
303                                 column, //TreeViewColumn*&
304                                 cell_x,cell_y //int&cell_x,int&cell_y
305                                 )
306                         ) break;
307                         const Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
308
309                         if(column->get_first_cell_renderer()==cellrenderer_time_track)
310                         {
311                                 return signal_user_click()(event->button.button,row,COLUMNID_TIME_TRACK);
312                         }
313                         else if(column->get_first_cell_renderer()==cellrenderer_value)
314                                 return signal_user_click()(event->button.button,row,COLUMNID_VALUE);
315                         else
316                                 return signal_user_click()(event->button.button,row,COLUMNID_ID);
317
318                 }
319                 break;
320
321         case GDK_MOTION_NOTIFY:
322                 {
323                         Gtk::TreeModel::Path path;
324                         Gtk::TreeViewColumn *column;
325                         int cell_x, cell_y;
326                         if(!tree_view.get_path_at_pos(
327                                 (int)event->button.x,(int)event->button.y,      // x, y
328                                 path, // TreeModel::Path&
329                                 column, //TreeViewColumn*&
330                                 cell_x,cell_y //int&cell_x,int&cell_y
331                                 )
332                         ) break;
333
334                         if(!tree_view.get_model()->get_iter(path))
335                                 break;
336
337                         Gtk::TreeRow row = *(tree_view.get_model()->get_iter(path));
338
339                         if(cellrenderer_time_track==column->get_first_cell_renderer())
340                         {
341                                 // Movement on TimeLine
342                                 return true;
343                         }
344                         else
345                         if(last_tooltip_path.get_depth()<=0 || path!=last_tooltip_path)
346                         {
347                                 tooltips_.unset_tip(*this);
348                                 Glib::ustring tooltips_string(row[model.tooltip]);
349                                 last_tooltip_path=path;
350                                 if(!tooltips_string.empty())
351                                 {
352                                         tooltips_.set_tip(*this,tooltips_string);
353                                         tooltips_.force_window();
354                                 }
355                         }
356                 }
357                 break;
358         case GDK_BUTTON_RELEASE:
359                 break;
360         default:
361                 break;
362         }
363         return false;
364 }
365
366 void
367 ChildrenTree::on_raise_pressed()
368 {
369 }
370
371 void
372 ChildrenTree::on_lower_pressed()
373 {
374 }
375
376 void
377 ChildrenTree::on_duplicate_pressed()
378 {
379 }
380
381 void
382 ChildrenTree::on_delete_pressed()
383 {
384 }