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.
6 * \author Abdelrazak Younes
8 * Full author contact details are available in file CREDITS.
13 #include "frontends/Application.h"
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"
23 #include "bufferlist.h"
24 #include "funcrequest.h"
25 #include "FuncStatus.h"
27 #include "LyXAction.h"
31 #include "lyxserver.h"
32 #include "lyxsocket.h"
34 #include "support/lstrings.h"
35 #include "support/os.h"
36 #include "support/package.h"
38 #include <boost/scoped_ptr.hpp>
39 #include <boost/shared_ptr.hpp>
41 using lyx::support::package;
46 /// The main application class private implementation.
47 struct Application_pimpl
49 /// our function handler
50 boost::scoped_ptr<LyXFunc> lyxfunc_;
52 boost::scoped_ptr<LyXServer> lyx_server_;
54 boost::scoped_ptr<LyXServerSocket> lyx_socket_;
58 Application::Application(int &, char **)
60 pimpl_ = new Application_pimpl;
64 LyXFunc & Application::lyxFunc()
66 return *pimpl_->lyxfunc_.get();
70 LyXFunc const & Application::lyxFunc() const
72 return *pimpl_->lyxfunc_.get();
76 LyXServer & Application::server()
78 return *pimpl_->lyx_server_.get();
82 LyXServer const & Application::server() const
84 return *pimpl_->lyx_server_.get();
88 LyXServerSocket & Application::socket()
90 return *pimpl_->lyx_socket_.get();
94 LyXServerSocket const & Application::socket() const
96 return *pimpl_->lyx_socket_.get();
100 void Application::setBufferView(BufferView * buffer_view)
102 buffer_view_ = buffer_view;
106 LyXView & Application::createView(unsigned int width,
111 // FIXME: please confirm: with unicode, I think initEncoding()
112 // is not needed anymore!
114 // this can't be done before because it needs the Languages object
117 int view_id = gui().newView();
118 LyXView & view = gui().view(view_id);
120 pimpl_->lyxfunc_.reset(new LyXFunc(&view));
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_);
127 view.setGeometry(width, height, posx, posy, maximize);
133 int Application::start(std::string const & batch)
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")));
139 // handle the batch commands the user asked for
140 if (!batch.empty()) {
141 pimpl_->lyxfunc_->dispatch(lyxaction.lookupFunc(batch));
147 } // namespace frontend
150 FuncStatus getStatus(FuncRequest const & action)
152 return theApp->lyxFunc().getStatus(action);
156 void dispatch(FuncRequest const & action)
158 theApp->lyxFunc().dispatch(action);
164 LyXFunc & theLyXFunc()
166 BOOST_ASSERT(theApp);
167 return theApp->lyxFunc();
171 lyx::frontend::FontLoader & theFontLoader()
173 static lyx::frontend::NoGuiFontLoader no_gui_font_loader;
176 return no_gui_font_loader;
178 BOOST_ASSERT(theApp);
179 return theApp->fontLoader();
183 lyx::frontend::FontMetrics const & theFontMetrics(LyXFont const & f)
185 static lyx::frontend::NoGuiFontMetrics no_gui_font_metrics;
188 return no_gui_font_metrics;
190 BOOST_ASSERT(theApp);
191 return theApp->fontLoader().metrics(f);
195 lyx::frontend::Clipboard & theClipboard()
197 BOOST_ASSERT(theApp);
198 return theApp->clipboard();
202 lyx::frontend::Selection & theSelection()
204 BOOST_ASSERT(theApp);
205 return theApp->selection();