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