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