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