]> git.lyx.org Git - lyx.git/blob - src/frontends/Application.C
enable Font cache only for MacOSX and inline width() for other platform.
[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 "Application.h"
14
15 #include "Gui.h"
16 #include "LyXView.h"
17 #include "WorkArea.h"
18
19 #include "bufferlist.h"
20 #include "funcrequest.h"
21 #include "LyXAction.h"
22 #include "lyxfunc.h"
23 #include "lyxrc.h"
24 #include "lyxserver.h"
25 #include "lyxsocket.h"
26
27 #include "support/lstrings.h"
28 #include "support/os.h"
29 #include "support/package.h"
30
31
32 using lyx::support::package;
33
34 namespace lyx {
35 namespace frontend {
36
37 /// The main application class private implementation.
38 struct Application_pimpl 
39 {
40         ///
41         BufferList buffer_list_;
42         /// our function handler
43         boost::scoped_ptr<LyXFunc> lyxfunc_;
44         ///
45         boost::scoped_ptr<LyXServer> lyx_server_;
46         ///
47         boost::scoped_ptr<LyXServerSocket> lyx_socket_;
48 };
49
50
51 Application::Application(int &, char **)
52 {
53         pimpl_ = new Application_pimpl;
54 }
55
56
57 LyXFunc & Application::lyxFunc()
58 {
59         return *pimpl_->lyxfunc_.get();
60 }
61
62
63 LyXFunc const & Application::lyxFunc() const
64 {
65         return *pimpl_->lyxfunc_.get(); 
66 }
67
68
69 LyXServer & Application::server()
70 {
71         return *pimpl_->lyx_server_.get(); 
72 }
73
74
75 LyXServer const & Application::server() const 
76 {
77         return *pimpl_->lyx_server_.get(); 
78 }
79
80
81 LyXServerSocket & Application::socket()
82 {
83         return *pimpl_->lyx_socket_.get();
84 }
85
86
87 LyXServerSocket const & Application::socket() const
88 {
89         return *pimpl_->lyx_socket_.get();
90 }
91
92
93 BufferList & Application::bufferList()
94 {
95         return pimpl_->buffer_list_;
96 }
97
98
99 BufferList const & Application::bufferList() const
100 {
101         return pimpl_->buffer_list_;
102 }
103
104
105 void Application::setBufferView(BufferView * buffer_view)
106 {
107         buffer_view_ = buffer_view;
108 }
109
110
111 LyXView & Application::createView(unsigned int width,
112                                                                   unsigned int height,
113                                                                   int posx, int posy,
114                                                                   bool maximize)
115 {
116         // FIXME: please confirm: with unicode, I think initEncoding()
117         // is not needed anymore!
118         
119         // this can't be done before because it needs the Languages object
120         //initEncodings();
121
122         int view_id = gui().newView(width, height);
123         LyXView & view = gui().view(view_id);
124
125         pimpl_->lyxfunc_.reset(new LyXFunc(&view));
126
127         // FIXME: for now we assume that there is only one LyXView with id = 0.
128         /*int workArea_id_ =*/ gui().newWorkArea(width, height, 0);
129         //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_);
130
131         view.init();
132         view.setGeometry(width, height, posx, posy, maximize);
133
134         return view;
135 }
136
137
138 int Application::start(std::string const & batch)
139 {
140         pimpl_->lyx_server_.reset(new LyXServer(pimpl_->lyxfunc_.get(), lyxrc.lyxpipes));
141         pimpl_->lyx_socket_.reset(new LyXServerSocket(pimpl_->lyxfunc_.get(), 
142                 lyx::support::os::internal_path(package().temp_dir() + "/lyxsocket")));
143
144         // handle the batch commands the user asked for
145         if (!batch.empty()) {
146                 pimpl_->lyxfunc_->dispatch(lyxaction.lookupFunc(batch));
147         }
148
149         return exec();
150 }
151
152
153 } // namespace frontend
154 } // namespace lyx