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 <boost/shared_ptr.hpp>
22 class ButtonController;
26 /** \c CheckedWidget is an abstract base class that can be stored
27 * in the button controller's view and can be interrogated by it
28 * when the activation state of the Ok, Apply buttons is refreshed.
29 * Ideally, the user will be prevented from returning invalid data
32 * Many widgets can be grouped together in the derived class if they
33 * make a logical whole. E.g., an input and a choice widget that together
34 * are used to set a LyXLength can be interrogated together.
36 struct CheckedWidget {
38 virtual ~CheckedWidget();
40 /** Returns true if the widget is in a valid state.
41 * Might also change the visual appearance of the widget,
42 * to reflect this state.
44 virtual bool check() const = 0;
48 /** \c BCView is the View to ButtonController's Controller. It
49 * stores the individual GUI widgets and sets their activation state
50 * upon receipt of instructions from the controller.
52 * It is a base class. The true, GUI, instantiations derive from it.
56 BCView(ButtonController const &);
60 /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
61 virtual void refresh() const = 0;
62 /// Refresh the status of any widgets in the read_only list
63 virtual void refreshReadOnly() const = 0;
66 /// A shortcut to the BP of the BC.
67 ButtonPolicy & bp() const;
69 /** Add a widget to the list of all widgets whose validity should
70 * be checked explicitly when the buttons are refreshed.
72 void addCheckedWidget(CheckedWidget * ptr);
75 /// \return true if all CheckedWidgets are in a valid state.
76 bool checkWidgets() const;
79 typedef boost::shared_ptr<CheckedWidget> checked_widget_ptr;
80 typedef std::list<checked_widget_ptr> checked_widget_list;
81 checked_widget_list checked_widgets;
82 ButtonController const & parent;
86 /** A templatised instantiation of the ButtonController's View requiring the
87 * gui-frontend widgets.
89 template <class Button, class Widget>
90 class GuiBC : public BCView {
93 GuiBC(ButtonController const & parent,
94 std::string const & cancel, std::string const & close);
97 /** Store pointers to these widgets. The pointers are _not_
100 void setOK(Button * obj) { okay_ = obj; }
101 void setApply(Button * obj) { apply_ = obj; }
102 void setCancel(Button * obj) { cancel_ = obj; }
103 void setRestore(Button * obj) { restore_ = obj; }
106 /** Add a pointer to the list of widgets whose activation
107 * state is dependent upon the read-only status of the
110 void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
112 /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
113 virtual void refresh() const;
114 /// Refresh the status of any widgets in the read_only list
115 virtual void refreshReadOnly() const;
118 /// Enable/Disable a widget
119 virtual void setWidgetEnabled(Widget * obj, bool enable) const = 0;
120 /// Enable/Disable a button
121 virtual void setButtonEnabled(Button * obj, bool enable) const = 0;
122 /// Set the Label on the button
123 virtual void setButtonLabel(Button * obj, std::string const & label) const = 0;
125 std::string const cancel_label_;
126 std::string const close_label_;
133 typedef std::list<Widget *> Widgets;
138 #include "BCView.tmpl"