]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ViewBase.h
fix tooltips in toolbar
[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 "ControlButtons.h"
19
20 class ViewBase {
21 public:
22         ///
23         ViewBase(ControlButtons & 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         /// build the dialog
38         virtual void build() = 0;
39
40         /** These shortcuts allow (e.g. xform's) global callback functions
41             access to the buttons without making the whole controller_ public.
42         */
43         ///
44         void ApplyButton() { controller_.ApplyButton(); }
45         ///
46         void OKButton() { controller_.OKButton(); }
47         ///
48         void CancelButton() { controller_.CancelButton(); }
49         ///
50         void RestoreButton() { controller_.RestoreButton(); }
51
52         /** Defaults to nothing. Can be used by the Controller, however, to
53             indicate to the View that something has changed and that the
54             dialog therefore needs updating. */
55         virtual void partialUpdate(int) {}
56
57 protected:
58         /// The view is, after all, controlled!
59         ControlButtons & controller_;
60 };
61
62
63 /** A generic class to cast the ButtonController controller_.bc_ to it's
64     daughter class. */
65 template <class GUIbc>
66 class ViewBC : public ViewBase {
67 public:
68         ///
69         ViewBC(ControlButtons & c) : ViewBase(c) {}
70
71 protected:
72         ///
73         GUIbc & bc() const
74         {
75                 return static_cast<GUIbc &>(controller_.bc());
76                 // return dynamic_cast<GUIbc &>(controller_.bc());
77         }
78 };
79
80 #endif // VIEWBASE_H