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