// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 2000 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
+ *
+ * Full author contact details are available in file CREDITS.
*/
#ifndef BUTTONCONTROLLER_H
#define BUTTONCONTROLLER_H
-#ifdef __GNUG__
-#pragma interface
-#endif
+#include "ButtonPolicy.h"
+#include "BCView.h"
-#include "ButtonPolicies.h"
-#include "LString.h"
-#include "gettext.h"
+#include <boost/scoped_ptr.hpp>
+#include <boost/noncopyable.hpp>
-/** Abstract base class for a ButtonController
+namespace lyx {
+namespace frontend {
- * Controls the activation of the OK, Apply and Cancel buttons.
- * Actually supports 4 buttons in all and it's up to the user to decide on
+/** \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.
- * Author: Allan Rae <rae@lyx.org>.
- * This abstract base class stripped of xforms-specific code by
- * Angus Leeming <a.leeming@ic.ac.uk>
*/
-class ButtonControllerBase : public boost::noncopyable
-{
+
+class ButtonController : boost::noncopyable {
public:
- /** Constructor.
- The cancel/close label entries are _not_ managed within the class
- thereby allowing you to reassign at will and to use static labels.
- It also means if you really don't want to have the Cancel button
- label be different when there is nothing changed in the dialog then
- you can just assign "Cancel" to both labels. Or even reuse this
- class for something completely different.
+ ButtonController() : policy_(ButtonPolicy::IgnorantPolicy) {}
+ //@{
+ /** Methods to set and get the GUI view (containing the actual
+ * button widgets.
+ * \param ptr is owned by the ButtonController.
*/
- ButtonControllerBase(string const & cancel, string const & close);
- ///
- virtual ~ButtonControllerBase() {}
- ///
- virtual void refresh() = 0;
- ///
- virtual ButtonPolicy & bp() = 0;
- ///
- virtual void input(ButtonPolicy::SMInput);
+ 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_; }
+ //@}
+
///
+ void input(ButtonPolicy::SMInput);
+
+ //@{
+ /// Tell the BC that a particular button has been pressed.
void ok();
- ///
void apply();
- ///
void cancel();
- ///
- void undoAll();
- ///
+ void restore();
+ //@}
+
+ /// Tell the BC that the dialog is being hidden
void hide();
- /// Passthrough function -- returns its input value
- bool readOnly(bool = true);
- ///
- void readWrite();
- ///
- void valid(bool = true);
- ///
- void invalid();
-protected:
- ///
- string cancel_label;
- ///
- string close_label;
-};
+ /**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);
-template <class BP, class GUIBC>
-class ButtonController: public GUIBC
-{
-public:
- ///
- ButtonController(string const & = _("Cancel"),
- string const & = _("Close"));
- ///
- virtual ButtonPolicy & bp() { return bp_; }
+ /** \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);
-protected:
- ///
- BP bp_;
+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