]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/BCView.h
Flatten the ButtonController tree by splitting it into a Controller and
[lyx.git] / src / frontends / controllers / BCView.h
1 // -*- C++ -*-
2 /**
3  * \file BCView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Allan Rae
8  * \author Angus Leeming
9  * \author Baruch Even
10  *
11  * Full author contact details are available in file CREDITS
12  */
13
14 #ifndef BCVIEW_H
15 #define BCVIEW_H
16
17 #include "LString.h"
18 #include <boost/shared_ptr.hpp>
19 #include <list>
20
21 class ButtonController;
22 class ButtonPolicy;
23
24 struct CheckedWidget {
25         ///
26         virtual ~CheckedWidget();
27
28         /** Returns true if the widget is in a valid state.
29         *  Might also change the visual appearance of the widget,
30         *  to reflect this state.
31         */
32         virtual bool check() const = 0;
33 };
34
35
36 class BCView {
37 public:
38         BCView(ButtonController const &);
39         ///
40         virtual ~BCView() {}
41         ///
42         virtual void refresh() = 0;
43         ///
44         virtual void refreshReadOnly() = 0;
45         ///
46         ButtonPolicy & bp() const;
47         ///
48         void addCheckedWidget(CheckedWidget * ptr);
49 protected:
50         ///
51         bool checkWidgets();
52
53 private:
54         ///
55         typedef boost::shared_ptr<CheckedWidget> checked_widget_ptr;
56         typedef std::list<checked_widget_ptr> checked_widget_list;
57         ///
58         checked_widget_list checked_widgets;
59         ///
60         ButtonController const & parent;
61 };
62
63
64 /** A templatised instantiation of the ButtonController's View requiring the
65  *  gui-frontend widgets.
66  */
67 template <class Button, class Widget>
68 class GuiBC : public BCView {
69 public:
70         ///
71         GuiBC(ButtonController const & parent,
72               string const & cancel, string const & close);
73
74         ///
75         void setOK(Button * obj) { okay_ = obj; }
76         ///
77         void setApply(Button * obj) { apply_ = obj; }
78         ///
79         void setCancel(Button * obj) { cancel_ = obj; }
80         ///
81         void setRestore(Button * obj) { restore_ = obj; }
82         ///
83         void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
84         ///
85         void eraseReadOnly() { read_only_.clear(); }
86
87         /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
88         void refresh();
89         /// Refresh the status of any widgets in the read_only list
90         void refreshReadOnly();
91 private:
92         /// Enable/Disable a widget
93         virtual void setWidgetEnabled(Widget * obj, bool enable) = 0;
94         /// Enable/Disable a button
95         virtual void setButtonEnabled(Button * obj, bool enable) = 0;
96         /// Set the Label on the button
97         virtual void setButtonLabel(Button * obj, string const & label) = 0;
98
99         string cancel_label_;
100         string close_label_;
101
102         Button * okay_;
103         Button * apply_;
104         Button * cancel_;
105         Button * restore_;
106
107         typedef std::list<Widget *> Widgets;
108         Widgets read_only_;
109 };
110
111
112 #include "BCView.tmpl"
113
114 #endif // BCVIEW_H