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>
24 class ButtonController;
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
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.
38 struct CheckedWidget {
40 virtual ~CheckedWidget();
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.
46 virtual bool check() const = 0;
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.
54 * It is a base class. The true, GUI, instantiations derive from it.
58 BCView(ButtonController const &);
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;
68 /// A shortcut to the BP of the BC.
69 ButtonPolicy & bp() const;
71 /** Add a widget to the list of all widgets whose validity should
72 * be checked explicitly when the buttons are refreshed.
74 void addCheckedWidget(CheckedWidget * ptr);
77 /// \return true if all CheckedWidgets are in a valid state.
78 bool checkWidgets() const;
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;
88 /** A templatised instantiation of the ButtonController's View requiring the
89 * gui-frontend widgets.
91 template <class Button, class Widget>
92 class GuiBC : public BCView {
95 GuiBC(ButtonController const & parent,
96 std::string const & cancel, std::string const & close);
99 /** Store pointers to these widgets. The pointers are _not_
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; }
108 /** Add a pointer to the list of widgets whose activation
109 * state is dependent upon the read-only status of the
112 void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
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;
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;
127 std::string const cancel_label_;
128 std::string const close_label_;
135 typedef std::list<Widget *> Widgets;
139 } // namespace frontend
142 #include "BCView.tmpl"