3 * \file FormDialogView.h
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.
15 #ifndef FORMDIALOGVIEW_H
16 #define FORMDIALOGVIEW_H
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 FormDialogView : public Dialog::View {
36 FormDialogView(Dialog &, string const &, bool allowResize);
38 virtual ~FormDialogView();
40 /** Input callback function.
41 * Invoked only by the xforms callback interface
43 void InputCB(FL_OBJECT *, long);
45 /** Message callback function.
46 * Invoked only by the xforms callback interface
48 void MessageCB(FL_OBJECT *, int event);
50 /** Prehandler callback function.
51 * Invoked only by the xforms callback interface
53 void PrehandlerCB(FL_OBJECT * ob, int event, int key);
56 Tooltips & tooltips();
60 virtual void build() = 0;
63 /// Create the dialog if necessary, update it and display it.
66 virtual bool isVisible() const;
68 /** Prepare the way to:
69 * 1. display feedback as the mouse moves over ob. This feedback will
70 * typically be rather more verbose than just a tooltip.
71 * 2. activate the button controller after a paste with the middle
74 static void setPrehandler(FL_OBJECT * ob);
76 /** Pass the class a pointer to the message_widget so that it can
78 void setMessageWidget(FL_OBJECT * message_widget);
80 /** Send the warning message from the daughter class to the
81 message_widget direct. The message will persist till the mouse
82 movesto a new object. */
83 void postWarning(string const & warning);
84 /// Reset the message_widget_
91 /// Pointer to the actual instantiation of xform's form
92 virtual FL_FORM * form() const = 0;
93 /// Filter the inputs on callback from xforms
94 virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
96 /** Redraw the form (on receipt of a Signal indicating, for example,
97 * that the xform colors have been re-mapped).
99 virtual void redraw();
101 /** Called on the first show() request, initialising various bits and
104 void prepare_to_show();
106 /** Get the feedback message for ob.
107 Called if warning_posted_ == false. */
108 virtual string const getFeedback(FL_OBJECT * /* ob */)
111 /// Post the feedback message for ob to message_widget_
112 void postMessage(string const & message);
114 /** Variable used to decide whether to remove the existing feedback
115 message or not (if it is in fact a warning) */
116 bool warning_posted_;
117 /// The widget to display the feedback
118 FL_OBJECT * message_widget_;
120 /// The dialog's minimum allowable dimensions.
124 /// Can the dialog be resized after it has been created?
126 /// dialog title, displayed by the window manager.
128 /// Passed to the window manager to give a pretty little symbol ;-)
133 Tooltips * tooltips_;
137 template <class FL_dialog>
138 class FormView: public FormDialogView {
141 FormView(Dialog &, 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<FL_dialog> dialog_;
149 template <class FL_dialog>
150 FormView<FL_dialog>::FormView(Dialog & parent, string const & t,
152 : FormDialogView(parent, t, allowResize)
156 template <class FL_dialog>
157 FL_FORM * FormView<FL_dialog>::form() const
159 return dialog_.get() ? dialog_->form : 0;
163 template <class Controller, class Base>
164 class FormController: public Base {
166 /// The parent controller
167 Controller & controller();
169 Controller const & controller() const;
173 FormController(Dialog &, string const &, bool allowResize = true);
177 template <class Controller, class Base>
178 FormController<Controller, Base>::FormController(Dialog & p,
179 string const & t, bool resize)
184 template <class Controller, class Base>
185 Controller & FormController<Controller, Base>::controller()
187 return static_cast<Controller &>(getController());
191 template <class Controller, class Base>
192 Controller const & FormController<Controller, Base>::controller() const
194 return static_cast<Controller const &>(getController());
198 #endif // FORMDIALOGVIEW_H