]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
reverse last change
[lyx.git] / src / frontends / xforms / FormBase.h
1 // -*- C++ -*-
2 /**
3  * \file FormBase.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 /* A base class for the MCV-ed xforms dialogs.
13  */
14
15 #ifndef FORMBASE_H
16 #define FORMBASE_H
17
18 #ifdef __GNUG__
19 #pragma interface
20 #endif
21
22 #include "ViewBase.h"
23 #include "ButtonPolicies.h"
24 #include "forms_fwd.h"
25
26 #include "LString.h"
27 #include <boost/scoped_ptr.hpp>
28 #include <X11/Xlib.h> // for Pixmap
29
30 class xformsBC;
31 class Tooltips;
32
33
34 /** This class is an XForms GUI base class.
35  */
36 class FormBase : public ViewBase
37 {
38 public:
39         ///
40         FormBase(string const &, bool allowResize);
41         ///
42         virtual ~FormBase();
43
44         /** Input callback function.
45          *  Invoked only by the xforms callback interface
46          */
47         void InputCB(FL_OBJECT *, long);
48
49         /** Message callback function.
50          *  Invoked only by the xforms callback interface
51          */
52         void MessageCB(FL_OBJECT *, int event);
53
54         /** Prehandler callback function.
55          *  Invoked only by the xforms callback interface
56          */
57         void PrehandlerCB(FL_OBJECT * ob, int event, int key);
58
59         ///
60         Tooltips & tooltips();
61
62 protected:
63         /// Build the dialog
64         virtual void build() = 0;
65         /// Hide the dialog.
66         virtual void hide();
67         /// Create the dialog if necessary, update it and display it.
68         virtual void show();
69         ///
70         virtual bool isVisible() const;
71
72         /** Prepare the way to:
73          *  1. display feedback as the mouse moves over ob. This feedback will
74          *  typically be rather more verbose than just a tooltip.
75          *  2. activate the button controller after a paste with the middle
76          *  mouse button.
77          */
78         static void setPrehandler(FL_OBJECT * ob);
79
80         /** Pass the class a pointer to the message_widget so that it can
81             post the message */
82         void setMessageWidget(FL_OBJECT * message_widget);
83
84         /** Send the warning message from the daughter class to the
85             message_widget direct. The message will persist till the mouse
86             movesto a new object. */
87         void postWarning(string const & warning);
88         /// Reset the message_widget_
89         void clearMessage();
90
91         ///
92         xformsBC & bc();
93
94 private:
95         /// Pointer to the actual instantiation of xform's form
96         virtual FL_FORM * form() const = 0;
97         /// Filter the inputs on callback from xforms
98         virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
99
100         /** Redraw the form (on receipt of a Signal indicating, for example,
101          *  that the xform colors have been re-mapped).
102          */
103         virtual void redraw();
104
105         /** Called on the first show() request, initialising various bits and
106          *  pieces.
107          */
108         void prepare_to_show();
109
110         /** Get the feedback message for ob.
111             Called if warning_posted_ == false. */
112         virtual string const getFeedback(FL_OBJECT * /* ob */)
113                 { return string(); }
114
115         /// Post the feedback message for ob to message_widget_
116         void postMessage(string const & message);
117
118         /** Variable used to decide whether to remove the existing feedback
119             message or not (if it is in fact a warning) */
120         bool warning_posted_;
121         /// The widget to display the feedback
122         FL_OBJECT * message_widget_;
123
124         /// The dialog's minimum allowable dimensions.
125         int minw_;
126         ///
127         int minh_;
128         /// Can the dialog be resized after it has been created?
129         bool allow_resize_;
130         /// dialog title, displayed by the window manager.
131         string title_;
132         /// Passed to the window manager to give a pretty little symbol ;-)
133         Pixmap icon_pixmap_;
134         ///
135         Pixmap icon_mask_;
136         ///
137         Tooltips * tooltips_;
138 };
139
140
141 template <class Dialog>
142 class FormDB: public FormBase
143 {
144 protected:
145         ///
146         FormDB(string const &, bool allowResize=true);
147         /// Pointer to the actual instantiation of xform's form
148         virtual FL_FORM * form() const;
149         /// Real GUI implementation.
150         boost::scoped_ptr<Dialog> dialog_;
151 };
152
153
154 template <class Dialog>
155 FormDB<Dialog>::FormDB(string const & t, bool allowResize)
156         : FormBase(t, allowResize)
157 {}
158
159
160 template <class Dialog>
161 FL_FORM * FormDB<Dialog>::form() const
162 {
163         return dialog_.get() ? dialog_->form : 0;
164 }
165
166
167 template <class Controller, class Base>
168 class FormCB: public Base
169 {
170 public:
171         /// The parent controller
172         Controller & controller();
173         ///
174         Controller const & controller() const;
175
176 protected:
177         ///
178         FormCB(string const &, bool allowResize = true);
179 };
180
181
182 template <class Controller, class Base>
183 FormCB<Controller, Base>::FormCB(string const & t, bool allowResize)
184         : Base(t, allowResize)
185 {}
186
187
188 template <class Controller, class Base>
189 Controller & FormCB<Controller, Base>::controller()
190 {
191         return static_cast<Controller &>(getController());
192 }
193
194
195 template <class Controller, class Base>
196 Controller const & FormCB<Controller, Base>::controller() const
197 {
198         return static_cast<Controller const &>(getController());
199 }
200
201
202 #endif // FORMBASE_H