]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
8668e3722f92c5f7fa4ae54ba78b152ae0fb3942
[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 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(ControlBase &, string const &);
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) = 0;
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 protected:
63         /// Overcome a dumb xforms sizing bug
64         mutable int minw_;
65         ///
66         mutable int minh_;
67
68 private:
69         /// dialog title, displayed by WM.
70         string title_;
71 };
72
73
74 template <class Controller, class Dialog>
75 class FormBase2: public FormBase
76 {
77 protected:
78         ///
79         FormBase2(ControlBase &, string const &);
80         /// The parent controller
81         Controller & controller() const;
82         /// Pointer to the actual instantiation of xform's form
83         virtual FL_FORM * form() const;
84         /// Real GUI implementation.
85         boost::scoped_ptr<Dialog> dialog_;
86 };
87
88
89 template <class Controller, class Dialog>
90 FormBase2<Controller, Dialog>::FormBase2(ControlBase & c, string const & t)
91         : FormBase(c, t)
92 {}
93
94
95 template <class Controller, class Dialog>
96 Controller & FormBase2<Controller, Dialog>::controller() const
97 {
98         return static_cast<Controller &>(controller_);
99         //return dynamic_cast<Controller &>(controller_);
100 }
101
102
103 template <class Controller, class Dialog>
104 FL_FORM * FormBase2<Controller, Dialog>::form() const
105 {
106         if (dialog_.get()) return dialog_->form;
107         return 0;
108 }
109
110
111 #endif // FORMBASE_H