]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormCommand.C
4f30c131ef848ab63b2bc0d3ca5ea8d915db9f26
[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         // companion to Lars' commenting out in insetcommand.
43         // need a better plan perhaps since there seems to be a small
44         // flaw here if we copy an inset while it's visible
45         //      ih_ = inset_->hide.connect(slot(this, &FormCommand::hide));
46
47         params = inset->params();
48         show();
49 }
50
51
52 void FormCommand::createInset( string const & arg )
53 {
54         if( dialogIsOpen ) return;
55
56         params.setFromString( arg );
57         show();
58 }
59
60
61 void FormCommand::show()
62 {
63         if (!form()) {
64                 build();
65                 fl_set_form_atclose(form(),
66                                     C_FormCommandWMHideCB, 0);
67         }
68
69         fl_freeze_form( form() );
70         update();  // make sure its up-to-date
71         fl_unfreeze_form( form() );
72
73         dialogIsOpen = true;
74         if (form()->visible) {
75                 fl_raise_form(form());
76         } else {
77                 fl_show_form(form(),
78                              FL_PLACE_MOUSE | FL_FREE_SIZE,
79                              FL_TRANSIENT,
80                              title.c_str());
81                 u_ = d_->updateBufferDependent.
82                          connect(slot(this, &FormCommand::update));
83                 h_ = d_->hideBufferDependent.
84                          connect(slot(this, &FormCommand::hide));
85         }
86 }
87
88
89 void FormCommand::free()
90 {
91         // we don't need to delete u and h here because
92         // hide() does that after disconnecting.
93         if( form() ) {
94                 if( form()->visible)
95                         hide();
96                 fl_free_form(form());
97         }
98 }
99
100
101 void FormCommand::hide()
102 {
103         if (form() && form()->visible) {
104                 fl_hide_form(form());
105                 u_.disconnect();
106                 h_.disconnect();
107         }
108
109         // free up the dialog for another inset
110         inset_ = 0;
111         ih_.disconnect();
112         dialogIsOpen = false;
113 }
114
115
116 int FormCommand::WMHideCB(FL_FORM * form, void *)
117 {
118         // Ensure that the signals (u and h) are disconnected even if the
119         // window manager is used to close the dialog.
120         FormCommand * pre = static_cast<FormCommand*>(form->u_vdata);
121         pre->hide();
122         return FL_CANCEL;
123 }
124
125
126 void FormCommand::ApplyCB(FL_OBJECT * ob, long)
127 {
128         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
129         pre->apply();
130 }
131
132
133 void FormCommand::CancelCB(FL_OBJECT * ob, long)
134 {
135         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
136         pre->hide();
137 }
138
139
140 void FormCommand::InputCB(FL_OBJECT * ob, long data )
141 {
142         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
143         pre->input( data );
144 }
145
146
147 void FormCommand::OKCB(FL_OBJECT * ob, long)
148 {
149         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
150         pre->apply();
151         pre->hide();
152 }
153
154