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