]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
Preference/Color changes from Angus
[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         //lyxerr << "bp_[" << bp_ << "]" << endl;
64         delete bp_;
65 }
66
67
68 void FormBase::redraw()
69 {
70         if (form() && form()->visible)
71                 fl_redraw_form(form());
72 }
73
74
75 void FormBase::connect()
76 {
77         fl_set_form_minsize(form(), minw_, minh_);
78         r_ = Dialogs::redrawGUI.connect(slot(this, &FormBase::redraw));
79 }
80
81
82 void FormBase::disconnect()
83 {
84         h_.disconnect();
85         r_.disconnect();
86 }
87
88
89 void FormBase::show()
90 {
91         if (!form()) {
92                 build();
93                 fl_set_form_atclose(form(),
94                                     C_FormBaseWMHideCB, 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         } else {
104                 // calls to fl_set_form_minsize/maxsize apply only to the next
105                 // fl_show_form(), so connect() comes first.
106                 connect();
107                 fl_show_form(form(),
108                              FL_PLACE_MOUSE | FL_FREE_SIZE,
109                              FL_TRANSIENT,
110                              title.c_str());
111         }
112 }
113
114
115 void FormBase::hide()
116 {
117         if (form() && form()->visible) {
118                 // some dialogs might do things to the form first
119                 // such as the nested tabfolder problem in Preferences
120                 disconnect();
121                 fl_hide_form(form());
122         }
123 }
124
125
126 int FormBase::WMHideCB(FL_FORM * form, void *)
127 {
128         Assert(form);
129         // Ensure that the signals (u and h) are disconnected even if the
130         // window manager is used to close the dialog.
131         FormBase * pre = static_cast<FormBase*>(form->u_vdata);
132         Assert(pre);
133         pre->hide();
134         pre->bc_.hide();
135         return FL_CANCEL;
136 }
137
138
139 void FormBase::ApplyCB(FL_OBJECT * ob, long)
140 {
141         Assert(ob && ob->form);
142         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
143         Assert(pre);
144         pre->apply();
145         pre->bc_.apply();
146 }
147
148
149 void FormBase::OKCB(FL_OBJECT * ob, long)
150 {
151         Assert(ob && ob->form);
152         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
153         Assert(pre);
154         pre->ok();
155         pre->bc_.ok();
156 }
157
158
159 void FormBase::CancelCB(FL_OBJECT * ob, long)
160 {
161         Assert(ob && ob->form);
162         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
163         Assert(pre);
164         pre->cancel();
165         pre->bc_.cancel();
166 }
167
168
169 void FormBase::InputCB(FL_OBJECT * ob, long data)
170 {
171         Assert(ob && ob->form);
172         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
173         Assert(ob);
174         pre->bc_.valid(pre->input(ob, data));
175 }
176
177
178 void FormBase::RestoreCB(FL_OBJECT * ob, long)
179 {
180         Assert(ob && ob->form);
181         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
182         Assert(ob);
183         pre->restore();
184         pre->bc_.undoAll();
185 }
186
187
188 FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
189                        ButtonPolicy * bp,
190                        char const * close, char const * cancel)
191         : FormBase(lv, d, t, bp, close, cancel)
192 {}
193
194
195 void FormBaseBI::connect()
196 {
197         h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide));
198         FormBase::connect();
199 }
200
201
202 FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
203                        ButtonPolicy * bp,
204                        char const * close, char const * cancel)
205         : FormBase(lv, d, t, bp, close, cancel),
206           u_(0)
207 {}
208
209
210 void FormBaseBD::connect()
211 {
212         u_ = d_->updateBufferDependent.
213                  connect(slot(this, &FormBaseBD::updateSlot));
214         h_ = d_->hideBufferDependent.
215                  connect(slot(this, &FormBaseBD::hide));
216         FormBase::connect();
217 }
218
219
220 void FormBaseBD::disconnect()
221 {
222         u_.disconnect();
223         FormBase::disconnect();
224 }