]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
try this for distinguishing inner and outer tabs
[lyx.git] / src / frontends / xforms / FormBase.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  */
11
12 #include <config.h>
13
14 #include FORMS_H_LOCATION
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "Dialogs.h"
21 #include "FormBase.h"
22 #include "LyXView.h"
23 #include "support/LAssert.h"
24 //#include "debug.h"
25
26 extern "C" int C_FormBaseWMHideCB(FL_FORM * ob, void * d)
27 {
28         return FormBase::WMHideCB(ob, d);
29 }
30 extern "C" void C_FormBaseApplyCB(FL_OBJECT * ob, long d)
31 {
32         FormBase::ApplyCB(ob, d);
33 }
34 extern "C" void C_FormBaseOKCB(FL_OBJECT * ob, long d)
35 {
36         FormBase::OKCB(ob, d);
37 }
38 extern "C" void C_FormBaseCancelCB(FL_OBJECT * ob, long d)
39 {
40         FormBase::CancelCB(ob, d);
41 }
42 extern "C" void C_FormBaseInputCB(FL_OBJECT * ob, long d)
43 {
44         FormBase::InputCB(ob, d);
45 }
46 extern "C" void C_FormBaseRestoreCB(FL_OBJECT * ob, long d)
47 {
48         FormBase::RestoreCB(ob, d);
49 }
50
51
52 FormBase::FormBase(LyXView * lv, Dialogs * d, string const & t,
53                    ButtonPolicy * bp, char const * close, char const * cancel)
54         : lv_(lv), bc_(bp, cancel, close), d_(d), h_(0), r_(0), title(t),
55           bp_(bp), minw_(0), minh_(0)
56 {
57         Assert(lv && d && bp);
58 }
59
60
61 FormBase::~FormBase()
62 {
63         delete bp_;
64 }
65
66
67 void FormBase::redraw()
68 {
69         if (form() && form()->visible)
70                 fl_redraw_form(form());
71 }
72
73
74 void FormBase::connect()
75 {
76         fl_set_form_minsize(form(), minw_, minh_);
77         r_ = Dialogs::redrawGUI.connect(slot(this, &FormBase::redraw));
78 }
79
80
81 void FormBase::disconnect()
82 {
83         h_.disconnect();
84         r_.disconnect();
85 }
86
87
88 void FormBase::show()
89 {
90         if (!form()) {
91                 build();
92                 fl_set_form_atclose(form(),
93                                     C_FormBaseWMHideCB, 0);
94         }
95
96         fl_freeze_form(form());
97         update();  // make sure its up-to-date
98         fl_unfreeze_form(form());
99
100         if (form()->visible) {
101                 fl_raise_form(form());
102         } else {
103                 // calls to fl_set_form_minsize/maxsize apply only to the next
104                 // fl_show_form(), so connect() comes first.
105                 connect();
106                 fl_show_form(form(),
107                              FL_PLACE_MOUSE | FL_FREE_SIZE,
108                              FL_TRANSIENT,
109                              title.c_str());
110         }
111 }
112
113
114 void FormBase::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 FormBase::WMHideCB(FL_FORM * form, void *)
126 {
127         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         FormBase * pre = static_cast<FormBase*>(form->u_vdata);
131         Assert(pre);
132         pre->hide();
133         pre->bc_.hide();
134         return FL_CANCEL;
135 }
136
137
138 void FormBase::ApplyCB(FL_OBJECT * ob, long)
139 {
140         Assert(ob && ob->form);
141         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
142         Assert(pre);
143         pre->apply();
144         pre->bc_.apply();
145 }
146
147
148 void FormBase::OKCB(FL_OBJECT * ob, long)
149 {
150         Assert(ob && ob->form);
151         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
152         Assert(pre);
153         pre->ok();
154         pre->bc_.ok();
155 }
156
157
158 void FormBase::CancelCB(FL_OBJECT * ob, long)
159 {
160         Assert(ob && ob->form);
161         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
162         Assert(pre);
163         pre->cancel();
164         pre->bc_.cancel();
165 }
166
167
168 void FormBase::InputCB(FL_OBJECT * ob, long data)
169 {
170         Assert(ob && ob->form);
171         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
172         Assert(ob);
173         pre->bc_.valid(pre->input(ob, data), ob);
174 }
175
176
177 void FormBase::RestoreCB(FL_OBJECT * ob, long)
178 {
179         Assert(ob && ob->form);
180         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
181         Assert(ob);
182         pre->bc_.undoAll();
183         pre->restore();
184 }
185
186
187 FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
188                        ButtonPolicy * bp,
189                        char const * close, char const * cancel)
190         : FormBase(lv, d, t, bp, close, cancel)
191 {}
192
193
194 void FormBaseBI::connect()
195 {
196         h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide));
197         FormBase::connect();
198 }
199
200
201 FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
202                        ButtonPolicy * bp,
203                        char const * close, char const * cancel)
204         : FormBase(lv, d, t, bp, close, cancel),
205           u_(0)
206 {}
207
208
209 void FormBaseBD::connect()
210 {
211         u_ = d_->updateBufferDependent.
212                  connect(slot(this, &FormBaseBD::updateSlot));
213         h_ = d_->hideBufferDependent.
214                  connect(slot(this, &FormBaseBD::hide));
215         FormBase::connect();
216 }
217
218
219 void FormBaseBD::disconnect()
220 {
221         u_.disconnect();
222         FormBase::disconnect();
223 }