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