]> git.lyx.org Git - features.git/blob - src/frontends/Application.C
5b8d846b596e8cbd5cc077954099c74dfd32adb7
[features.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         /// our function handler
45         boost::scoped_ptr<LyXFunc> lyxfunc_;
46         ///
47         boost::scoped_ptr<LyXServer> lyx_server_;
48         ///
49         boost::scoped_ptr<LyXServerSocket> lyx_socket_;
50 };
51
52
53 Application::Application(int &, char **)
54 {
55         pimpl_ = new Application_pimpl;
56 }
57
58
59 LyXFunc & Application::lyxFunc()
60 {
61         return *pimpl_->lyxfunc_.get();
62 }
63
64
65 LyXFunc const & Application::lyxFunc() const
66 {
67         return *pimpl_->lyxfunc_.get(); 
68 }
69
70
71 LyXServer & Application::server()
72 {
73         return *pimpl_->lyx_server_.get(); 
74 }
75
76
77 LyXServer const & Application::server() const 
78 {
79         return *pimpl_->lyx_server_.get(); 
80 }
81
82
83 LyXServerSocket & Application::socket()
84 {
85         return *pimpl_->lyx_socket_.get();
86 }
87
88
89 LyXServerSocket const & Application::socket() const
90 {
91         return *pimpl_->lyx_socket_.get();
92 }
93
94
95 void Application::setBufferView(BufferView * buffer_view)
96 {
97         buffer_view_ = buffer_view;
98 }
99
100
101 LyXView & Application::createView(unsigned int width,
102                                                                   unsigned int height,
103                                                                   int posx, int posy,
104                                                                   bool maximize)
105 {
106         // FIXME: please confirm: with unicode, I think initEncoding()
107         // is not needed anymore!
108         
109         // this can't be done before because it needs the Languages object
110         //initEncodings();
111
112         int view_id = gui().newView(width, height);
113         LyXView & view = gui().view(view_id);
114
115         pimpl_->lyxfunc_.reset(new LyXFunc(&view));
116
117         // FIXME: for now we assume that there is only one LyXView with id = 0.
118         /*int workArea_id_ =*/ gui().newWorkArea(width, height, 0);
119         //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_);
120
121         view.init();
122         view.setGeometry(width, height, posx, posy, maximize);
123
124         return view;
125 }
126
127
128 int Application::start(std::string const & batch)
129 {
130         pimpl_->lyx_server_.reset(new LyXServer(pimpl_->lyxfunc_.get(), lyxrc.lyxpipes));
131         pimpl_->lyx_socket_.reset(new LyXServerSocket(pimpl_->lyxfunc_.get(), 
132                 lyx::support::os::internal_path(package().temp_dir() + "/lyxsocket")));
133
134         // handle the batch commands the user asked for
135         if (!batch.empty()) {
136                 pimpl_->lyxfunc_->dispatch(lyxaction.lookupFunc(batch));
137         }
138
139         return exec();
140 }
141
142
143 } // namespace frontend
144
145
146 FuncStatus getStatus(FuncRequest const & action)
147 {
148         return theApp->lyxFunc().getStatus(action);
149 }
150
151
152 void dispatch(FuncRequest const & action)
153 {
154         theApp->lyxFunc().dispatch(action);
155 }
156
157 } // namespace lyx
158
159
160 LyXFunc & theLyXFunc()
161 {
162         return theApp->lyxFunc();
163 }
164
165
166 lyx::frontend::FontLoader & theFontLoader()
167 {
168         return theApp->fontLoader();
169 }
170
171
172 lyx::frontend::FontMetrics const & theFontMetrics(LyXFont const & f)
173 {
174         return theApp->fontLoader().metrics(f);
175 }
176
177
178 lyx::frontend::Clipboard & theClipboard()
179 {
180         return theApp->clipboard();
181 }
182
183
184 lyx::frontend::Selection & theSelection()
185 {
186         return theApp->selection();
187 }