]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[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" {
25         // Callback function invoked by xforms when the dialog is closed by the
26         // window manager
27         static int C_FormBaseWMHideCB(FL_FORM * form, void *);
28
29 }
30
31
32 FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize)
33         : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
34           title_(t)
35 {}
36
37
38 void FormBase::redraw()
39 {
40         if (form() && form()->visible)
41                 fl_redraw_form(form());
42 }
43
44
45 void FormBase::show()
46 {
47         if (!form()) {
48                 build();
49         }
50         
51         // use minw_ to flag whether the dialog has ever been shown
52         // (Needed now that build() is/should be called from the controller)
53         if (minw_ == 0) {
54                 bc().refresh();
55  
56                 // work around dumb xforms sizing bug
57                 minw_ = form()->w;
58                 minh_ = form()->h;
59
60                 fl_set_form_atclose(form(), C_FormBaseWMHideCB, 0);
61         }
62         
63         fl_freeze_form(form());
64         update();  // make sure its up-to-date
65         fl_unfreeze_form(form());
66
67         if (form()->visible) {
68                 fl_raise_form(form());
69                 /* This XMapWindow() will hopefully ensure that
70                  * iconified dialogs are de-iconified. Mad props
71                  * out to those crazy Xlib guys for forgetting a
72                  * XDeiconifyWindow(). At least WindowMaker, when
73                  * being notified of the redirected MapRequest will
74                  * specifically de-iconify. From source, fvwm2 seems
75                  * to do the same.
76                  */
77                 XMapWindow(fl_get_display(), form()->window);
78         } else {
79                 // calls to fl_set_form_minsize/maxsize apply only to the next
80                 // fl_show_form(), so this comes first.
81                 fl_set_form_minsize(form(), minw_, minh_);
82                 if (!allow_resize_)
83                         fl_set_form_maxsize(form(), minw_, minh_);
84
85                 fl_show_form(form(),
86                         FL_PLACE_MOUSE | FL_FREE_SIZE,
87                         (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
88                         title_.c_str());
89         }
90 }
91
92
93 void FormBase::hide()
94 {
95         if (form() && form()->visible)
96                 fl_hide_form(form());
97 }
98
99
100 void FormBase::InputCB(FL_OBJECT * ob, long data)
101 {
102         // It is possible to set the choice to 0 when using the
103         // keyboard shortcuts. This work-around deals with the problem.
104         if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
105                 fl_set_choice(ob, 1);
106         }
107
108         bc().input(input(ob, data));
109 }
110
111
112 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
113 {
114         return ButtonPolicy::SMI_VALID;
115 }
116
117
118 namespace {
119
120 FormBase * GetForm(FL_OBJECT * ob)
121 {
122         lyx::Assert(ob && ob->form && ob->form->u_vdata);
123         FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
124         return pre;
125 }
126
127 } // namespace anon
128
129
130 extern "C" {
131         
132         static
133         int C_FormBaseWMHideCB(FL_FORM * form, void *)
134         {
135                 // Close the dialog cleanly, even if the WM is used to do so.
136                 lyx::Assert(form && form->u_vdata);
137                 FormBase * pre = static_cast<FormBase *>(form->u_vdata);
138                 pre->CancelButton();
139                 return FL_CANCEL;
140         }
141
142
143         void C_FormBaseApplyCB(FL_OBJECT * ob, long)
144         {
145                 GetForm(ob)->ApplyButton();
146         }
147
148
149         void C_FormBaseOKCB(FL_OBJECT * ob, long)
150         {
151                 GetForm(ob)->OKButton();
152         }
153
154
155         void C_FormBaseCancelCB(FL_OBJECT * ob, long)
156         {
157                 FormBase * form = GetForm(ob);
158                 form->CancelButton();
159         }
160
161
162         void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
163         {
164                 GetForm(ob)->RestoreButton();
165         }
166
167
168         void C_FormBaseInputCB(FL_OBJECT * ob, long d)
169         {
170                 GetForm(ob)->InputCB(ob, d);
171         }
172
173
174         // To trigger an input event when pasting in an xforms input object
175         // using the middle mouse button.
176         int C_CutandPastePH(FL_OBJECT * ob, int event,
177                             FL_Coord, FL_Coord, int key, void *)
178         {
179                 if ((event == FL_PUSH) && (key == 2)
180                     && (ob->objclass == FL_INPUT)) {
181                         C_FormBaseInputCB(ob, 0);
182                 }
183                 return 0;
184         }
185
186 }