]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
More pref work 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
25 C_RETURNCB (FormBase, WMHideCB)
26 C_GENERICCB(FormBase, ApplyCB)
27 C_GENERICCB(FormBase, OKCB)
28 C_GENERICCB(FormBase, CancelCB)
29 C_GENERICCB(FormBase, InputCB)
30 C_GENERICCB(FormBase, RestoreCB)
31
32
33 FormBase::FormBase(LyXView * lv, Dialogs * d, string const & t,
34                    ButtonPolicy * bp, char const * close, char const * cancel)
35         : lv_(lv), bc_(bp, cancel, close), d_(d), h_(0), title(t), bp_(bp),
36           minw_(0), minh_(0)
37 {}
38
39
40 FormBase::~FormBase()
41 {
42         delete bp_;
43 }
44
45
46 void FormBase::connect()
47 {
48         fl_set_form_minsize( form(), minw_, minh_ );
49 }
50
51
52 void FormBase::show()
53 {
54         if (!form()) {
55                 build();
56                 fl_set_form_atclose(form(),
57                                     C_FormBaseWMHideCB, 0);
58         }
59
60         fl_freeze_form( form() );
61         update();  // make sure its up-to-date
62         fl_unfreeze_form( form() );
63
64         if (form()->visible) {
65                 fl_raise_form(form());
66         } else {
67                 // calls to fl_set_form_minsize/maxsize apply only to the next
68                 // fl_show_form(), so connect() comes first.
69                 connect();
70                 fl_show_form(form(),
71                              FL_PLACE_MOUSE | FL_FREE_SIZE,
72                              FL_TRANSIENT,
73                              title.c_str());
74         }
75 }
76
77
78 void FormBase::hide()
79 {
80         if (form() && form()->visible) {
81                 // some dialogs might do things to the form first
82                 // such as the nested tabfolder problem in Preferences
83                 disconnect();
84                 fl_hide_form(form());
85         }
86 }
87
88
89 int FormBase::WMHideCB(FL_FORM * form, void *)
90 {
91         // Ensure that the signals (u and h) are disconnected even if the
92         // window manager is used to close the dialog.
93         FormBase * pre = static_cast<FormBase*>(form->u_vdata);
94         pre->hide();
95         pre->bc_.hide();
96         return FL_CANCEL;
97 }
98
99
100 void FormBase::ApplyCB(FL_OBJECT * ob, long)
101 {
102         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
103         pre->apply();
104         pre->bc_.apply();
105 }
106
107
108 void FormBase::OKCB(FL_OBJECT * ob, long)
109 {
110         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
111         pre->ok();
112         pre->bc_.ok();
113 }
114
115
116 void FormBase::CancelCB(FL_OBJECT * ob, long)
117 {
118         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
119         pre->cancel();
120         pre->bc_.cancel();
121 }
122
123
124 void FormBase::InputCB(FL_OBJECT * ob, long data )
125 {
126         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
127         pre->bc_.valid( pre->input( ob, data ) );
128 }
129
130
131 void FormBase::RestoreCB(FL_OBJECT * ob, long)
132 {
133         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
134         pre->restore();
135         pre->bc_.undoAll();
136 }
137
138
139 FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
140                        ButtonPolicy * bp,
141                        char const * close, char const * cancel)
142         : FormBase( lv, d, t, bp, close, cancel )
143 {}
144
145
146 void FormBaseBI::connect()
147 {
148         h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide));
149         FormBase::connect();
150 }
151
152
153 void FormBaseBI::disconnect()
154 {
155         h_.disconnect();
156 }
157
158
159 FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
160                        ButtonPolicy * bp,
161                        char const * close, char const * cancel)
162         : FormBase( lv, d, t, bp, close, cancel ),
163           u_(0)
164 {}
165
166
167 void FormBaseBD::connect()
168 {
169         u_ = d_->updateBufferDependent.
170                  connect(slot(this, &FormBaseBD::updateSlot));
171         h_ = d_->hideBufferDependent.
172                  connect(slot(this, &FormBaseBD::hide));
173         FormBase::connect();
174 }
175
176
177 void FormBaseBD::disconnect()
178 {
179         u_.disconnect();
180         h_.disconnect();
181 }