]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
Removed // -*- C++ -*- from all .C files!
[lyx.git] / src / frontends / xforms / FormBase.C
1 /* This file is part of
2  * ====================================================== 
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2000-2001 The LyX Team.
7  *
8  * ======================================================
9  *
10  * \author Angus Leeming <a.leeming@ic.ac.uk>
11  */
12
13 #include <config.h>
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19 #include "Dialogs.h"
20 #include "FormBase.h"
21 #include "xformsBC.h"
22 #include "support/LAssert.h"
23
24 extern "C" int C_FormBaseWMHideCB(FL_FORM * form, void *);
25
26
27 FormBase::FormBase(ControlButtons & c, string const & t)
28         : ViewBC<xformsBC>(c), minw_(0), minh_(0), title_(t)
29 {}
30
31
32 void FormBase::redraw()
33 {
34         if (form() && form()->visible)
35                 fl_redraw_form(form());
36 }
37
38
39 void FormBase::show()
40 {
41         if (!form()) {
42                 build();
43
44                 bc().refresh();
45  
46                 // work around dumb xforms sizing bug
47                 minw_ = form()->w;
48                 minh_ = form()->h;
49
50                 fl_set_form_atclose(form(), 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         lyx::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"
111 int C_FormBaseWMHideCB(FL_FORM * form, void *)
112 {
113         // Close the dialog cleanly, even if the WM is used to do so.
114         lyx::Assert(form && form->u_vdata);
115         FormBase * pre = static_cast<FormBase *>(form->u_vdata);
116         pre->CancelButton();
117         return FL_CANCEL;
118 }
119
120
121 extern "C" void C_FormBaseApplyCB(FL_OBJECT * ob, long)
122 {
123         GetForm(ob)->ApplyButton();
124 }
125
126
127 extern "C" void C_FormBaseOKCB(FL_OBJECT * ob, long)
128 {
129         GetForm(ob)->OKButton();
130 }
131
132
133 extern "C" void C_FormBaseCancelCB(FL_OBJECT * ob, long)
134 {
135         FormBase * form = GetForm(ob);
136         form->CancelButton();
137 }
138
139
140 extern "C" void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
141 {
142         GetForm(ob)->RestoreButton();
143 }
144
145
146 extern "C" void C_FormBaseInputCB(FL_OBJECT * ob, long d)
147 {
148         GetForm(ob)->InputCB(ob, d);
149 }