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