]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
remove defaults stuff, let Qt handle no toolbar
[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
19 #include "ViewBase.h"
20 #include "ButtonPolicies.h"
21 #include "forms_fwd.h"
22
23 #include "LString.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         /// dialog title, displayed by the window manager.
128         string title_;
129         /// Passed to the window manager to give a pretty little symbol ;-)
130         Pixmap icon_pixmap_;
131         ///
132         Pixmap icon_mask_;
133         ///
134         Tooltips * tooltips_;
135 };
136
137
138 template <class Dialog>
139 class FormDB: public FormBase
140 {
141 protected:
142         ///
143         FormDB(string const &, bool allowResize=true);
144         /// Pointer to the actual instantiation of xform's form
145         virtual FL_FORM * form() const;
146         /// Real GUI implementation.
147         boost::scoped_ptr<Dialog> dialog_;
148 };
149
150
151 template <class Dialog>
152 FormDB<Dialog>::FormDB(string const & t, bool allowResize)
153         : FormBase(t, allowResize)
154 {}
155
156
157 template <class Dialog>
158 FL_FORM * FormDB<Dialog>::form() const
159 {
160         return dialog_.get() ? dialog_->form : 0;
161 }
162
163
164 template <class Controller, class Base>
165 class FormCB: public Base
166 {
167 public:
168         /// The parent controller
169         Controller & controller();
170         ///
171         Controller const & controller() const;
172
173 protected:
174         ///
175         FormCB(string const &, bool allowResize = true);
176 };
177
178
179 template <class Controller, class Base>
180 FormCB<Controller, Base>::FormCB(string const & t, bool allowResize)
181         : Base(t, allowResize)
182 {}
183
184
185 template <class Controller, class Base>
186 Controller & FormCB<Controller, Base>::controller()
187 {
188         return static_cast<Controller &>(getController());
189 }
190
191
192 template <class Controller, class Base>
193 Controller const & FormCB<Controller, Base>::controller() const
194 {
195         return static_cast<Controller const &>(getController());
196 }
197
198
199 #endif // FORMBASE_H