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"
36 using lyx::support::package;
41 /// The main application class private implementation.
42 struct Application_pimpl
45 BufferList buffer_list_;
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 BufferList & Application::bufferList()
99 return pimpl_->buffer_list_;
103 BufferList const & Application::bufferList() const
105 return pimpl_->buffer_list_;
109 void Application::setBufferView(BufferView * buffer_view)
111 buffer_view_ = buffer_view;
115 LyXView & Application::createView(unsigned int width,
120 // FIXME: please confirm: with unicode, I think initEncoding()
121 // is not needed anymore!
123 // this can't be done before because it needs the Languages object
126 int view_id = gui().newView(width, height);
127 LyXView & view = gui().view(view_id);
129 pimpl_->lyxfunc_.reset(new LyXFunc(&view));
131 // FIXME: for now we assume that there is only one LyXView with id = 0.
132 /*int workArea_id_ =*/ gui().newWorkArea(width, height, 0);
133 //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_);
136 view.setGeometry(width, height, posx, posy, maximize);
142 int Application::start(std::string const & batch)
144 pimpl_->lyx_server_.reset(new LyXServer(pimpl_->lyxfunc_.get(), lyxrc.lyxpipes));
145 pimpl_->lyx_socket_.reset(new LyXServerSocket(pimpl_->lyxfunc_.get(),
146 lyx::support::os::internal_path(package().temp_dir() + "/lyxsocket")));
148 // handle the batch commands the user asked for
149 if (!batch.empty()) {
150 pimpl_->lyxfunc_->dispatch(lyxaction.lookupFunc(batch));
157 } // namespace frontend
160 FuncStatus getStatus(FuncRequest const & action)
162 return theApp->lyxFunc().getStatus(action);
166 void dispatch(FuncRequest const & action)
168 theApp->lyxFunc().dispatch(action);
174 LyXFunc & theLyXFunc()
176 return theApp->lyxFunc();
180 BufferList & theBufferList()
182 return theApp->bufferList();
186 lyx::frontend::FontLoader & theFontLoader()
188 return theApp->fontLoader();
192 lyx::frontend::FontMetrics const & theFontMetrics(LyXFont const & f)
194 return theApp->fontLoader().metrics(f);
198 lyx::frontend::Clipboard & theClipboard()
200 return theApp->clipboard();
204 lyx::frontend::Selection & theSelection()
206 return theApp->selection();