]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
Provide the framework for really easy feedback messages.
[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
28 class xformsBC;
29
30 /** This class is an XForms GUI base class.
31  */
32 class FormBase : public ViewBC<xformsBC>
33 {
34 public:
35         ///
36         FormBase(ControlButtons &, string const &, bool allowResize);
37         ///
38         virtual ~FormBase() {}
39
40         /// input callback function
41         void InputCB(FL_OBJECT *, long);
42
43         /// feedback callback function
44         void FeedbackCB(FL_OBJECT *, int event);
45
46 protected:
47         /// Build the dialog
48         virtual void build() = 0;
49         /// Hide the dialog.
50         void hide();
51         /// Create the dialog if necessary, update it and display it.
52         void show();
53         /** Set a prehandler for ob to:
54             1. display feedback as the mouse moves over it
55             2. activate the button controller after a paste with the middle
56             mouse button */
57         void setPrehandler(FL_OBJECT * ob);
58
59         /// post feedback for ob. Defaults to nothing
60         virtual void feedback(FL_OBJECT * /* ob */) {}
61         /// clear the feedback message
62         virtual void clear_feedback() {}
63
64         /** Flag that the message is a warning and should not be removed
65             when the mouse is no longer over the object */
66         void setWarningPosted(bool);
67
68 private:
69         /// Pointer to the actual instantiation of xform's form
70         virtual FL_FORM * form() const = 0;
71         /// Filter the inputs on callback from xforms 
72         virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
73
74         /** Redraw the form (on receipt of a Signal indicating, for example,
75             that the xform colors have been re-mapped). */
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         /** Variable used to decide whether to remove the existing feedback
87             message or not (if it is infact a warning) */
88         bool warning_posted_;
89 };
90
91
92 template <class Dialog>
93 class FormDB: public FormBase
94 {
95 protected:
96         ///
97         FormDB(ControlButtons &, 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, string const & t, bool allowResize)
107         : FormBase(c, t, allowResize)
108 {}
109
110
111 template <class Dialog>
112 FL_FORM * FormDB<Dialog>::form() const
113 {
114         if (dialog_.get()) return dialog_->form;
115         return 0;
116 }
117
118
119 template <class Controller, class Base>
120 class FormCB: public Base
121 {
122 protected:
123         ///
124         FormCB(ControlButtons &, string const &, bool allowResize=true);
125         /// The parent controller
126         Controller & controller() const;
127 };
128
129
130 template <class Controller, class Base>
131 FormCB<Controller, Base>::FormCB(ControlButtons & c, string const & t,
132                                  bool allowResize)
133         : Base(c, t, allowResize)
134 {}
135
136
137 template <class Controller, class Base>
138 Controller & FormCB<Controller, Base>::controller() const
139 {
140         return static_cast<Controller &>(controller_);
141         //return dynamic_cast<Controller &>(controller_);
142 }
143
144
145 #endif // FORMBASE_H