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 widgets status.
46 /// Enable/Disable a widget
47 virtual void setWidgetEnabled(Widget * obj, bool enable) = 0;
48 /// Enable/Disable a button
49 virtual void setButtonEnabled(Button * obj, bool enable) = 0;
50 /// Set the Label on the button
51 virtual void setButtonLabel(Button * obj, string const & label) = 0;
58 typedef std::list<Widget *> Widgets;
63 template <class Button, class Widget>
64 GuiBC<Button, Widget>::GuiBC(string const & cancel, string const & close)
65 : ButtonControllerBase(cancel, close),
66 okay_(0), apply_(0), cancel_(0), restore_(0)
70 template <class Button, class Widget>
71 void GuiBC<Button, Widget>::refresh()
74 bool const enabled = bp().buttonStatus(ButtonPolicy::OKAY);
75 setButtonEnabled(okay_, enabled);
78 bool const enabled = bp().buttonStatus(ButtonPolicy::APPLY);
79 setButtonEnabled(apply_, enabled);
82 bool const enabled = bp().buttonStatus(ButtonPolicy::RESTORE);
83 setButtonEnabled(restore_, enabled);
86 bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL);
88 setButtonLabel(cancel_, cancel_label_);
90 setButtonLabel(cancel_, close_label_);
93 // Enable/Disable read-only handled widgets.
94 if (!read_only_.empty()) {
95 bool const enable = !bp().isReadOnly();
97 Widgets::const_iterator end = read_only_.end();
98 Widgets::const_iterator iter = read_only_.begin();
99 for (; iter != end; ++iter) {
100 setWidgetEnabled(*iter, enable);
107 template <class BP, class GUIBC>
108 class ButtonController: public GUIBC
112 ButtonController(string const & = _("Cancel"),
113 string const & = _("Close"));
115 virtual ButtonPolicy & bp() { return bp_; }
123 template <class BP, class GUIBC>
124 ButtonController<BP, GUIBC>::ButtonController(string const & cancel,
125 string const & close)
126 : GUIBC(cancel, close)
129 #endif // BUTTONCONTROLLER_H