]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormCommand.C
patch from Angus
[features.git] / src / frontends / xforms / FormCommand.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
21 #include "Dialogs.h"
22 #include "FormCommand.h"
23 #include "xform_macros.h"
24
25 C_RETURNCB(FormCommand, WMHideCB)
26 C_GENERICCB(FormCommand, ApplyCB)
27 C_GENERICCB(FormCommand, CancelCB)
28 C_GENERICCB(FormCommand, InputCB)
29 C_GENERICCB(FormCommand, OKCB)
30
31 FormCommand::FormCommand(LyXView * lv, Dialogs * d, string const & t)
32         : lv_(lv), d_(d), u_(0), h_(0), ih_(0),
33           inset_(0), dialogIsOpen(false), title(t)
34 {}
35
36
37 void FormCommand::showInset( InsetCommand * const inset )
38 {
39         if( dialogIsOpen || inset == 0 ) return;
40
41         inset_ = inset;
42         ih_ = inset_->hide.connect(slot(this, &FormCommand::hide));
43
44         params = inset->params();
45         show();
46 }
47
48
49 void FormCommand::createInset( string const & arg )
50 {
51         if( dialogIsOpen ) return;
52
53         params.setFromString( arg );
54         show();
55 }
56
57
58 void FormCommand::show()
59 {
60         if (!form()) {
61                 build();
62                 fl_set_form_atclose(form(),
63                                     C_FormCommandWMHideCB, 0);
64         }
65
66         fl_freeze_form( form() );
67         update();  // make sure its up-to-date
68         fl_unfreeze_form( form() );
69
70         dialogIsOpen = true;
71         if (form()->visible) {
72                 fl_raise_form(form());
73         } else {
74                 fl_show_form(form(),
75                              FL_PLACE_MOUSE | FL_FREE_SIZE,
76                              FL_TRANSIENT,
77                              title.c_str());
78                 u_ = d_->updateBufferDependent.
79                          connect(slot(this, &FormCommand::update));
80                 h_ = d_->hideBufferDependent.
81                          connect(slot(this, &FormCommand::hide));
82         }
83 }
84
85
86 void FormCommand::free()
87 {
88         // we don't need to delete u and h here because
89         // hide() does that after disconnecting.
90         if( form() ) {
91                 if( form()->visible)
92                         hide();
93                 fl_free_form(form());
94         }
95 }
96
97
98 void FormCommand::hide()
99 {
100         if (form() && form()->visible) {
101                 fl_hide_form(form());
102                 u_.disconnect();
103                 h_.disconnect();
104         }
105
106         // free up the dialog for another inset
107         inset_ = 0;
108         ih_.disconnect();
109         dialogIsOpen = false;
110 }
111
112
113 int FormCommand::WMHideCB(FL_FORM * form, void *)
114 {
115         // Ensure that the signals (u and h) are disconnected even if the
116         // window manager is used to close the dialog.
117         FormCommand * pre = static_cast<FormCommand*>(form->u_vdata);
118         pre->hide();
119         return FL_CANCEL;
120 }
121
122
123 void FormCommand::ApplyCB(FL_OBJECT * ob, long)
124 {
125         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
126         pre->apply();
127 }
128
129
130 void FormCommand::CancelCB(FL_OBJECT * ob, long)
131 {
132         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
133         pre->hide();
134 }
135
136
137 void FormCommand::InputCB(FL_OBJECT * ob, long data )
138 {
139         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
140         pre->input( data );
141 }
142
143
144 void FormCommand::OKCB(FL_OBJECT * ob, long)
145 {
146         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
147         pre->apply();
148         pre->hide();
149 }
150
151