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>
43 /* === U S I N G =========================================================== */
47 using namespace synfig;
48 using namespace studio;
50 /* === M A C R O S ========================================================= */
52 /* === P R O C E D U R E S ================================================= */
54 class studio::DockSettings : public synfigapp::Settings
56 DockManager* dock_manager;
59 DockSettings(DockManager* dock_manager):dock_manager(dock_manager)
61 synfigapp::Main::settings().add_domain(this,"dock");
64 virtual ~DockSettings()
66 synfigapp::Main::settings().remove_domain("dock");
68 #define SCALE_FACTOR (1280)
69 virtual bool get_value(const synfig::String& key_, synfig::String& value)const
71 int screen_w(Gdk::screen_width());
72 int screen_h(Gdk::screen_height());
74 if(key_.size()>6 && String(key_.begin(),key_.begin()+6)=="dialog")try
76 synfig::String key(key_.begin()+7,key_.end());
77 synfig::String::size_type separator=key.find_first_of('.');
78 int id(atoi(synfig::String(key.begin(),key.begin()+separator).c_str()));
79 key=synfig::String(key.begin()+separator+1,key.end());
81 DockDialog& dock_dialog(dock_manager->find_dock_dialog(id));
83 if(key=="contents_size")
85 dock_dialog.rebuild_sizes();
86 vector<int>::const_iterator iter(dock_dialog.get_dock_book_sizes().begin());
87 vector<int>::const_iterator end(dock_dialog.get_dock_book_sizes().end());
89 for(;iter!=end;++iter)
90 value+=strprintf("%d ",(*iter)*SCALE_FACTOR/screen_h);
95 int x,y; dock_dialog.get_position(x,y);
96 value=strprintf("%d %d",x*SCALE_FACTOR/screen_w,y*SCALE_FACTOR/screen_h);
101 int x,y; dock_dialog.get_size(x,y);
102 value=strprintf("%d %d",x*SCALE_FACTOR/screen_w,y*SCALE_FACTOR/screen_h);
107 value=dock_dialog.get_contents();
110 if(key=="comp_selector")
112 value=dock_dialog.get_composition_selector()?"1":"0";
115 }catch (...) { return false; }
116 return synfigapp::Settings::get_value(key_,value);
119 virtual bool set_value(const synfig::String& key_,const synfig::String& value)
121 int screen_w(Gdk::screen_width());
122 int screen_h(Gdk::screen_height());
124 if(key_.size()>6 && String(key_.begin(),key_.begin()+6)=="dialog")
126 synfig::String key(key_.begin()+7,key_.end());
127 synfig::String::size_type separator=key.find_first_of('.');
128 int id(atoi(synfig::String(key.begin(),key.begin()+separator).c_str()));
129 key=synfig::String(key.begin()+separator+1,key.end());
131 DockDialog& dock_dialog(dock_manager->find_dock_dialog(id));
133 if(key=="contents_size")
138 String::size_type n=0;
139 String value_(value);
140 while(value_.size() && value_.size()>n){
141 value_=String(value_.begin()+n,value_.end());
143 if(!strscanf(value_,"%d",&size))
145 size=size*screen_h/SCALE_FACTOR;
146 data.push_back(size);
153 dock_dialog.set_dock_book_sizes(data);
157 synfig::error("Exception caught!!!");
165 if(!strscanf(value,"%d %d",&x, &y))
167 x=x*screen_w/SCALE_FACTOR;
168 y=y*screen_h/SCALE_FACTOR;
169 dock_dialog.move(x,y);
175 if(!strscanf(value,"%d %d",&x, &y))
177 x=x*screen_w/SCALE_FACTOR;
178 y=y*screen_h/SCALE_FACTOR;
179 dock_dialog.set_default_size(x,y);
180 dock_dialog.resize(x,y);
185 dock_dialog.set_contents(value);
188 if(key=="comp_selector")
190 if(value.empty() || value[0]=='0')
191 dock_dialog.set_composition_selector(false);
193 dock_dialog.set_composition_selector(true);
197 return synfigapp::Settings::set_value(key_,value);
200 virtual KeyList get_key_list()const
202 synfigapp::Settings::KeyList ret(synfigapp::Settings::get_key_list());
204 std::list<DockDialog*>::const_iterator iter;
205 for(iter=dock_manager->dock_dialog_list_.begin();iter!=dock_manager->dock_dialog_list_.end();++iter)
207 ret.push_back(strprintf("dialog.%d.contents",(*iter)->get_id()));
208 ret.push_back(strprintf("dialog.%d.comp_selector",(*iter)->get_id()));
209 ret.push_back(strprintf("dialog.%d.pos",(*iter)->get_id()));
210 ret.push_back(strprintf("dialog.%d.size",(*iter)->get_id()));
211 ret.push_back(strprintf("dialog.%d.contents_size",(*iter)->get_id()));
217 /* === M E T H O D S ======================================================= */
219 DockManager::DockManager():
220 dock_settings(new DockSettings(this))
224 DockManager::~DockManager()
226 while(!dock_dialog_list_.empty())
228 dock_dialog_list_.back()->close();
230 while(!dockable_list_.empty())
232 Dockable* dockable(dockable_list_.back());
233 // synfig::info("DockManager::~DockManager(): Deleting dockable \"%s\"",dockable->get_name().c_str());
234 dockable_list_.pop_back();
240 DockManager::register_dockable(Dockable& x)
242 dockable_list_.push_back(&x);
243 // synfig::info("DockManager::register_dockable(): Registered dockable \"%s\"",dockable_list_.back()->get_name().c_str());
244 signal_dockable_registered()(&x);
248 DockManager::unregister_dockable(Dockable& x)
250 std::list<Dockable*>::iterator iter;
251 for(iter=dockable_list_.begin();iter!=dockable_list_.end();++iter)
256 dockable_list_.erase(iter);
257 synfig::info("DockManager::unregister_dockable(): \"%s\" has been Unregistered",x.get_name().c_str());
265 DockManager::find_dockable(const synfig::String& x)
267 std::list<Dockable*>::iterator iter;
268 for(iter=dockable_list_.begin();iter!=dockable_list_.end();++iter)
269 if((*iter)->get_name()==x)
272 throw std::runtime_error("DockManager::find_dockable(): not found");
276 DockManager::present(synfig::String x)
280 find_dockable(x).present();
288 DockManager::find_dock_dialog(int id)
290 std::list<DockDialog*>::iterator iter;
291 for(iter=dock_dialog_list_.begin();iter!=dock_dialog_list_.end();++iter)
292 if((*iter)->get_id()==id)
295 DockDialog* dock_dialog(new DockDialog());
296 dock_dialog->set_id(id);
302 DockManager::find_dock_dialog(int id)const
304 std::list<DockDialog*>::const_iterator iter;
305 for(iter=dock_dialog_list_.begin();iter!=dock_dialog_list_.end();++iter)
306 if((*iter)->get_id()==id)
309 throw std::runtime_error("DockManager::find_dock_dialog(int id)const: not found");