2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000-2001 The LyX Team.
9 * ======================================================
11 * \author Angus Leeming <a.leeming@ic.ac.uk>
17 #include <boost/smart_ptr.hpp>
18 #include FORMS_H_LOCATION // Can't forward-declare FL_FORM
26 #include "ButtonPolicies.h"
31 /** This class is an XForms GUI base class.
33 class FormBase : public ViewBC<xformsBC>
37 FormBase(ControlButtons &, string const &, bool allowResize);
39 virtual ~FormBase() {}
41 /** input callback function.
42 Invoked only by C_FormBaseInputCB and by C_FormBasePrehandler */
43 void InputCB(FL_OBJECT *, long);
44 /// feedback callback function, invoked only by C_FormBasePrehandler
45 void FeedbackCB(FL_OBJECT *, int event);
48 /// invoked only by TooltipTimerCB
49 string const getTooltipCB(FL_OBJECT *);
54 virtual void build() = 0;
57 /// Create the dialog if necessary, update it and display it.
60 /// Prepare the way to produce a tooltip when the mouse is over ob.
61 void setTooltipHandler(FL_OBJECT * ob);
63 /** Prepare the way to:
64 1. display feedback as the mouse moves over ob. This feedback will
65 typically be rather more verbose than just a tooltip.
66 2. activate the button controller after a paste with the middle
68 void setPrehandler(FL_OBJECT * ob);
70 /** Flag that the message is a warning and should not be removed
71 when the mouse is no longer over the object.
72 Used in conjunction with setPrehandler(ob) and with feedback(ob),
74 void setWarningPosted(bool);
77 /// Pointer to the actual instantiation of xform's form
78 virtual FL_FORM * form() const = 0;
79 /// Filter the inputs on callback from xforms
80 virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
82 /** Redraw the form (on receipt of a Signal indicating, for example,
83 that the xform colors have been re-mapped). */
84 virtual void redraw();
87 virtual string const getTooltip(FL_OBJECT *) { return string(); }
89 /// post feedback for ob. Defaults to nothing
90 virtual void feedback(FL_OBJECT * /* ob */) {}
91 /// clear the feedback message
92 virtual void clear_feedback() {}
94 /// The dialog's minimum allowable dimensions.
98 /// Can the dialog be resized after it has been created?
100 /// dialog title, displayed by WM.
102 /** Variable used to decide whether to remove the existing feedback
103 message or not (if it is infact a warning) */
104 bool warning_posted_;
105 /// Enables tooltips for crappy GUI libraries...
107 FL_OBJECT * tooltip_timer_;
112 template <class Dialog>
113 class FormDB: public FormBase
117 FormDB(ControlButtons &, string const &, bool allowResize=true);
118 /// Pointer to the actual instantiation of xform's form
119 virtual FL_FORM * form() const;
120 /// Real GUI implementation.
121 boost::scoped_ptr<Dialog> dialog_;
125 template <class Dialog>
126 FormDB<Dialog>::FormDB(ControlButtons & c, string const & t, bool allowResize)
127 : FormBase(c, t, allowResize)
131 template <class Dialog>
132 FL_FORM * FormDB<Dialog>::form() const
134 if (dialog_.get()) return dialog_->form;
139 template <class Controller, class Base>
140 class FormCB: public Base
144 FormCB(ControlButtons &, string const &, bool allowResize=true);
145 /// The parent controller
146 Controller & controller() const;
150 template <class Controller, class Base>
151 FormCB<Controller, Base>::FormCB(ControlButtons & c, string const & t,
153 : Base(c, t, allowResize)
157 template <class Controller, class Base>
158 Controller & FormCB<Controller, Base>::controller() const
160 return static_cast<Controller &>(controller_);
161 //return dynamic_cast<Controller &>(controller_);