]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
change some __GNUG_ to __GNUG__
[lyx.git] / src / frontends / xforms / FormBase.h
1 // -*- C++ -*-
2 /**
3  * \file FormBase.h
4  * Copyright 2000-2002 the LyX Team
5  * Read the file COPYING
6  *
7  * \author Angus Leeming, a.leeming@ic.ac.uk
8  */
9
10 /* A base class for the MCV-ed xforms dialogs.
11  */
12
13 #ifndef FORMBASE_H
14 #define FORMBASE_H
15
16 #include <boost/smart_ptr.hpp>
17 #include FORMS_H_LOCATION // Can't forward-declare FL_FORM
18
19 #ifdef __GNUG__
20 #pragma interface
21 #endif
22
23 #include "ViewBase.h"
24 #include "LString.h"
25 #include "ButtonPolicies.h"
26 #include "FeedbackController.h"
27
28 class xformsBC;
29 class Tooltips;
30
31 /** This class is an XForms GUI base class.
32  */
33 class FormBase : public ViewBC<xformsBC>, public FeedbackController
34 {
35 public:
36         ///
37         FormBase(ControlButtons &, string const &, bool allowResize);
38         ///
39         virtual ~FormBase();
40
41         /** input callback function. invoked only by the xforms callback
42          *  interface
43          */
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          */
73         virtual void redraw();
74
75         /// The dialog's minimum allowable dimensions.
76         int minw_;
77         ///
78         int minh_;
79         /// Can the dialog be resized after it has been created?
80         bool allow_resize_;
81         /// dialog title, displayed by WM.
82         string title_;
83         ///
84         Tooltips * tooltips_;
85 };
86
87
88 template <class Dialog>
89 class FormDB: public FormBase
90 {
91 protected:
92         ///
93         FormDB(ControlButtons &, string const &, bool allowResize=true);
94         /// Pointer to the actual instantiation of xform's form
95         virtual FL_FORM * form() const;
96         /// Real GUI implementation.
97         boost::scoped_ptr<Dialog> dialog_;
98 };
99
100
101 template <class Dialog>
102 FormDB<Dialog>::FormDB(ControlButtons & c, string const & t, bool allowResize)
103         : FormBase(c, t, allowResize)
104 {}
105
106
107 template <class Dialog>
108 FL_FORM * FormDB<Dialog>::form() const
109 {
110         if (dialog_.get()) return dialog_->form;
111         return 0;
112 }
113
114
115 template <class Controller, class Base>
116 class FormCB: public Base
117 {
118 protected:
119         ///
120         FormCB(Controller &, string const &, bool allowResize=true);
121         /// The parent controller
122         Controller & controller() const;
123 };
124
125
126 template <class Controller, class Base>
127 FormCB<Controller, Base>::FormCB(Controller & c, string const & t,
128                                  bool allowResize)
129         : Base(c, t, allowResize)
130 {}
131
132
133 template <class Controller, class Base>
134 Controller & FormCB<Controller, Base>::controller() const
135 {
136         return static_cast<Controller &>(controller_);
137         //return dynamic_cast<Controller &>(controller_);
138 }
139
140
141 #endif // FORMBASE_H