]> git.lyx.org Git - lyx.git/blob - src/frontends/Application.C
852dcdb5b1d29ec97ec09a9e41a63eb54e8586d8
[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 #include <boost/scoped_ptr.hpp>
36 #include <boost/shared_ptr.hpp>
37
38 using lyx::support::package;
39
40 namespace lyx {
41 namespace frontend {
42
43 /// The main application class private implementation.
44 struct Application_pimpl 
45 {
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 void Application::setBufferView(BufferView * buffer_view)
98 {
99         buffer_view_ = buffer_view;
100 }
101
102
103 LyXView & Application::createView(unsigned int width,
104                                                                   unsigned int height,
105                                                                   int posx, int posy,
106                                                                   bool maximize)
107 {
108         // FIXME: please confirm: with unicode, I think initEncoding()
109         // is not needed anymore!
110         
111         // this can't be done before because it needs the Languages object
112         //initEncodings();
113
114         int view_id = gui().newView();
115         LyXView & view = gui().view(view_id);
116
117         pimpl_->lyxfunc_.reset(new LyXFunc(&view));
118
119         // FIXME: for now we assume that there is only one LyXView with id = 0.
120         /*int workArea_id_ =*/ gui().newWorkArea(width, height, 0);
121         //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_);
122
123         view.init();
124         view.setGeometry(width, height, posx, posy, maximize);
125
126         return view;
127 }
128
129
130 int Application::start(std::string const & batch)
131 {
132         pimpl_->lyx_server_.reset(new LyXServer(pimpl_->lyxfunc_.get(), lyxrc.lyxpipes));
133         pimpl_->lyx_socket_.reset(new LyXServerSocket(pimpl_->lyxfunc_.get(), 
134                 lyx::support::os::internal_path(package().temp_dir() + "/lyxsocket")));
135
136         // handle the batch commands the user asked for
137         if (!batch.empty()) {
138                 pimpl_->lyxfunc_->dispatch(lyxaction.lookupFunc(batch));
139         }
140
141         return exec();
142 }
143
144 } // namespace frontend
145
146
147 FuncStatus getStatus(FuncRequest const & action)
148 {
149         return theApp->lyxFunc().getStatus(action);
150 }
151
152
153 void dispatch(FuncRequest const & action)
154 {
155         theApp->lyxFunc().dispatch(action);
156 }
157
158 } // namespace lyx
159
160
161 LyXFunc & theLyXFunc()
162 {
163         BOOST_ASSERT(theApp);
164         return theApp->lyxFunc();
165 }
166
167
168 lyx::frontend::FontLoader & theFontLoader()
169 {
170         BOOST_ASSERT(theApp);
171         return theApp->fontLoader();
172 }
173
174
175 lyx::frontend::FontMetrics const & theFontMetrics(LyXFont const & f)
176 {
177         BOOST_ASSERT(theApp);
178         return theApp->fontLoader().metrics(f);
179 }
180
181
182 lyx::frontend::Clipboard & theClipboard()
183 {
184         BOOST_ASSERT(theApp);
185         return theApp->clipboard();
186 }
187
188
189 lyx::frontend::Selection & theSelection()
190 {
191         BOOST_ASSERT(theApp);
192         return theApp->selection();
193 }
194