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.
14 #include "ColorCode.h"
16 #include "support/strfwd.h"
18 #include <boost/function.hpp>
42 /// The main application class
44 There should be only one instance of this class. No Qt object
45 initialisation should be done before the instanciation of this class.
47 Model/View/Controller separation at frontend level in LyX-qt4:
49 BufferList (N Buffers)
56 Application (this is the frontend really, should probably be renamed).
58 LyXView-1 (one or more in case of split-view mode).
62 | | WorkArea-1-1-1 (M1-1 WorkAreas, M1-1 <= N)
64 | | | BufferView <-----------> Buffer-c
70 | | | BufferView <-----------> Buffer-a
76 LyXView-2 (one or more in case of split-view mode).
80 | | WorkArea-2-1-1 (M2-1 WorkAreas, M2-1 <= N, M2-1 independent of M1-1)
84 1) The Model: \c Buffer
86 The Buffer is the in-memory representation of a LyX file format. The
87 Buffer does not (should not) have any information on what part of it
88 is represented on screen. There is one unique Buffer per opened LyX
89 file. A Buffer may or may not be represented on screen; typically, a
90 child document does not have an associated BufferView unless the user
91 choose to visualize it.
94 2) The Controller: \c BufferView / \c Painter \c Cursor
96 The BufferView is a tool used by the view (\sa WorkArea) that
97 translates a part of the Buffer contents into drawing routines. The
98 BufferView asks each inset of the Buffer to draw itself onto the
99 screen using the Painter. There can be only one Buffer displayed in
100 a BufferView and it is set on construction. Ideally, a BufferView
101 should not be able to change the contents of its associated Buffer.
102 A BufferView is instanciated and destroyed by a \c WorkArea; it is
103 automatically destroyed by the parent WorkArea when its Buffer is
106 \todo Move all Buffer changing LFUN to Buffer::dispatch(),
107 LyXFunc::dispatch() or Cursor::dispatch().
108 \todo BufferView::buffer() should only offer const access.
110 The \c Painter is just a virtual interface to formalize each kind of
111 drawing routines (text, line, rectangle, etc).
113 The \c BufferView also contains a Cursor which may or may not be
114 visible on screen. The cursor is really just a bookmark to remember
115 where the next Buffer insertion/deletion is going to take place.
118 3) The View: \c WorkArea (and it's qt4 specialisation GuiWorkArea)
120 This contains the real screen area where the drawing is done by the
121 Painter. One WorkArea holds one unique \c BufferView. While it could
122 be possible that multiple WorkArea share one BufferView, this is not
123 something desirable because a BufferView is dependent of the WorkArea
125 The WorkArea also provide a scrollbar which position is translated
126 into scrolling command to the inner \c BufferView.
128 The WorkArea use the BufferView to translate each keyboard or mouse
129 events into terms that the Buffer can understand:
135 4) The Window: \c LyXView (and its qt4 specialisation \c GuiView)
137 This is a full window containing a menubar, toolbars and a central
138 widget. A LyXView is in charge of creating and closing a View for a
140 In the qt4 specialisation, \c GuiView, the central widget is a tab
141 widget. Each tab is reverved to the visualisation of one Buffer and
142 contains one WorkArea. In the qt4 frontend, one LyXView thus contains
143 multiple WorkAreas but this number can limited to one for another
144 frontend. The idea is that the kernel should not know how a Buffer
145 is displayed on screen; it's the frontend business.
146 It is also possible to have multiple Workareas showing
147 simultaneously in the same GuiView (ex: with split window), thus
148 sharing the menubar and toolbars.
150 In any case, there should be only one WorkArea that gets the focus
153 With our current implementation using a QTabWidget, each Tab own its
154 own \c WorkArea. Clicking on a tab switch a WorkArea and not really
155 a Buffer. LFUN_BUFFER_SWITCH will tell the frontend to search the
156 WorkArea associated to this Buffer. The WorkArea is automatically
157 created if not already present.
159 A WorkArea is connected to the Buffer::closing signal and is thus
160 automatically destroyed when its Buffer is closed.
169 virtual ~Application() {}
171 virtual LyXView * currentWindow() = 0;
173 virtual bool getStatus(FuncRequest const & cmd, FuncStatus & flag) const = 0;
174 /// dispatch command.
175 /// \return true if the \c FuncRequest has been dispatched.
176 virtual bool dispatch(FuncRequest const & cmd) = 0;
179 virtual void resetGui() = 0;
181 /// Load files and restore GUI Session.
182 virtual void restoreGuiSession() = 0;
185 virtual void hideDialogs(std::string const & name, Inset * inset) const = 0;
187 virtual Buffer const * updateInset(Inset const * inset) const = 0;
189 /// Start the main event loop.
190 /// The batch command is programmed to be execute once
191 /// the event loop is started.
192 virtual int exec() = 0;
194 /// Quit running LyX.
196 * This may either quit directly or record the exit status
197 * and only stop the event loop.
199 virtual void exit(int status) = 0;
202 * Given col, fills r, g, b in the range 0-255.
203 * The function returns true if successful.
204 * It returns false on failure and sets r, g, b to 0.
206 virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol) = 0;
208 /** Eg, passing Color_black returns "000000",
209 * passing Color_white returns "ffffff".
211 virtual std::string const hexName(ColorCode col) = 0;
214 * add a callback for socket read notification
215 * @param fd socket descriptor (file/socket/etc)
217 typedef boost::function<void()> SocketCallback;
218 virtual void registerSocketCallback(int fd, SocketCallback func) = 0;
221 * remove a I/O read callback
222 * @param fd socket descriptor (file/socket/etc)
224 virtual void unregisterSocketCallback(int fd) = 0;
226 virtual bool searchMenu(FuncRequest const & func,
227 docstring_list & names) const = 0;
229 /// \return the icon file name for the given action.
230 virtual docstring iconName(FuncRequest const & f, bool unknown) = 0;
233 /// Return the list of loadable formats.
234 std::vector<std::string> loadableImageFormats();
236 } // namespace frontend
238 frontend::Application * theApp();
239 frontend::Application * createApplication(int & argc, char * argv[]);
240 void hideDialogs(std::string const & name, Inset * inset);
245 #endif // APPLICATION_H