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