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