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/FontLoader.h"
16 #include "frontends/FontMetrics.h"
17 #include "frontends/Gui.h"
18 #include "frontends/LyXView.h"
19 #include "frontends/WorkArea.h"
21 #include "bufferlist.h"
22 #include "funcrequest.h"
23 #include "FuncStatus.h"
24 #include "LyXAction.h"
28 #include "lyxserver.h"
29 #include "lyxsocket.h"
31 #include "support/lstrings.h"
32 #include "support/os.h"
33 #include "support/package.h"
35 #include <boost/scoped_ptr.hpp>
36 #include <boost/shared_ptr.hpp>
38 using lyx::support::package;
43 /// The main application class private implementation.
44 struct Application_pimpl
46 /// our function handler
47 boost::scoped_ptr<LyXFunc> lyxfunc_;
49 boost::scoped_ptr<LyXServer> lyx_server_;
51 boost::scoped_ptr<LyXServerSocket> lyx_socket_;
55 Application::Application(int &, char **)
57 pimpl_ = new Application_pimpl;
61 LyXFunc & Application::lyxFunc()
63 return *pimpl_->lyxfunc_.get();
67 LyXFunc const & Application::lyxFunc() const
69 return *pimpl_->lyxfunc_.get();
73 LyXServer & Application::server()
75 return *pimpl_->lyx_server_.get();
79 LyXServer const & Application::server() const
81 return *pimpl_->lyx_server_.get();
85 LyXServerSocket & Application::socket()
87 return *pimpl_->lyx_socket_.get();
91 LyXServerSocket const & Application::socket() const
93 return *pimpl_->lyx_socket_.get();
97 void Application::setBufferView(BufferView * buffer_view)
99 buffer_view_ = buffer_view;
103 LyXView & Application::createView(unsigned int width,
108 // FIXME: please confirm: with unicode, I think initEncoding()
109 // is not needed anymore!
111 // this can't be done before because it needs the Languages object
114 int view_id = gui().newView();
115 LyXView & view = gui().view(view_id);
117 pimpl_->lyxfunc_.reset(new LyXFunc(&view));
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_);
124 view.setGeometry(width, height, posx, posy, maximize);
130 int Application::start(std::string const & batch)
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")));
136 // handle the batch commands the user asked for
137 if (!batch.empty()) {
138 pimpl_->lyxfunc_->dispatch(lyxaction.lookupFunc(batch));
144 } // namespace frontend
147 FuncStatus getStatus(FuncRequest const & action)
149 return theApp->lyxFunc().getStatus(action);
153 void dispatch(FuncRequest const & action)
155 theApp->lyxFunc().dispatch(action);
161 LyXFunc & theLyXFunc()
163 BOOST_ASSERT(theApp);
164 return theApp->lyxFunc();
168 lyx::frontend::FontLoader & theFontLoader()
170 BOOST_ASSERT(theApp);
171 return theApp->fontLoader();
175 lyx::frontend::FontMetrics const & theFontMetrics(LyXFont const & f)
177 BOOST_ASSERT(theApp);
178 return theApp->fontLoader().metrics(f);
182 lyx::frontend::Clipboard & theClipboard()
184 BOOST_ASSERT(theApp);
185 return theApp->clipboard();
189 lyx::frontend::Selection & theSelection()
191 BOOST_ASSERT(theApp);
192 return theApp->selection();