]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormBase.C
more type changes, some consts added
[features.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         u_.disconnect();
97         h_.disconnect();
98 }
99
100
101 int FormBase::WMHideCB(FL_FORM * form, void *)
102 {
103         // Ensure that the signals (u and h) are disconnected even if the
104         // window manager is used to close the dialog.
105         FormBase * pre = static_cast<FormBase*>(form->u_vdata);
106         pre->hide();
107         return FL_CANCEL;
108 }
109
110
111 void FormBase::ApplyCB(FL_OBJECT * ob, long)
112 {
113         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
114         pre->apply();
115 }
116
117
118 void FormBase::ApplyHideCB(FL_OBJECT * ob, long)
119 {
120         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
121         pre->apply();
122         pre->hide();
123 }
124
125
126 void FormBase::HideCB(FL_OBJECT * ob, long)
127 {
128         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
129         pre->hide();
130 }
131
132
133 void FormBase::InputCB(FL_OBJECT * ob, long data)
134 {
135         FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
136         pre->input( data );
137 }