]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/BCView.h
some support for pch
[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 <boost/shared_ptr.hpp>
18 #include <list>
19 #include <string>
20
21 namespace lyx {
22 namespace frontend {
23
24 class ButtonController;
25 class ButtonPolicy;
26
27
28 /** \c CheckedWidget is an abstract base class that can be stored
29  *  in the button controller's view and can be interrogated by it
30  *  when the activation state of the Ok, Apply buttons is refreshed.
31  *  Ideally, the user will be prevented from returning invalid data
32  *  to the LyX kernel.
33  *
34  *  Many widgets can be grouped together in the derived class if they
35  *  make a logical whole. E.g., an input and a choice widget that together
36  *  are used to set a LyXLength can be interrogated together.
37  */
38 struct CheckedWidget {
39         ///
40         virtual ~CheckedWidget();
41
42         /** Returns true if the widget is in a valid state.
43         *  Might also change the visual appearance of the widget,
44         *  to reflect this state.
45         */
46         virtual bool check() const = 0;
47 };
48
49
50 /** \c BCView is the View to ButtonController's Controller. It
51  *  stores the individual GUI widgets and sets their activation state
52  *  upon receipt of instructions from the controller.
53  *
54  *  It is a base class. The true, GUI, instantiations derive from it.
55  */
56 class BCView {
57 public:
58         BCView(ButtonController const &);
59         virtual ~BCView() {}
60
61         //@{
62         /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
63         virtual void refresh() const = 0;
64         /// Refresh the status of any widgets in the read_only list
65         virtual void refreshReadOnly() const = 0;
66         //@}
67
68         /// A shortcut to the BP of the BC.
69         ButtonPolicy & bp() const;
70
71         /** Add a widget to the list of all widgets whose validity should
72          *  be checked explicitly when the buttons are refreshed.
73          */
74         void addCheckedWidget(CheckedWidget * ptr);
75
76 protected:
77         /// \return true if all CheckedWidgets are in a valid state.
78         bool checkWidgets() const;
79
80 private:
81         typedef boost::shared_ptr<CheckedWidget> checked_widget_ptr;
82         typedef std::list<checked_widget_ptr> checked_widget_list;
83         checked_widget_list checked_widgets;
84         ButtonController const & parent;
85 };
86
87
88 /** A templatised instantiation of the ButtonController's View requiring the
89  *  gui-frontend widgets.
90  */
91 template <class Button, class Widget>
92 class GuiBC : public BCView {
93 public:
94         ///
95         GuiBC(ButtonController const & parent,
96               std::string const & cancel, std::string const & close);
97
98         //@{
99         /** Store pointers to these widgets. The pointers are _not_
100          *  owned by GuiBC.
101          */
102         void setOK(Button * obj) { okay_ = obj; }
103         void setApply(Button * obj) { apply_ = obj; }
104         void setCancel(Button * obj) { cancel_ = obj; }
105         void setRestore(Button * obj) { restore_ = obj; }
106         //@}
107
108         /** Add a pointer to the list of widgets whose activation
109          *  state is dependent upon the read-only status of the
110          *  underlying buffer.
111          */
112         void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
113
114         /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
115         virtual void refresh() const;
116         /// Refresh the status of any widgets in the read_only list
117         virtual void refreshReadOnly() const;
118
119 private:
120         /// Enable/Disable a widget
121         virtual void setWidgetEnabled(Widget * obj, bool enable) const = 0;
122         /// Enable/Disable a button
123         virtual void setButtonEnabled(Button * obj, bool enable) const = 0;
124         /// Set the Label on the button
125         virtual void setButtonLabel(Button * obj, std::string const & label) const = 0;
126
127         std::string const cancel_label_;
128         std::string const close_label_;
129
130         Button * okay_;
131         Button * apply_;
132         Button * cancel_;
133         Button * restore_;
134
135         typedef std::list<Widget *> Widgets;
136         Widgets read_only_;
137 };
138
139 } // namespace frontend
140 } // namespace lyx
141
142 #include "BCView.tmpl"
143
144 #endif // BCVIEW_H