]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
Fix leaking pixmap icon.
[lyx.git] / src / frontends / xforms / FormBase.h
1 // -*- C++ -*-
2 /**
3  * \file FormBase.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming 
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 /* A base class for the MCV-ed xforms dialogs.
13  */
14
15 #ifndef FORMBASE_H
16 #define FORMBASE_H
17
18 #ifdef __GNUG__
19 #pragma interface
20 #endif
21
22 #include "ViewBase.h"
23 #include "ButtonPolicies.h"
24 #include "FeedbackController.h"
25 #include "forms_fwd.h"
26
27 #include "LString.h"
28 #include <boost/scoped_ptr.hpp>
29 #include <X11/Xlib.h> // for Pixmap
30
31 class xformsBC;
32 class Tooltips;
33
34
35 /** This class is an XForms GUI base class.
36  */
37 class FormBase : public ViewBase, public FeedbackController
38 {
39 public:
40         ///
41         FormBase(string const &, bool allowResize);
42         ///
43         virtual ~FormBase();
44
45         /** input callback function. invoked only by the xforms callback
46          *  interface
47          */
48         void InputCB(FL_OBJECT *, long);
49
50         Tooltips & tooltips();
51
52 protected:
53         /// Build the dialog
54         virtual void build() = 0;
55         /// Hide the dialog.
56         void hide();
57         /// Create the dialog if necessary, update it and display it.
58         void show();
59
60         /** Prepare the way to:
61          *  1. display feedback as the mouse moves over ob. This feedback will
62          *  typically be rather more verbose than just a tooltip.
63          *  2. activate the button controller after a paste with the middle
64          *  mouse button.
65          */
66         static void setPrehandler(FL_OBJECT * ob);
67
68         ///
69         xformsBC & bc();
70
71 private:
72         /// Pointer to the actual instantiation of xform's form
73         virtual FL_FORM * form() const = 0;
74         /// Filter the inputs on callback from xforms
75         virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
76
77         /** Redraw the form (on receipt of a Signal indicating, for example,
78          *  that the xform colors have been re-mapped).
79          */
80         virtual void redraw();
81
82         /** Called on the first show() request, initialising various bits and
83          *  pieces.
84          */
85         void prepare_to_show();
86
87         /// The dialog's minimum allowable dimensions.
88         int minw_;
89         ///
90         int minh_;
91         /// Can the dialog be resized after it has been created?
92         bool allow_resize_;
93         /// dialog title, displayed by the window manager.
94         string title_;
95         /// Passed to the window manager to give a pretty little symbol ;-)
96         Pixmap icon_pixmap_;
97         ///
98         Pixmap icon_mask_;
99         ///
100         Tooltips * tooltips_;
101 };
102
103
104 template <class Dialog>
105 class FormDB: public FormBase
106 {
107 protected:
108         ///
109         FormDB(string const &, bool allowResize=true);
110         /// Pointer to the actual instantiation of xform's form
111         virtual FL_FORM * form() const;
112         /// Real GUI implementation.
113         boost::scoped_ptr<Dialog> dialog_;
114 };
115
116
117 template <class Dialog>
118 FormDB<Dialog>::FormDB(string const & t, bool allowResize)
119         : FormBase(t, allowResize)
120 {}
121
122
123 template <class Dialog>
124 FL_FORM * FormDB<Dialog>::form() const
125 {
126         if (dialog_.get()) return dialog_->form;
127         return 0;
128 }
129
130
131 template <class Controller, class Base>
132 class FormCB: public Base
133 {
134 protected:
135         ///
136         FormCB(string const &, bool allowResize = true);
137         /// The parent controller
138         Controller & controller();
139         ///
140         Controller const & controller() const;
141 };
142
143
144 template <class Controller, class Base>
145 FormCB<Controller, Base>::FormCB(string const & t, bool allowResize)
146         : Base(t, allowResize)
147 {}
148
149
150 template <class Controller, class Base>
151 Controller & FormCB<Controller, Base>::controller()
152 {
153         return static_cast<Controller &>(getController());
154 }
155
156
157 template <class Controller, class Base>
158 Controller const & FormCB<Controller, Base>::controller() const
159 {
160         return static_cast<Controller const &>(getController());
161 }
162
163
164 #endif // FORMBASE_H