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 /** Prepare the way to:
71 * 1. display feedback as the mouse moves over ob. This feedback will
72 * typically be rather more verbose than just a tooltip.
73 * 2. activate the button controller after a paste with the middle
76 static void setPrehandler(FL_OBJECT * ob);
78 /** Pass the class a pointer to the message_widget so that it can
80 void setMessageWidget(FL_OBJECT * message_widget);
82 /** Send the warning message from the daughter class to the
83 message_widget direct. The message will persist till the mouse
84 movesto a new object. */
85 void postWarning(string const & warning);
86 /// Reset the message_widget_
93 /// Pointer to the actual instantiation of xform's form
94 virtual FL_FORM * form() const = 0;
95 /// Filter the inputs on callback from xforms
96 virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
98 /** Redraw the form (on receipt of a Signal indicating, for example,
99 * that the xform colors have been re-mapped).
101 virtual void redraw();
103 /** Called on the first show() request, initialising various bits and
106 void prepare_to_show();
108 /** Get the feedback message for ob.
109 Called if warning_posted_ == false. */
110 virtual string const getFeedback(FL_OBJECT * /* ob */)
113 /// Post the feedback message for ob to message_widget_
114 void postMessage(string const & message);
116 /** Variable used to decide whether to remove the existing feedback
117 message or not (if it is in fact a warning) */
118 bool warning_posted_;
119 /// The widget to display the feedback
120 FL_OBJECT * message_widget_;
122 /// The dialog's minimum allowable dimensions.
126 /// Can the dialog be resized after it has been created?
128 /// dialog title, displayed by the window manager.
130 /// Passed to the window manager to give a pretty little symbol ;-)
135 Tooltips * tooltips_;
139 template <class Dialog>
140 class FormDB: public FormBase
144 FormDB(string const &, bool allowResize=true);
145 /// Pointer to the actual instantiation of xform's form
146 virtual FL_FORM * form() const;
147 /// Real GUI implementation.
148 boost::scoped_ptr<Dialog> dialog_;
152 template <class Dialog>
153 FormDB<Dialog>::FormDB(string const & t, bool allowResize)
154 : FormBase(t, allowResize)
158 template <class Dialog>
159 FL_FORM * FormDB<Dialog>::form() const
161 return dialog_.get() ? dialog_->form : 0;
165 template <class Controller, class Base>
166 class FormCB: public Base
169 /// The parent controller
170 Controller & controller();
172 Controller const & controller() const;
176 FormCB(string const &, bool allowResize = true);
180 template <class Controller, class Base>
181 FormCB<Controller, Base>::FormCB(string const & t, bool allowResize)
182 : Base(t, allowResize)
186 template <class Controller, class Base>
187 Controller & FormCB<Controller, Base>::controller()
189 return static_cast<Controller &>(getController());
193 template <class Controller, class Base>
194 Controller const & FormCB<Controller, Base>::controller() const
196 return static_cast<Controller const &>(getController());