3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Juergen Spitzmueller j.spitzmueller@gmx.de
9 * Full author contact details are available in file CREDITS
15 #pragma implementation
19 #include "ControlFloat.h"
20 #include "FormFloat.h"
21 #include "forms/form_float.h"
22 #include "support/lstrings.h"
23 #include "xforms_helpers.h"
24 #include FORMS_H_LOCATION
26 typedef FormCB<ControlFloat, FormDB<FD_float> > base_class;
28 FormFloat::FormFloat()
29 : base_class(_("Float Options"))
33 void FormFloat::build()
35 dialog_.reset(build_float(this));
37 // Manage the ok, apply and cancel/close buttons
38 bc().setOK(dialog_->button_ok);
39 bc().setApply(dialog_->button_apply);
40 bc().setCancel(dialog_->button_close);
41 bc().setRestore(dialog_->button_restore);
43 bc().addReadOnly(dialog_->check_default);
44 bc().addReadOnly(dialog_->check_top);
45 bc().addReadOnly(dialog_->check_bottom);
46 bc().addReadOnly(dialog_->check_page);
47 bc().addReadOnly(dialog_->check_here);
48 bc().addReadOnly(dialog_->check_force);
49 bc().addReadOnly(dialog_->check_here_definitely);
50 bc().addReadOnly(dialog_->check_wide);
54 void FormFloat::apply()
57 if (fl_get_button(dialog_->check_here_definitely)) {
60 if (fl_get_button(dialog_->check_force)) {
63 if (fl_get_button(dialog_->check_here)) {
66 if (fl_get_button(dialog_->check_top)) {
69 if (fl_get_button(dialog_->check_bottom)) {
72 if (fl_get_button(dialog_->check_page)) {
77 controller().params().placement = placement;
78 controller().params().wide = fl_get_button(dialog_->check_wide);
82 void FormFloat::update()
84 bool def_placement = false;
90 bool here_definitely = false;
92 string placement(controller().params().placement);
94 if (placement.empty()) {
97 } else if (contains(placement, "H")) {
98 here_definitely = true;
101 if (contains(placement, "!")) {
104 if (contains(placement, "t")) {
107 if (contains(placement, "b")) {
110 if (contains(placement, "p")) {
113 if (contains(placement, "h")) {
117 fl_set_button(dialog_->check_default, def_placement);
118 fl_set_button(dialog_->check_top, top);
119 fl_set_button(dialog_->check_bottom, bottom);
120 fl_set_button(dialog_->check_page, page);
121 fl_set_button(dialog_->check_here, here);
122 fl_set_button(dialog_->check_force, force);
123 fl_set_button(dialog_->check_here_definitely, here_definitely);
124 setEnabled(dialog_->check_here_definitely, !controller().params().wide
126 if (controller().params().wide) {
127 fl_set_button(dialog_->check_here, false);
128 fl_set_button(dialog_->check_bottom, false);
130 setEnabled(dialog_->check_here, !controller().params().wide && !def_placement);
131 setEnabled(dialog_->check_bottom, !controller().params().wide && !def_placement);
132 fl_set_button(dialog_->check_wide, controller().params().wide);
133 setEnabled(dialog_->check_top, !def_placement);
134 setEnabled(dialog_->check_page, !def_placement);
135 setEnabled(dialog_->check_force, top || bottom || page || here);
139 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
141 bool const def_place = fl_get_button(dialog_->check_default);
142 bool const wide_float = fl_get_button(dialog_->check_wide);
143 // with wide floats, h[ere] is not allowed
144 // b[ottom] is allowed (only) for figure* in multicolumn, don't
145 // disallow it therefore
146 bool const wide_options = (fl_get_button(dialog_->check_top)
147 || fl_get_button(dialog_->check_bottom)
148 || fl_get_button(dialog_->check_page));
149 // The !-option is only allowed together with h, t, b, or p
150 // We have to take this into account
151 bool const standard_options = (wide_options || fl_get_button(dialog_->check_here));
153 if (ob == dialog_->check_default) {
155 fl_set_button(dialog_->check_top, false);
156 fl_set_button(dialog_->check_bottom, false);
157 fl_set_button(dialog_->check_page, false);
158 fl_set_button(dialog_->check_here, false);
159 fl_set_button(dialog_->check_force, false);
160 fl_set_button(dialog_->check_here_definitely, false);
162 setEnabled(dialog_->check_top, !def_place);
163 setEnabled(dialog_->check_bottom, !def_place);
164 setEnabled(dialog_->check_page, !def_place);
165 setEnabled(dialog_->check_here, !def_place && !wide_float);
166 setEnabled(dialog_->check_force, !def_place && standard_options);
167 setEnabled(dialog_->check_here_definitely, !def_place && !wide_float);
169 } else if (ob == dialog_->check_wide) {
171 fl_set_button(dialog_->check_here_definitely, false);
172 fl_set_button(dialog_->check_here, false);
174 fl_set_button(dialog_->check_force, false);
175 setEnabled(dialog_->check_force, false);
178 setEnabled(dialog_->check_here, !def_place && !wide_float);
179 setEnabled(dialog_->check_force, !def_place && wide_options);
180 setEnabled(dialog_->check_here_definitely, !def_place && !wide_float);
182 } else if (ob == dialog_->check_here_definitely) {
183 if (fl_get_button(dialog_->check_here_definitely)) {
184 fl_set_button(dialog_->check_top, false);
185 fl_set_button(dialog_->check_bottom, false);
186 fl_set_button(dialog_->check_page, false);
187 fl_set_button(dialog_->check_here, false);
188 fl_set_button(dialog_->check_force, false);
189 setEnabled(dialog_->check_force, false);
192 } else if (ob == dialog_->check_here || ob == dialog_->check_top
193 || ob == dialog_->check_bottom || ob == dialog_->check_page) {
194 if (!standard_options)
195 fl_set_button(dialog_->check_force, false);
197 fl_set_button(dialog_->check_here_definitely, false);
198 setEnabled(dialog_->check_force, standard_options);
202 return ButtonPolicy::SMI_VALID;