*
* LyX, The Document Processor
*
- * Copyright 2000 The LyX Team.
+ * Copyright 2000-2001 The LyX Team.
*
* ======================================================
+ *
+ * \author Angus Leeming <a.leeming@ic.ac.uk>
*/
#ifndef FORMBASE_H
#define FORMBASE_H
-#include "DialogBase.h"
-#include "LString.h"
-#include <boost/utility.hpp>
-#include FORMS_H_LOCATION
-#include "ButtonController.h"
-#include "gettext.h"
-
-class Buffer;
-class Dialogs;
-class LyXView;
+#include <boost/smart_ptr.hpp>
+#include FORMS_H_LOCATION // Can't forward-declare FL_FORM
#ifdef __GNUG__
#pragma interface
#endif
+#include "ViewBase.h"
+#include "LString.h"
+#include "ButtonPolicies.h"
+
+class xformsBC;
+
/** This class is an XForms GUI base class.
- It is meant to be used solely as the parent class to FormBaseBI and FormBaseBD
- @author Angus Leeming
*/
-class FormBase : public DialogBase, public noncopyable {
+class FormBase : public ViewBC<xformsBC>
+{
public:
- /// Callback functions
- static int WMHideCB(FL_FORM *, void *);
- ///
- static void ApplyCB(FL_OBJECT *, long);
- ///
- static void OKCB(FL_OBJECT *, long);
- ///
- static void CancelCB(FL_OBJECT *, long);
- ///
- static void InputCB(FL_OBJECT *, long);
///
- static void RestoreCB(FL_OBJECT *, long);
-
-protected: // methods
- /** Constructor.
- #FormBase(lv, d, _("DialogName"), BUFFER_DEPENDENT, new ButtonPolicy)#
- */
- FormBase(LyXView *, Dialogs *, string const &,
- ButtonPolicy *, char const *, char const *);
+ FormBase(ControlButtons &, string const &, bool allowResize);
///
- virtual ~FormBase();
+ virtual ~FormBase() {}
- /// Create the dialog if necessary, update it and display it.
- void show();
- /// Hide the dialog.
- virtual void hide();
- /// bool indicates if a buffer switch took place
- virtual void update(bool = false) {}
- /// Connect signals. Also perform any necessary initialisation.
- virtual void connect();
- /// Disconnect signals. Also perform any necessary housekeeping.
- virtual void disconnect() = 0;
+ /// input callback function
+ void InputCB(FL_OBJECT *, long);
+
+protected:
/// Build the dialog
virtual void build() = 0;
- /** Filter the inputs on callback from xforms
- Return true if inputs are valid.
- */
- virtual bool input( FL_OBJECT *, long ) {
- return true;
- }
- /// Apply from dialog (modify or create inset)
- virtual void apply() {}
- /// OK from dialog
- virtual void ok() {
- apply();
- hide();
- }
- /// Cancel from dialog
- virtual void cancel() {
- hide();
- }
- /// Restore from dialog
- virtual void restore() {
- update();
- }
+ /// Hide the dialog.
+ void hide();
+ /// Create the dialog if necessary, update it and display it.
+ void show();
+
+private:
/// Pointer to the actual instantiation of xform's form
virtual FL_FORM * form() const = 0;
+ /// Filter the inputs on callback from xforms
+ virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
- /** Which LyXFunc do we use?
- We could modify Dialogs to have a visible LyXFunc* instead and
- save a couple of bytes per dialog.
- */
- LyXView * lv_;
- /// Useable even in derived-class's const functions.
- mutable ButtonController bc_;
- /// Used so we can get at the signals we have to connect to.
- Dialogs * d_;
- /// Hide connection.
- Connection h_;
- /// dialog title, displayed by WM.
- string title;
- ///
- ButtonPolicy * bp_;
- /// Overcome a dumb xforms sizing bug
- mutable int minw_;
+ /** Redraw the form (on receipt of a Signal indicating, for example,
+ that the xform colors have been re-mapped). */
+ virtual void redraw();
+
+ /// The dialog's minimum allowable dimensions.
+ int minw_;
///
- mutable int minh_;
+ int minh_;
+ /// Can the dialog be resized after it has been created?
+ bool allow_resize_;
+ /// dialog title, displayed by WM.
+ string title_;
};
-/** This class is an XForms GUI base class for Buffer Independent dialogs.
- Such dialogs do not require an update Connection although they may use
- an update() function which is also supported by restore().
- */
-class FormBaseBI : public FormBase {
+template <class Dialog>
+class FormDB: public FormBase
+{
protected:
- /// Constructor
- FormBaseBI(LyXView *, Dialogs *, string const &,
- ButtonPolicy * bp = new OkApplyCancelPolicy,
- char const * close = N_("Close"),
- char const * cancel = N_("Cancel"));
-
- /// Connect signals
- virtual void connect();
- /// Disconnect signals
- virtual void disconnect();
+ ///
+ FormDB(ControlButtons &, string const &, bool allowResize=true);
+ /// Pointer to the actual instantiation of xform's form
+ virtual FL_FORM * form() const;
+ /// Real GUI implementation.
+ boost::scoped_ptr<Dialog> dialog_;
};
-/** This class is an XForms GUI base class for Buffer Dependent dialogs
- */
-class FormBaseBD : public FormBase {
+template <class Dialog>
+FormDB<Dialog>::FormDB(ControlButtons & c, string const & t, bool allowResize)
+ : FormBase(c, t, allowResize)
+{}
+
+
+template <class Dialog>
+FL_FORM * FormDB<Dialog>::form() const
+{
+ if (dialog_.get()) return dialog_->form;
+ return 0;
+}
+
+
+template <class Controller, class Base>
+class FormCB: public Base
+{
protected:
- /// Constructor
- FormBaseBD(LyXView *, Dialogs *, string const &,
- ButtonPolicy * bp = new OkApplyCancelReadOnlyPolicy,
- char const * close = N_("Close"),
- char const * cancel = N_("Cancel"));
-
- /// Connect signals
- virtual void connect();
- /// Disconnect signals
- virtual void disconnect();
-
- /// Update connection.
- Connection u_;
+ ///
+ FormCB(ControlButtons &, string const &, bool allowResize=true);
+ /// The parent controller
+ Controller & controller() const;
};
-#endif
+template <class Controller, class Base>
+FormCB<Controller, Base>::FormCB(ControlButtons & c, string const & t,
+ bool allowResize)
+ : Base(c, t, allowResize)
+{}
+
+
+template <class Controller, class Base>
+Controller & FormCB<Controller, Base>::controller() const
+{
+ return static_cast<Controller &>(controller_);
+ //return dynamic_cast<Controller &>(controller_);
+}
+
+
+#endif // FORMBASE_H