]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
2002-07-02 Lars Gullik Bj�nnes <larsbj@birdstep.com>
[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 class Dialogs;
32
33 /** This class is an XForms GUI base class.
34  */
35 class FormBase : public ViewBC<xformsBC>, public FeedbackController
36 {
37 public:
38         ///
39         FormBase(ControlButtons &, Dialogs &,
40                  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 private:
68         /// Pointer to the actual instantiation of xform's form
69         virtual FL_FORM * form() const = 0;
70         /// Filter the inputs on callback from xforms
71         virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
72
73         /** Redraw the form (on receipt of a Signal indicating, for example,
74          *  that the xform colors have been re-mapped).
75          */
76         virtual void redraw();
77
78         /// The dialog's minimum allowable dimensions.
79         int minw_;
80         ///
81         int minh_;
82         /// Can the dialog be resized after it has been created?
83         bool allow_resize_;
84         /// dialog title, displayed by WM.
85         string title_;
86         ///
87         Tooltips * tooltips_;
88 };
89
90
91 template <class Dialog>
92 class FormDB: public FormBase
93 {
94 protected:
95         ///
96         FormDB(ControlButtons &, Dialogs &,
97                string const &, bool allowResize=true);
98         /// Pointer to the actual instantiation of xform's form
99         virtual FL_FORM * form() const;
100         /// Real GUI implementation.
101         boost::scoped_ptr<Dialog> dialog_;
102 };
103
104
105 template <class Dialog>
106 FormDB<Dialog>::FormDB(ControlButtons & c, Dialogs & d,
107                        string const & t, bool allowResize)
108         : FormBase(c, d, 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(Controller &, Dialogs &,
126                string const &, bool allowResize = true);
127         /// The parent controller
128         Controller & controller() const;
129 };
130
131
132 template <class Controller, class Base>
133 FormCB<Controller, Base>::FormCB(Controller & c, Dialogs & d,
134                                  string const & t, bool allowResize)
135         : Base(c, d, t, allowResize)
136 {}
137
138
139 template <class Controller, class Base>
140 Controller & FormCB<Controller, Base>::controller() const
141 {
142         return static_cast<Controller &>(controller_);
143         //return dynamic_cast<Controller &>(controller_);
144 }
145
146
147 #endif // FORMBASE_H