]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiImplementation.C
remove unused function
[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 #include <QApplication>
28
29 using boost::shared_ptr;
30
31
32 namespace
33 {
34         template<class T>
35         void updateIds(std::map<int, T*> const & stdmap, std::vector<int> & ids) 
36         {
37                 ids.clear();
38                 typename std::map<int, T*>::const_iterator it;
39                 for (it = stdmap.begin(); it != stdmap.end(); ++it)
40                         ids.push_back(it->first);
41         }
42 }
43
44
45 namespace lyx {
46 namespace frontend {
47
48
49 GuiImplementation::GuiImplementation()
50 {
51         view_ids_.clear();
52         work_area_ids_.clear();
53 }
54
55
56 LyXView& GuiImplementation::createRegisteredView()
57 {
58         updateIds(views_, view_ids_);
59         int id = 0;
60         while (views_.find(id) != views_.end())
61                 id++;
62         views_.insert(std::pair<int, GuiView *>(id, new GuiView(id)));
63         updateIds(views_, view_ids_);
64         return *views_[id];
65 }
66
67
68 bool GuiImplementation::unregisterView(int id)
69 {
70         updateIds(views_, view_ids_);
71         BOOST_ASSERT(views_.find(id) != views_.end());
72         BOOST_ASSERT(views_[id]);
73
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]);
80                         views_.erase(id);
81                         break;
82                 }
83         }
84         updateIds(views_, view_ids_);
85         return true;
86 }
87
88
89 bool GuiImplementation::closeAllViews()
90 {
91         updateIds(views_, view_ids_);
92         if (views_.empty())
93         {
94                 // quit in CloseEvent will not be triggert
95                 qApp->quit();
96                 return true;
97         }
98
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)
102         {
103                 it->second->close();
104                 // unregisterd by the CloseEvent
105         }
106
107         views_.clear();
108         work_areas_.clear();
109         view_ids_.clear();
110         work_area_ids_.clear();
111         return true;
112 }
113
114
115 LyXView& GuiImplementation::view(int id) const
116 {
117         BOOST_ASSERT(views_.find(id) != views_.end());
118         return *views_.find(id)->second;
119 }
120
121
122 std::vector<int> const & GuiImplementation::workAreaIds()
123 {
124         updateIds(work_areas_, work_area_ids_);
125         return work_area_ids_;
126 }
127
128
129 int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int view_id)
130 {
131         updateIds(views_, view_ids_);
132         int id = 0;
133         while (work_areas_.find(id) != work_areas_.end())
134                 id++;
135
136         GuiView * view = views_[view_id];
137
138         work_areas_.insert(std::pair<int, GuiWorkArea *>
139                                         (id, new GuiWorkArea(w, h, id, *view)));
140
141         // FIXME BufferView creation should be independant of WorkArea creation
142         buffer_views_[id].reset(new BufferView);
143         work_areas_[id]->setBufferView(buffer_views_[id].get());
144
145         view->setWorkArea(work_areas_[id]);
146         view->initTab(work_areas_[id]);
147         work_areas_[id]->setFocus();
148
149         return id;
150 }
151
152
153 WorkArea& GuiImplementation::workArea(int id)
154 {
155         BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
156         return *work_areas_[id];
157 }
158
159
160 } // namespace frontend
161 } // namespace lyx
162
163 #include "GuiImplementation_moc.cpp"