]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
Really dull and boring header shit
[lyx.git] / src / frontends / xforms / FormBase.h
1 // -*- C++ -*-
2 /**
3  * \file FormBase.h
4  * Read the file COPYING
5  *
6  * \author Angus Leeming 
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 /* A base class for the MCV-ed xforms dialogs.
12  */
13
14 #ifndef FORMBASE_H
15 #define FORMBASE_H
16
17 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include "ViewBase.h"
22 #include "LString.h"
23 #include "ButtonPolicies.h"
24 #include "FeedbackController.h"
25
26 #include <boost/scoped_ptr.hpp>
27
28 #include "forms_fwd.h"
29
30 class xformsBC;
31 class Tooltips;
32
33
34 /** This class is an XForms GUI base class.
35  */
36 class FormBase : public ViewBase, public FeedbackController
37 {
38 public:
39         ///
40         FormBase(string const &, bool allowResize);
41         ///
42         virtual ~FormBase();
43
44         /** input callback function. invoked only by the xforms callback
45          *  interface
46          */
47         void InputCB(FL_OBJECT *, long);
48
49         Tooltips & tooltips();
50
51 protected:
52         /// Build the dialog
53         virtual void build() = 0;
54         /// Hide the dialog.
55         void hide();
56         /// Create the dialog if necessary, update it and display it.
57         void show();
58
59         /** Prepare the way to:
60          *  1. display feedback as the mouse moves over ob. This feedback will
61          *  typically be rather more verbose than just a tooltip.
62          *  2. activate the button controller after a paste with the middle
63          *  mouse button.
64          */
65         static void setPrehandler(FL_OBJECT * ob);
66
67         ///
68         xformsBC & bc();
69
70 private:
71         /// Pointer to the actual instantiation of xform's form
72         virtual FL_FORM * form() const = 0;
73         /// Filter the inputs on callback from xforms
74         virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
75
76         /** Redraw the form (on receipt of a Signal indicating, for example,
77          *  that the xform colors have been re-mapped).
78          */
79         virtual void redraw();
80
81         /// The dialog's minimum allowable dimensions.
82         int minw_;
83         ///
84         int minh_;
85         /// Can the dialog be resized after it has been created?
86         bool allow_resize_;
87         /// dialog title, displayed by WM.
88         string title_;
89         ///
90         Tooltips * tooltips_;
91 };
92
93
94 template <class Dialog>
95 class FormDB: public FormBase
96 {
97 protected:
98         ///
99         FormDB(string const &, bool allowResize=true);
100         /// Pointer to the actual instantiation of xform's form
101         virtual FL_FORM * form() const;
102         /// Real GUI implementation.
103         boost::scoped_ptr<Dialog> dialog_;
104 };
105
106
107 template <class Dialog>
108 FormDB<Dialog>::FormDB(string const & t, bool allowResize)
109         : FormBase(t, allowResize)
110 {}
111
112
113 template <class Dialog>
114 FL_FORM * FormDB<Dialog>::form() const
115 {
116         if (dialog_.get()) return dialog_->form;
117         return 0;
118 }
119
120
121 template <class Controller, class Base>
122 class FormCB: public Base
123 {
124 protected:
125         ///
126         FormCB(string const &, bool allowResize = true);
127         /// The parent controller
128         Controller & controller();
129         ///
130         Controller const & controller() const;
131 };
132
133
134 template <class Controller, class Base>
135 FormCB<Controller, Base>::FormCB(string const & t, bool allowResize)
136         : Base(t, allowResize)
137 {}
138
139
140 template <class Controller, class Base>
141 Controller & FormCB<Controller, Base>::controller()
142 {
143         return static_cast<Controller &>(getController());
144 }
145
146
147 template <class Controller, class Base>
148 Controller const & FormCB<Controller, Base>::controller() const
149 {
150         return static_cast<Controller const &>(getController());
151 }
152
153
154 #endif // FORMBASE_H