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 ======================================================= */
33 #include "docks/dockbook.h"
34 #include "docks/dockable.h"
36 #include "docks/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;
134 DockBook::refresh_tab(Dockable* dockable)
136 Gtk::Widget* label(dockable->create_tab_label());
138 label->signal_button_press_event().connect(
142 &DockBook::tab_button_pressed
148 set_tab_label(*dockable, *label);
154 DockBook::remove(Dockable& dockable)
157 remove_page(dockable);
176 DockBook::get_local_contents()const
180 for(int i(0);i!=const_cast<DockBook*>(this)->get_n_pages();i++)
182 Dockable& dockable(static_cast<Dockable&>(*const_cast<DockBook*>(this)->get_nth_page(i)));
186 ret+=dockable.get_local_name();
193 DockBook::get_contents()const
197 for(int i(0);i!=const_cast<DockBook*>(this)->get_n_pages();i++)
199 Dockable& dockable(static_cast<Dockable&>(*const_cast<DockBook*>(this)->get_nth_page(i)));
203 ret+=dockable.get_name();
210 DockBook::set_contents(const synfig::String& x)
212 synfig::String str(x);
215 synfig::String::size_type separator=str.find_first_of(' ');
217 if(separator==synfig::String::npos)
224 dock=String(str.begin(),str.begin()+separator);
225 str=String(str.begin()+separator+1,str.end());
230 add(App::dock_manager->find_dockable(dock));
236 DockBook::tab_button_pressed(GdkEventButton* event, Dockable* dockable)
241 Gtk::Menu *tabmenu=manage(new class Gtk::Menu());
242 tabmenu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), tabmenu));
244 tabmenu->items().push_back(
245 Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-close"),
246 sigc::mem_fun(*dockable,&Dockable::detach)
250 tabmenu->popup(event->button,gtk_get_current_event_time());