1 /* === S Y N F I G ========================================================= */
2 /*! \file dockdialog.cpp
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 ======================================================= */
33 #include <sigc++/adaptors/hide.h>
35 #include "dockdialog.h"
37 #include "dockmanager.h"
39 #include "widget_compselect.h"
40 #include <synfig/general.h>
41 #include <synfig/uniqueid.h>
42 #include <gtkmm/table.h>
43 #include <sigc++/hide.h>
44 #include <sigc++/slot.h>
45 #include <sigc++/retype_return.h>
46 #include <sigc++/retype.h>
47 #include "canvasview.h"
48 #include <gtkmm/paned.h>
49 #include <gtkmm/box.h>
50 #include <synfigapp/main.h>
54 /* === U S I N G =========================================================== */
58 using namespace synfig;
59 using namespace studio;
61 /* === M A C R O S ========================================================= */
63 #define GRAB_HINT_DATA(y,default) { \
65 if(synfigapp::Main::settings().get_value(String("pref.")+y+"_hints",x)) \
67 set_type_hint((Gdk::WindowTypeHint)atoi(x.c_str())); \
69 set_type_hint(default); \
73 /* === G L O B A L S ======================================================= */
75 /* === P R O C E D U R E S ================================================= */
77 /* === M E T H O D S ======================================================= */
79 DockDialog::DockDialog():
80 Gtk::Window(Gtk::WINDOW_TOPLEVEL)
82 composition_selector_=false;
88 widget_comp_select=new Widget_CompSelect();
90 // Give ourselves an ID that is most likely unique
91 set_id(synfig::UniqueID().get_uid()^reinterpret_cast<long>(this));
93 set_role(strprintf("dock_dialog_%d",get_id()));
97 Gdk::WINDOW_TYPE_HINT_NORMAL
99 Gdk::WINDOW_TYPE_HINT_UTILITY
102 set_keep_above(false);
104 //! \todo can we set dialog windows transient for all normal windows, not just the toolbox?
105 //! paragraph 3 of http://standards.freedesktop.org/wm-spec/1.3/ar01s07.html suggests we can
106 // this seems to have bad effects on KDE, so leave it disabled by default
107 if(getenv("SYNFIG_TRANSIENT_DIALOGS"))
108 set_transient_for(*App::toolbox);
111 //set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
112 set_title("Dock Dialog");
114 // Register with the dock manager
115 App::dock_manager->dock_dialog_list_.push_back(this);
118 // connect our signals
119 signal_delete_event().connect(
121 sigc::mem_fun(*this,&DockDialog::close)
126 App::signal_canvas_view_focus().connect(
130 &DockDialog::refresh_accel_group
136 add_accel_group(App::ui_manager()->get_accel_group());
137 App::signal_present_all().connect(sigc::mem_fun0(*this,&DockDialog::present));
141 DockDialog::~DockDialog()
143 empty_sig.disconnect();
147 // Remove all of the dock books
148 for(;!dock_book_list.empty();dock_book_list.pop_front())
150 dock_book_list.front()->clear();
152 //! \fixme: UGLY HACK
153 // The following line really should be uncommented,
154 // but it causes crashes. Without it, a small
155 // memory hole is created--but at least it doesn't crash
156 // delete dock_book_list.front();
158 // Oddly enough, the following line should
159 // theoreticly do the same thing after this
160 // class is destroyed, but it doesn't seem to
161 // cause a crash. It does, however, trigger this warning:
163 // A floating object was finalized. This means that someone
164 // called g_object_unref() on an object that had only a
165 // floating reference; the initial floating reference is not
166 // owned by anyone and must be removed with g_object_ref_sink().
168 // manage(dock_book_list.front());
171 // Remove us from the dock manager
172 if(App::dock_manager)try{
173 std::list<DockDialog*>::iterator iter;
174 for(iter=App::dock_manager->dock_dialog_list_.begin();iter!=App::dock_manager->dock_dialog_list_.end();++iter)
177 App::dock_manager->dock_dialog_list_.erase(iter);
183 synfig::warning("DockDialog::~DockDialog(): Exception thrown when trying to remove from dock manager...?");
186 delete widget_comp_select;
190 DockDialog::drop_on_prepend(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
192 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
194 Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));
195 prepend_dock_book()->add(dockable);
196 context->drag_finish(true, false, time);
200 context->drag_finish(false, false, time);
204 DockDialog::drop_on_append(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time)
206 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
208 Dockable& dockable(**reinterpret_cast<Dockable**>(const_cast<guint8*>(selection_data.get_data())));
209 append_dock_book()->add(dockable);
210 context->drag_finish(true, false, time);
214 context->drag_finish(false, false, time);
219 DockDialog::on_hide()
221 Gtk::Window::on_hide();
226 DockDialog::prepend_dock_book()
228 if(is_deleting)return 0;
230 dock_book_list.push_front(new DockBook);
231 last_dock_book=dock_book_list.front();
234 last_dock_book->signal_empty().connect(
236 sigc::mem_fun(*this,&DockDialog::erase_dock_book),
241 dock_book_sizes_.insert(dock_book_sizes_.begin(),225);
243 return last_dock_book;
247 DockDialog::append_dock_book()
249 if(is_deleting)return 0;
251 dock_book_list.push_back(new DockBook);
252 last_dock_book=dock_book_list.back();
253 last_dock_book->signal_empty().connect(
255 sigc::mem_fun(*this,&DockDialog::erase_dock_book),
259 last_dock_book->signal_changed().connect(
260 sigc::mem_fun(*this,&DockDialog::refresh_title)
262 last_dock_book->signal_changed().connect(
263 sigc::mem_fun(*this,&DockDialog::refresh_title)
265 dock_book_sizes_.push_back(225);
267 //last_dock_book->show();
269 return last_dock_book;
273 DockDialog::erase_dock_book(DockBook* dock_book)
275 if(is_deleting)return;
277 std::list<DockBook*>::iterator iter;
278 for(iter=dock_book_list.begin();iter!=dock_book_list.end();++iter)
281 dock_book_list.erase(iter);
283 if(dock_book_list.empty())
291 if(last_dock_book==dock_book)
292 last_dock_book=dock_book_list.front();
302 DockDialog::refresh()
304 // synfig::info("dock_book_list.size()=%d",dock_book_list.size());
307 if(dock_book_list.empty())
311 box=(manage(is_horizontal?(Gtk::Box*)new Gtk::HBox:(Gtk::Box*)new Gtk::VBox));
314 box->pack_start(*widget_comp_select,false,true);
316 Gtk::Button* append_button(manage(new Gtk::Button));
317 Gtk::Button* prepend_button(manage(new Gtk::Button));
319 std::list<Gtk::TargetEntry> listTargets;
320 listTargets.push_back( Gtk::TargetEntry("DOCK") );
322 append_button->drag_dest_set(listTargets);
323 prepend_button->drag_dest_set(listTargets);
325 append_button->signal_drag_data_received().connect(
326 sigc::mem_fun(*this,&DockDialog::drop_on_append)
329 prepend_button->signal_drag_data_received().connect(
330 sigc::mem_fun(*this,&DockDialog::drop_on_prepend)
333 box->pack_start(*prepend_button,false,true);
334 box->pack_end(*append_button,false,true);
336 //prepend_button->show();
337 //append_button->show();
340 if(dock_book_list.size()==1)
342 box->pack_start(get_dock_book(),true,true);
346 Gtk::Paned* parent(manage(is_horizontal?(Gtk::Paned*)new Gtk::HPaned:(Gtk::Paned*)new Gtk::VPaned));
348 pannels_.push_back(parent);
350 if(pannels_.size()<=dock_book_sizes_.size())
351 pannels_.back()->set_position(dock_book_sizes_[pannels_.size()-1]);
352 pannels_.back()->property_position().signal_changed().connect(
353 sigc::mem_fun(*this,&DockDialog::rebuild_sizes)
356 parent->add1(*dock_book_list.front());
357 //dock_book_list.front()->show();
359 box->pack_start(*parent,true,true);
361 std::list<DockBook*>::iterator iter,next;
362 for(next=dock_book_list.begin(),next++,iter=next++;next!=dock_book_list.end();iter=next++)
364 Gtk::Paned* current(manage(is_horizontal?(Gtk::Paned*)new Gtk::HPaned:(Gtk::Paned*)new Gtk::VPaned));
365 pannels_.push_back(current);
367 if(pannels_.size()<=dock_book_sizes_.size())
368 pannels_.back()->set_position(dock_book_sizes_[pannels_.size()-1]);
369 pannels_.back()->property_position().signal_changed().connect(
370 sigc::mem_fun(*this,&DockDialog::rebuild_sizes)
374 parent->add2(*current);
376 current->add1(**iter);
382 parent->add2(**iter);
387 if(!composition_selector_)
388 widget_comp_select->hide();
393 DockDialog::rebuild_sizes()
396 dock_book_sizes_.clear();
397 for(i=0;i<pannels_.size();i++)
399 dock_book_sizes_.push_back(pannels_[i]->get_position());
404 DockDialog::set_dock_book_sizes(const std::vector<int>& new_sizes)
407 for(i=0;i<pannels_.size() && i<new_sizes.size();i++)
409 pannels_[i]->set_position(new_sizes[i]);
411 dock_book_sizes_=new_sizes;
416 DockDialog::refresh_accel_group()
419 if(last_accel_group_)
421 last_accel_group_->unlock();
422 remove_accel_group(last_accel_group_);
423 last_accel_group_=Glib::RefPtr<Gtk::AccelGroup>();
426 etl::loose_handle<CanvasView> canvas_view(App::get_selected_canvas_view());
429 last_accel_group_=canvas_view->get_accel_group();
430 last_accel_group_->lock();
431 add_accel_group(last_accel_group_);
434 etl::loose_handle<CanvasView> canvas_view(App::get_selected_canvas_view());
437 canvas_view->mainmenu.accelerate(*this);
444 synfig::info("DockDialog::close(): DELETED!");
445 empty_sig.disconnect();
446 //get_dock_book().clear();
452 DockDialog::get_dock_book()
455 return *append_dock_book();
456 return *last_dock_book;
460 DockDialog::get_dock_book()const
462 return *last_dock_book;
467 DockDialog::get_contents()const
471 std::list<DockBook*>::const_iterator iter;
472 for(iter=dock_book_list.begin();iter!=dock_book_list.end();++iter)
475 ret+=is_horizontal?" | ":" - ";
476 ret+=(*iter)->get_contents();
484 DockDialog::set_contents(const synfig::String& z)
489 synfig::String str(z);
492 synfig::String::size_type separator=str.find_first_of('-');
494 synfig::String::size_type sep2=str.find_first_of('|');
495 if(separator!=synfig::String::npos || sep2!=synfig::String::npos)
497 if((separator==synfig::String::npos || sep2<separator) && sep2!=synfig::String::npos)
507 synfig::String book_contents;
508 if(separator==synfig::String::npos)
515 book_contents=String(str.begin(),str.begin()+separator);
516 str=String(str.begin()+separator+1,str.end());
521 append_dock_book()->set_contents(book_contents);
529 DockDialog::set_composition_selector(bool x)
531 if(x==get_composition_selector())
533 composition_selector_=x;
535 widget_comp_select->show();
537 widget_comp_select->hide();
541 DockDialog::refresh_title()
543 if(is_deleting)return;
544 if(dock_book_list.size())
546 synfig::String title;
548 std::list<DockBook*>::const_iterator iter;
549 for(iter=dock_book_list.begin();iter!=dock_book_list.end();++iter)
553 title+=(*iter)->get_local_contents();
558 set_title(_("Empty Dock Dialog"));