1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
35 #include "dockmanager.h"
37 #include <gtkmm/image.h>
38 #include <gtkmm/eventbox.h>
39 #include <gtkmm/menu.h>
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
50 using namespace studio;
52 /* === M A C R O S ========================================================= */
54 /* === G L O B A L S ======================================================= */
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
62 std::list<Gtk::TargetEntry> listTargets;
63 listTargets.push_back( Gtk::TargetEntry("DOCK") );
65 drag_dest_set(listTargets);
66 //set_sensitive(true);
67 set_flags(get_flags()|Gtk::RECEIVES_DEFAULT|Gtk::HAS_GRAB);
68 //add_events(Gdk::ALL_EVENTS_MASK);
69 //set_extension_events(Gdk::EXTENSION_EVENTS_ALL);
84 remove(static_cast<Dockable&>(*get_nth_page(get_n_pages()-1)));
88 DockBook::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
90 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
92 Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));
93 if(dockable.parent_!=this)
96 context->drag_finish(true, false, time);
100 context->drag_finish(false, false, time);
104 DockBook::add(Dockable& dockable, int position)
109 append_page(dockable, " ");
111 insert_page(dockable, " ", position);
113 refresh_tab(&dockable);
115 dockable.signal_stock_id_changed().connect(
119 &DockBook::refresh_tab
125 dockable.parent_=this;
129 //set_current_page(get_n_pages()-1);
135 DockBook::refresh_tab(Dockable* dockable)
137 Gtk::Widget* label(dockable->create_tab_label());
139 label->signal_button_press_event().connect(
143 &DockBook::tab_button_pressed
149 set_tab_label(*dockable, *label);
155 DockBook::remove(Dockable& dockable)
158 remove_page(dockable);
177 DockBook::get_local_contents()const
181 for(int i(0);i!=const_cast<DockBook*>(this)->get_n_pages();i++)
183 Dockable& dockable(static_cast<Dockable&>(*const_cast<DockBook*>(this)->get_nth_page(i)));
187 ret+=dockable.get_local_name();
194 DockBook::get_contents()const
198 for(int i(0);i!=const_cast<DockBook*>(this)->get_n_pages();i++)
200 Dockable& dockable(static_cast<Dockable&>(*const_cast<DockBook*>(this)->get_nth_page(i)));
204 ret+=dockable.get_name();
211 DockBook::set_contents(const synfig::String& x)
213 synfig::String str(x);
216 synfig::String::size_type separator=str.find_first_of(' ');
218 if(separator==synfig::String::npos)
225 dock=String(str.begin(),str.begin()+separator);
226 str=String(str.begin()+separator+1,str.end());
231 add(App::dock_manager->find_dockable(dock));
237 DockBook::tab_button_pressed(GdkEventButton* event, Dockable* dockable)
242 Gtk::Menu *tabmenu=manage(new class Gtk::Menu());
243 tabmenu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), tabmenu));
245 tabmenu->items().push_back(
246 Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-close"),
247 sigc::mem_fun(*dockable,&Dockable::detach)
251 tabmenu->popup(event->button,gtk_get_current_event_time());