1 /* === S Y N F I G ========================================================= */
2 /*! \file dockmanager.cpp
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 "dockmanager.h"
36 #include "dockdialog.h"
37 #include <synfigapp/settings.h>
38 #include <synfigapp/main.h>
39 #include <gdkmm/general.h>
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
50 using namespace studio;
52 /* === M A C R O S ========================================================= */
54 /* === P R O C E D U R E S ================================================= */
56 class studio::DockSettings : public synfigapp::Settings
58 DockManager* dock_manager;
61 DockSettings(DockManager* dock_manager):dock_manager(dock_manager)
63 synfigapp::Main::settings().add_domain(this,"dock");
66 virtual ~DockSettings()
68 synfigapp::Main::settings().remove_domain("dock");
70 #define SCALE_FACTOR (1280)
71 virtual bool get_value(const synfig::String& key_, synfig::String& value)const
73 int screen_w(Gdk::screen_width());
74 int screen_h(Gdk::screen_height());
76 if(key_.size()>6 && String(key_.begin(),key_.begin()+6)=="dialog")try
78 synfig::String key(key_.begin()+7,key_.end());
79 synfig::String::size_type separator=key.find_first_of('.');
80 int id(atoi(synfig::String(key.begin(),key.begin()+separator).c_str()));
81 key=synfig::String(key.begin()+separator+1,key.end());
83 DockDialog& dock_dialog(dock_manager->find_dock_dialog(id));
85 if(key=="contents_size")
87 dock_dialog.rebuild_sizes();
88 vector<int>::const_iterator iter(dock_dialog.get_dock_book_sizes().begin());
89 vector<int>::const_iterator end(dock_dialog.get_dock_book_sizes().end());
91 for(;iter!=end;++iter)
92 value+=strprintf("%d ",(*iter)*SCALE_FACTOR/screen_h);
97 int x,y; dock_dialog.get_position(x,y);
98 value=strprintf("%d %d",x*SCALE_FACTOR/screen_w,y*SCALE_FACTOR/screen_h);
103 int x,y; dock_dialog.get_size(x,y);
104 value=strprintf("%d %d",x*SCALE_FACTOR/screen_w,y*SCALE_FACTOR/screen_h);
109 value=dock_dialog.get_contents();
112 if(key=="comp_selector")
114 value=dock_dialog.get_composition_selector()?"1":"0";
117 }catch (...) { return false; }
118 return synfigapp::Settings::get_value(key_,value);
121 virtual bool set_value(const synfig::String& key_,const synfig::String& value)
123 int screen_w(Gdk::screen_width());
124 int screen_h(Gdk::screen_height());
126 if(key_.size()>6 && String(key_.begin(),key_.begin()+6)=="dialog")
128 synfig::String key(key_.begin()+7,key_.end());
129 synfig::String::size_type separator=key.find_first_of('.');
130 int id(atoi(synfig::String(key.begin(),key.begin()+separator).c_str()));
131 key=synfig::String(key.begin()+separator+1,key.end());
133 DockDialog& dock_dialog(dock_manager->find_dock_dialog(id));
135 if(key=="contents_size")
139 Gtk::IconSize::lookup(Gtk::IconSize(4),width,height);
141 String::size_type n=0;
142 String value_(value);
143 while(value_.size() && value_.size()>n){
144 value_=String(value_.begin()+n,value_.end());
146 if(!strscanf(value_,"%d",&size))
148 if (size > SCALE_FACTOR) size = SCALE_FACTOR - 150;
149 if (size < 0) size = 0;
150 size=size*screen_h/SCALE_FACTOR;
152 // prevent errors like this, by allowing space for at least the dockable's icon:
153 // ** CRITICAL **: clearlooks_style_draw_box_gap: assertion `height >= -1' failed
154 if (size < height + 9) size = height + 9;
156 data.push_back(size);
163 dock_dialog.set_dock_book_sizes(data);
167 synfig::error("Exception caught!!!");
175 if(!strscanf(value,"%d %d",&x, &y))
177 if (x > SCALE_FACTOR) x = SCALE_FACTOR - 150; if (x < 0) x = 0;
178 if (y > SCALE_FACTOR) y = SCALE_FACTOR - 150; if (y < 0) y = 0;
179 x=x*screen_w/SCALE_FACTOR;
180 y=y*screen_h/SCALE_FACTOR;
181 dock_dialog.move(x,y);
187 if(!strscanf(value,"%d %d",&x, &y))
189 if (x > SCALE_FACTOR) x = 150; if (x < 0) x = 0;
190 if (y > SCALE_FACTOR) y = 150; if (y < 0) y = 0;
191 x=x*screen_w/SCALE_FACTOR;
192 y=y*screen_h/SCALE_FACTOR;
193 dock_dialog.set_default_size(x,y);
194 dock_dialog.resize(x,y);
199 dock_dialog.set_contents(value);
202 if(key=="comp_selector")
204 if(value.empty() || value[0]=='0')
205 dock_dialog.set_composition_selector(false);
207 dock_dialog.set_composition_selector(true);
211 return synfigapp::Settings::set_value(key_,value);
214 virtual KeyList get_key_list()const
216 synfigapp::Settings::KeyList ret(synfigapp::Settings::get_key_list());
218 std::list<DockDialog*>::const_iterator iter;
219 for(iter=dock_manager->dock_dialog_list_.begin();iter!=dock_manager->dock_dialog_list_.end();++iter)
221 ret.push_back(strprintf("dialog.%d.contents",(*iter)->get_id()));
222 ret.push_back(strprintf("dialog.%d.comp_selector",(*iter)->get_id()));
223 ret.push_back(strprintf("dialog.%d.pos",(*iter)->get_id()));
224 ret.push_back(strprintf("dialog.%d.size",(*iter)->get_id()));
225 ret.push_back(strprintf("dialog.%d.contents_size",(*iter)->get_id()));
231 /* === M E T H O D S ======================================================= */
233 DockManager::DockManager():
234 dock_settings(new DockSettings(this))
238 DockManager::~DockManager()
240 while(!dock_dialog_list_.empty())
242 dock_dialog_list_.back()->close();
244 while(!dockable_list_.empty())
246 Dockable* dockable(dockable_list_.back());
247 // synfig::info("DockManager::~DockManager(): Deleting dockable \"%s\"",dockable->get_name().c_str());
248 dockable_list_.pop_back();
254 DockManager::register_dockable(Dockable& x)
256 dockable_list_.push_back(&x);
257 // synfig::info("DockManager::register_dockable(): Registered dockable \"%s\"",dockable_list_.back()->get_name().c_str());
258 signal_dockable_registered()(&x);
262 DockManager::unregister_dockable(Dockable& x)
264 std::list<Dockable*>::iterator iter;
265 for(iter=dockable_list_.begin();iter!=dockable_list_.end();++iter)
270 dockable_list_.erase(iter);
271 synfig::info("DockManager::unregister_dockable(): \"%s\" has been Unregistered",x.get_name().c_str());
279 DockManager::find_dockable(const synfig::String& x)
281 std::list<Dockable*>::iterator iter;
282 for(iter=dockable_list_.begin();iter!=dockable_list_.end();++iter)
283 if((*iter)->get_name()==x)
286 throw std::runtime_error("DockManager::find_dockable(): not found");
290 DockManager::present(synfig::String x)
294 find_dockable(x).present();
302 DockManager::find_dock_dialog(int id)
304 std::list<DockDialog*>::iterator iter;
305 for(iter=dock_dialog_list_.begin();iter!=dock_dialog_list_.end();++iter)
306 if((*iter)->get_id()==id)
309 DockDialog* dock_dialog(new DockDialog());
310 dock_dialog->set_id(id);
316 DockManager::find_dock_dialog(int id)const
318 std::list<DockDialog*>::const_iterator iter;
319 for(iter=dock_dialog_list_.begin();iter!=dock_dialog_list_.end();++iter)
320 if((*iter)->get_id()==id)
323 throw std::runtime_error("DockManager::find_dock_dialog(int id)const: not found");