]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
use more specific smart_ptr headers
[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 #ifdef __GNUG__
17 #pragma interface
18 #endif
19
20 #include "ViewBase.h"
21 #include "LString.h"
22 #include "ButtonPolicies.h"
23 #include "FeedbackController.h"
24
25 #include <boost/scoped_ptr.hpp>
26
27 #include FORMS_H_LOCATION // Can't forward-declare FL_FORM
28
29 class xformsBC;
30 class Tooltips;
31
32 /** This class is an XForms GUI base class.
33  */
34 class FormBase : public ViewBC<xformsBC>, public FeedbackController
35 {
36 public:
37         ///
38         FormBase(ControlButtons &, string const &, bool allowResize);
39         ///
40         virtual ~FormBase();
41
42         /** input callback function. invoked only by the xforms callback
43          *  interface
44          */
45         void InputCB(FL_OBJECT *, long);
46
47         Tooltips & tooltips();
48
49 protected:
50         /// Build the dialog
51         virtual void build() = 0;
52         /// Hide the dialog.
53         void hide();
54         /// Create the dialog if necessary, update it and display it.
55         void show();
56
57         /** Prepare the way to:
58          *  1. display feedback as the mouse moves over ob. This feedback will
59          *  typically be rather more verbose than just a tooltip.
60          *  2. activate the button controller after a paste with the middle
61          *  mouse button.
62          */
63         static void setPrehandler(FL_OBJECT * ob);
64
65 private:
66         /// Pointer to the actual instantiation of xform's form
67         virtual FL_FORM * form() const = 0;
68         /// Filter the inputs on callback from xforms
69         virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
70
71         /** Redraw the form (on receipt of a Signal indicating, for example,
72          *  that the xform colors have been re-mapped).
73          */
74         virtual void redraw();
75
76         /// The dialog's minimum allowable dimensions.
77         int minw_;
78         ///
79         int minh_;
80         /// Can the dialog be resized after it has been created?
81         bool allow_resize_;
82         /// dialog title, displayed by WM.
83         string title_;
84         ///
85         Tooltips * tooltips_;
86 };
87
88
89 template <class Dialog>
90 class FormDB: public FormBase
91 {
92 protected:
93         ///
94         FormDB(ControlButtons &, string const &, bool allowResize=true);
95         /// Pointer to the actual instantiation of xform's form
96         virtual FL_FORM * form() const;
97         /// Real GUI implementation.
98         boost::scoped_ptr<Dialog> dialog_;
99 };
100
101
102 template <class Dialog>
103 FormDB<Dialog>::FormDB(ControlButtons & c, string const & t, bool allowResize)
104         : FormBase(c, t, allowResize)
105 {}
106
107
108 template <class Dialog>
109 FL_FORM * FormDB<Dialog>::form() const
110 {
111         if (dialog_.get()) return dialog_->form;
112         return 0;
113 }
114
115
116 template <class Controller, class Base>
117 class FormCB: public Base
118 {
119 protected:
120         ///
121         FormCB(Controller &, string const &, bool allowResize=true);
122         /// The parent controller
123         Controller & controller() const;
124 };
125
126
127 template <class Controller, class Base>
128 FormCB<Controller, Base>::FormCB(Controller & c, string const & t,
129                                  bool allowResize)
130         : Base(c, t, allowResize)
131 {}
132
133
134 template <class Controller, class Base>
135 Controller & FormCB<Controller, Base>::controller() const
136 {
137         return static_cast<Controller &>(controller_);
138         //return dynamic_cast<Controller &>(controller_);
139 }
140
141
142 #endif // FORMBASE_H