4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS
12 /* A base class for the MCV-ed xforms dialogs.
20 #include "ButtonPolicies.h"
21 #include "forms_fwd.h"
24 #include <boost/scoped_ptr.hpp>
25 #include <X11/Xlib.h> // for Pixmap
31 /** This class is an XForms GUI base class.
33 class FormBase : public ViewBase
37 FormBase(string const &, bool allowResize);
41 /** Input callback function.
42 * Invoked only by the xforms callback interface
44 void InputCB(FL_OBJECT *, long);
46 /** Message callback function.
47 * Invoked only by the xforms callback interface
49 void MessageCB(FL_OBJECT *, int event);
51 /** Prehandler callback function.
52 * Invoked only by the xforms callback interface
54 void PrehandlerCB(FL_OBJECT * ob, int event, int key);
57 Tooltips & tooltips();
61 virtual void build() = 0;
64 /// Create the dialog if necessary, update it and display it.
67 virtual bool isVisible() const;
69 /** Prepare the way to:
70 * 1. display feedback as the mouse moves over ob. This feedback will
71 * typically be rather more verbose than just a tooltip.
72 * 2. activate the button controller after a paste with the middle
75 static void setPrehandler(FL_OBJECT * ob);
77 /** Pass the class a pointer to the message_widget so that it can
79 void setMessageWidget(FL_OBJECT * message_widget);
81 /** Send the warning message from the daughter class to the
82 message_widget direct. The message will persist till the mouse
83 movesto a new object. */
84 void postWarning(string const & warning);
85 /// Reset the message_widget_
92 /// Pointer to the actual instantiation of xform's form
93 virtual FL_FORM * form() const = 0;
94 /// Filter the inputs on callback from xforms
95 virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
97 /** Redraw the form (on receipt of a Signal indicating, for example,
98 * that the xform colors have been re-mapped).
100 virtual void redraw();
102 /** Called on the first show() request, initialising various bits and
105 void prepare_to_show();
107 /** Get the feedback message for ob.
108 Called if warning_posted_ == false. */
109 virtual string const getFeedback(FL_OBJECT * /* ob */)
112 /// Post the feedback message for ob to message_widget_
113 void postMessage(string const & message);
115 /** Variable used to decide whether to remove the existing feedback
116 message or not (if it is in fact a warning) */
117 bool warning_posted_;
118 /// The widget to display the feedback
119 FL_OBJECT * message_widget_;
121 /// The dialog's minimum allowable dimensions.
125 /// Can the dialog be resized after it has been created?
127 /// Passed to the window manager to give a pretty little symbol ;-)
132 Tooltips * tooltips_;
136 template <class Dialog>
137 class FormDB: public FormBase
141 FormDB(string const &, bool allowResize=true);
142 /// Pointer to the actual instantiation of xform's form
143 virtual FL_FORM * form() const;
144 /// Real GUI implementation.
145 boost::scoped_ptr<Dialog> dialog_;
149 template <class Dialog>
150 FormDB<Dialog>::FormDB(string const & t, bool allowResize)
151 : FormBase(t, allowResize)
155 template <class Dialog>
156 FL_FORM * FormDB<Dialog>::form() const
158 return dialog_.get() ? dialog_->form : 0;
162 template <class Controller, class Base>
163 class FormCB: public Base
166 /// The parent controller
167 Controller & controller();
169 Controller const & controller() const;
173 FormCB(string const &, bool allowResize = true);
177 template <class Controller, class Base>
178 FormCB<Controller, Base>::FormCB(string const & t, bool allowResize)
179 : Base(t, allowResize)
183 template <class Controller, class Base>
184 Controller & FormCB<Controller, Base>::controller()
186 return static_cast<Controller &>(this->getController());
190 template <class Controller, class Base>
191 Controller const & FormCB<Controller, Base>::controller() const
193 return static_cast<Controller const &>(this->getController());