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.
41 virtual ~CheckedWidget();
43 /** Returns true if the widget is in a valid state.
44 * Might also change the visual appearance of the widget,
45 * to reflect this state.
47 virtual bool check() const = 0;
51 /** \c BCView is the View to ButtonController's Controller. It
52 * stores the individual GUI widgets and sets their activation state
53 * upon receipt of instructions from the controller.
55 * It is a base class. The true, GUI, instantiations derive from it.
59 BCView(ButtonController const &);
63 /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
64 virtual void refresh() const = 0;
65 /// Refresh the status of any widgets in the read_only list
66 virtual void refreshReadOnly() const = 0;
69 /// A shortcut to the BP of the BC.
70 ButtonPolicy & bp() const;
72 /** Add a widget to the list of all widgets whose validity should
73 * be checked explicitly when the buttons are refreshed.
75 void addCheckedWidget(CheckedWidget * ptr);
78 /// \return true if all CheckedWidgets are in a valid state.
79 bool checkWidgets() const;
82 typedef boost::shared_ptr<CheckedWidget> checked_widget_ptr;
83 typedef std::list<checked_widget_ptr> checked_widget_list;
84 checked_widget_list checked_widgets;
85 ButtonController const & parent;
89 /** A templatised instantiation of the ButtonController's View requiring the
90 * gui-frontend widgets.
92 template <class Button, class Widget>
93 class GuiBC : public BCView {
96 GuiBC(ButtonController const & parent,
97 std::string const & cancel, std::string const & close);
100 /** Store pointers to these widgets. The pointers are _not_
103 void setOK(Button * obj) { okay_ = obj; }
104 void setApply(Button * obj) { apply_ = obj; }
105 void setCancel(Button * obj) { cancel_ = obj; }
106 void setRestore(Button * obj) { restore_ = obj; }
109 /** Add a pointer to the list of widgets whose activation
110 * state is dependent upon the read-only status of the
113 void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
115 /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
116 virtual void refresh() const;
117 /// Refresh the status of any widgets in the read_only list
118 virtual void refreshReadOnly() const;
121 /// Enable/Disable a widget
122 virtual void setWidgetEnabled(Widget * obj, bool enable) const = 0;
123 /// Enable/Disable a button
124 virtual void setButtonEnabled(Button * obj, bool enable) const = 0;
125 /// Set the Label on the button
126 virtual void setButtonLabel(Button * obj, std::string const & label) const = 0;
128 std::string const cancel_label_;
129 std::string const close_label_;
136 typedef std::list<Widget *> Widgets;
140 } // namespace frontend
143 #include "BCView.tmpl"