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