]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormFloat.C
f481a7b37b27990cbe247ff912fdf87232503e37
[lyx.git] / src / frontends / xforms / FormFloat.C
1 /**
2  * \file FormFloat.C
3  * See the file COPYING.
4  *
5  * \author Lars Gullik Bjønnes
6  * \author Juergen Spitzmueller j.spitzmueller@gmx.de
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "xformsBC.h"
18 #include "ControlFloat.h"
19 #include "FormFloat.h"
20 #include "forms/form_float.h"
21 #include "support/lstrings.h"
22 #include "xforms_helpers.h"
23 #include FORMS_H_LOCATION
24
25 typedef FormCB<ControlFloat, FormDB<FD_float> > base_class;
26
27 FormFloat::FormFloat()
28         : base_class(_("Float Options"))
29 {}
30
31
32 void FormFloat::build()
33 {
34         dialog_.reset(build_float(this));
35
36         // Manage the ok, apply and cancel/close buttons
37         bc().setOK(dialog_->button_ok);
38         bc().setApply(dialog_->button_apply);
39         bc().setCancel(dialog_->button_close);
40         bc().setRestore(dialog_->button_restore);
41
42         bc().addReadOnly(dialog_->check_default);
43         bc().addReadOnly(dialog_->check_top);
44         bc().addReadOnly(dialog_->check_bottom);
45         bc().addReadOnly(dialog_->check_page);
46         bc().addReadOnly(dialog_->check_here);
47         bc().addReadOnly(dialog_->check_force);
48         bc().addReadOnly(dialog_->check_here_definitely);
49         bc().addReadOnly(dialog_->check_wide);
50 }
51
52
53 void FormFloat::apply()
54 {
55         string placement;
56         if (fl_get_button(dialog_->check_here_definitely)) {
57                 placement += "H";
58         } else {
59                 if (fl_get_button(dialog_->check_force)) {
60                         placement += "!";
61                 }
62                 if (fl_get_button(dialog_->check_here)) {
63                         placement += "h";
64                 }
65                 if (fl_get_button(dialog_->check_top)) {
66                         placement += "t";
67                 }
68                 if (fl_get_button(dialog_->check_bottom)) {
69                         placement += "b";
70                 }
71                 if (fl_get_button(dialog_->check_page)) {
72                         placement += "p";
73                 }
74
75         }
76         controller().params().placement = placement;
77         controller().params().wide = fl_get_button(dialog_->check_wide);
78 }
79
80
81 void FormFloat::update()
82 {
83         bool def_placement = false;
84         bool top = false;
85         bool bottom = false;
86         bool page = false;
87         bool here = false;
88         bool force = false;
89         bool here_definitely = false;
90
91         string placement(controller().params().placement);
92
93         if (placement.empty()) {
94                 def_placement = true;
95
96         } else if (contains(placement, "H")) {
97                 here_definitely = true;
98
99         } else {
100                 if (contains(placement, "!")) {
101                         force = true;
102                 }
103                 if (contains(placement, "t")) {
104                         top = true;
105                 }
106                 if (contains(placement, "b")) {
107                         bottom = true;
108                 }
109                 if (contains(placement, "p")) {
110                         page = true;
111                 }
112                 if (contains(placement, "h")) {
113                         here = true;
114                 }
115         }
116         fl_set_button(dialog_->check_default, def_placement);
117         fl_set_button(dialog_->check_top, top);
118         fl_set_button(dialog_->check_bottom, bottom);
119         fl_set_button(dialog_->check_page, page);
120         fl_set_button(dialog_->check_here, here);
121         fl_set_button(dialog_->check_force, force);
122         fl_set_button(dialog_->check_here_definitely, here_definitely);
123         setEnabled(dialog_->check_here_definitely, !controller().params().wide 
124                         && !def_placement);
125         if (controller().params().wide) {
126                         fl_set_button(dialog_->check_here, false);
127                         fl_set_button(dialog_->check_bottom, false);
128         }
129         setEnabled(dialog_->check_here, !controller().params().wide && !def_placement);
130         setEnabled(dialog_->check_bottom, !controller().params().wide && !def_placement);
131         fl_set_button(dialog_->check_wide, controller().params().wide);
132         setEnabled(dialog_->check_top, !def_placement);
133         setEnabled(dialog_->check_page, !def_placement);
134         setEnabled(dialog_->check_force, top || bottom || page || here);
135 }
136
137
138 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
139 {
140         bool const def_place = fl_get_button(dialog_->check_default);
141         bool const wide_float = fl_get_button(dialog_->check_wide);
142         // with wide floats, h[ere] is not allowed
143         // b[ottom] is allowed (only) for figure* in multicolumn, don't
144         // disallow it therefore
145         bool const wide_options = (fl_get_button(dialog_->check_top)
146                                         || fl_get_button(dialog_->check_bottom)
147                                         || fl_get_button(dialog_->check_page));
148         // The !-option is only allowed together with h, t, b, or p
149         // We have to take this into account
150         bool const standard_options = (wide_options || fl_get_button(dialog_->check_here));
151         
152         if (ob == dialog_->check_default) {
153                 if (def_place) {
154                         fl_set_button(dialog_->check_top, false);
155                         fl_set_button(dialog_->check_bottom,  false);
156                         fl_set_button(dialog_->check_page, false);
157                         fl_set_button(dialog_->check_here, false);
158                         fl_set_button(dialog_->check_force, false);
159                         fl_set_button(dialog_->check_here_definitely, false);
160                         }
161                 setEnabled(dialog_->check_top, !def_place);
162                 setEnabled(dialog_->check_bottom, !def_place);
163                 setEnabled(dialog_->check_page, !def_place);
164                 setEnabled(dialog_->check_here, !def_place && !wide_float);
165                 setEnabled(dialog_->check_force, !def_place && standard_options);
166                 setEnabled(dialog_->check_here_definitely, !def_place && !wide_float);
167
168         } else if (ob == dialog_->check_wide) {
169                 if (wide_float) {
170                         fl_set_button(dialog_->check_here_definitely, false);
171                         fl_set_button(dialog_->check_here, false);
172                         if (!wide_options) {
173                                 fl_set_button(dialog_->check_force, false);
174                                 setEnabled(dialog_->check_force, false);
175                         }
176                 }
177                 setEnabled(dialog_->check_here, !def_place && !wide_float);
178                 setEnabled(dialog_->check_force, !def_place && wide_options);
179                 setEnabled(dialog_->check_here_definitely, !def_place && !wide_float);
180
181         } else if (ob == dialog_->check_here_definitely) {
182                 if (fl_get_button(dialog_->check_here_definitely)) {
183                         fl_set_button(dialog_->check_top,    false);
184                         fl_set_button(dialog_->check_bottom, false);
185                         fl_set_button(dialog_->check_page,   false);
186                         fl_set_button(dialog_->check_here,   false);
187                         fl_set_button(dialog_->check_force,   false);
188                         setEnabled(dialog_->check_force, false);
189                 }
190
191         } else if (ob == dialog_->check_here || ob == dialog_->check_top
192                 || ob == dialog_->check_bottom || ob == dialog_->check_page) {
193                 if (!standard_options)
194                         fl_set_button(dialog_->check_force, false);
195                 else
196                         fl_set_button(dialog_->check_here_definitely, false);
197                 setEnabled(dialog_->check_force, standard_options);
198
199         }
200
201         return ButtonPolicy::SMI_VALID;
202 }