]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormBase.h
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormBase.h
index 00774e4cb9e29f0b9fec7835228f5e9253026620..3774f2bbf24c8725e510859d4f7713a22cd504e4 100644 (file)
  *
  *           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 "support/utility.hpp"
-#include FORMS_H_LOCATION
-
-class Dialogs;
-class LyXView;
+#include <boost/smart_ptr.hpp>
+#include FORMS_H_LOCATION // Can't forward-declare FL_FORM
 
 #ifdef __GNUG__
 #pragma interface
 #endif
 
-/** This class is an XForms GUI base class
+#include "ViewBase.h"
+#include "LString.h"
+#include "ButtonPolicies.h"
+
+class xformsBC;
+
+/** This class is an XForms GUI base class.
  */
-class FormBase : public DialogBase, public noncopyable {
+class FormBase : public ViewBC<xformsBC>
+{
 public:
-       /// Constructor
-       FormBase(LyXView *, Dialogs *, string const &);
-
-       /// Callback functions
-       static  int WMHideCB(FL_FORM *, void *);
-       ///
-       static void ApplyCB(FL_OBJECT *, long);
-       ///
-       static void CancelCB(FL_OBJECT *, long);
        ///
-       static void InputCB(FL_OBJECT *, long);
+       FormBase(ControlButtons &, string const &, bool allowResize);
        ///
-       static void OKCB(FL_OBJECT *, long);
+       virtual ~FormBase() {}
+
+       /// input callback function
+       void InputCB(FL_OBJECT *, long);
 
 protected:
-       /// Create the dialog if necessary, update it and display it.
-       void show();
+       /// Build the dialog
+       virtual void build() = 0;
        /// Hide the dialog.
        void hide();
+       /// Create the dialog if necessary, update it and display it.
+       void show();
 
-       /// Build the dialog
-       virtual void build() = 0;
-       /// Filter the inputs on callback from xforms
-       virtual void input( long ) {}
-       /// Update dialog before showing it
-       virtual void update() {}
-       /// Apply from dialog (modify or create inset)
-       virtual void apply() {}
-       /// delete derived class variables when hide()ing
-       virtual void clearStore() {}
-       /// Pointer to the actual instantiation of xform's form
-       virtual FL_FORM * const form() const = 0;
-
-       /** 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_;
-       /** Which Dialogs do we belong to?
-           Used so we can get at the signals we have to connect to.
-       */
-       Dialogs * d_;
 private:
-       /// Update connection.
-       Connection u_;
-       /// Hide connection.
-       Connection h_;
+       /// 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);
+
+       /** 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_;
+       ///
+       int minh_;
+       /// Can the dialog be resized after it has been created?
+       bool allow_resize_;
        /// dialog title, displayed by WM.
-       string title;
+       string title_;
+};
 
+
+template <class Dialog>
+class FormDB: public FormBase
+{
 protected:
-       /// block opening of form twice at the same time
-       bool dialogIsOpen;
+       ///
+       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_;
 };
 
-#endif
+
+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:
+       ///
+       FormCB(ControlButtons &, string const &, bool allowResize=true);
+       /// The parent controller
+       Controller & controller() const;
+};
+
+
+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