]> git.lyx.org Git - lyx.git/blob - src/frontends/Application.h
bfe4a9229f924925cf30880c98f0e4bb68caef4b
[lyx.git] / src / frontends / Application.h
1 /**
2  * \file frontend/Application.h
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 #ifndef LYX_APPLICATION_H
12 #define LYX_APPLICATION_H
13
14 #include <boost/function.hpp>
15
16 #include <string>
17
18 namespace lyx {
19
20 class BufferView;
21 class LyXView;
22 class Color_color;
23 struct RGBColor;
24
25 namespace frontend {
26
27 class Clipboard;
28 class FontLoader;
29 class Gui;
30 class Selection;
31
32 /// The main application class
33 /**
34 There should be only one instance of this class. No Qt object
35 initialisation should be done before the instanciation of this class.
36
37 \todo The work areas handling could be moved to a base virtual class
38 common to all frontends.
39
40  Model/View/Controller separation in LyX:
41
42  1) The Model: \c Buffer
43
44  The Buffer is the in-memory representation of a LyX file format. The
45  Buffer does not (should not) have any information on what part of it
46  is represented on screen. There is one unique Buffer per opened LyX
47  file.
48
49
50  2) The Controller: \c BufferView / \c Painter
51
52  The BufferView is a tool used by the view that translates a part of
53  the Buffer contents into drawing routines. The BufferView asks each
54  inset of the Buffer to draw itself onto the screen using the Painter.
55  There can be only one Buffer displayed in a BufferView. While there
56  is the possibility to switch Buffer inside the BufferView, the goal
57  is to instantiate a new BufferView on each Buffer switch.
58
59  \todo Instantiate a new BufferView on each Buffer switch.
60
61  The \c Painter is just a virtual interface to formalize each kind of
62  drawing routines (text, line, rectangle, etc).
63
64  The \c BufferView also contains a Cursor which may or may not be
65  visible on screen. The cursor is really just a bookmark to remember
66  where the next Buffer insertion/deletion is going to take place.
67
68
69  3) The View: \c WorkArea (and it's qt4 specialisation GuiWorkArea)
70
71  This contains the real screen area where the drawing is done by the
72  Painter. One WorkArea holds one unique \c BufferView. While it could be
73  possible that multiple WorkArea share one BufferView, this is not
74  possible right now.
75  The WorkArea also provide a scrollbar which position is translated
76  into scrolling command to the inner \c BufferView.
77
78  The WorkArea use the BufferView to translate each keyboard or mouse
79  events into terms that the Buffer can understand:
80  - insert/delete char
81  - select char
82  - etc.
83
84
85  4) The Window: \c LyXView (and its qt4 specialisation \c GuiView)
86
87  This is a full window containing a menubar, toolbars, a tabbar and a
88  WorkArea. One LyXView could in theory contain multiple WorkArea
89  (ex: with split window) but this number is limited to one only for
90  now. In any case, there would be only one WorkArea that gets the focus
91  at a time.
92
93  Now, concerning the TabBar versus TabWidget issue. Right now, there is
94  only one WorkArea and the TabBar just used to tell the BufferView inside
95  the WorkArea to switch to this another Buffer.
96
97  With a TabWidget, each Tab would own its own \c WorkArea. Clicking on a tab
98  would switch a WorkArea instead of a Buffer.
99 */
100 class Application
101 {
102 public:
103         ///
104         Application(int & argc, char ** argv);
105         ///
106         virtual ~Application() {}
107
108         ///
109         virtual Gui & gui() = 0;
110
111         /// Start the main event loop.
112         /// The batch command is programmed to be execute once
113         /// the event loop is started.
114         virtual int const exec() = 0;
115
116         /// Quit running LyX.
117         /**
118         * This may either quit directly or record the exit status
119         * and only stop the event loop.
120         */
121         virtual void exit(int status) = 0;
122
123         /**
124         * Synchronise all pending events.
125         */
126         virtual void syncEvents() = 0;
127         ///
128         virtual Clipboard & clipboard() = 0;
129         ///
130         virtual Selection & selection() = 0;
131         ///
132         virtual FontLoader & fontLoader() = 0;
133
134         /// return a suitable serif font name.
135         virtual std::string const romanFontName() = 0;
136
137         /// return a suitable sans serif font name.
138         virtual std::string const sansFontName() = 0;
139
140         /// return a suitable monospaced font name.
141         virtual std::string const typewriterFontName() = 0;
142
143         /**
144         * Given col, fills r, g, b in the range 0-255.
145         * The function returns true if successful.
146         * It returns false on failure and sets r, g, b to 0.
147         */
148         virtual bool getRgbColor(Color_color col, RGBColor & rgbcol) = 0;
149
150         /** Eg, passing Color::black returns "000000",
151         *      passing Color::white returns "ffffff".
152         */
153         virtual std::string const hexName(Color_color col) = 0;
154
155         /**
156         * update an altered GUI color
157         */
158         virtual void updateColor(Color_color col) = 0;
159
160         /**
161         * add a callback for socket read notification
162         * @param fd socket descriptor (file/socket/etc)
163         */
164         virtual void registerSocketCallback(
165                 int fd, boost::function<void()> func) = 0;
166
167         /**
168         * remove a I/O read callback
169         * @param fd socket descriptor (file/socket/etc)
170         */
171         virtual void unregisterSocketCallback(int fd) = 0;
172
173         /// Create the main window with given geometry settings.
174         LyXView & createView(unsigned int width, unsigned int height,
175                 int posx, int posy, int maximized,
176                 unsigned int iconSizeXY, const std::string & geometryArg);
177
178         ///
179         LyXView const * currentView() const;
180
181         ///
182         LyXView * currentView();
183
184         ///
185         void setCurrentView(LyXView & current_view);
186
187 private:
188         /// This LyXView is the one receiving Clipboard and Selection
189         /// Events
190         LyXView * current_view_;
191
192 }; // Application
193
194 } // namespace frontend
195
196 frontend::Application * theApp();
197 frontend::Application * createApplication(int & argc, char * argv[]);
198
199
200 } // namespace lyx
201
202
203 #endif // LYX_APPLICATION_H