4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Angus Leeming
11 * Full author contact details are available in file CREDITS.
17 #include "support/docstring.h"
19 #include <boost/shared_ptr.hpp>
25 class ButtonController;
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
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 Length can be interrogated together.
42 virtual ~CheckedWidget() {}
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.
48 virtual bool check() const = 0;
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.
56 * It is a base class. The true, GUI, instantiations derive from it.
60 BCView(ButtonController const &);
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;
70 /// A shortcut to the BP of the BC.
71 ButtonPolicy & bp() const;
73 /** Add a widget to the list of all widgets whose validity should
74 * be checked explicitly when the buttons are refreshed.
76 void addCheckedWidget(CheckedWidget * ptr);
79 /// \return true if all CheckedWidgets are in a valid state.
80 bool checkWidgets() const;
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;
90 /** A templatised instantiation of the ButtonController's View requiring the
91 * gui-frontend widgets.
93 template <class Button, class Widget>
94 class GuiBC : public BCView {
97 GuiBC(ButtonController const & parent,
98 docstring const & cancel, docstring const & close);
101 /** Store pointers to these widgets. The pointers are _not_
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; }
110 /** Add a pointer to the list of widgets whose activation
111 * state is dependent upon the read-only status of the
114 void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
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;
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, docstring const & label) const = 0;
129 docstring const cancel_label_;
130 docstring const close_label_;
137 typedef std::list<Widget *> Widgets;
141 } // namespace frontend
144 #include "BCView.tmpl"