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"
26 template <class Button, class Widget>
27 class GuiBC : public ButtonControllerBase
31 GuiBC(string const & cancel, string const & close);
34 void setOK(Button * obj) { okay_ = obj; }
36 void setApply(Button * obj) { apply_ = obj; }
38 void setCancel(Button * obj) { cancel_ = obj; }
40 void setRestore(Button * obj) { restore_ = obj; }
42 void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
44 void eraseReadOnly() { read_only_.clear(); }
46 /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
48 /// Refresh the status of any widgets in the read_only list
49 void refreshReadOnly();
52 /// Enable/Disable a widget
53 virtual void setWidgetEnabled(Widget * obj, bool enable) = 0;
54 /// Enable/Disable a button
55 virtual void setButtonEnabled(Button * obj, bool enable) = 0;
56 /// Set the Label on the button
57 virtual void setButtonLabel(Button * obj, string const & label) = 0;
64 typedef std::list<Widget *> Widgets;
69 template <class Button, class Widget>
70 GuiBC<Button, Widget>::GuiBC(string const & cancel, string const & close)
71 : ButtonControllerBase(cancel, close),
72 okay_(0), apply_(0), cancel_(0), restore_(0)
76 template <class Button, class Widget>
77 void GuiBC<Button, Widget>::refresh()
79 lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl;
82 bool const enabled = bp().buttonStatus(ButtonPolicy::OKAY);
83 setButtonEnabled(okay_, enabled);
86 bool const enabled = bp().buttonStatus(ButtonPolicy::APPLY);
87 setButtonEnabled(apply_, enabled);
90 bool const enabled = bp().buttonStatus(ButtonPolicy::RESTORE);
91 setButtonEnabled(restore_, enabled);
94 bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL);
96 setButtonLabel(cancel_, cancel_label_);
98 setButtonLabel(cancel_, close_label_);
103 template <class Button, class Widget>
104 void GuiBC<Button, Widget>::refreshReadOnly()
106 if (read_only_.empty()) return;
108 bool const enable = !bp().isReadOnly();
110 Widgets::const_iterator end = read_only_.end();
111 Widgets::const_iterator iter = read_only_.begin();
112 for (; iter != end; ++iter) {
113 setWidgetEnabled(*iter, enable);
118 template <class BP, class GUIBC>
119 class ButtonController: public GUIBC
123 ButtonController(string const & = _("Cancel"),
124 string const & = _("Close"));
126 virtual ButtonPolicy & bp() { return bp_; }
134 template <class BP, class GUIBC>
135 ButtonController<BP, GUIBC>::ButtonController(string const & cancel,
136 string const & close)
137 : GUIBC(cancel, close)
140 #endif // BUTTONCONTROLLER_H