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