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