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