]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
Angus inseterror patch + Dekel mathed fix + added language_country code and
[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 "xform_macros.h"
23
24 C_RETURNCB(FormBase, WMHideCB)
25 C_GENERICCB(FormBase, ApplyCB)
26 C_GENERICCB(FormBase, CancelCB)
27 C_GENERICCB(FormBase, InputCB)
28 C_GENERICCB(FormBase, OKCB)
29
30 FormBase::FormBase(LyXView * lv, Dialogs * d, string const & t)
31         : lv_(lv), d_(d), u_(0), h_(0), title(t), dialogIsOpen(false)
32 {}
33
34
35 void FormBase::show()
36 {
37         if (!form()) {
38                 build();
39                 fl_set_form_atclose(form(),
40                                     C_FormBaseWMHideCB, 0);
41         }
42
43         fl_freeze_form( form() );
44         update();  // make sure its up-to-date
45         fl_unfreeze_form( form() );
46
47         dialogIsOpen = true;
48         if (form()->visible) {
49                 fl_raise_form(form());
50         } else {
51                 fl_show_form(form(),
52                              FL_PLACE_MOUSE | FL_FREE_SIZE,
53                              FL_TRANSIENT,
54                              title.c_str());
55                 u_ = d_->updateBufferDependent.
56                          connect(slot(this, &FormBase::update));
57                 h_ = d_->hideBufferDependent.
58                          connect(slot(this, &FormBase::hide));
59         }
60 }
61
62
63 void FormBase::hide()
64 {
65         if (form() && form()->visible) {
66                 fl_hide_form(form());
67                 u_.disconnect();
68                 h_.disconnect();
69         }
70
71         // free up the dialog for another inset
72         dialogIsOpen = false;
73         clearStore();
74 }
75
76
77 int FormBase::WMHideCB(FL_FORM * form, void *)
78 {
79         // Ensure that the signals (u and h) are disconnected even if the
80         // window manager is used to close the dialog.
81         FormBase * pre = static_cast<FormBase*>(form->u_vdata);
82         pre->hide();
83         return FL_CANCEL;
84 }
85
86
87 void FormBase::ApplyCB(FL_OBJECT * ob, long)
88 {
89         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
90         pre->apply();
91 }
92
93
94 void FormBase::CancelCB(FL_OBJECT * ob, long)
95 {
96         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
97         pre->hide();
98 }
99
100
101 void FormBase::InputCB(FL_OBJECT * ob, long data )
102 {
103         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
104         pre->input( data );
105 }
106
107
108 void FormBase::OKCB(FL_OBJECT * ob, long)
109 {
110         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
111         pre->apply();
112         pre->hide();
113 }