]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiImplementation.cpp
Fix mouse selection drawing by brute force.
[features.git] / src / frontends / qt4 / GuiImplementation.cpp
1 // -*- C++ -*-
2 /**
3  * \file GuiImplementation.cpp
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 #include "GuiImplementation.h"
16 #include "GuiView.h"
17 #include "Dialogs.h"
18
19 #include <boost/assert.hpp>
20
21 #include <QApplication>
22
23 using std::map;
24 using std::vector;
25 using std::string;
26
27
28 namespace lyx {
29 namespace frontend {
30
31
32 static void updateIds(map<int, GuiView *> const & stdmap, vector<int> & ids)
33 {
34         ids.clear();
35         map<int, GuiView *>::const_iterator it;
36         for (it = stdmap.begin(); it != stdmap.end(); ++it)
37                 ids.push_back(it->first);
38 }
39
40
41 GuiImplementation::GuiImplementation()
42 {
43         view_ids_.clear();
44 }
45
46
47 int GuiImplementation::createRegisteredView()
48 {
49         updateIds(views_, view_ids_);
50         int id = 0;
51         while (views_.find(id) != views_.end())
52                 id++;
53         views_[id] = new GuiView(id);
54         updateIds(views_, view_ids_);
55         return id;
56 }
57
58
59 bool GuiImplementation::unregisterView(int id)
60 {
61         updateIds(views_, view_ids_);
62         BOOST_ASSERT(views_.find(id) != views_.end());
63         BOOST_ASSERT(views_[id]);
64
65         map<int, GuiView *>::iterator it;
66         for (it = views_.begin(); it != views_.end(); ++it) {
67                 if (it->first == id) {
68                         views_.erase(id);
69                         break;
70                 }
71         }
72         updateIds(views_, view_ids_);
73         return true;
74 }
75
76
77 bool GuiImplementation::closeAllViews()
78 {
79         updateIds(views_, view_ids_);
80         if (views_.empty()) {
81                 // quit in CloseEvent will not be triggert
82                 qApp->quit();
83                 return true;
84         }
85
86         map<int, GuiView*> const cmap = views_;
87         map<int, GuiView*>::const_iterator it;
88         for (it = cmap.begin(); it != cmap.end(); ++it) {
89                 // TODO: return false when close event was ignored
90                 //       e.g. quitWriteAll()->'Cancel'
91                 //       maybe we need something like 'bool closeView()'
92                 it->second->close();
93                 // unregisterd by the CloseEvent
94         }
95
96         views_.clear();
97         view_ids_.clear();
98         return true;
99 }
100
101
102 LyXView & GuiImplementation::view(int id) const
103 {
104         BOOST_ASSERT(views_.find(id) != views_.end());
105         return *views_.find(id)->second;
106 }
107
108
109 void GuiImplementation::hideDialogs(string const & name, Inset * inset) const
110 {
111         vector<int>::const_iterator it = view_ids_.begin();
112         vector<int>::const_iterator const end = view_ids_.end();
113         for (; it != end; ++it)
114                 view(*it).getDialogs().hide(name, inset);
115 }
116
117
118 Buffer const * GuiImplementation::updateInset(Inset const * inset) const
119 {
120         Buffer const * buffer_ptr = 0;
121         vector<int>::const_iterator it = view_ids_.begin();
122         vector<int>::const_iterator const end = view_ids_.end();
123         for (; it != end; ++it) {
124                 Buffer const * ptr = view(*it).updateInset(inset);
125                 if (ptr)
126                         buffer_ptr = ptr;
127         }
128         return buffer_ptr;
129 }
130
131
132 } // namespace frontend
133 } // namespace lyx
134
135 #include "GuiImplementation_moc.cpp"