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