]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ViewBase.h
Reorganised, cleaned-up and improved documentation of controllers.
[lyx.git] / src / frontends / controllers / ViewBase.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2001 The LyX Team.
8  *
9  * ======================================================
10  *
11  * Author: Angus Leeming <a.leeming@ic.ac.uk>
12  */
13
14 #ifndef VIEWBASE_H
15 #define VIEWBASE_H
16
17 #include <boost/utility.hpp>
18 #include "ControlBase.h"
19
20 class ViewBase {
21 public:
22         /// 
23         ViewBase(ControlBase & c) : controller_(c) {}
24         /// 
25         virtual ~ViewBase() {}
26
27         /// Apply changes to LyX data from dialog.
28         virtual void apply() = 0;
29         /// Hide the dialog.
30         virtual void hide() = 0;
31         /// Redraw the dialog (e.g. if the colors have been remapped).
32         virtual void redraw() {}
33         /// Create the dialog if necessary, update it and display it.
34         virtual void show() = 0;
35         /// Update dialog before/whilst showing it.
36         virtual void update() = 0;
37
38         /** These shortcuts allow (e.g. xform's) global callback functions
39             access to the buttons without making the whole controller_ public.
40         */
41         ///
42         void ApplyButton() { controller_.ApplyButton(); }
43         ///
44         void OKButton() { controller_.OKButton(); }
45         ///
46         void CancelButton() { controller_.CancelButton(); }
47         ///
48         void RestoreButton() { controller_.RestoreButton(); }
49
50 protected:
51         /// The view is, after all, controlled!
52         ControlBase & controller_;
53 };
54
55
56 /** A generic class to cast the ButtonController controller_.bc_ to it's
57     daughter class. */
58 template <class GUIbc>
59 class ViewBC : public ViewBase {
60 public:
61         ///
62         ViewBC(ControlBase & c) : ViewBase(c) {}
63
64 protected:
65         ///
66         GUIbc & bc() const
67         {
68                 return static_cast<GUIbc &>(controller_.bc());
69                 // return dynamic_cast<GUIbc &>(controller_.bc());
70         }
71 };
72
73 #endif // VIEWBASE_H