3 * \file GuiImplementation.cpp
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
15 // This include must be declared before everything else because
16 // of boost/Qt/LyX clash...
19 #include "GuiImplementation.h"
20 #include "GuiWorkArea.h"
22 #include "BufferView.h"
23 #include "BufferList.h"
24 #include "FuncRequest.h"
27 #include <QApplication>
29 using boost::shared_ptr;
35 void updateIds(std::map<int, T*> const & stdmap, std::vector<int> & ids)
38 typename std::map<int, T*>::const_iterator it;
39 for (it = stdmap.begin(); it != stdmap.end(); ++it)
40 ids.push_back(it->first);
49 GuiImplementation::GuiImplementation()
52 work_area_ids_.clear();
56 LyXView& GuiImplementation::createRegisteredView()
58 updateIds(views_, view_ids_);
60 while (views_.find(id) != views_.end())
62 views_.insert(std::pair<int, GuiView *>(id, new GuiView(id)));
63 updateIds(views_, view_ids_);
68 bool GuiImplementation::unregisterView(int id)
70 updateIds(views_, view_ids_);
71 BOOST_ASSERT(views_.find(id) != views_.end());
72 BOOST_ASSERT(views_[id]);
74 std::map<int, GuiView *>::iterator it;
75 for (it = views_.begin(); it != views_.end(); ++it) {
76 if (it->first == id) {
77 std::vector<int> const & wa_ids = it->second->workAreaIds();
78 for (size_t i = 0; i < wa_ids.size(); ++i)
79 work_areas_.erase(wa_ids[i]);
84 updateIds(views_, view_ids_);
89 bool GuiImplementation::closeAllViews()
91 updateIds(views_, view_ids_);
94 // quit in CloseEvent will not be triggert
99 std::map<int, GuiView*> const cmap = views_;
100 std::map<int, GuiView*>::const_iterator it;
101 for (it = cmap.begin(); it != cmap.end(); ++it)
103 // TODO: return false when close event was ignored
104 // e.g. quitWriteAll()->'Cancel'
105 // maybe we need something like 'bool closeView()'
107 // unregisterd by the CloseEvent
113 work_area_ids_.clear();
118 LyXView& GuiImplementation::view(int id) const
120 BOOST_ASSERT(views_.find(id) != views_.end());
121 return *views_.find(id)->second;
125 std::vector<int> const & GuiImplementation::workAreaIds()
127 updateIds(work_areas_, work_area_ids_);
128 return work_area_ids_;
132 int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int view_id)
134 updateIds(views_, view_ids_);
136 while (work_areas_.find(id) != work_areas_.end())
139 GuiView * view = views_[view_id];
141 work_areas_.insert(std::pair<int, GuiWorkArea *>
142 (id, new GuiWorkArea(w, h, id, *view)));
144 // FIXME BufferView creation should be independant of WorkArea creation
145 buffer_views_[id].reset(new BufferView);
146 work_areas_[id]->setBufferView(buffer_views_[id].get());
148 view->setWorkArea(work_areas_[id]);
149 view->initTab(work_areas_[id]);
155 WorkArea& GuiImplementation::workArea(int id)
157 BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
158 return *work_areas_[id];
162 } // namespace frontend
165 #include "GuiImplementation_moc.cpp"