]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormCommand.C
Fix xforms menus display problems
[lyx.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), inset_(0), u_(0), h_(0), ih_(0),
33           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::hide()
87 {
88         if (form() && form()->visible) {
89                 fl_hide_form(form());
90                 u_.disconnect();
91                 h_.disconnect();
92         }
93
94         // free up the dialog for another inset
95         inset_ = 0;
96         ih_.disconnect();
97         dialogIsOpen = false;
98         clearStore();
99 }
100
101
102 int FormCommand::WMHideCB(FL_FORM * form, void *)
103 {
104         // Ensure that the signals (u and h) are disconnected even if the
105         // window manager is used to close the dialog.
106         FormCommand * pre = static_cast<FormCommand*>(form->u_vdata);
107         pre->hide();
108         return FL_CANCEL;
109 }
110
111
112 void FormCommand::ApplyCB(FL_OBJECT * ob, long)
113 {
114         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
115         pre->apply();
116 }
117
118
119 void FormCommand::CancelCB(FL_OBJECT * ob, long)
120 {
121         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
122         pre->hide();
123 }
124
125
126 void FormCommand::InputCB(FL_OBJECT * ob, long data )
127 {
128         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
129         pre->input( data );
130 }
131
132
133 void FormCommand::OKCB(FL_OBJECT * ob, long)
134 {
135         FormCommand * pre = static_cast<FormCommand*>(ob->form->u_vdata);
136         pre->apply();
137         pre->hide();
138 }