]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
Add fl_set_input_return to input_paperoption.
[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 protected:
44         /// Build the dialog
45         virtual void build() = 0;
46         /// Hide the dialog.
47         void hide();
48         /// Create the dialog if necessary, update it and display it.
49         void show();
50
51 private:
52         /// Pointer to the actual instantiation of xform's form
53         virtual FL_FORM * form() const = 0;
54         /** Filter the inputs on callback from xforms
55             Return true if inputs are valid. */
56         virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
57
58         /** Redraw the form (on receipt of a Signal indicating, for example,
59             that the xform colors have been re-mapped). */
60         virtual void redraw();
61
62         /// Overcome a dumb xforms sizing bug
63         mutable int minw_;
64         ///
65         mutable int minh_;
66         /// Can the dialog be resized after it has been created?
67         bool allow_resize_;
68
69         /// dialog title, displayed by WM.
70         string title_;
71 };
72
73
74 template <class Dialog>
75 class FormDB: public FormBase
76 {
77 protected:
78         ///
79         FormDB(ControlButtons &, string const &, bool allowResize=true);
80         /// Pointer to the actual instantiation of xform's form
81         virtual FL_FORM * form() const;
82         /// Real GUI implementation.
83         boost::scoped_ptr<Dialog> dialog_;
84 };
85
86
87 template <class Dialog>
88 FormDB<Dialog>::FormDB(ControlButtons & c, string const & t, bool allowResize)
89         : FormBase(c, t, allowResize)
90 {}
91
92
93 template <class Dialog>
94 FL_FORM * FormDB<Dialog>::form() const
95 {
96         if (dialog_.get()) return dialog_->form;
97         return 0;
98 }
99
100
101 template <class Controller, class Base>
102 class FormCB: public Base
103 {
104 protected:
105         ///
106         FormCB(ControlButtons &, string const &, bool allowResize=true);
107         /// The parent controller
108         Controller & controller() const;
109 };
110
111
112 template <class Controller, class Base>
113 FormCB<Controller, Base>::FormCB(ControlButtons & c, string const & t,
114                                  bool allowResize)
115         : Base(c, t, allowResize)
116 {}
117
118
119 template <class Controller, class Base>
120 Controller & FormCB<Controller, Base>::controller() const
121 {
122         return static_cast<Controller &>(controller_);
123         //return dynamic_cast<Controller &>(controller_);
124 }
125
126
127 #endif // FORMBASE_H