]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
apply the patch 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 "xform_macros.h"
24 #include "support/LAssert.h"
25 //#include "debug.h"
26
27 // The current scheme muddles debugging.
28 // Can we please use some other means to create these functions?
29 // I really don't like to use the preprossessor for this.
30 // My suggestion: First of all move these functions into their own
31 // file (that can be included here if wanted, and use m4 to expand
32 // that file. So create a m4 function to do the expansion, a file
33 // that contains the calls to to this function and a script to run
34 // it and create the C++ file with the expanded functions. (Lgb)
35 // Possible startoff point:
36 // define([C_RETURNCB],[extern "C" int C_$1$2(FL_FORM * ob, void * d) { return $1::$2(ob, d); }])
37
38 C_RETURNCB (FormBase, WMHideCB)
39 C_GENERICCB(FormBase, ApplyCB)
40 C_GENERICCB(FormBase, OKCB)
41 C_GENERICCB(FormBase, CancelCB)
42 C_GENERICCB(FormBase, InputCB)
43 C_GENERICCB(FormBase, RestoreCB)
44
45
46 FormBase::FormBase(LyXView * lv, Dialogs * d, string const & t,
47                    ButtonPolicy * bp, char const * close, char const * cancel)
48         : lv_(lv), bc_(bp, cancel, close), d_(d), h_(0), r_(0), title(t),
49           bp_(bp), minw_(0), minh_(0)
50 {
51         Assert(lv && d && bp);
52 }
53
54
55 FormBase::~FormBase()
56 {
57         //lyxerr << "bp_[" << bp_ << "]" << endl;
58         delete bp_;
59 }
60
61
62 void FormBase::redraw()
63 {
64         if (form() && form()->visible)
65                 fl_redraw_form(form());
66 }
67
68
69 void FormBase::connect()
70 {
71         fl_set_form_minsize(form(), minw_, minh_);
72         r_ = Dialogs::redrawGUI.connect(slot(this, &FormBase::redraw));
73 }
74
75
76 void FormBase::disconnect()
77 {
78         h_.disconnect();
79         r_.disconnect();
80 }
81
82
83 void FormBase::show()
84 {
85         if (!form()) {
86                 build();
87                 fl_set_form_atclose(form(),
88                                     C_FormBaseWMHideCB, 0);
89         }
90
91         fl_freeze_form(form());
92         update();  // make sure its up-to-date
93         fl_unfreeze_form(form());
94
95         if (form()->visible) {
96                 fl_raise_form(form());
97         } else {
98                 // calls to fl_set_form_minsize/maxsize apply only to the next
99                 // fl_show_form(), so connect() comes first.
100                 connect();
101                 fl_show_form(form(),
102                              FL_PLACE_MOUSE | FL_FREE_SIZE,
103                              FL_TRANSIENT,
104                              title.c_str());
105         }
106 }
107
108
109 void FormBase::hide()
110 {
111         if (form() && form()->visible) {
112                 // some dialogs might do things to the form first
113                 // such as the nested tabfolder problem in Preferences
114                 disconnect();
115                 fl_hide_form(form());
116         }
117 }
118
119
120 int FormBase::WMHideCB(FL_FORM * form, void *)
121 {
122         Assert(form);
123         // Ensure that the signals (u and h) are disconnected even if the
124         // window manager is used to close the dialog.
125         FormBase * pre = static_cast<FormBase*>(form->u_vdata);
126         Assert(pre);
127         pre->hide();
128         pre->bc_.hide();
129         return FL_CANCEL;
130 }
131
132
133 void FormBase::ApplyCB(FL_OBJECT * ob, long)
134 {
135         Assert(ob && ob->form);
136         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
137         Assert(pre);
138         pre->apply();
139         pre->bc_.apply();
140 }
141
142
143 void FormBase::OKCB(FL_OBJECT * ob, long)
144 {
145         Assert(ob && ob->form);
146         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
147         Assert(pre);
148         pre->ok();
149         pre->bc_.ok();
150 }
151
152
153 void FormBase::CancelCB(FL_OBJECT * ob, long)
154 {
155         Assert(ob && ob->form);
156         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
157         Assert(pre);
158         pre->cancel();
159         pre->bc_.cancel();
160 }
161
162
163 void FormBase::InputCB(FL_OBJECT * ob, long data)
164 {
165         Assert(ob && ob->form);
166         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
167         Assert(ob);
168         pre->bc_.valid(pre->input(ob, data));
169 }
170
171
172 void FormBase::RestoreCB(FL_OBJECT * ob, long)
173 {
174         Assert(ob && ob->form);
175         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
176         Assert(ob);
177         pre->restore();
178         pre->bc_.undoAll();
179 }
180
181
182 FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
183                        ButtonPolicy * bp,
184                        char const * close, char const * cancel)
185         : FormBase(lv, d, t, bp, close, cancel)
186 {}
187
188
189 void FormBaseBI::connect()
190 {
191         h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide));
192         FormBase::connect();
193 }
194
195
196 FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
197                        ButtonPolicy * bp,
198                        char const * close, char const * cancel)
199         : FormBase(lv, d, t, bp, close, cancel),
200           u_(0)
201 {}
202
203
204 void FormBaseBD::connect()
205 {
206         u_ = d_->updateBufferDependent.
207                  connect(slot(this, &FormBaseBD::updateSlot));
208         h_ = d_->hideBufferDependent.
209                  connect(slot(this, &FormBaseBD::hide));
210         FormBase::connect();
211 }
212
213
214 void FormBaseBD::disconnect()
215 {
216         u_.disconnect();
217         FormBase::disconnect();
218 }