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