]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
Yet more dialog tweaking from Rob.
[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 "LString.h"
24 #include "ButtonPolicies.h"
25 #include "FeedbackController.h"
26
27 #include <boost/scoped_ptr.hpp>
28
29 #include "forms_fwd.h"
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         /// The dialog's minimum allowable dimensions.
83         int minw_;
84         ///
85         int minh_;
86         /// Can the dialog be resized after it has been created?
87         bool allow_resize_;
88         /// dialog title, displayed by WM.
89         string title_;
90         ///
91         Tooltips * tooltips_;
92 };
93
94
95 template <class Dialog>
96 class FormDB: public FormBase
97 {
98 protected:
99         ///
100         FormDB(string const &, bool allowResize=true);
101         /// Pointer to the actual instantiation of xform's form
102         virtual FL_FORM * form() const;
103         /// Real GUI implementation.
104         boost::scoped_ptr<Dialog> dialog_;
105 };
106
107
108 template <class Dialog>
109 FormDB<Dialog>::FormDB(string const & t, bool allowResize)
110         : FormBase(t, allowResize)
111 {}
112
113
114 template <class Dialog>
115 FL_FORM * FormDB<Dialog>::form() const
116 {
117         if (dialog_.get()) return dialog_->form;
118         return 0;
119 }
120
121
122 template <class Controller, class Base>
123 class FormCB: public Base
124 {
125 protected:
126         ///
127         FormCB(string const &, bool allowResize = true);
128         /// The parent controller
129         Controller & controller();
130         ///
131         Controller const & controller() const;
132 };
133
134
135 template <class Controller, class Base>
136 FormCB<Controller, Base>::FormCB(string const & t, bool allowResize)
137         : Base(t, allowResize)
138 {}
139
140
141 template <class Controller, class Base>
142 Controller & FormCB<Controller, Base>::controller()
143 {
144         return static_cast<Controller &>(getController());
145 }
146
147
148 template <class Controller, class Base>
149 Controller const & FormCB<Controller, Base>::controller() const
150 {
151         return static_cast<Controller const &>(getController());
152 }
153
154
155 #endif // FORMBASE_H