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