]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
Add a pre-handler that triggers an input event when text is pasted into
[lyx.git] / src / frontends / xforms / FormBase.C
1 /* This file is part of
2  * ====================================================== 
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2000-2001 The LyX Team.
7  *
8  * ======================================================
9  *
10  * \author Angus Leeming <a.leeming@ic.ac.uk>
11  */
12
13 #include <config.h>
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19 #include "Dialogs.h"
20 #include "FormBase.h"
21 #include "xformsBC.h"
22 #include "support/LAssert.h"
23
24 // Callback function invoked by xforms when the dialog is closed by the
25 // window manager
26 extern "C" int C_FormBaseWMHideCB(FL_FORM * form, void *);
27
28 // To trigger an input event when pasting in an xforms input object
29 // using the middle mouse button.
30 extern "C" int C_CutandPastePH(FL_OBJECT *, int, FL_Coord, FL_Coord,
31                                int, void *);
32
33
34 FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize)
35         : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
36           title_(t)
37 {}
38
39
40 void FormBase::redraw()
41 {
42         if (form() && form()->visible)
43                 fl_redraw_form(form());
44 }
45
46
47 void FormBase::show()
48 {
49         if (!form()) {
50                 build();
51         }
52         
53         // use minw_ to flag whether the dialog has ever been shown
54         // (Needed now that build() is/should be called from the controller)
55         if (minw_ == 0) {
56                 bc().refresh();
57  
58                 // work around dumb xforms sizing bug
59                 minw_ = form()->w;
60                 minh_ = form()->h;
61
62                 fl_set_form_atclose(form(), C_FormBaseWMHideCB, 0);
63         }
64         
65         fl_freeze_form(form());
66         update();  // make sure its up-to-date
67         fl_unfreeze_form(form());
68
69         if (form()->visible) {
70                 fl_raise_form(form());
71                 /* This XMapWindow() will hopefully ensure that
72                  * iconified dialogs are de-iconified. Mad props
73                  * out to those crazy Xlib guys for forgetting a
74                  * XDeiconifyWindow(). At least WindowMaker, when
75                  * being notified of the redirected MapRequest will
76                  * specifically de-iconify. From source, fvwm2 seems
77                  * to do the same.
78                  */
79                 XMapWindow(fl_get_display(), form()->window);
80         } else {
81                 // calls to fl_set_form_minsize/maxsize apply only to the next
82                 // fl_show_form(), so this comes first.
83                 fl_set_form_minsize(form(), minw_, minh_);
84                 if (!allow_resize_)
85                         fl_set_form_maxsize(form(), minw_, minh_);
86
87                 fl_show_form(form(),
88                              FL_PLACE_MOUSE | FL_FREE_SIZE, 0,
89                              title_.c_str());
90         }
91 }
92
93
94 void FormBase::hide()
95 {
96         if (form() && form()->visible)
97                 fl_hide_form(form());
98 }
99
100
101 void FormBase::InputCB(FL_OBJECT * ob, long data)
102 {
103         bc().input(input(ob, data));
104 }
105
106
107 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
108 {
109         return ButtonPolicy::SMI_VALID;
110 }
111
112
113 namespace {
114
115 FormBase * GetForm(FL_OBJECT * ob)
116 {
117         lyx::Assert(ob && ob->form && ob->form->u_vdata);
118         FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
119         return pre;
120 }
121
122 } // namespace anon
123
124
125 extern "C"
126 int C_FormBaseWMHideCB(FL_FORM * form, void *)
127 {
128         // Close the dialog cleanly, even if the WM is used to do so.
129         lyx::Assert(form && form->u_vdata);
130         FormBase * pre = static_cast<FormBase *>(form->u_vdata);
131         pre->CancelButton();
132         return FL_CANCEL;
133 }
134
135
136 extern "C" void C_FormBaseApplyCB(FL_OBJECT * ob, long)
137 {
138         GetForm(ob)->ApplyButton();
139 }
140
141
142 extern "C" void C_FormBaseOKCB(FL_OBJECT * ob, long)
143 {
144         GetForm(ob)->OKButton();
145 }
146
147
148 extern "C" void C_FormBaseCancelCB(FL_OBJECT * ob, long)
149 {
150         FormBase * form = GetForm(ob);
151         form->CancelButton();
152 }
153
154
155 extern "C" void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
156 {
157         GetForm(ob)->RestoreButton();
158 }
159
160
161 extern "C" void C_FormBaseInputCB(FL_OBJECT * ob, long d)
162 {
163         GetForm(ob)->InputCB(ob, d);
164 }
165
166
167 // To trigger an input event when pasting in an xforms input object
168 // using the middle mouse button.
169 extern "C" int C_CutandPastePH(FL_OBJECT * ob, int event,
170                                FL_Coord, FL_Coord, int key, void *)
171 {
172         if ((event == FL_PUSH) && (key == 2) && (ob->objclass == FL_INPUT)) {
173                 C_FormBaseInputCB(ob, 0);
174         }
175
176         return 0;
177 }