]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[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         virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
56
57         /** Redraw the form (on receipt of a Signal indicating, for example,
58             that the xform colors have been re-mapped). */
59         virtual void redraw();
60
61         /// The dialog's minimum allowable dimensions.
62         int minw_;
63         ///
64         int minh_;
65         /// Can the dialog be resized after it has been created?
66         bool allow_resize_;
67         /// dialog title, displayed by WM.
68         string title_;
69 };
70
71
72 template <class Dialog>
73 class FormDB: public FormBase
74 {
75 protected:
76         ///
77         FormDB(ControlButtons &, string const &, bool allowResize=true);
78         /// Pointer to the actual instantiation of xform's form
79         virtual FL_FORM * form() const;
80         /// Real GUI implementation.
81         boost::scoped_ptr<Dialog> dialog_;
82 };
83
84
85 template <class Dialog>
86 FormDB<Dialog>::FormDB(ControlButtons & c, string const & t, bool allowResize)
87         : FormBase(c, t, allowResize)
88 {}
89
90
91 template <class Dialog>
92 FL_FORM * FormDB<Dialog>::form() const
93 {
94         if (dialog_.get()) return dialog_->form;
95         return 0;
96 }
97
98
99 template <class Controller, class Base>
100 class FormCB: public Base
101 {
102 protected:
103         ///
104         FormCB(ControlButtons &, string const &, bool allowResize=true);
105         /// The parent controller
106         Controller & controller() const;
107 };
108
109
110 template <class Controller, class Base>
111 FormCB<Controller, Base>::FormCB(ControlButtons & c, string const & t,
112                                  bool allowResize)
113         : Base(c, t, allowResize)
114 {}
115
116
117 template <class Controller, class Base>
118 Controller & FormCB<Controller, Base>::controller() const
119 {
120         return static_cast<Controller &>(controller_);
121         //return dynamic_cast<Controller &>(controller_);
122 }
123
124
125 #endif // FORMBASE_H