]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
You want real tooltips too? You got 'em. See the ChangeLog for how to use.
[lyx.git] / src / frontends / xforms / FormBase.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000-2001 The LyX Team.
8  *
9  * ======================================================
10  *
11  * \author Angus Leeming <a.leeming@ic.ac.uk>
12  */
13
14 #ifndef FORMBASE_H
15 #define FORMBASE_H
16
17 #include <boost/smart_ptr.hpp>
18 #include FORMS_H_LOCATION // Can't forward-declare FL_FORM
19
20 #ifdef __GNUG__
21 #pragma interface
22 #endif
23
24 #include "ViewBase.h"
25 #include "LString.h"
26 #include "ButtonPolicies.h"
27
28 class xformsBC;
29
30
31 /** This class is an XForms GUI base class.
32  */
33 class FormBase : public ViewBC<xformsBC>
34 {
35 public:
36         ///
37         FormBase(ControlButtons &, string const &, bool allowResize);
38         ///
39         virtual ~FormBase() {}
40
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);
46
47 #if FL_REVISION < 89
48         /// invoked only by TooltipTimerCB
49         string const getTooltipCB(FL_OBJECT *);
50 #endif
51
52 protected:
53         /// Build the dialog
54         virtual void build() = 0;
55         /// Hide the dialog.
56         void hide();
57         /// Create the dialog if necessary, update it and display it.
58         void show();
59
60         /// Prepare the way to produce a tooltip when the mouse is over ob.
61         void setTooltipHandler(FL_OBJECT * ob);
62
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
67             mouse button */
68         void setPrehandler(FL_OBJECT * ob);
69
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),
73             clear_feedback(). */
74         void setWarningPosted(bool);
75
76 private:
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);
81
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();
85
86         ///
87         virtual string const getTooltip(FL_OBJECT *) { return string(); }
88
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() {}
93
94         /// The dialog's minimum allowable dimensions.
95         int minw_;
96         ///
97         int minh_;
98         /// Can the dialog be resized after it has been created?
99         bool allow_resize_;
100         /// dialog title, displayed by WM.
101         string title_;
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...
106 #if FL_REVISION < 89
107         FL_OBJECT * tooltip_timer_;
108 #endif
109 };
110
111
112 template <class Dialog>
113 class FormDB: public FormBase
114 {
115 protected:
116         ///
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_;
122 };
123
124
125 template <class Dialog>
126 FormDB<Dialog>::FormDB(ControlButtons & c, string const & t, bool allowResize)
127         : FormBase(c, t, allowResize)
128 {}
129
130
131 template <class Dialog>
132 FL_FORM * FormDB<Dialog>::form() const
133 {
134         if (dialog_.get()) return dialog_->form;
135         return 0;
136 }
137
138
139 template <class Controller, class Base>
140 class FormCB: public Base
141 {
142 protected:
143         ///
144         FormCB(ControlButtons &, string const &, bool allowResize=true);
145         /// The parent controller
146         Controller & controller() const;
147 };
148
149
150 template <class Controller, class Base>
151 FormCB<Controller, Base>::FormCB(ControlButtons & c, string const & t,
152                                  bool allowResize)
153         : Base(c, t, allowResize)
154 {}
155
156
157 template <class Controller, class Base>
158 Controller & FormCB<Controller, Base>::controller() const
159 {
160         return static_cast<Controller &>(controller_);
161         //return dynamic_cast<Controller &>(controller_);
162 }
163
164
165 #endif // FORMBASE_H