]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / LyXView.h
1 // -*- C++ -*-
2 /**
3  * \file LyXView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef LYXVIEW_H
14 #define LYXVIEW_H
15
16 #include "frontends/Application.h"
17 #include "frontends/Toolbars.h"
18
19 #include "lyxfunc.h"
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/shared_ptr.hpp>
22 #include <boost/signal.hpp>
23 #include <boost/signals/trackable.hpp>
24 #include <boost/utility.hpp>
25
26 class Buffer;
27 class InsetBase;
28 class Menubar;
29
30 class BufferView;
31 class Dialogs;
32 class LyXFunc;
33 class LyXFont;
34 class Timeout;
35 class FuncRequest;
36
37 namespace lyx {
38 namespace frontend {
39 class WorkArea;
40 class ControlCommandBuffer;
41 } // namespace frontend
42
43 } // namespace lyx
44
45 /**
46  * LyXView - main LyX window
47  *
48  * This class represents the main LyX window and provides
49  * accessor functions to its content.
50  *
51  * The eventual intention is that LyX will support a number
52  * of containing LyXViews. Currently a lot of code still
53  * relies on there being a single top-level view.
54  *
55  * Additionally we would like to support multiple views
56  * in a single LyXView.
57  */
58 class LyXView : public boost::signals::trackable, boost::noncopyable {
59 public:
60
61         LyXView();
62
63         virtual ~LyXView();
64
65         void setWorkArea(lyx::frontend::WorkArea * work_area);
66
67         /**
68          * This is called after the concrete view has been created.
69          * We have to have the toolbar and the other stuff created
70          * before we can populate it with this call.
71          */
72         virtual void init() = 0;
73
74         virtual void setGeometry(
75                 unsigned int width,
76                 unsigned int height,
77                 int posx, int posy,
78                 bool maximize) = 0;
79
80         /// show busy cursor
81         virtual void busy(bool) const = 0;
82
83         virtual Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const & tbb) = 0;
84
85         //@{ generic accessor functions
86
87         /** return the current buffer view
88             Returned as a shared_ptr so that anything wanting to cache the
89             buffer view can do so safely using a boost::weak_ptr.
90          */
91         BufferView * view() const;
92
93         /// return the buffer currently shown in this window
94         Buffer * buffer() const;
95
96         /* FIXME: Abdel 22/09/71
97         there is only one lyxFunc() for now but there is maybe a need
98         for more in the feature. Something like that:
99         
100                 LyXFunc & getLyXFunc() { return theApp->lyxFunc(id_); }
101
102         where id_ would be the this LyXView ID.
103         That's the reason why I didn't remove these methods for now.
104         */
105         /// return the LyX function handler for this view
106         LyXFunc & getLyXFunc() { return theApp->lyxFunc(); }
107         ///
108         LyXFunc const & getLyXFunc() const { return theApp->lyxFunc(); }
109
110         /// return the toolbar for this view
111         Toolbars & getToolbars() { return *toolbars_.get(); }
112         ///
113         Toolbars const & getToolbars() const { return *toolbars_.get(); }
114
115         /// return the menubar for this view
116         Menubar & getMenubar() { return *menubar_.get(); }
117         ///
118         Menubar const & getMenubar() const { return *menubar_.get(); }
119
120         /// get access to the dialogs
121         Dialogs & getDialogs() { return *dialogs_.get(); }
122         ///
123         Dialogs const & getDialogs() const { return *dialogs_.get(); }
124
125         //@}
126
127         /// load a buffer into the current workarea
128         bool loadLyXFile(std::string const &  name, bool tolastfiles = true);
129
130         /// set a buffer to the current workarea
131         void setBuffer(Buffer * b);
132
133         /// updates the possible layouts selectable
134         void updateLayoutChoice();
135
136         /// update the toolbar
137         void updateToolbars();
138         /// update the menubar
139         void updateMenubar();
140         /// update the status bar
141         virtual void updateStatusBar() = 0;
142
143         /// focus the command buffer (minibuffer)
144         boost::signal<void()> focus_command_buffer;
145
146         /// display a message in the view
147         virtual void message(lyx::docstring const &) = 0;
148
149         /// clear any temporary message and replace with current status
150         virtual void clearMessage() = 0;
151
152         /// updates the title of the window
153         void updateWindowTitle();
154
155         /// reset autosave timer
156         void resetAutosaveTimer();
157
158         /// dispatch to current BufferView
159         void dispatch(FuncRequest const & cmd);
160
161         /** redraw \c inset in all the BufferViews in which it is currently
162          *  visible. If successful return a pointer to the owning Buffer.
163          */
164         Buffer const * const updateInset(InsetBase const *) const;
165
166         /// returns true if this view has the focus.
167         virtual bool hasFocus() const = 0;
168
169         /// Temporary method used by the kernel to redraw the work area.
170         virtual void redrawWorkArea();
171
172         /// Temporary method to access the current workArea.
173         /// This is needed for the qt3 and gtk frontend.
174         lyx::frontend::WorkArea * workArea();
175
176         /// show the error list to the user
177         void showErrorList(std::string const &);
178
179         /// connect to signals in the given BufferView
180         void connectBufferView(BufferView & bv);
181         /// disconnect from signals in the given BufferView
182         void disconnectBufferView();
183
184 protected:
185         /// current work area (screen view of a BufferView).
186         /**
187         \todo FIXME: there is only one workArea per LyXView for now.
188         */
189         lyx::frontend::WorkArea * work_area_;
190
191         /// view's menubar
192         boost::scoped_ptr<Menubar> menubar_;
193
194 private:
195         /**
196          * setWindowTitle - set title of window
197          * @param t main window title
198          * @param it iconified (short) title
199          */
200         virtual void setWindowTitle(lyx::docstring const & t, lyx::docstring const & it) = 0;
201
202         /// called on timeout
203         void autoSave();
204
205         /// view's toolbar
206         boost::scoped_ptr<Toolbars> toolbars_;
207         /// auto-saving of buffers
208         boost::scoped_ptr<Timeout> const autosave_timeout_;
209         /// our function handler
210         boost::scoped_ptr<LyXFunc> lyxfunc_;
211         /// dialogs for this view
212         boost::scoped_ptr<Dialogs> dialogs_;
213
214         /// buffer errors signal connection
215         boost::signals::connection errorsConnection_;
216         /// buffer messages signal connection
217         boost::signals::connection messageConnection_;
218         /// buffer busy status signal connection
219         boost::signals::connection busyConnection_;
220         /// buffer title changed signal connection
221         boost::signals::connection titleConnection_;
222         /// buffer reset timers signal connection
223         boost::signals::connection timerConnection_;
224         /// buffer readonly status changed signal connection
225         boost::signals::connection readonlyConnection_;
226         /// buffer closing signal connection
227         boost::signals::connection closingConnection_;
228         /// connect to signals in the given buffer
229         void connectBuffer(Buffer & buf);
230         /// disconnect from signals in the given buffer
231         void disconnectBuffer();
232
233         /// BufferView messages signal connection
234         //@{
235         boost::signals::connection message_connection_;
236         boost::signals::connection show_dialog_connection_;
237         boost::signals::connection show_dialog_with_data_connection_;
238         boost::signals::connection show_inset_dialog_connection_;
239         boost::signals::connection update_dialog_connection_;
240         boost::signals::connection layout_changed_connection_;
241         //@}
242
243         /// Bind methods for BufferView messages signal connection
244         //@{
245         void showDialog(std::string const & name);
246         void showDialogWithData(std::string const & name,
247                 std::string const & data);
248         void showInsetDialog(std::string const & name,
249                 std::string const & data, InsetBase * inset);
250         void updateDialog(std::string const & name,
251                 std::string const & data);
252         //@}
253
254         /// notify readonly status
255         void showReadonly(bool);
256
257 protected:
258         /// view's command buffer controller
259         // this has to be declared _after_ lyxfunc_ as its initialization depends
260         // on it!
261         typedef boost::scoped_ptr<lyx::frontend::ControlCommandBuffer>
262         CommandBufferPtr;
263
264         CommandBufferPtr const controlcommand_;
265 };
266
267 #endif // LYXVIEW_H