3 * \file GuiImplementation.C
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 using boost::shared_ptr;
33 GuiImplementation::GuiImplementation(): max_view_id_(0), max_wa_id_(0)
38 int GuiImplementation::newView()
40 size_t const id = max_view_id_;
43 views_[id] = new GuiView(id);
44 view_ids_.push_back(id);
50 LyXView& GuiImplementation::view(int id)
52 BOOST_ASSERT(views_.find(id) != views_.end());
58 bool GuiImplementation::closeAll()
61 if (!theBufferList().quitWriteAll())
64 // In order to know if it is the last opened window,
65 // GuiView::closeEvent() check for (view_ids_.size() == 1)
66 // We deny this check by setting the vector size to zero.
67 // But we still need the vector, hence the temporary copy.
68 std::vector<int> view_ids_tmp = view_ids_;
71 for (size_t i = 0; i < view_ids_tmp.size(); ++i) {
72 // LFUN_LYX_QUIT has already been triggered so we need
73 // to disable the lastWindowClosed() signal before closing
75 views_[view_ids_tmp[i]]->setAttribute(Qt::WA_QuitOnClose, false);
76 views_[view_ids_tmp[i]]->close();
77 // The view_ids_ vector is reconstructed in the closeEvent; so
78 // let's clear that out again!
90 void GuiImplementation::unregisterView(GuiView * view)
92 std::map<int, GuiView *>::iterator I;
94 for (I = views_.begin(); I != views_.end(); ++I) {
95 if (I->second == view) {
96 std::vector<int> const & wa_ids = view->workAreaIds();
97 for (size_t i = 0; i < wa_ids.size(); ++i)
98 work_areas_.erase(wa_ids[i]);
100 views_.erase(I->first);
107 if (views_.empty()) {
108 theLyXFunc().setLyXView(0);
109 dispatch(FuncRequest(LFUN_LYX_QUIT));
113 theLyXFunc().setLyXView(views_.begin()->second);
117 void GuiImplementation::buildViewIds()
120 std::map<int, GuiView *>::const_iterator I;
121 for (I = views_.begin(); I != views_.end(); ++I)
122 view_ids_.push_back(I->first);
126 int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int view_id)
128 size_t const id = max_wa_id_;
131 GuiView * view = views_[view_id];
133 work_areas_[id] = new GuiWorkArea(w, h, id, *view);
135 // FIXME BufferView creation should be independant of WorkArea creation
136 buffer_views_[id].reset(new BufferView);
137 work_areas_[id]->setBufferView(buffer_views_[id].get());
139 view->setWorkArea(work_areas_[id]);
140 view->initTab(work_areas_[id]);
141 work_areas_[id]->setFocus();
147 WorkArea& GuiImplementation::workArea(int id)
149 BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
151 return *work_areas_[id];
155 } // namespace frontend
158 #include "GuiImplementation_moc.cpp"