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
23 #include "ButtonControllerBase.h"
25 template <class Button, class Widget>
26 class GuiBC : public ButtonControllerBase
30 GuiBC(string const & cancel, string const & close);
33 void setOK(Button * obj) { okay_ = obj; }
35 void setApply(Button * obj) { apply_ = obj; }
37 void setCancel(Button * obj) { cancel_ = obj; }
39 void setRestore(Button * obj) { restore_ = obj; }
41 void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
43 void eraseReadOnly() { read_only_.clear(); }
45 /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
47 /// Refresh the status of any widgets in the read_only list
48 void refreshReadOnly();
51 /// Enable/Disable a widget
52 virtual void setWidgetEnabled(Widget * obj, bool enable) = 0;
53 /// Enable/Disable a button
54 virtual void setButtonEnabled(Button * obj, bool enable) = 0;
55 /// Set the Label on the button
56 virtual void setButtonLabel(Button * obj, string const & label) = 0;
63 typedef std::list<Widget *> Widgets;
68 template <class Button, class Widget>
69 GuiBC<Button, Widget>::GuiBC(string const & cancel, string const & close)
70 : ButtonControllerBase(cancel, close),
71 okay_(0), apply_(0), cancel_(0), restore_(0)
75 template <class Button, class Widget>
76 void GuiBC<Button, Widget>::refresh()
79 bool const enabled = bp().buttonStatus(ButtonPolicy::OKAY);
80 setButtonEnabled(okay_, enabled);
83 bool const enabled = bp().buttonStatus(ButtonPolicy::APPLY);
84 setButtonEnabled(apply_, enabled);
87 bool const enabled = bp().buttonStatus(ButtonPolicy::RESTORE);
88 setButtonEnabled(restore_, enabled);
91 bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL);
93 setButtonLabel(cancel_, cancel_label_);
95 setButtonLabel(cancel_, close_label_);
100 template <class Button, class Widget>
101 void GuiBC<Button, Widget>::refreshReadOnly()
103 if (read_only_.empty()) return;
105 bool const enable = !bp().isReadOnly();
107 Widgets::const_iterator end = read_only_.end();
108 Widgets::const_iterator iter = read_only_.begin();
109 for (; iter != end; ++iter) {
110 setWidgetEnabled(*iter, enable);
115 template <class BP, class GUIBC>
116 class ButtonController: public GUIBC
120 ButtonController(string const & = _("Cancel"),
121 string const & = _("Close"));
123 virtual ButtonPolicy & bp() { return bp_; }
131 template <class BP, class GUIBC>
132 ButtonController<BP, GUIBC>::ButtonController(string const & cancel,
133 string const & close)
134 : GUIBC(cancel, close)
137 #endif // BUTTONCONTROLLER_H