]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
use anon namespace, somewhat better comp. handling of minipages, not quite there yet
[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 namespace {
91
92 FormBase * GetForm(FL_OBJECT * ob)
93 {
94         Assert(ob && ob->form && ob->form->u_vdata);
95         FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
96         return pre;
97 }
98
99 } // namespace anon
100
101
102 extern "C" int C_FormBaseWMHideCB(FL_FORM * form, void *)
103 {
104         // Close the dialog cleanly, even if the WM is used to do so.
105         Assert(form && form->u_vdata);
106         FormBase * pre = static_cast<FormBase *>(form->u_vdata);
107         pre->CancelButton();
108         return FL_CANCEL;
109 }
110
111
112 extern "C" void C_FormBaseApplyCB(FL_OBJECT * ob, long)
113 {
114         GetForm(ob)->ApplyButton();
115 }
116
117
118 extern "C" void C_FormBaseOKCB(FL_OBJECT * ob, long)
119 {
120         GetForm(ob)->OKButton();
121 }
122
123
124 extern "C" void C_FormBaseCancelCB(FL_OBJECT * ob, long)
125 {
126         FormBase * form = GetForm(ob);
127         form->CancelButton();
128 }
129
130
131 extern "C" void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
132 {
133         GetForm(ob)->RestoreButton();
134 }
135
136
137 extern "C" void C_FormBaseInputCB(FL_OBJECT * ob, long d)
138 {
139         GetForm(ob)->InputCB(ob, d);
140 }