]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
90b77d7b799a82d5af8522ed7a09cf83feeca006
[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, ApplyHideCB)
27 C_GENERICCB(FormBase, HideCB)
28 C_GENERICCB(FormBase, InputCB)
29
30
31 FormBase::FormBase(LyXView * lv, Dialogs * d, BufferDependency bd, string const & t)
32         : dialogIsOpen(false), lv_(lv), u_(0), h_(0), title(t)
33 {
34         switch( bd ) {
35         case BUFFER_DEPENDENT:
36                 hSignal_ = &d->hideBufferDependent;
37                 uSignal_ = &d->updateBufferDependent;
38                 break;
39         case BUFFER_INDEPENDENT:
40                 hSignal_ = &d->hideAll;
41                 uSignal_ = 0;
42                 break;
43         }
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         fl_freeze_form( form() );
56         update();  // make sure its up-to-date
57         fl_unfreeze_form( form() );
58
59         dialogIsOpen = true;
60         if (form()->visible) {
61                 fl_raise_form(form());
62         } else {
63                 fl_show_form(form(),
64                              FL_PLACE_MOUSE | FL_FREE_SIZE,
65                              FL_TRANSIENT,
66                              title.c_str());
67                 connect();
68         }
69 }
70
71
72 void FormBase::hide()
73 {
74         if (form() && form()->visible) {
75                 fl_hide_form(form());
76                 disconnect();
77         }
78
79         // free up the dialog for another inset
80         dialogIsOpen = false;
81         clearStore();
82 }
83
84
85 void FormBase::connect()
86 {
87         if ( uSignal_ ) {
88                 u_ = uSignal_->connect(slot(this, &FormBase::update));
89         }
90         h_ = hSignal_->connect(slot(this, &FormBase::hide));
91 }
92
93
94 void FormBase::disconnect()
95 {
96         if (u_) {
97                 u_.disconnect();
98         }
99         h_.disconnect();
100 }
101
102
103 int FormBase::WMHideCB(FL_FORM * form, void *)
104 {
105         // Ensure that the signals (u and h) are disconnected even if the
106         // window manager is used to close the dialog.
107         FormBase * pre = static_cast<FormBase*>(form->u_vdata);
108         pre->hide();
109         return FL_CANCEL;
110 }
111
112
113 void FormBase::ApplyCB(FL_OBJECT * ob, long)
114 {
115         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
116         pre->apply();
117 }
118
119
120 void FormBase::ApplyHideCB(FL_OBJECT * ob, long)
121 {
122         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
123         pre->apply();
124         pre->hide();
125 }
126
127
128 void FormBase::HideCB(FL_OBJECT * ob, long)
129 {
130         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
131         pre->hide();
132 }
133
134
135 void FormBase::InputCB(FL_OBJECT * ob, long data )
136 {
137         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
138         pre->input( data );
139 }