]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
* Baruch's GuiBC template.
[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(ControlButton & 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                 // work around dumb xforms sizing bug
46                 minw_ = form()->w;
47                 minh_ = form()->h;
48
49                 fl_set_form_atclose(form(),
50                                     C_FormBaseWMHideCB, 0);
51         }
52
53         fl_freeze_form(form());
54         update();  // make sure its up-to-date
55         fl_unfreeze_form(form());
56
57         if (form()->visible) {
58                 fl_raise_form(form());
59                 /* This XMapWindow() will hopefully ensure that
60                  * iconified dialogs are de-iconified. Mad props
61                  * out to those crazy Xlib guys for forgetting a
62                  * XDeiconifyWindow(). At least WindowMaker, when
63                  * being notified of the redirected MapRequest will
64                  * specifically de-iconify. From source, fvwm2 seems
65                  * to do the same.
66                  */
67                 XMapWindow(fl_get_display(), form()->window);
68         } else {
69                 // calls to fl_set_form_minsize/maxsize apply only to the next
70                 // fl_show_form(), so this comes first.
71                 fl_set_form_minsize(form(), minw_, minh_);
72                 fl_show_form(form(),
73                              FL_PLACE_MOUSE | FL_FREE_SIZE, 0,
74                              title_.c_str());
75         }
76 }
77
78
79 void FormBase::hide()
80 {
81         if (form() && form()->visible)
82                 fl_hide_form(form());
83 }
84
85
86 void FormBase::InputCB(FL_OBJECT * ob, long data)
87 {
88         bc().input(input(ob, data));
89 }
90
91
92 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
93 {
94         return ButtonPolicy::SMI_VALID;
95 }
96
97
98 namespace {
99
100 FormBase * GetForm(FL_OBJECT * ob)
101 {
102         Assert(ob && ob->form && ob->form->u_vdata);
103         FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
104         return pre;
105 }
106
107 } // namespace anon
108
109
110 extern "C" int C_FormBaseWMHideCB(FL_FORM * form, void *)
111 {
112         // Close the dialog cleanly, even if the WM is used to do so.
113         Assert(form && form->u_vdata);
114         FormBase * pre = static_cast<FormBase *>(form->u_vdata);
115         pre->CancelButton();
116         return FL_CANCEL;
117 }
118
119
120 extern "C" void C_FormBaseApplyCB(FL_OBJECT * ob, long)
121 {
122         GetForm(ob)->ApplyButton();
123 }
124
125
126 extern "C" void C_FormBaseOKCB(FL_OBJECT * ob, long)
127 {
128         GetForm(ob)->OKButton();
129 }
130
131
132 extern "C" void C_FormBaseCancelCB(FL_OBJECT * ob, long)
133 {
134         FormBase * form = GetForm(ob);
135         form->CancelButton();
136 }
137
138
139 extern "C" void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
140 {
141         GetForm(ob)->RestoreButton();
142 }
143
144
145 extern "C" void C_FormBaseInputCB(FL_OBJECT * ob, long d)
146 {
147         GetForm(ob)->InputCB(ob, d);
148 }