]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
implement getLabelList
[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  * \author Angus Leeming <a.leeming@ic.ac.uk>
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "Dialogs.h"
21 #include "FormBase.h"
22 #include "xformsBC.h"
23 #include "support/LAssert.h"
24
25 extern "C" int C_FormBaseWMHideCB(FL_FORM * form, void *);
26
27
28 FormBase::FormBase(ControlButtons & c, string const & t)
29         : ViewBC<xformsBC>(c), minw_(0), minh_(0), title_(t)
30 {}
31
32
33 void FormBase::redraw()
34 {
35         if (form() && form()->visible)
36                 fl_redraw_form(form());
37 }
38
39
40 void FormBase::show()
41 {
42         if (!form()) {
43                 build();
44
45                 bc().refresh();
46  
47                 // work around dumb xforms sizing bug
48                 minw_ = form()->w;
49                 minh_ = form()->h;
50
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         if (form()->visible) {
60                 fl_raise_form(form());
61                 /* This XMapWindow() will hopefully ensure that
62                  * iconified dialogs are de-iconified. Mad props
63                  * out to those crazy Xlib guys for forgetting a
64                  * XDeiconifyWindow(). At least WindowMaker, when
65                  * being notified of the redirected MapRequest will
66                  * specifically de-iconify. From source, fvwm2 seems
67                  * to do the same.
68                  */
69                 XMapWindow(fl_get_display(), form()->window);
70         } else {
71                 // calls to fl_set_form_minsize/maxsize apply only to the next
72                 // fl_show_form(), so this comes first.
73                 fl_set_form_minsize(form(), minw_, minh_);
74                 fl_show_form(form(),
75                              FL_PLACE_MOUSE | FL_FREE_SIZE, 0,
76                              title_.c_str());
77         }
78 }
79
80
81 void FormBase::hide()
82 {
83         if (form() && form()->visible)
84                 fl_hide_form(form());
85 }
86
87
88 void FormBase::InputCB(FL_OBJECT * ob, long data)
89 {
90         bc().input(input(ob, data));
91 }
92
93
94 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
95 {
96         return ButtonPolicy::SMI_VALID;
97 }
98
99
100 namespace {
101
102 FormBase * GetForm(FL_OBJECT * ob)
103 {
104         Assert(ob && ob->form && ob->form->u_vdata);
105         FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
106         return pre;
107 }
108
109 } // namespace anon
110
111
112 extern "C" int C_FormBaseWMHideCB(FL_FORM * form, void *)
113 {
114         // Close the dialog cleanly, even if the WM is used to do so.
115         Assert(form && form->u_vdata);
116         FormBase * pre = static_cast<FormBase *>(form->u_vdata);
117         pre->CancelButton();
118         return FL_CANCEL;
119 }
120
121
122 extern "C" void C_FormBaseApplyCB(FL_OBJECT * ob, long)
123 {
124         GetForm(ob)->ApplyButton();
125 }
126
127
128 extern "C" void C_FormBaseOKCB(FL_OBJECT * ob, long)
129 {
130         GetForm(ob)->OKButton();
131 }
132
133
134 extern "C" void C_FormBaseCancelCB(FL_OBJECT * ob, long)
135 {
136         FormBase * form = GetForm(ob);
137         form->CancelButton();
138 }
139
140
141 extern "C" void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
142 {
143         GetForm(ob)->RestoreButton();
144 }
145
146
147 extern "C" void C_FormBaseInputCB(FL_OBJECT * ob, long d)
148 {
149         GetForm(ob)->InputCB(ob, d);
150 }