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