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.
23 #include "ButtonPolicies.h"
24 #include "forms_fwd.h"
27 #include <boost/scoped_ptr.hpp>
28 #include <X11/Xlib.h> // for Pixmap
34 /** This class is an XForms GUI base class.
36 class FormBase : public ViewBase
40 FormBase(string const &, bool allowResize);
44 /** Input callback function.
45 * Invoked only by the xforms callback interface
47 void InputCB(FL_OBJECT *, long);
49 /** Message callback function.
50 * Invoked only by the xforms callback interface
52 void MessageCB(FL_OBJECT *, int event);
54 /** Prehandler callback function.
55 * Invoked only by the xforms callback interface
57 void PrehandlerCB(FL_OBJECT * ob, int event, int key);
60 Tooltips & tooltips();
64 virtual void build() = 0;
67 /// Create the dialog if necessary, update it and display it.
70 virtual bool isVisible() const;
72 /** Prepare the way to:
73 * 1. display feedback as the mouse moves over ob. This feedback will
74 * typically be rather more verbose than just a tooltip.
75 * 2. activate the button controller after a paste with the middle
78 static void setPrehandler(FL_OBJECT * ob);
80 /** Pass the class a pointer to the message_widget so that it can
82 void setMessageWidget(FL_OBJECT * message_widget);
84 /** Send the warning message from the daughter class to the
85 message_widget direct. The message will persist till the mouse
86 movesto a new object. */
87 void postWarning(string const & warning);
88 /// Reset the message_widget_
95 /// Pointer to the actual instantiation of xform's form
96 virtual FL_FORM * form() const = 0;
97 /// Filter the inputs on callback from xforms
98 virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
100 /** Redraw the form (on receipt of a Signal indicating, for example,
101 * that the xform colors have been re-mapped).
103 virtual void redraw();
105 /** Called on the first show() request, initialising various bits and
108 void prepare_to_show();
110 /** Get the feedback message for ob.
111 Called if warning_posted_ == false. */
112 virtual string const getFeedback(FL_OBJECT * /* ob */)
115 /// Post the feedback message for ob to message_widget_
116 void postMessage(string const & message);
118 /** Variable used to decide whether to remove the existing feedback
119 message or not (if it is in fact a warning) */
120 bool warning_posted_;
121 /// The widget to display the feedback
122 FL_OBJECT * message_widget_;
124 /// The dialog's minimum allowable dimensions.
128 /// Can the dialog be resized after it has been created?
130 /// dialog title, displayed by the window manager.
132 /// Passed to the window manager to give a pretty little symbol ;-)
137 Tooltips * tooltips_;
141 template <class Dialog>
142 class FormDB: public FormBase
146 FormDB(string const &, bool allowResize=true);
147 /// Pointer to the actual instantiation of xform's form
148 virtual FL_FORM * form() const;
149 /// Real GUI implementation.
150 boost::scoped_ptr<Dialog> dialog_;
154 template <class Dialog>
155 FormDB<Dialog>::FormDB(string const & t, bool allowResize)
156 : FormBase(t, allowResize)
160 template <class Dialog>
161 FL_FORM * FormDB<Dialog>::form() const
163 return dialog_.get() ? dialog_->form : 0;
167 template <class Controller, class Base>
168 class FormCB: public Base
171 /// The parent controller
172 Controller & controller();
174 Controller const & controller() const;
178 FormCB(string const &, bool allowResize = true);
182 template <class Controller, class Base>
183 FormCB<Controller, Base>::FormCB(string const & t, bool allowResize)
184 : Base(t, allowResize)
188 template <class Controller, class Base>
189 Controller & FormCB<Controller, Base>::controller()
191 return static_cast<Controller &>(getController());
195 template <class Controller, class Base>
196 Controller const & FormCB<Controller, Base>::controller() const
198 return static_cast<Controller const &>(getController());