1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
8 * ======================================================
10 * \file ButtonController.h
11 * \author Allan Rae, rae@lyx.org
12 * \author Angus Leeming, a.leeming@ic.ac.uk
13 * \author Baruch Even, baruch.even@writeme.com
16 #ifndef BUTTONCONTROLLER_H
17 #define BUTTONCONTROLLER_H
21 template <class Button, class Widget>
22 class GuiBC : public ButtonControllerBase
26 GuiBC(string const & cancel, string const & close);
29 void setOK(Button * obj) { okay_ = obj; }
31 void setApply(Button * obj) { apply_ = obj; }
33 void setCancel(Button * obj) { cancel_ = obj; }
35 void setUndoAll(Button * obj) { undo_all_ = obj; }
37 void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
39 void eraseReadOnly() { read_only_.clear(); }
41 /// Refresh the widgets status.
45 /// Enable/Disable a widget
46 virtual void setWidgetEnabled(Widget * obj, bool enable) = 0;
47 /// Enable/Disable a button
48 virtual void setButtonEnabled(Button * obj, bool enable) = 0;
49 /// Set the Label on the button
50 virtual void setButtonLabel(Button * obj, string const & label) = 0;
57 typedef std::list<Widget *> Widgets;
62 template <class Button, class Widget>
63 GuiBC<Button, Widget>::GuiBC(string const & cancel, string const & close)
64 : ButtonControllerBase(cancel, close)
65 , okay_(0), apply_(0), cancel_(0), undo_all_(0)
69 template <class Button, class Widget>
70 void GuiBC<Button, Widget>::refresh()
73 bool const enabled = bp().buttonStatus(ButtonPolicy::OKAY);
74 setButtonEnabled(okay_, enabled);
77 bool const enabled = bp().buttonStatus(ButtonPolicy::APPLY);
78 setButtonEnabled(apply_, enabled);
81 bool const enabled = bp().buttonStatus(ButtonPolicy::UNDO_ALL);
82 setButtonEnabled(undo_all_, enabled);
85 bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL);
87 setButtonLabel(cancel_, cancel_label_);
89 setButtonLabel(cancel_, close_label_);
92 // Enable/Disable read-only handled widgets.
93 if (!read_only_.empty()) {
94 bool const enable = !bp().isReadOnly();
96 Widgets::const_iterator end = read_only_.end();
97 Widgets::const_iterator iter = read_only_.begin();
98 for (; iter != end; ++iter) {
99 setWidgetEnabled(*iter, enable);
106 template <class BP, class GUIBC>
107 class ButtonController: public GUIBC
111 ButtonController(string const & = _("Cancel"),
112 string const & = _("Close"));
114 virtual ButtonPolicy & bp() { return bp_; }
122 template <class BP, class GUIBC>
123 ButtonController<BP, GUIBC>::ButtonController(string const & cancel,
124 string const & close)
125 : GUIBC(cancel, close)
128 #endif // BUTTONCONTROLLER_H