// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 2000-2001 The LyX Team.
+/**
+ * \file ButtonController.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * ======================================================
+ * \author Allan Rae
*
- * \file ButtonController.h
- * \author Allan Rae, rae@lyx.org
- * \author Angus Leeming, a.leeming@ic.ac.uk
- * \author Baruch Even, baruch.even@writeme.com
+ * Full author contact details are available in file CREDITS.
*/
#ifndef BUTTONCONTROLLER_H
#define BUTTONCONTROLLER_H
-#include <list>
-
-#include "gettext.h"
-#include "ButtonControllerBase.h"
-#include "debug.h"
-
-template <class Button, class Widget>
-class GuiBC : public ButtonControllerBase
-{
-public:
- ///
- GuiBC(string const & cancel, string const & close);
-
- ///
- void setOK(Button * obj) { okay_ = obj; }
- ///
- void setApply(Button * obj) { apply_ = obj; }
- ///
- void setCancel(Button * obj) { cancel_ = obj; }
- ///
- void setRestore(Button * obj) { restore_ = obj; }
- ///
- void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
- ///
- void eraseReadOnly() { read_only_.clear(); }
+#include "ButtonPolicy.h"
+#include "BCView.h"
- /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
- void refresh();
- /// Refresh the status of any widgets in the read_only list
- void refreshReadOnly();
+#include <boost/scoped_ptr.hpp>
+#include <boost/noncopyable.hpp>
-private:
- /// Enable/Disable a widget
- virtual void setWidgetEnabled(Widget * obj, bool enable) = 0;
- /// Enable/Disable a button
- virtual void setButtonEnabled(Button * obj, bool enable) = 0;
- /// Set the Label on the button
- virtual void setButtonLabel(Button * obj, string const & label) = 0;
-
- Button * okay_;
- Button * apply_;
- Button * cancel_;
- Button * restore_;
-
- typedef std::list<Widget *> Widgets;
- Widgets read_only_;
-};
+namespace lyx {
+namespace frontend {
+/** \c ButtonController controls the activation of the OK, Apply and
+ * Cancel buttons.
+ *
+ * It actually supports 4 buttons in all and it's up to the user to decide on
+ * the activation policy and which buttons correspond to which output of the
+ * state machine.
+ */
-template <class Button, class Widget>
-GuiBC<Button, Widget>::GuiBC(string const & cancel, string const & close)
- : ButtonControllerBase(cancel, close),
- okay_(0), apply_(0), cancel_(0), restore_(0)
-{}
-
-
-template <class Button, class Widget>
-void GuiBC<Button, Widget>::refresh()
-{
- lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl;
-
- if (okay_) {
- bool const enabled = bp().buttonStatus(ButtonPolicy::OKAY);
- setButtonEnabled(okay_, enabled);
- }
- if (apply_) {
- bool const enabled = bp().buttonStatus(ButtonPolicy::APPLY);
- setButtonEnabled(apply_, enabled);
- }
- if (restore_) {
- bool const enabled = bp().buttonStatus(ButtonPolicy::RESTORE);
- setButtonEnabled(restore_, enabled);
- }
- if (cancel_) {
- bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL);
- if (enabled)
- setButtonLabel(cancel_, cancel_label_);
- else
- setButtonLabel(cancel_, close_label_);
- }
-}
-
-
-template <class Button, class Widget>
-void GuiBC<Button, Widget>::refreshReadOnly()
-{
- if (read_only_.empty()) return;
-
- bool const enable = !bp().isReadOnly();
-
- Widgets::const_iterator end = read_only_.end();
- Widgets::const_iterator iter = read_only_.begin();
- for (; iter != end; ++iter) {
- setWidgetEnabled(*iter, enable);
- }
-}
-
-
-template <class BP, class GUIBC>
-class ButtonController: public GUIBC
-{
+class ButtonController : boost::noncopyable {
public:
- ///
- ButtonController(string const & = _("Cancel"),
- string const & = _("Close"));
- ///
- virtual ButtonPolicy & bp() { return bp_; }
+ ButtonController() : policy_(ButtonPolicy::IgnorantPolicy) {}
+ //@{
+ /** Methods to set and get the GUI view (containing the actual
+ * button widgets.
+ * \param ptr is owned by the ButtonController.
+ */
+ void view(BCView * ptr);
+ BCView & view() const;
+ //@}
+
+ //@{
+ /** Methods to set and get the ButtonPolicy.
+ * \param ptr is owned by the ButtonController.
+ */
+ void setPolicy(ButtonPolicy::Policy policy);
+ ButtonPolicy const & policy() const { return policy_; }
+ ButtonPolicy & policy() { return policy_; }
+ //@}
-protected:
///
- BP bp_;
-};
+ void input(ButtonPolicy::SMInput);
+
+ //@{
+ /// Tell the BC that a particular button has been pressed.
+ void ok();
+ void apply();
+ void cancel();
+ void restore();
+ //@}
+
+ /// Tell the BC that the dialog is being hidden
+ void hide();
+
+ /**Refresh the activation state of the Ok, Apply, Close and
+ * Restore buttons.
+ */
+ void refresh() const;
+
+ /** Refresh the activation state of all the widgets under the control
+ * of the BC to reflect the read-only status of the underlying buffer.
+ */
+ void refreshReadOnly() const;
+
+ /** Passthrough function -- returns its input value
+ * Tell the BC about the read-only status of the underlying buffer.
+ */
+ bool readOnly(bool = true);
+
+ /** \param validity Tell the BC that the data is, or is not, valid.
+ * Sets the activation state of the buttons immediately.
+ */
+ void valid(bool = true);
+private:
+ ButtonPolicy policy_;
+ boost::scoped_ptr<BCView> view_;
+};
-template <class BP, class GUIBC>
-ButtonController<BP, GUIBC>::ButtonController(string const & cancel,
- string const & close)
- : GUIBC(cancel, close)
-{}
+} // namespace frontend
+} // namespace lyx
#endif // BUTTONCONTROLLER_H