]> git.lyx.org Git - lyx.git/blob - src/frontends/Application.C
This commit cleans up everything related to singleton. The other important change...
[lyx.git] / src / frontends / Application.C
1 /**
2  * \file frontend/Application.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Abdelrazak Younes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "frontends/Application.h"
14
15 #include "frontends/FontLoader.h"
16 #include "frontends/FontMetrics.h"
17 #include "frontends/Gui.h"
18 #include "frontends/LyXView.h"
19 #include "frontends/WorkArea.h"
20
21 #include "bufferlist.h"
22 #include "funcrequest.h"
23 #include "FuncStatus.h"
24 #include "LyXAction.h"
25 #include "lyxfont.h"
26 #include "lyxfunc.h"
27 #include "lyxrc.h"
28 #include "lyxserver.h"
29 #include "lyxsocket.h"
30
31 #include "support/lstrings.h"
32 #include "support/os.h"
33 #include "support/package.h"
34
35
36 using lyx::support::package;
37
38 namespace lyx {
39 namespace frontend {
40
41 /// The main application class private implementation.
42 struct Application_pimpl 
43 {
44         ///
45         BufferList buffer_list_;
46         /// our function handler
47         boost::scoped_ptr<LyXFunc> lyxfunc_;
48         ///
49         boost::scoped_ptr<LyXServer> lyx_server_;
50         ///
51         boost::scoped_ptr<LyXServerSocket> lyx_socket_;
52 };
53
54
55 Application::Application(int &, char **)
56 {
57         pimpl_ = new Application_pimpl;
58 }
59
60
61 LyXFunc & Application::lyxFunc()
62 {
63         return *pimpl_->lyxfunc_.get();
64 }
65
66
67 LyXFunc const & Application::lyxFunc() const
68 {
69         return *pimpl_->lyxfunc_.get(); 
70 }
71
72
73 LyXServer & Application::server()
74 {
75         return *pimpl_->lyx_server_.get(); 
76 }
77
78
79 LyXServer const & Application::server() const 
80 {
81         return *pimpl_->lyx_server_.get(); 
82 }
83
84
85 LyXServerSocket & Application::socket()
86 {
87         return *pimpl_->lyx_socket_.get();
88 }
89
90
91 LyXServerSocket const & Application::socket() const
92 {
93         return *pimpl_->lyx_socket_.get();
94 }
95
96
97 BufferList & Application::bufferList()
98 {
99         return pimpl_->buffer_list_;
100 }
101
102
103 BufferList const & Application::bufferList() const
104 {
105         return pimpl_->buffer_list_;
106 }
107
108
109 void Application::setBufferView(BufferView * buffer_view)
110 {
111         buffer_view_ = buffer_view;
112 }
113
114
115 LyXView & Application::createView(unsigned int width,
116                                                                   unsigned int height,
117                                                                   int posx, int posy,
118                                                                   bool maximize)
119 {
120         // FIXME: please confirm: with unicode, I think initEncoding()
121         // is not needed anymore!
122         
123         // this can't be done before because it needs the Languages object
124         //initEncodings();
125
126         int view_id = gui().newView(width, height);
127         LyXView & view = gui().view(view_id);
128
129         pimpl_->lyxfunc_.reset(new LyXFunc(&view));
130
131         // FIXME: for now we assume that there is only one LyXView with id = 0.
132         /*int workArea_id_ =*/ gui().newWorkArea(width, height, 0);
133         //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_);
134
135         view.init();
136         view.setGeometry(width, height, posx, posy, maximize);
137
138         return view;
139 }
140
141
142 int Application::start(std::string const & batch)
143 {
144         pimpl_->lyx_server_.reset(new LyXServer(pimpl_->lyxfunc_.get(), lyxrc.lyxpipes));
145         pimpl_->lyx_socket_.reset(new LyXServerSocket(pimpl_->lyxfunc_.get(), 
146                 lyx::support::os::internal_path(package().temp_dir() + "/lyxsocket")));
147
148         // handle the batch commands the user asked for
149         if (!batch.empty()) {
150                 pimpl_->lyxfunc_->dispatch(lyxaction.lookupFunc(batch));
151         }
152
153         return exec();
154 }
155
156
157 } // namespace frontend
158
159
160 FuncStatus getStatus(FuncRequest const & action)
161 {
162         return theApp->lyxFunc().getStatus(action);
163 }
164
165
166 void dispatch(FuncRequest const & action)
167 {
168         theApp->lyxFunc().dispatch(action);
169 }
170
171 } // namespace lyx
172
173
174 LyXFunc & theLyXFunc()
175 {
176         return theApp->lyxFunc();
177 }
178
179
180 BufferList & theBufferList()
181 {
182         return theApp->bufferList();
183 }
184
185
186 lyx::frontend::FontLoader & theFontLoader()
187 {
188         return theApp->fontLoader();
189 }
190
191
192 lyx::frontend::FontMetrics const & theFontMetrics(LyXFont const & f)
193 {
194         return theApp->fontLoader().metrics(f);
195 }
196
197
198 lyx::frontend::Clipboard & theClipboard()
199 {
200         return theApp->clipboard();
201 }
202
203
204 lyx::frontend::Selection & theSelection()
205 {
206         return theApp->selection();
207 }