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