// -*- C++ -*-
-/* This file is part of
- * ======================================================
+/**
+ * \file FormBase.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * LyX, The Document Processor
+ * \author Angus Leeming
*
- * Copyright 2000 The LyX Team.
- *
- * ======================================================
+ * Full author contact details are available in file CREDITS.
+ */
+
+/* A base class for the MCV-ed xforms dialogs.
*/
#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 "ViewBase.h"
+#include "ButtonPolicies.h"
+#include "forms_fwd.h"
+
+#include <boost/scoped_ptr.hpp>
+#include <X11/Xlib.h> // for Pixmap
-#ifdef __GNUG__
-#pragma interface
-#endif
+class xformsBC;
+class Tooltips;
-/** This class is an XForms GUI base class
- @author Angus Leeming
+
+/** This class is an XForms GUI base class.
*/
-class FormBase : public DialogBase, public noncopyable {
+class FormBase : public ViewBase
+{
public:
///
- enum BufferDependency {
- ///
- BUFFER_DEPENDENT,
- ///
- BUFFER_INDEPENDENT
- };
+ FormBase(std::string const &, bool allowResize);
///
- enum ChangedBufferAction {
- ///
- UPDATE,
- ///
- HIDE
- };
-
- /** Constructor.
- #FormBase(lv, d, _("DialogName"), BUFFER_DEPENDENT, new ButtonPolicy)#
+ virtual ~FormBase();
+
+ /** Input callback function.
+ * Invoked only by the xforms callback interface
*/
- FormBase(LyXView *, Dialogs *, string const &,
- BufferDependency, ChangedBufferAction,
- ButtonPolicy * bp = new OkApplyCancelReadOnlyPolicy,
- char const * close = N_("Close"),
- char const * cancel = N_("Cancel"));
+ void InputCB(FL_OBJECT *, long);
+
+ /** Message callback function.
+ * Invoked only by the xforms callback interface
+ */
+ void MessageCB(FL_OBJECT *, int event);
+
+ /** Prehandler callback function.
+ * Invoked only by the xforms callback interface
+ */
+ void PrehandlerCB(FL_OBJECT * ob, int event, int key);
+
///
- virtual ~FormBase();
+ Tooltips & tooltips();
- /// Callback functions
- static int WMHideCB(FL_FORM *, void *);
+protected:
+ /// Build the dialog
+ virtual void build() = 0;
+ /// Hide the dialog.
+ virtual void hide();
+ /// Create the dialog if necessary, update it and display it.
+ virtual void show();
///
- static void ApplyCB(FL_OBJECT *, long);
+ virtual bool isVisible() const;
+
+ /** Prepare the way to:
+ * 1. display feedback as the mouse moves over ob. This feedback will
+ * typically be rather more verbose than just a tooltip.
+ * 2. activate the button controller after a paste with the middle
+ * mouse button.
+ */
+ static void setPrehandler(FL_OBJECT * ob);
+
+ /** Pass the class a pointer to the message_widget so that it can
+ post the message */
+ void setMessageWidget(FL_OBJECT * message_widget);
+
+ /** Send the warning message from the daughter class to the
+ message_widget direct. The message will persist till the mouse
+ movesto a new object. */
+ void postWarning(std::string const & warning);
+ /// Reset the message_widget_
+ void clearMessage();
+
///
- static void OKCB(FL_OBJECT *, long);
+ xformsBC & bcview();
+
+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);
+
+ /** Redraw the form (on receipt of a Signal indicating, for example,
+ * that the xform colors have been re-mapped).
+ */
+ virtual void redraw();
+
+ /** Called on the first show() request, initialising various bits and
+ * pieces.
+ */
+ void prepare_to_show();
+
+ /** Get the feedback message for ob.
+ Called if warning_posted_ == false. */
+ virtual std::string const getFeedback(FL_OBJECT * /* ob */)
+ { return std::string(); }
+
+ /// Post the feedback message for ob to message_widget_
+ void postMessage(std::string const & message);
+
+ /** Variable used to decide whether to remove the existing feedback
+ message or not (if it is in fact a warning) */
+ bool warning_posted_;
+ /// The widget to display the feedback
+ FL_OBJECT * message_widget_;
+
+ /// The dialog's minimum allowable dimensions.
+ int minw_;
///
- static void CancelCB(FL_OBJECT *, long);
+ int minh_;
+ /// Can the dialog be resized after it has been created?
+ bool allow_resize_;
+ /// Passed to the window manager to give a pretty little symbol ;-)
+ Pixmap icon_pixmap_;
///
- static void InputCB(FL_OBJECT *, long);
+ Pixmap icon_mask_;
///
- static void RestoreCB(FL_OBJECT *, long);
+ Tooltips * tooltips_;
+};
-protected: // methods
- /// Create the dialog if necessary, update it and display it.
- void show();
- /// Hide the dialog.
- virtual void hide();
- /// Connect signals
- virtual void connect();
- /// Disconnect signals
- virtual void disconnect();
- /// 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;
- }
- /// Update dialog before showing it
- virtual void update() {}
- /// 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();
- }
- /// delete derived class variables when hide()ing
- virtual void clearStore() {}
+
+template <class Dialog>
+class FormDB: public FormBase
+{
+protected:
+ ///
+ FormDB(std::string const &, bool allowResize=true);
/// Pointer to the actual instantiation of xform's form
- virtual FL_FORM * form() const = 0;
+ virtual FL_FORM * form() const;
+ /// Real GUI implementation.
+ boost::scoped_ptr<Dialog> dialog_;
+};
-private: // methods
- /// method connected to updateBufferDependent signal.
- void updateOrHide();
-
-protected: // data
- /// block opening of form twice at the same time.
- bool dialogIsOpen;
- /** 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_;
-
-private: // data
- /// Used so we can get at the signals we have to connect to.
- Dialogs * d_;
- /// flag whether dialog is buffer dependent or not.
- BufferDependency const bd_;
- /// flag whether to hide or update on updateBufferDependent signal.
- ChangedBufferAction const cba_;
- /// stores parent buffer when popup was launched.
- Buffer * parent_;
- /// Update connection.
- Connection u_;
- /// Hide connection.
- Connection h_;
- /// dialog title, displayed by WM.
- string title;
+
+template <class Dialog>
+FormDB<Dialog>::FormDB(std::string const & t, bool allowResize)
+ : FormBase(t, allowResize)
+{}
+
+
+template <class Dialog>
+FL_FORM * FormDB<Dialog>::form() const
+{
+ return dialog_.get() ? dialog_->form : 0;
+}
+
+
+template <class Controller, class Base>
+class FormCB: public Base
+{
+public:
+ /// The parent controller
+ Controller & controller();
+ ///
+ Controller const & controller() const;
+
+protected:
///
- ButtonPolicy * bp_;
+ FormCB(std::string const &, bool allowResize = true);
};
-#endif
+
+template <class Controller, class Base>
+FormCB<Controller, Base>::FormCB(std::string const & t, bool allowResize)
+ : Base(t, allowResize)
+{}
+
+
+template <class Controller, class Base>
+Controller & FormCB<Controller, Base>::controller()
+{
+ return static_cast<Controller &>(this->getController());
+}
+
+
+template <class Controller, class Base>
+Controller const & FormCB<Controller, Base>::controller() const
+{
+ return static_cast<Controller const &>(this->getController());
+}
+
+
+#endif // FORMBASE_H