1 /* === S Y N F I G ========================================================= */
2 /*! \file dockdialog.cpp
3 ** \brief Template File
5 ** $Id: dockdialog.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
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 ======================================================= */
33 #include <sigc++/adaptors/hide.h>
35 #include "dockdialog.h"
37 #include "dockmanager.h"
38 #include "widget_compselect.h"
39 #include <synfig/general.h>
40 #include <synfig/uniqueid.h>
41 #include <gtkmm/table.h>
42 #include <sigc++/hide.h>
43 #include <sigc++/slot.h>
44 #include <sigc++/retype_return.h>
45 #include <sigc++/retype.h>
46 #include "canvasview.h"
47 #include <gtkmm/paned.h>
48 #include <gtkmm/box.h>
49 #include <synfigapp/main.h>
53 /* === U S I N G =========================================================== */
57 using namespace synfig;
58 using namespace studio;
60 /* === M A C R O S ========================================================= */
62 #define GRAB_HINT_DATA(y,default) { \
64 if(synfigapp::Main::settings().get_value(String("pref.")+y+"_hints",x)) \
66 set_type_hint((Gdk::WindowTypeHint)atoi(x.c_str())); \
68 set_type_hint(default); \
72 /* === G L O B A L S ======================================================= */
74 /* === P R O C E D U R E S ================================================= */
76 /* === M E T H O D S ======================================================= */
78 DockDialog::DockDialog():
79 Gtk::Window(Gtk::WINDOW_TOPLEVEL)
81 composition_selector_=false;
87 widget_comp_select=new Widget_CompSelect();
89 // Give ourselves an ID that is most likely unique
90 set_id(synfig::UniqueID().get_uid()^reinterpret_cast<int>(this));
92 set_role(strprintf("dock_dialog_%d",get_id()));
96 Gdk::WINDOW_TYPE_HINT_NORMAL
98 Gdk::WINDOW_TYPE_HINT_UTILITY
101 set_keep_below(true);
102 set_keep_above(false);
105 //set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
106 set_title("Dock Dialog");
108 // Register with the dock manager
109 App::dock_manager->dock_dialog_list_.push_back(this);
112 // connect our signals
113 signal_delete_event().connect(
115 sigc::mem_fun(*this,&DockDialog::close)
120 App::signal_canvas_view_focus().connect(
124 &DockDialog::refresh_accel_group
130 add_accel_group(App::ui_manager()->get_accel_group());
131 App::signal_present_all().connect(sigc::mem_fun(*this,&DockDialog::present));
135 DockDialog::~DockDialog()
137 empty_sig.disconnect();
143 // Remove all of the dock books
144 for(;!dock_book_list.empty();dock_book_list.pop_front())
146 dock_book_list.front()->clear();
149 // The following line really should be uncommented,
150 // but it causes crashes. Without it, a small
151 // memory hole is created--but at least it doesn't crash
152 // delete dock_book_list.front();
154 // Oddly enough, the following line should
155 // theoreticly do the same thing after this
156 // class is destroyed, but it doesn't seem to
158 manage(dock_book_list.front());
161 // Remove us from the dock manager
162 if(App::dock_manager)try{
163 std::list<DockDialog*>::iterator iter;
164 for(iter=App::dock_manager->dock_dialog_list_.begin();iter!=App::dock_manager->dock_dialog_list_.end();++iter)
167 App::dock_manager->dock_dialog_list_.erase(iter);
173 synfig::warning("DockDialog::~DockDialog(): Exception thrown when trying to remove from dock manager...?");
176 delete widget_comp_select;
182 DockDialog::drop_on_prepend(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
184 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
186 Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));
187 prepend_dock_book()->add(dockable);
188 context->drag_finish(true, false, time);
192 context->drag_finish(false, false, time);
196 DockDialog::drop_on_append(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
198 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
200 Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));
201 append_dock_book()->add(dockable);
202 context->drag_finish(true, false, time);
206 context->drag_finish(false, false, time);
211 DockDialog::on_hide()
213 Gtk::Window::on_hide();
218 DockDialog::prepend_dock_book()
220 if(is_deleting)return 0;
222 dock_book_list.push_front(new DockBook);
223 last_dock_book=dock_book_list.front();
226 last_dock_book->signal_empty().connect(
228 sigc::mem_fun(*this,&DockDialog::erase_dock_book),
233 dock_book_sizes_.insert(dock_book_sizes_.begin(),225);
235 return last_dock_book;
239 DockDialog::append_dock_book()
241 if(is_deleting)return 0;
243 dock_book_list.push_back(new DockBook);
244 last_dock_book=dock_book_list.back();
245 last_dock_book->signal_empty().connect(
247 sigc::mem_fun(*this,&DockDialog::erase_dock_book),
251 last_dock_book->signal_changed().connect(
252 sigc::mem_fun(*this,&DockDialog::refresh_title)
254 last_dock_book->signal_changed().connect(
255 sigc::mem_fun(*this,&DockDialog::refresh_title)
257 dock_book_sizes_.push_back(225);
259 //last_dock_book->show();
261 return last_dock_book;
265 DockDialog::erase_dock_book(DockBook* dock_book)
267 if(is_deleting)return;
269 std::list<DockBook*>::iterator iter;
270 for(iter=dock_book_list.begin();iter!=dock_book_list.end();++iter)
273 dock_book_list.erase(iter);
275 if(dock_book_list.empty())
283 if(last_dock_book==dock_book)
284 last_dock_book=dock_book_list.front();
294 DockDialog::refresh()
296 synfig::info("dock_book_list.size()=%d",dock_book_list.size());
299 if(dock_book_list.empty())
303 box=(manage(is_horizontal?(Gtk::Box*)new Gtk::HBox:(Gtk::Box*)new Gtk::VBox));
306 box->pack_start(*widget_comp_select,false,true);
308 Gtk::Button* append_button(manage(new Gtk::Button));
309 Gtk::Button* prepend_button(manage(new Gtk::Button));
311 std::list<Gtk::TargetEntry> listTargets;
312 listTargets.push_back( Gtk::TargetEntry("DOCK") );
314 append_button->drag_dest_set(listTargets);
315 prepend_button->drag_dest_set(listTargets);
317 append_button->signal_drag_data_received().connect(
318 sigc::mem_fun(*this,&DockDialog::drop_on_append)
321 prepend_button->signal_drag_data_received().connect(
322 sigc::mem_fun(*this,&DockDialog::drop_on_prepend)
325 box->pack_start(*prepend_button,false,true);
326 box->pack_end(*append_button,false,true);
328 //prepend_button->show();
329 //append_button->show();
332 if(dock_book_list.size()==1)
334 box->pack_start(get_dock_book(),true,true);
338 Gtk::Paned* parent(manage(is_horizontal?(Gtk::Paned*)new Gtk::HPaned:(Gtk::Paned*)new Gtk::VPaned));
340 pannels_.push_back(parent);
342 if(pannels_.size()<=dock_book_sizes_.size())
343 pannels_.back()->set_position(dock_book_sizes_[pannels_.size()-1]);
344 pannels_.back()->property_position().signal_changed().connect(
345 sigc::mem_fun(*this,&DockDialog::rebuild_sizes)
348 parent->add1(*dock_book_list.front());
349 //dock_book_list.front()->show();
351 box->pack_start(*parent,true,true);
353 std::list<DockBook*>::iterator iter,next;
354 for(next=dock_book_list.begin(),next++,iter=next++;next!=dock_book_list.end();iter=next++)
356 Gtk::Paned* current(manage(is_horizontal?(Gtk::Paned*)new Gtk::HPaned:(Gtk::Paned*)new Gtk::VPaned));
357 pannels_.push_back(current);
359 if(pannels_.size()<=dock_book_sizes_.size())
360 pannels_.back()->set_position(dock_book_sizes_[pannels_.size()-1]);
361 pannels_.back()->property_position().signal_changed().connect(
362 sigc::mem_fun(*this,&DockDialog::rebuild_sizes)
366 parent->add2(*current);
368 current->add1(**iter);
374 parent->add2(**iter);
379 if(!composition_selector_)
380 widget_comp_select->hide();
385 DockDialog::rebuild_sizes()
388 dock_book_sizes_.clear();
389 for(i=0;i<pannels_.size();i++)
391 dock_book_sizes_.push_back(pannels_[i]->get_position());
396 DockDialog::set_dock_book_sizes(const std::vector<int>& new_sizes)
399 for(i=0;i<pannels_.size() && i<new_sizes.size();i++)
401 pannels_[i]->set_position(new_sizes[i]);
403 dock_book_sizes_=new_sizes;
408 DockDialog::refresh_accel_group()
411 if(last_accel_group_)
413 last_accel_group_->unlock();
414 remove_accel_group(last_accel_group_);
415 last_accel_group_=Glib::RefPtr<Gtk::AccelGroup>();
418 etl::loose_handle<CanvasView> canvas_view(App::get_selected_canvas_view());
421 last_accel_group_=canvas_view->get_accel_group();
422 last_accel_group_->lock();
423 add_accel_group(last_accel_group_);
426 etl::loose_handle<CanvasView> canvas_view(App::get_selected_canvas_view());
429 canvas_view->mainmenu.accelerate(*this);
436 synfig::info("DockDialog::close(): DELETED!");
437 empty_sig.disconnect();
438 //get_dock_book().clear();
444 DockDialog::get_dock_book()
447 return *append_dock_book();
448 return *last_dock_book;
452 DockDialog::get_dock_book()const
454 return *last_dock_book;
459 DockDialog::get_contents()const
463 std::list<DockBook*>::const_iterator iter;
464 for(iter=dock_book_list.begin();iter!=dock_book_list.end();++iter)
467 ret+=is_horizontal?" | ":" - ";
468 ret+=(*iter)->get_contents();
476 DockDialog::set_contents(const synfig::String& z)
481 synfig::String str(z);
484 unsigned int separator=str.find_first_of('-');
486 unsigned int sep2=str.find_first_of('|');
487 if(separator!=synfig::String::npos || sep2!=synfig::String::npos)
489 if((separator==synfig::String::npos || sep2<separator) && sep2!=synfig::String::npos)
499 synfig::String book_contents;
500 if(separator==synfig::String::npos)
507 book_contents=String(str.begin(),str.begin()+separator);
508 str=String(str.begin()+separator+1,str.end());
513 append_dock_book()->set_contents(book_contents);
521 DockDialog::set_composition_selector(bool x)
523 if(x==get_composition_selector())
525 composition_selector_=x;
527 widget_comp_select->show();
529 widget_comp_select->hide();
533 DockDialog::refresh_title()
535 if(is_deleting)return;
536 if(dock_book_list.size())
538 synfig::String title;
540 std::list<DockBook*>::const_iterator iter;
541 for(iter=dock_book_list.begin();iter!=dock_book_list.end();++iter)
545 title+=(*iter)->get_local_contents();
550 set_title(_("Empty Dock Dialog"));