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