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
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 ======================================================= */
32 #include "dockmanager.h"
35 #include "dockdialog.h"
36 #include <synfigapp/settings.h>
37 #include <synfigapp/main.h>
38 #include <gdkmm/general.h>
42 /* === U S I N G =========================================================== */
46 using namespace synfig;
47 using namespace studio;
49 /* === M A C R O S ========================================================= */
51 /* === P R O C E D U R E S ================================================= */
53 class studio::DockSettings : public synfigapp::Settings
55 DockManager* dock_manager;
58 DockSettings(DockManager* dock_manager):dock_manager(dock_manager)
60 synfigapp::Main::settings().add_domain(this,"dock");
63 virtual ~DockSettings()
65 synfigapp::Main::settings().remove_domain("dock");
67 #define SCALE_FACTOR (1280)
68 virtual bool get_value(const synfig::String& key_, synfig::String& value)const
70 int screen_w(Gdk::screen_width());
71 int screen_h(Gdk::screen_height());
73 if(key_.size()>6 && String(key_.begin(),key_.begin()+6)=="dialog")try
75 synfig::String key(key_.begin()+7,key_.end());
76 synfig::String::size_type separator=key.find_first_of('.');
77 int id(atoi(synfig::String(key.begin(),key.begin()+separator).c_str()));
78 key=synfig::String(key.begin()+separator+1,key.end());
80 DockDialog& dock_dialog(dock_manager->find_dock_dialog(id));
82 if(key=="contents_size")
84 dock_dialog.rebuild_sizes();
85 vector<int>::const_iterator iter(dock_dialog.get_dock_book_sizes().begin());
86 vector<int>::const_iterator end(dock_dialog.get_dock_book_sizes().end());
88 for(;iter!=end;++iter)
89 value+=strprintf("%d ",(*iter)*SCALE_FACTOR/screen_h);
94 int x,y; dock_dialog.get_position(x,y);
95 value=strprintf("%d %d",x*SCALE_FACTOR/screen_w,y*SCALE_FACTOR/screen_h);
100 int x,y; dock_dialog.get_size(x,y);
101 value=strprintf("%d %d",x*SCALE_FACTOR/screen_w,y*SCALE_FACTOR/screen_h);
106 value=dock_dialog.get_contents();
109 if(key=="comp_selector")
111 value=dock_dialog.get_composition_selector()?"1":"0";
114 }catch (...) { return false; }
115 return synfigapp::Settings::get_value(key_,value);
118 virtual bool set_value(const synfig::String& key_,const synfig::String& value)
120 int screen_w(Gdk::screen_width());
121 int screen_h(Gdk::screen_height());
123 if(key_.size()>6 && String(key_.begin(),key_.begin()+6)=="dialog")
125 synfig::String key(key_.begin()+7,key_.end());
126 synfig::String::size_type separator=key.find_first_of('.');
127 int id(atoi(synfig::String(key.begin(),key.begin()+separator).c_str()));
128 key=synfig::String(key.begin()+separator+1,key.end());
130 DockDialog& dock_dialog(dock_manager->find_dock_dialog(id));
132 if(key=="contents_size")
137 String::size_type n=0;
138 String value_(value);
139 while(value_.size() && (signed)value_.size()>n && n>=0){
140 value_=String(value_.begin()+n,value_.end());
142 if(!strscanf(value_,"%d",&size))
144 size=size*screen_h/SCALE_FACTOR;
145 data.push_back(size);
152 dock_dialog.set_dock_book_sizes(data);
156 synfig::error("Exception caught!!!");
164 if(!strscanf(value,"%d %d",&x, &y))
166 x=x*screen_w/SCALE_FACTOR;
167 y=y*screen_h/SCALE_FACTOR;
168 dock_dialog.move(x,y);
174 if(!strscanf(value,"%d %d",&x, &y))
176 x=x*screen_w/SCALE_FACTOR;
177 y=y*screen_h/SCALE_FACTOR;
178 dock_dialog.set_default_size(x,y);
179 dock_dialog.resize(x,y);
184 dock_dialog.set_contents(value);
187 if(key=="comp_selector")
189 if(value.empty() || value[0]=='0')
190 dock_dialog.set_composition_selector(false);
192 dock_dialog.set_composition_selector(true);
196 return synfigapp::Settings::set_value(key_,value);
199 virtual KeyList get_key_list()const
201 synfigapp::Settings::KeyList ret(synfigapp::Settings::get_key_list());
203 std::list<DockDialog*>::const_iterator iter;
204 for(iter=dock_manager->dock_dialog_list_.begin();iter!=dock_manager->dock_dialog_list_.end();++iter)
206 ret.push_back(strprintf("dialog.%d.contents",(*iter)->get_id()));
207 ret.push_back(strprintf("dialog.%d.comp_selector",(*iter)->get_id()));
208 ret.push_back(strprintf("dialog.%d.pos",(*iter)->get_id()));
209 ret.push_back(strprintf("dialog.%d.size",(*iter)->get_id()));
210 ret.push_back(strprintf("dialog.%d.contents_size",(*iter)->get_id()));
216 /* === M E T H O D S ======================================================= */
218 DockManager::DockManager():
219 dock_settings(new DockSettings(this))
223 DockManager::~DockManager()
225 while(!dock_dialog_list_.empty())
227 dock_dialog_list_.back()->close();
229 while(!dockable_list_.empty())
231 Dockable* dockable(dockable_list_.back());
232 synfig::info("DockManager::~DockManager(): Deleting dockable \"%s\"",dockable->get_name().c_str());
233 dockable_list_.pop_back();
239 DockManager::register_dockable(Dockable& x)
241 dockable_list_.push_back(&x);
242 synfig::info("DockManager::register_dockable(): Registered dockable \"%s\"",dockable_list_.back()->get_name().c_str());
243 signal_dockable_registered()(&x);
247 DockManager::unregister_dockable(Dockable& x)
249 std::list<Dockable*>::iterator iter;
250 for(iter=dockable_list_.begin();iter!=dockable_list_.end();++iter)
255 dockable_list_.erase(iter);
256 synfig::info("DockManager::unregister_dockable(): \"%s\" has been Unregistered",x.get_name().c_str());
264 DockManager::find_dockable(const synfig::String& x)
266 std::list<Dockable*>::iterator iter;
267 for(iter=dockable_list_.begin();iter!=dockable_list_.end();++iter)
268 if((*iter)->get_name()==x)
271 throw std::runtime_error("DockManager::find_dockable(): not found");
275 DockManager::present(synfig::String x)
279 find_dockable(x).present();
287 DockManager::find_dock_dialog(int id)
289 std::list<DockDialog*>::iterator iter;
290 for(iter=dock_dialog_list_.begin();iter!=dock_dialog_list_.end();++iter)
291 if((*iter)->get_id()==id)
294 DockDialog* dock_dialog(new DockDialog());
295 dock_dialog->set_id(id);
301 DockManager::find_dock_dialog(int id)const
303 std::list<DockDialog*>::const_iterator iter;
304 for(iter=dock_dialog_list_.begin();iter!=dock_dialog_list_.end();++iter)
305 if((*iter)->get_id()==id)
308 throw std::runtime_error("DockManager::find_dock_dialog(int id)const: not found");