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