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()
60 if (!theBufferList().quitWriteAll())
63 // In order to know if it is the last opened window,
64 // GuiView::closeEvent() check for (view_ids_.size() == 1)
65 // We deny this check by setting the vector size to zero.
66 // But we still need the vector, hence the temporary copy.
67 std::vector<int> view_ids_tmp = view_ids_;
70 for (size_t i = 0; i < view_ids_tmp.size(); ++i) {
71 // LFUN_LYX_QUIT has already been triggered so we need
72 // to disable the lastWindowClosed() signal before closing
74 views_[view_ids_tmp[i]]->setAttribute(Qt::WA_QuitOnClose, false);
75 views_[view_ids_tmp[i]]->close();
76 // The view_ids_ vector is reconstructed in the closeEvent; so
77 // let's clear that out again!
89 void GuiImplementation::unregisterView(GuiView * view)
91 std::map<int, GuiView *>::iterator I;
93 for (I = views_.begin(); I != views_.end(); ++I) {
94 if (I->second == view) {
95 std::vector<int> const & wa_ids = view->workAreaIds();
96 for (size_t i = 0; i < wa_ids.size(); ++i)
97 work_areas_.erase(wa_ids[i]);
99 views_.erase(I->first);
106 if (views_.empty()) {
107 theLyXFunc().setLyXView(0);
108 // dispatch(FuncRequest(LFUN_LYX_QUIT));
112 theLyXFunc().setLyXView(views_.begin()->second);
116 void GuiImplementation::buildViewIds()
119 std::map<int, GuiView *>::const_iterator I;
120 for (I = views_.begin(); I != views_.end(); ++I)
121 view_ids_.push_back(I->first);
125 int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int view_id)
127 size_t const id = max_wa_id_;
130 GuiView * view = views_[view_id];
132 work_areas_[id] = new GuiWorkArea(w, h, id, *view);
134 // FIXME BufferView creation should be independant of WorkArea creation
135 buffer_views_[id].reset(new BufferView);
136 work_areas_[id]->setBufferView(buffer_views_[id].get());
137 view->setWorkArea(work_areas_[id]);
139 view->setCentralWidget(work_areas_[id]);
145 WorkArea& GuiImplementation::workArea(int id)
147 BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
149 return *work_areas_[id];
153 } // namespace frontend
156 #include "GuiImplementation_moc.cpp"