1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
36 #include "dockmanager.h"
38 #include <gtkmm/image.h>
39 #include <gtkmm/eventbox.h>
40 #include <gtkmm/menu.h>
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
51 using namespace studio;
53 /* === M A C R O S ========================================================= */
55 /* === G L O B A L S ======================================================= */
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
63 std::list<Gtk::TargetEntry> listTargets;
64 listTargets.push_back( Gtk::TargetEntry("DOCK") );
66 drag_dest_set(listTargets);
67 //set_sensitive(true);
68 set_flags(get_flags()|Gtk::RECEIVES_DEFAULT|Gtk::HAS_GRAB);
69 //add_events(Gdk::ALL_EVENTS_MASK);
70 //set_extension_events(Gdk::EXTENSION_EVENTS_ALL);
85 remove(static_cast<Dockable&>(*get_nth_page(get_n_pages()-1)));
89 DockBook::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
91 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
93 Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));
94 if(dockable.parent_!=this)
97 context->drag_finish(true, false, time);
101 context->drag_finish(false, false, time);
105 DockBook::add(Dockable& dockable, int position)
110 append_page(dockable, " ");
112 insert_page(dockable, " ", position);
114 refresh_tab(&dockable);
116 dockable.signal_stock_id_changed().connect(
120 &DockBook::refresh_tab
126 dockable.parent_=this;
130 //set_current_page(get_n_pages()-1);
136 DockBook::refresh_tab(Dockable* dockable)
138 Gtk::Widget* label(dockable->create_tab_label());
140 label->signal_button_press_event().connect(
144 &DockBook::tab_button_pressed
150 set_tab_label(*dockable, *label);
156 DockBook::remove(Dockable& dockable)
159 remove_page(dockable);
178 DockBook::get_local_contents()const
182 for(int i(0);i!=const_cast<DockBook*>(this)->get_n_pages();i++)
184 Dockable& dockable(static_cast<Dockable&>(*const_cast<DockBook*>(this)->get_nth_page(i)));
188 ret+=dockable.get_local_name();
195 DockBook::get_contents()const
199 for(int i(0);i!=const_cast<DockBook*>(this)->get_n_pages();i++)
201 Dockable& dockable(static_cast<Dockable&>(*const_cast<DockBook*>(this)->get_nth_page(i)));
205 ret+=dockable.get_name();
212 DockBook::set_contents(const synfig::String& x)
214 synfig::String str(x);
217 synfig::String::size_type separator=str.find_first_of(' ');
219 if(separator==synfig::String::npos)
226 dock=String(str.begin(),str.begin()+separator);
227 str=String(str.begin()+separator+1,str.end());
232 add(App::dock_manager->find_dockable(dock));
238 DockBook::tab_button_pressed(GdkEventButton* event, Dockable* dockable)
243 Gtk::Menu *tabmenu=manage(new class Gtk::Menu());
244 tabmenu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), tabmenu));
246 tabmenu->items().push_back(
247 Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-close"),
248 sigc::mem_fun(*dockable,&Dockable::detach)
252 tabmenu->popup(event->button,gtk_get_current_event_time());