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