]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
This is the merging of the GUI API cleanup branch that was developed in svn+ssh:...
[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
37 namespace frontend {
38 class Gui;
39 } // namespace frontend
40
41 namespace frontend {
42 class ControlCommandBuffer;
43 } // namespace frontend
44
45 } // namespace lyx
46
47 /**
48  * LyXView - main LyX window
49  *
50  * This class represents the main LyX window and provides
51  * accessor functions to its content.
52  *
53  * The eventual intention is that LyX will support a number
54  * of containing LyXViews. Currently a lot of code still
55  * relies on there being a single top-level view.
56  *
57  * Additionally we would like to support multiple views
58  * in a single LyXView.
59  */
60 class LyXView : public boost::signals::trackable, boost::noncopyable {
61 public:
62
63         LyXView();
64
65         virtual ~LyXView();
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         void init();
73
74         /// show busy cursor
75         virtual void busy(bool) const = 0;
76
77         //@{ generic accessor functions
78
79         /** return the current buffer view
80             Returned as a shared_ptr so that anything wanting to cache the
81             buffer view can do so safely using a boost::weak_ptr.
82          */
83         boost::shared_ptr<BufferView> const & view() const;
84
85         /// return the buffer currently shown in this window
86         Buffer * buffer() const;
87
88         /// return the LyX function handler for this view
89         LyXFunc & getLyXFunc() { return *lyxfunc_.get(); }
90         ///
91         LyXFunc const & getLyXFunc() const { return *lyxfunc_.get(); }
92
93         /// return the toolbar for this view
94         Toolbars & getToolbars() { return *toolbars_.get(); }
95         ///
96         Toolbars const & getToolbars() const { return *toolbars_.get(); }
97
98         /// return the menubar for this view
99         Menubar & getMenubar() { return *menubar_.get(); }
100         ///
101         Menubar const & getMenubar() const { return *menubar_.get(); }
102
103         /// get access to the dialogs
104         Dialogs & getDialogs() { return *dialogs_.get(); }
105         ///
106         Dialogs const & getDialogs() const { return *dialogs_.get(); }
107
108         /// get this view's keyboard map handler
109         Intl & getIntl() { return *intl_.get(); }
110         ///
111         Intl const & getIntl() const { return *intl_.get(); }
112
113         //@}
114
115         /// sets the layout in the toolbar layout selection
116         void setLayout(std::string const & layout);
117         /// updates the possible layouts selectable
118         void updateLayoutChoice();
119
120         /// update the toolbar
121         void updateToolbars();
122         /// update the menubar
123         void updateMenubar();
124
125         /// focus the command buffer (minibuffer)
126         boost::signal<void()> focus_command_buffer;
127
128         /// view state string changed
129         boost::signal<void()> view_state_changed;
130
131         /// display a message in the view
132         virtual void message(std::string const &) = 0;
133
134         /// clear any temporary message and replace with current status
135         virtual void clearMessage() = 0;
136
137         /// updates the title of the window
138         void updateWindowTitle();
139
140         /// reset autosave timer
141         void resetAutosaveTimer();
142
143         /// dispatch to current BufferView
144         void dispatch(FuncRequest const & cmd);
145
146         /** redraw \c inset in all the BufferViews in which it is currently
147          *  visible. If successful return a pointer to the owning Buffer.
148          */
149         Buffer const * const updateInset(InsetBase const *) const;
150
151         // returns true if this view has the focus.
152         virtual bool hasFocus() const = 0;
153
154         virtual lyx::frontend::Gui & gui() = 0;
155
156 protected:
157         /// view of a buffer. Eventually there will be several.
158         boost::shared_ptr<BufferView> bufferview_;
159
160         /// view's menubar
161         boost::scoped_ptr<Menubar> menubar_;
162
163 private:
164         /**
165          * setWindowTitle - set title of window
166          * @param t main window title
167          * @param it iconified (short) title
168          */
169         virtual void setWindowTitle(std::string const & t, std::string const & it) = 0;
170
171         /// called on timeout
172         void autoSave();
173
174         /// view's toolbar
175         boost::scoped_ptr<Toolbars> toolbars_;
176         /// keyboard mapping object
177         boost::scoped_ptr<Intl> const intl_;
178         /// auto-saving of buffers
179         boost::scoped_ptr<Timeout> const autosave_timeout_;
180         /// our function handler
181         boost::scoped_ptr<LyXFunc> lyxfunc_;
182         /// dialogs for this view
183         boost::scoped_ptr<Dialogs> dialogs_;
184
185 protected:
186         /// view's command buffer controller
187         // this has to be declared _after_ lyxfunc_ as its initialization depends
188         // on it!
189         typedef boost::scoped_ptr<lyx::frontend::ControlCommandBuffer>
190         CommandBufferPtr;
191
192         CommandBufferPtr const controlcommand_;
193 };
194
195 #endif // LYXVIEW_H