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