2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000-2001 The LyX Team.
9 * ======================================================
11 * \file ButtonController.h
12 * \author Allan Rae, rae@lyx.org
13 * \author Angus Leeming, a.leeming@ic.ac.uk
14 * \author Baruch Even, baruch.even@writeme.com
17 #ifndef BUTTONCONTROLLER_H
18 #define BUTTONCONTROLLER_H
22 template <class Button, class Widget>
23 class GuiBC : public ButtonControllerBase
27 GuiBC(string const & cancel, string const & close);
30 void setOK(Button * obj) { okay_ = obj; }
32 void setApply(Button * obj) { apply_ = obj; }
34 void setCancel(Button * obj) { cancel_ = obj; }
36 void setRestore(Button * obj) { restore_ = obj; }
38 void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
40 void eraseReadOnly() { read_only_.clear(); }
42 /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
44 /// Refresh the status of any widgets in the read_only list
45 void refreshReadOnly();
48 /// Enable/Disable a widget
49 virtual void setWidgetEnabled(Widget * obj, bool enable) = 0;
50 /// Enable/Disable a button
51 virtual void setButtonEnabled(Button * obj, bool enable) = 0;
52 /// Set the Label on the button
53 virtual void setButtonLabel(Button * obj, string const & label) = 0;
60 typedef std::list<Widget *> Widgets;
65 template <class Button, class Widget>
66 GuiBC<Button, Widget>::GuiBC(string const & cancel, string const & close)
67 : ButtonControllerBase(cancel, close),
68 okay_(0), apply_(0), cancel_(0), restore_(0)
72 template <class Button, class Widget>
73 void GuiBC<Button, Widget>::refresh()
76 bool const enabled = bp().buttonStatus(ButtonPolicy::OKAY);
77 setButtonEnabled(okay_, enabled);
80 bool const enabled = bp().buttonStatus(ButtonPolicy::APPLY);
81 setButtonEnabled(apply_, enabled);
84 bool const enabled = bp().buttonStatus(ButtonPolicy::RESTORE);
85 setButtonEnabled(restore_, enabled);
88 bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL);
90 setButtonLabel(cancel_, cancel_label_);
92 setButtonLabel(cancel_, close_label_);
97 template <class Button, class Widget>
98 void GuiBC<Button, Widget>::refreshReadOnly()
100 if (read_only_.empty()) return;
102 bool const enable = !bp().isReadOnly();
104 Widgets::const_iterator end = read_only_.end();
105 Widgets::const_iterator iter = read_only_.begin();
106 for (; iter != end; ++iter) {
107 setWidgetEnabled(*iter, enable);
112 template <class BP, class GUIBC>
113 class ButtonController: public GUIBC
117 ButtonController(string const & = _("Cancel"),
118 string const & = _("Close"));
120 virtual ButtonPolicy & bp() { return bp_; }
128 template <class BP, class GUIBC>
129 ButtonController<BP, GUIBC>::ButtonController(string const & cancel,
130 string const & close)
131 : GUIBC(cancel, close)
134 #endif // BUTTONCONTROLLER_H