]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiImplementation.C
Remove unused symbol encoding
[lyx.git] / src / frontends / qt4 / GuiImplementation.C
1 // -*- C++ -*-
2 /**
3  * \file GuiImplementation.C
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 // This include must be declared before everything else because
16 // of boost/Qt/LyX clash...
17 #include "GuiView.h"
18
19 #include "GuiImplementation.h"
20 #include "GuiWorkArea.h"
21
22 #include "BufferView.h"
23 #include "bufferlist.h"
24 #include "funcrequest.h"
25 #include "lyxfunc.h"
26
27 using boost::shared_ptr;
28
29 namespace lyx {
30 namespace frontend {
31
32
33 GuiImplementation::GuiImplementation(): max_view_id_(0), max_wa_id_(0)
34 {
35 }
36
37
38 int GuiImplementation::newView()
39 {
40         size_t const id = max_view_id_;
41         ++max_view_id_;
42
43         views_[id] = new GuiView(id);
44         view_ids_.push_back(id);
45
46         return id;
47 }
48
49
50 LyXView& GuiImplementation::view(int id)
51 {
52         BOOST_ASSERT(views_.find(id) != views_.end());
53
54         return *views_[id];
55 }
56
57
58 bool GuiImplementation::closeAll()
59 {
60         if (!theBufferList().quitWriteAll())
61                 return false;
62
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_;
68         view_ids_.clear();
69
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
73                 // the last window.
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!
78                 view_ids_.clear();
79         }
80
81         views_.clear();
82         view_ids_.clear();
83         work_areas_.clear();
84
85         return true;
86 }
87
88
89 void GuiImplementation::unregisterView(GuiView * view)
90 {
91         std::map<int, GuiView *>::iterator I;
92
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]);
98
99                         views_.erase(I->first);
100                         break;
101                 }
102         }
103
104         buildViewIds();
105
106         if (views_.empty()) {
107                 theLyXFunc().setLyXView(0);
108 //              dispatch(FuncRequest(LFUN_LYX_QUIT));
109                 return;
110         }
111
112         theLyXFunc().setLyXView(views_.begin()->second);
113 }
114
115
116 void GuiImplementation::buildViewIds()
117 {
118         view_ids_.clear();
119         std::map<int, GuiView *>::const_iterator I;
120         for (I = views_.begin(); I != views_.end(); ++I)
121                 view_ids_.push_back(I->first);
122 }
123
124
125 int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int view_id)
126 {
127         size_t const id = max_wa_id_;
128         ++max_wa_id_;
129
130         GuiView * view = views_[view_id];
131
132         work_areas_[id] = new GuiWorkArea(w, h, id, *view);
133
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
138         view->setWorkArea(work_areas_[id]);
139         view->initTab(work_areas_[id]);
140         work_areas_[id]->setFocus();
141
142         return id;
143 }
144
145
146 WorkArea& GuiImplementation::workArea(int id)
147 {
148         BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
149
150         return *work_areas_[id];
151 }
152
153
154 } // namespace frontend
155 } // namespace lyx
156
157 #include "GuiImplementation_moc.cpp"