3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
6 * \author Lars Gullik Bjønnes, larsbj@lyx.org
7 * \author Juergen Spitzmueller j.spitzmueller@gmx.de
13 #pragma implementation
17 #include "ControlFloat.h"
18 #include "FormFloat.h"
19 #include "forms/form_float.h"
20 #include "support/lstrings.h"
21 #include "xforms_helpers.h"
22 #include FORMS_H_LOCATION
24 typedef FormCB<ControlFloat, FormDB<FD_float> > base_class;
26 FormFloat::FormFloat()
27 : base_class(_("Float Options"))
31 void FormFloat::build()
33 dialog_.reset(build_float(this));
35 // Manage the ok, apply and cancel/close buttons
36 bc().setOK(dialog_->button_ok);
37 bc().setApply(dialog_->button_apply);
38 bc().setCancel(dialog_->button_close);
39 bc().setRestore(dialog_->button_restore);
41 bc().addReadOnly(dialog_->check_default);
42 bc().addReadOnly(dialog_->check_top);
43 bc().addReadOnly(dialog_->check_bottom);
44 bc().addReadOnly(dialog_->check_page);
45 bc().addReadOnly(dialog_->check_here);
46 bc().addReadOnly(dialog_->check_force);
47 bc().addReadOnly(dialog_->check_here_definitely);
48 bc().addReadOnly(dialog_->check_wide);
52 void FormFloat::apply()
55 if (fl_get_button(dialog_->check_here_definitely)) {
58 if (fl_get_button(dialog_->check_force)) {
61 if (fl_get_button(dialog_->check_here)) {
64 if (fl_get_button(dialog_->check_top)) {
67 if (fl_get_button(dialog_->check_bottom)) {
70 if (fl_get_button(dialog_->check_page)) {
75 controller().params().placement = placement;
76 controller().params().wide = fl_get_button(dialog_->check_wide);
80 void FormFloat::update()
82 bool def_placement = false;
88 bool here_definitely = false;
90 string placement(controller().params().placement);
92 if (placement.empty()) {
95 } else if (contains(placement, "H")) {
96 here_definitely = true;
99 if (contains(placement, "!")) {
102 if (contains(placement, "t")) {
105 if (contains(placement, "b")) {
108 if (contains(placement, "p")) {
111 if (contains(placement, "h")) {
115 fl_set_button(dialog_->check_default, def_placement);
116 fl_set_button(dialog_->check_top, top);
117 fl_set_button(dialog_->check_bottom, bottom);
118 fl_set_button(dialog_->check_page, page);
119 fl_set_button(dialog_->check_here, here);
120 fl_set_button(dialog_->check_force, force);
121 fl_set_button(dialog_->check_here_definitely, here_definitely);
122 setEnabled(dialog_->check_here_definitely, !controller().params().wide
124 if (controller().params().wide) {
125 fl_set_button(dialog_->check_here, false);
126 fl_set_button(dialog_->check_bottom, false);
128 setEnabled(dialog_->check_here, !controller().params().wide && !def_placement);
129 setEnabled(dialog_->check_bottom, !controller().params().wide && !def_placement);
130 fl_set_button(dialog_->check_wide, controller().params().wide);
131 setEnabled(dialog_->check_top, !def_placement);
132 setEnabled(dialog_->check_page, !def_placement);
133 setEnabled(dialog_->check_force, top || bottom || page || here);
137 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
139 bool const def_place = fl_get_button(dialog_->check_default);
140 bool const wide_float = fl_get_button(dialog_->check_wide);
141 // with wide floats, h[ere] is not allowed
142 // b[ottom] is allowed (only) for figure* in multicolumn, don't
143 // disallow it therefore
144 bool const wide_options = (fl_get_button(dialog_->check_top)
145 || fl_get_button(dialog_->check_bottom)
146 || fl_get_button(dialog_->check_page));
147 // The !-option is only allowed together with h, t, b, or p
148 // We have to take this into account
149 bool const standard_options = (wide_options || fl_get_button(dialog_->check_here));
151 if (ob == dialog_->check_default) {
153 fl_set_button(dialog_->check_top, false);
154 fl_set_button(dialog_->check_bottom, false);
155 fl_set_button(dialog_->check_page, false);
156 fl_set_button(dialog_->check_here, false);
157 fl_set_button(dialog_->check_force, false);
158 fl_set_button(dialog_->check_here_definitely, false);
160 setEnabled(dialog_->check_top, !def_place);
161 setEnabled(dialog_->check_bottom, !def_place);
162 setEnabled(dialog_->check_page, !def_place);
163 setEnabled(dialog_->check_here, !def_place && !wide_float);
164 setEnabled(dialog_->check_force, !def_place && standard_options);
165 setEnabled(dialog_->check_here_definitely, !def_place && !wide_float);
167 } else if (ob == dialog_->check_wide) {
169 fl_set_button(dialog_->check_here_definitely, false);
170 fl_set_button(dialog_->check_here, false);
172 fl_set_button(dialog_->check_force, false);
173 setEnabled(dialog_->check_force, false);
176 setEnabled(dialog_->check_here, !def_place && !wide_float);
177 setEnabled(dialog_->check_force, !def_place && wide_options);
178 setEnabled(dialog_->check_here_definitely, !def_place && !wide_float);
180 } else if (ob == dialog_->check_here_definitely) {
181 if (fl_get_button(dialog_->check_here_definitely)) {
182 fl_set_button(dialog_->check_top, false);
183 fl_set_button(dialog_->check_bottom, false);
184 fl_set_button(dialog_->check_page, false);
185 fl_set_button(dialog_->check_here, false);
186 fl_set_button(dialog_->check_force, false);
187 setEnabled(dialog_->check_force, false);
190 } else if (ob == dialog_->check_here || ob == dialog_->check_top
191 || ob == dialog_->check_bottom || ob == dialog_->check_page) {
192 if (!standard_options)
193 fl_set_button(dialog_->check_force, false);
195 fl_set_button(dialog_->check_here_definitely, false);
196 setEnabled(dialog_->check_force, standard_options);
200 return ButtonPolicy::SMI_VALID;