]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
We don't currently use fork anywhere (or if we do it's by mistake!), so
[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 class Tooltips;
30
31 /** This class is an XForms GUI base class.
32  */
33 class FormBase : public ViewBC<xformsBC>, public SigC::Object
34 {
35 public:
36         ///
37         enum TooltipLevel {
38                 NO_TOOLTIP,
39                 MINIMAL_TOOLTIP,
40                 VERBOSE_TOOLTIP
41         };
42
43         ///
44         FormBase(ControlButtons &, string const &, bool allowResize);
45         ///
46         virtual ~FormBase();
47
48         /** input callback function.
49             Invoked only by C_FormBaseInputCB and by C_FormBasePrehandler */
50         void InputCB(FL_OBJECT *, long);
51         /// feedback callback function, invoked only by C_FormBasePrehandler
52         void FeedbackCB(FL_OBJECT *, int event);
53
54         /** Return the tooltip dependent on the value of tooltip_level_
55             currently non-const becuase it gets connected to a SigC::slot */
56         string getTooltip(FL_OBJECT const *);
57
58 protected:
59         /// Build the dialog
60         virtual void build() = 0;
61         /// Hide the dialog.
62         void hide();
63         /// Create the dialog if necessary, update it and display it.
64         void show();
65
66         /// Prepare the way to produce a tooltip when the mouse is over ob.
67         void setTooltipHandler(FL_OBJECT * ob);
68
69         /** Prepare the way to:
70             1. display feedback as the mouse moves over ob. This feedback will
71             typically be rather more verbose than just a tooltip.
72             2. activate the button controller after a paste with the middle
73             mouse button */
74         void setPrehandler(FL_OBJECT * ob);
75
76         /** Flag that the message is a warning and should not be removed
77             when the mouse is no longer over the object.
78             Used in conjunction with setPrehandler(ob) and with feedback(ob),
79             clear_feedback(). */
80         void setWarningPosted(bool);
81
82         /** Fill the tooltips chooser with the standard descriptions
83             and set it to the tooltips_level_ */
84         void fillTooltipChoice(FL_OBJECT *);
85         /// Set tooltips_level_ from the chooser.
86         void setTooltipLevel(FL_OBJECT *);
87         
88 private:
89         /// Pointer to the actual instantiation of xform's form
90         virtual FL_FORM * form() const = 0;
91         /// Filter the inputs on callback from xforms 
92         virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
93
94         /** Redraw the form (on receipt of a Signal indicating, for example,
95             that the xform colors have been re-mapped). */
96         virtual void redraw();
97
98         /// These methods can be overridden in the daughter classes.
99         virtual string const getMinimalTooltip(FL_OBJECT const *) const
100                 { return string(); }
101         virtual string const getVerboseTooltip(FL_OBJECT const *) const
102                 { return string(); }
103
104         /// Post feedback for ob. Defaults to nothing
105         virtual void feedback(FL_OBJECT * /* ob */) {}
106         /// clear the feedback message
107         virtual void clear_feedback() {}
108
109         /// The dialog's minimum allowable dimensions.
110         int minw_;
111         ///
112         int minh_;
113         /// Can the dialog be resized after it has been created?
114         bool allow_resize_;
115         /// dialog title, displayed by WM.
116         string title_;
117         /** Variable used to decide whether to remove the existing feedback
118             message or not (if it is infact a warning) */
119         bool warning_posted_;
120         ///
121         Tooltips * tooltip_;
122         /// How verbose are the tooltips?
123         TooltipLevel tooltip_level_;
124 };
125
126
127 template <class Dialog>
128 class FormDB: public FormBase
129 {
130 protected:
131         ///
132         FormDB(ControlButtons &, string const &, bool allowResize=true);
133         /// Pointer to the actual instantiation of xform's form
134         virtual FL_FORM * form() const;
135         /// Real GUI implementation.
136         boost::scoped_ptr<Dialog> dialog_;
137 };
138
139
140 template <class Dialog>
141 FormDB<Dialog>::FormDB(ControlButtons & c, string const & t, bool allowResize)
142         : FormBase(c, t, allowResize)
143 {}
144
145
146 template <class Dialog>
147 FL_FORM * FormDB<Dialog>::form() const
148 {
149         if (dialog_.get()) return dialog_->form;
150         return 0;
151 }
152
153
154 template <class Controller, class Base>
155 class FormCB: public Base
156 {
157 protected:
158         ///
159         FormCB(ControlButtons &, string const &, bool allowResize=true);
160         /// The parent controller
161         Controller & controller() const;
162 };
163
164
165 template <class Controller, class Base>
166 FormCB<Controller, Base>::FormCB(ControlButtons & c, string const & t,
167                                  bool allowResize)
168         : Base(c, t, allowResize)
169 {}
170
171
172 template <class Controller, class Base>
173 Controller & FormCB<Controller, Base>::controller() const
174 {
175         return static_cast<Controller &>(controller_);
176         //return dynamic_cast<Controller &>(controller_);
177 }
178
179
180 #endif // FORMBASE_H