]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBaseDeprecated.C
John's possible fix to the Bad Window problems that some people have
[lyx.git] / src / frontends / xforms / FormBaseDeprecated.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
11 #include <config.h>
12
13 #include FORMS_H_LOCATION
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19 #include "Dialogs.h"
20 #include "FormBaseDeprecated.h"
21 #include "LyXView.h"
22 #include "GUIRunTime.h"
23 #include "support/LAssert.h"
24 #include "xformsBC.h"
25 #include "lyxrc.h"
26
27 using SigC::slot;
28
29 extern "C" {
30
31 // Callback function invoked by xforms when the dialog is closed by the
32 // window manager
33 static int C_FormBaseDeprecatedWMHideCB(FL_FORM *, void *);
34  
35 } // extern "C"
36
37
38 FormBaseDeprecated::FormBaseDeprecated(LyXView * lv, Dialogs * d,
39                                        string const & t, bool allowResize)
40         : lv_(lv), d_(d), h_(0), r_(0), title_(t),
41           minw_(0), minh_(0), allow_resize_(allowResize)
42 {
43         lyx::Assert(lv && d);
44 }
45
46
47 void FormBaseDeprecated::redraw()
48 {
49         if (form() && form()->visible)
50                 fl_redraw_form(form());
51 }
52
53
54 void FormBaseDeprecated::connect()
55 {
56         fl_set_form_minsize(form(), minw_, minh_);
57         r_ = Dialogs::redrawGUI.connect(slot(this,&FormBaseDeprecated::redraw));
58 }
59
60
61 void FormBaseDeprecated::disconnect()
62 {
63         h_.disconnect();
64         r_.disconnect();
65 }
66
67
68 void FormBaseDeprecated::show()
69 {
70         if (!form()) {
71                 build();
72
73                 bc().refresh();
74  
75                 // work around dumb xforms sizing bug
76                 minw_ = form()->w;
77                 minh_ = form()->h;
78
79                 fl_set_form_atclose(form(),
80                                     C_FormBaseDeprecatedWMHideCB, 0);
81         }
82
83         fl_freeze_form(form());
84         update();  // make sure its up-to-date
85         fl_unfreeze_form(form());
86
87         if (form()->visible) {
88                 fl_raise_form(form());
89                 /* This XMapWindow() will hopefully ensure that
90                  * iconified dialogs are de-iconified. Mad props
91                  * out to those crazy Xlib guys for forgetting a
92                  * XDeiconifyWindow(). At least WindowMaker, when
93                  * being notified of the redirected MapRequest will
94                  * specifically de-iconify. From source, fvwm2 seems
95                  * to do the same.
96                  */
97                 XMapWindow(fl_get_display(), form()->window);
98         } else {
99                 connect();
100
101                 // calls to fl_set_form_minsize/maxsize apply only to the next
102                 // fl_show_form(), so this comes first.
103                 fl_set_form_minsize(form(), minw_, minh_);
104                 if (!allow_resize_)
105                         fl_set_form_maxsize(form(), minw_, minh_);
106
107                 fl_show_form(form(),
108                         FL_PLACE_MOUSE | FL_FREE_SIZE,
109                         (lyxrc.dialogs_iconify_with_main ? FL_TRANSIENT : 0),
110                         title_.c_str());
111         }
112 }
113
114
115 void FormBaseDeprecated::hide()
116 {
117         // xforms sometimes tries to process a hint-type MotionNotify, and
118         // use XQueryPointer, without verifying if the window still exists.
119         // So we try to clear out motion events in the queue before the
120         // DestroyNotify
121         XSync(fl_get_display(), false);
122         GUIRunTime::processEvents();
123
124         if (form() && form()->visible) {
125                 // some dialogs might do things to the form first
126                 // such as the nested tabfolder problem in Preferences
127                 disconnect();
128                 fl_hide_form(form());
129         }
130 }
131
132
133 int FormBaseDeprecated::WMHideCB(FL_FORM * form, void *)
134 {
135         lyx::Assert(form);
136         // Ensure that the signals (u and h) are disconnected even if the
137         // window manager is used to close the dialog.
138         FormBaseDeprecated * pre =
139                 static_cast<FormBaseDeprecated*>(form->u_vdata);
140         lyx::Assert(pre);
141         pre->hide();
142         pre->bc().hide();
143         return FL_CANCEL;
144 }
145
146
147 void FormBaseDeprecated::ApplyCB(FL_OBJECT * ob, long)
148 {
149         lyx::Assert(ob && ob->form);
150         FormBaseDeprecated * pre =
151                 static_cast<FormBaseDeprecated*>(ob->form->u_vdata);
152         lyx::Assert(pre);
153         pre->apply();
154         pre->bc().apply();
155 }
156
157
158 void FormBaseDeprecated::OKCB(FL_OBJECT * ob, long)
159 {
160         lyx::Assert(ob && ob->form);
161         FormBaseDeprecated * pre =
162                 static_cast<FormBaseDeprecated*>(ob->form->u_vdata);
163         lyx::Assert(pre);
164         pre->ok();
165         pre->bc().ok();
166 }
167
168
169 void FormBaseDeprecated::CancelCB(FL_OBJECT * ob, long)
170 {
171         lyx::Assert(ob && ob->form);
172         FormBaseDeprecated * pre =
173                 static_cast<FormBaseDeprecated*>(ob->form->u_vdata);
174         lyx::Assert(pre);
175         pre->cancel();
176         pre->bc().cancel();
177 }
178
179
180 void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data)
181 {
182         lyx::Assert(ob && ob->form);
183         FormBaseDeprecated * pre =
184                 static_cast<FormBaseDeprecated*>(ob->form->u_vdata);
185         lyx::Assert(pre);
186
187         // It is possible to set the choice to 0 when using the
188         // keyboard shortcuts. This work-around deals with the problem.
189         if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
190                 fl_set_choice(ob, 1);
191         }
192
193         pre->bc().valid(pre->input(ob, data));
194 }
195
196
197 void FormBaseDeprecated::RestoreCB(FL_OBJECT * ob, long)
198 {
199         lyx::Assert(ob && ob->form);
200         FormBaseDeprecated * pre =
201                 static_cast<FormBaseDeprecated*>(ob->form->u_vdata);
202         lyx::Assert(pre);
203         pre->bc().restore();
204         pre->restore();
205 }
206
207
208 FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
209                        bool allowResize)
210         : FormBaseDeprecated(lv, d, t, allowResize)
211 {}
212
213
214 void FormBaseBI::connect()
215 {
216         h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide));
217         FormBaseDeprecated::connect();
218 }
219
220
221 FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
222                        bool allowResize)
223         : FormBaseDeprecated(lv, d, t, allowResize),
224           u_(0)
225 {}
226
227
228 void FormBaseBD::connect()
229 {
230         u_ = d_->updateBufferDependent.
231                  connect(slot(this, &FormBaseBD::updateSlot));
232         h_ = d_->hideBufferDependent.
233                  connect(slot(this, &FormBaseBD::hide));
234         FormBaseDeprecated::connect();
235 }
236
237
238 void FormBaseBD::disconnect()
239 {
240         u_.disconnect();
241         FormBaseDeprecated::disconnect();
242 }
243
244
245 extern "C" {
246         
247 static int C_FormBaseDeprecatedWMHideCB(FL_FORM * ob, void * d)
248 {
249         return FormBaseDeprecated::WMHideCB(ob, d);
250 }
251
252
253 void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long d)
254 {
255         FormBaseDeprecated::ApplyCB(ob, d);
256 }
257
258
259 void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long d)
260 {
261         FormBaseDeprecated::OKCB(ob, d);
262 }
263
264
265 void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long d)
266 {
267         FormBaseDeprecated::CancelCB(ob, d);
268 }
269
270
271 void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
272 {
273                 FormBaseDeprecated::InputCB(ob, d);
274 }
275
276
277 void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long d)
278 {
279         FormBaseDeprecated::RestoreCB(ob, d);
280 }
281
282 } // extern "C"
283