]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
GUI API Cleanup step 3: merge with "younes" branch.
[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 <boost/scoped_ptr.hpp>
17 #include <boost/shared_ptr.hpp>
18 #include <boost/signal.hpp>
19 #include <boost/signals/trackable.hpp>
20 #include <boost/utility.hpp>
21
22 class Buffer;
23 class Toolbars;
24 class InsetBase;
25 class Intl;
26 class Menubar;
27
28 class BufferView;
29 class Dialogs;
30 class LyXFunc;
31 class LyXFont;
32 class Timeout;
33 class FuncRequest;
34
35 namespace lyx {
36 namespace frontend {
37 class Gui;
38 class WorkArea;
39 class ControlCommandBuffer;
40 } // namespace frontend
41
42 } // namespace lyx
43
44 /**
45  * LyXView - main LyX window
46  *
47  * This class represents the main LyX window and provides
48  * accessor functions to its content.
49  *
50  * The eventual intention is that LyX will support a number
51  * of containing LyXViews. Currently a lot of code still
52  * relies on there being a single top-level view.
53  *
54  * Additionally we would like to support multiple views
55  * in a single LyXView.
56  */
57 class LyXView : public boost::signals::trackable, boost::noncopyable {
58 public:
59
60         LyXView(lyx::frontend::Gui & owner);
61
62         virtual ~LyXView();
63
64         void setWorkArea(lyx::frontend::WorkArea * work_area);
65
66         /**
67          * This is called after the concrete view has been created.
68          * We have to have the toolbar and the other stuff created
69          * before we can populate it with this call.
70          */
71         void init();
72
73         /// show busy cursor
74         virtual void busy(bool) const = 0;
75
76         //@{ generic accessor functions
77
78         /** return the current buffer view
79             Returned as a shared_ptr so that anything wanting to cache the
80             buffer view can do so safely using a boost::weak_ptr.
81          */
82         BufferView * view() const;
83
84         /// return the buffer currently shown in this window
85         Buffer * buffer() const;
86
87         /// return the LyX function handler for this view
88         LyXFunc & getLyXFunc() { return *lyxfunc_.get(); }
89         ///
90         LyXFunc const & getLyXFunc() const { return *lyxfunc_.get(); }
91
92         /// return the toolbar for this view
93         Toolbars & getToolbars() { return *toolbars_.get(); }
94         ///
95         Toolbars const & getToolbars() const { return *toolbars_.get(); }
96
97         /// return the menubar for this view
98         Menubar & getMenubar() { return *menubar_.get(); }
99         ///
100         Menubar const & getMenubar() const { return *menubar_.get(); }
101
102         /// get access to the dialogs
103         Dialogs & getDialogs() { return *dialogs_.get(); }
104         ///
105         Dialogs const & getDialogs() const { return *dialogs_.get(); }
106
107         /// get this view's keyboard map handler
108         Intl & getIntl() { return *intl_.get(); }
109         ///
110         Intl const & getIntl() const { return *intl_.get(); }
111
112         //@}
113
114         /// load a buffer into the current workarea
115         bool loadLyXFile(std::string const &  name, bool tolastfiles = true);
116
117         /// set a buffer to the current workarea
118         void setBuffer(Buffer * b);
119
120         /// sets the layout in the toolbar layout selection
121         void setLayout(std::string const & layout);
122         /// updates the possible layouts selectable
123         void updateLayoutChoice();
124
125         /// update the toolbar
126         void updateToolbars();
127         /// update the menubar
128         void updateMenubar();
129         /// update the status bar
130         virtual void updateStatusBar() = 0;
131
132         /// focus the command buffer (minibuffer)
133         boost::signal<void()> focus_command_buffer;
134
135         /// display a message in the view
136         virtual void message(std::string const &) = 0;
137
138         /// clear any temporary message and replace with current status
139         virtual void clearMessage() = 0;
140
141         /// updates the title of the window
142         void updateWindowTitle();
143
144         /// reset autosave timer
145         void resetAutosaveTimer();
146
147         /// dispatch to current BufferView
148         void dispatch(FuncRequest const & cmd);
149
150         /** redraw \c inset in all the BufferViews in which it is currently
151          *  visible. If successful return a pointer to the owning Buffer.
152          */
153         Buffer const * const updateInset(InsetBase const *) const;
154
155         /// returns true if this view has the focus.
156         virtual bool hasFocus() const = 0;
157
158         ///
159         virtual lyx::frontend::Gui & gui();
160
161         /// Temporary method used by the kernel to redraw the work area.
162         virtual void redrawWorkArea();
163
164         /// Temporary method to access the current workArea.
165         /// This is needed for the qt3 and gtk frontend.
166         lyx::frontend::WorkArea * workArea();
167
168 protected:
169         /// current work area (screen view of a BufferView).
170         /**
171         \todo FIXME: there is only one workArea per LyXView for now.
172         */
173         lyx::frontend::WorkArea * work_area_;
174
175         /// view's menubar
176         boost::scoped_ptr<Menubar> menubar_;
177
178 private:
179         lyx::frontend::Gui & owner_;
180         /**
181          * setWindowTitle - set title of window
182          * @param t main window title
183          * @param it iconified (short) title
184          */
185         virtual void setWindowTitle(std::string const & t, std::string const & it) = 0;
186
187         /// called on timeout
188         void autoSave();
189
190         /// view's toolbar
191         boost::scoped_ptr<Toolbars> toolbars_;
192         /// keyboard mapping object
193         boost::scoped_ptr<Intl> const intl_;
194         /// auto-saving of buffers
195         boost::scoped_ptr<Timeout> const autosave_timeout_;
196         /// our function handler
197         boost::scoped_ptr<LyXFunc> lyxfunc_;
198         /// dialogs for this view
199         boost::scoped_ptr<Dialogs> dialogs_;
200
201 protected:
202         /// view's command buffer controller
203         // this has to be declared _after_ lyxfunc_ as its initialization depends
204         // on it!
205         typedef boost::scoped_ptr<lyx::frontend::ControlCommandBuffer>
206         CommandBufferPtr;
207
208         CommandBufferPtr const controlcommand_;
209 };
210
211 #endif // LYXVIEW_H