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.
6 * \author Abdelrazak Younes
8 * Full author contact details are available in file CREDITS.
11 #ifndef LYX_APPLICATION_H
12 #define LYX_APPLICATION_H
14 #include <boost/function.hpp>
32 /// The main application class
34 There should be only one instance of this class. No Qt object
35 initialisation should be done before the instanciation of this class.
37 \todo The work areas handling could be moved to a base virtual class
38 common to all frontends.
40 Model/View/Controller separation in LyX:
42 1) The Model: \c Buffer
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
50 2) The Controller: \c BufferView / \c Painter
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.
59 \todo Instantiate a new BufferView on each Buffer switch.
61 The \c Painter is just a virtual interface to formalize each kind of
62 drawing routines (text, line, rectangle, etc).
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.
69 3) The View: \c WorkArea (and it's qt4 specialisation GuiWorkArea)
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
75 The WorkArea also provide a scrollbar which position is translated
76 into scrolling command to the inner \c BufferView.
78 The WorkArea use the BufferView to translate each keyboard or mouse
79 events into terms that the Buffer can understand:
85 4) The Window: \c LyXView (and its qt4 specialisation \c GuiView)
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
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.
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.
104 Application(int & argc, char ** argv);
106 virtual ~Application() {}
109 virtual Gui & gui() = 0;
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;
116 /// Quit running LyX.
118 * This may either quit directly or record the exit status
119 * and only stop the event loop.
121 virtual void exit(int status) = 0;
124 * Synchronise all pending events.
126 virtual void syncEvents() = 0;
128 virtual Clipboard & clipboard() = 0;
130 virtual Selection & selection() = 0;
132 virtual FontLoader & fontLoader() = 0;
134 /// return a suitable serif font name.
135 virtual std::string const romanFontName() = 0;
137 /// return a suitable sans serif font name.
138 virtual std::string const sansFontName() = 0;
140 /// return a suitable monospaced font name.
141 virtual std::string const typewriterFontName() = 0;
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.
148 virtual bool getRgbColor(LColor_color col, RGBColor & rgbcol) = 0;
150 /** Eg, passing LColor::black returns "000000",
151 * passing LColor::white returns "ffffff".
153 virtual std::string const hexName(LColor_color col) = 0;
156 * update an altered GUI color
158 virtual void updateColor(LColor_color col) = 0;
161 * add a callback for socket read notification
162 * @param fd socket descriptor (file/socket/etc)
164 virtual void registerSocketCallback(
165 int fd, boost::function<void()> func) = 0;
168 * remove a I/O read callback
169 * @param fd socket descriptor (file/socket/etc)
171 virtual void unregisterSocketCallback(int fd) = 0;
173 /// Create the main window with given geometry settings.
174 LyXView & createView(unsigned int width, unsigned int height,
175 int posx, int posy, bool maximize, unsigned int iconSizeXY,
176 const std::string & geometryArg);
179 LyXView const & currentView() const;
182 LyXView & currentView();
185 void setCurrentView(LyXView & current_view);
188 /// This LyXView is the one receiving Clipboard and Selection
190 LyXView * current_view_;
194 } // namespace frontend
196 frontend::Application * theApp();
197 frontend::Application * createApplication(int & argc, char * argv[]);
203 #endif // LYX_APPLICATION_H