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