]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
ws changes
[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         /** Prepare the way to:
71          *  1. display feedback as the mouse moves over ob. This feedback will
72          *  typically be rather more verbose than just a tooltip.
73          *  2. activate the button controller after a paste with the middle
74          *  mouse button.
75          */
76         static void setPrehandler(FL_OBJECT * ob);
77
78         /** Pass the class a pointer to the message_widget so that it can
79             post the message */
80         void setMessageWidget(FL_OBJECT * message_widget);
81
82         /** Send the warning message from the daughter class to the
83             message_widget direct. The message will persist till the mouse
84             movesto a new object. */
85         void postWarning(string const & warning);
86         /// Reset the message_widget_
87         void clearMessage();
88
89         ///
90         xformsBC & bc();
91
92 private:
93         /// Pointer to the actual instantiation of xform's form
94         virtual FL_FORM * form() const = 0;
95         /// Filter the inputs on callback from xforms
96         virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
97
98         /** Redraw the form (on receipt of a Signal indicating, for example,
99          *  that the xform colors have been re-mapped).
100          */
101         virtual void redraw();
102
103         /** Called on the first show() request, initialising various bits and
104          *  pieces.
105          */
106         void prepare_to_show();
107
108         /** Get the feedback message for ob.
109             Called if warning_posted_ == false. */
110         virtual string const getFeedback(FL_OBJECT * /* ob */)
111                 { return string(); }
112
113         /// Post the feedback message for ob to message_widget_
114         void postMessage(string const & message);
115
116         /** Variable used to decide whether to remove the existing feedback
117             message or not (if it is in fact a warning) */
118         bool warning_posted_;
119         /// The widget to display the feedback
120         FL_OBJECT * message_widget_;
121
122         /// The dialog's minimum allowable dimensions.
123         int minw_;
124         ///
125         int minh_;
126         /// Can the dialog be resized after it has been created?
127         bool allow_resize_;
128         /// dialog title, displayed by the window manager.
129         string title_;
130         /// Passed to the window manager to give a pretty little symbol ;-)
131         Pixmap icon_pixmap_;
132         ///
133         Pixmap icon_mask_;
134         ///
135         Tooltips * tooltips_;
136 };
137
138
139 template <class Dialog>
140 class FormDB: public FormBase
141 {
142 protected:
143         ///
144         FormDB(string const &, bool allowResize=true);
145         /// Pointer to the actual instantiation of xform's form
146         virtual FL_FORM * form() const;
147         /// Real GUI implementation.
148         boost::scoped_ptr<Dialog> dialog_;
149 };
150
151
152 template <class Dialog>
153 FormDB<Dialog>::FormDB(string const & t, bool allowResize)
154         : FormBase(t, allowResize)
155 {}
156
157
158 template <class Dialog>
159 FL_FORM * FormDB<Dialog>::form() const
160 {
161         return dialog_.get() ? dialog_->form : 0;
162 }
163
164
165 template <class Controller, class Base>
166 class FormCB: public Base
167 {
168 public:
169         /// The parent controller
170         Controller & controller();
171         ///
172         Controller const & controller() const;
173
174 protected:
175         ///
176         FormCB(string const &, bool allowResize = true);
177 };
178
179
180 template <class Controller, class Base>
181 FormCB<Controller, Base>::FormCB(string const & t, bool allowResize)
182         : Base(t, allowResize)
183 {}
184
185
186 template <class Controller, class Base>
187 Controller & FormCB<Controller, Base>::controller()
188 {
189         return static_cast<Controller &>(getController());
190 }
191
192
193 template <class Controller, class Base>
194 Controller const & FormCB<Controller, Base>::controller() const
195 {
196         return static_cast<Controller const &>(getController());
197 }
198
199
200 #endif // FORMBASE_H