]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.h
Extracted from r14281
[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          * This is called after the concrete view has been created.
67          * We have to have the toolbar and the other stuff created
68          * before we can populate it with this call.
69          */
70         void init();
71
72         /// show busy cursor
73         virtual void busy(bool) const = 0;
74
75         //@{ generic accessor functions
76
77         /** return the current buffer view
78             Returned as a shared_ptr so that anything wanting to cache the
79             buffer view can do so safely using a boost::weak_ptr.
80          */
81         BufferView * view() const;
82
83         /// return the buffer currently shown in this window
84         Buffer * buffer() const;
85
86         /// return the LyX function handler for this view
87         LyXFunc & getLyXFunc() { return *lyxfunc_.get(); }
88         ///
89         LyXFunc const & getLyXFunc() const { return *lyxfunc_.get(); }
90
91         /// return the toolbar for this view
92         Toolbars & getToolbars() { return *toolbars_.get(); }
93         ///
94         Toolbars const & getToolbars() const { return *toolbars_.get(); }
95
96         /// return the menubar for this view
97         Menubar & getMenubar() { return *menubar_.get(); }
98         ///
99         Menubar const & getMenubar() const { return *menubar_.get(); }
100
101         /// get access to the dialogs
102         Dialogs & getDialogs() { return *dialogs_.get(); }
103         ///
104         Dialogs const & getDialogs() const { return *dialogs_.get(); }
105
106         /// get this view's keyboard map handler
107         Intl & getIntl() { return *intl_.get(); }
108         ///
109         Intl const & getIntl() const { return *intl_.get(); }
110
111         //@}
112
113         /// sets the layout in the toolbar layout selection
114         void setLayout(std::string const & layout);
115         /// updates the possible layouts selectable
116         void updateLayoutChoice();
117
118         /// update the toolbar
119         void updateToolbars();
120         /// update the menubar
121         void updateMenubar();
122
123         /// focus the command buffer (minibuffer)
124         boost::signal<void()> focus_command_buffer;
125
126         /// view state string changed
127         boost::signal<void()> view_state_changed;
128
129         /// display a message in the view
130         virtual void message(std::string const &) = 0;
131
132         /// clear any temporary message and replace with current status
133         virtual void clearMessage() = 0;
134
135         /// updates the title of the window
136         void updateWindowTitle();
137
138         /// reset autosave timer
139         void resetAutosaveTimer();
140
141         /// dispatch to current BufferView
142         void dispatch(FuncRequest const & cmd);
143
144         /** redraw \c inset in all the BufferViews in which it is currently
145          *  visible. If successful return a pointer to the owning Buffer.
146          */
147         Buffer const * const updateInset(InsetBase const *) const;
148
149         /// returns true if this view has the focus.
150         virtual bool hasFocus() const = 0;
151
152         ///
153         virtual lyx::frontend::Gui & gui();
154
155         lyx::frontend::WorkArea * workArea() const { return work_area_; }
156
157         /// Temporary method used by the kernel to redraw the work area.
158         virtual void redrawWorkArea();
159 protected:
160         /// current work area (screen view of a BufferView).
161         /**
162         \todo FIXME: there is only one workArea per LyXView for now.
163         */
164         lyx::frontend::WorkArea * work_area_;
165
166         /// view's menubar
167         boost::scoped_ptr<Menubar> menubar_;
168
169 private:
170         lyx::frontend::Gui & owner_;
171         /**
172          * setWindowTitle - set title of window
173          * @param t main window title
174          * @param it iconified (short) title
175          */
176         virtual void setWindowTitle(std::string const & t, std::string const & it) = 0;
177
178         /// called on timeout
179         void autoSave();
180
181         /// view's toolbar
182         boost::scoped_ptr<Toolbars> toolbars_;
183         /// keyboard mapping object
184         boost::scoped_ptr<Intl> const intl_;
185         /// auto-saving of buffers
186         boost::scoped_ptr<Timeout> const autosave_timeout_;
187         /// our function handler
188         boost::scoped_ptr<LyXFunc> lyxfunc_;
189         /// dialogs for this view
190         boost::scoped_ptr<Dialogs> dialogs_;
191
192 protected:
193         /// view's command buffer controller
194         // this has to be declared _after_ lyxfunc_ as its initialization depends
195         // on it!
196         typedef boost::scoped_ptr<lyx::frontend::ControlCommandBuffer>
197         CommandBufferPtr;
198
199         CommandBufferPtr const controlcommand_;
200 };
201
202 #endif // LYXVIEW_H