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 Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "FormFloat.h"
16 #include "ControlFloat.h"
17 #include "forms/form_float.h"
20 #include "xforms_helpers.h"
23 #include "insets/insetfloat.h"
25 #include "support/lstrings.h"
27 #include "lyx_forms.h"
33 using support::contains;
48 typedef FormController<ControlFloat, FormView<FD_float> > base_class;
50 FormFloat::FormFloat(Dialog & parent)
51 : base_class(parent, _("Float Settings"))
55 void FormFloat::build()
57 dialog_.reset(build_float(this));
59 // Manage the ok, apply and cancel/close buttons
60 bcview().setOK(dialog_->button_ok);
61 bcview().setApply(dialog_->button_apply);
62 bcview().setCancel(dialog_->button_close);
63 bcview().setRestore(dialog_->button_restore);
65 // disable for read-only documents
66 bcview().addReadOnly(dialog_->radio_default);
67 bcview().addReadOnly(dialog_->radio_here_definitely);
68 bcview().addReadOnly(dialog_->radio_alternatives);
69 bcview().addReadOnly(dialog_->check_top);
70 bcview().addReadOnly(dialog_->check_bottom);
71 bcview().addReadOnly(dialog_->check_page);
72 bcview().addReadOnly(dialog_->check_here);
73 bcview().addReadOnly(dialog_->check_force);
74 bcview().addReadOnly(dialog_->check_wide);
75 bcview().addReadOnly(dialog_->check_sideways);
77 placement_.init(dialog_->radio_default, DOCUMENT_DEFAULTS);
78 placement_.init(dialog_->radio_here_definitely, HERE_DEFINITELY);
79 placement_.init(dialog_->radio_alternatives, ALTERNATIVES);
81 // set up the tooltips
82 string str = _("Use the document's default settings.");
83 tooltips().init(dialog_->radio_default, str);
84 str = _("Enforce placement of float here.");
85 tooltips().init(dialog_->radio_here_definitely, str);
86 str = _("Alternative suggestions for placement of float.");
87 tooltips().init(dialog_->radio_alternatives, str);
88 str = _("Try top of page.");
89 tooltips().init(dialog_->check_top, str);
90 str = _("Try bottom of page.");
91 tooltips().init(dialog_->check_bottom, str);
92 str = _("Put float on a separate page of floats.");
93 tooltips().init(dialog_->check_page, str);
94 str = _("Try float here.");
95 tooltips().init(dialog_->check_here, str);
96 str = _("Ignore internal settings. This is the \"!\" in LaTeX.");
97 tooltips().init(dialog_->check_force, str);
98 str = _("Span float over the columns.");
99 tooltips().init(dialog_->check_wide, str);
100 str = _("Rotate the float sideways by 90 degs.");
101 tooltips().init(dialog_->check_sideways, str);
105 void FormFloat::apply()
107 bool const wide = fl_get_button(dialog_->check_wide);
108 bool const sideways = fl_get_button(dialog_->check_sideways);
111 switch (placement_.get()) {
113 if (fl_get_button(dialog_->check_force)) {
114 // Ignore internal LaTeX rules
117 if (fl_get_button(dialog_->check_top)) {
121 if (fl_get_button(dialog_->check_bottom)) {
125 if (fl_get_button(dialog_->check_page)) {
129 // ignore if wide is selected
130 if (!wide && fl_get_button(dialog_->check_here)) {
134 if (placement == "!") {
135 // ignore placement if only force is selected.
139 if (placement.length() == 0) {
140 // none of Alternatives is selected; flip to default
142 placement_.set(dialog_->radio_default);
143 setEnabled(dialog_->check_force, false);
144 setEnabled(dialog_->check_top, false);
145 setEnabled(dialog_->check_bottom, false);
146 setEnabled(dialog_->check_page, false);
147 setEnabled(dialog_->check_here, false);
151 case HERE_DEFINITELY:
155 case DOCUMENT_DEFAULTS:
156 // default, do nothing.
160 controller().params().placement = placement;
161 controller().params().wide = wide;
162 controller().params().sideways = sideways;
166 void FormFloat::update()
168 string placement(controller().params().placement);
169 bool const wide = controller().params().wide;
170 bool const sideways = controller().params().sideways;
171 bool const sideways_possible = (controller().params().type == "figure"
172 || controller().params().type == "table");
174 bool const here_definitely = contains(placement, 'H');
176 bool const top = contains(placement, 't');
177 bool const bottom = contains(placement, 'b');
178 bool const page = contains(placement, 'p');
179 bool const here = contains(placement, 'h');
180 bool const force = contains(placement, '!');
181 bool const alternatives = top || bottom || page || (here && !wide);
184 placement_.set(dialog_->radio_alternatives);
185 } else if (here_definitely) {
186 placement_.set(dialog_->radio_here_definitely);
188 placement_.set(dialog_->radio_default);
190 fl_set_button(dialog_->check_force, force);
191 fl_set_button(dialog_->check_top, top);
192 fl_set_button(dialog_->check_bottom, bottom);
193 fl_set_button(dialog_->check_page, page);
194 fl_set_button(dialog_->check_here, here);
195 fl_set_button(dialog_->check_wide, wide);
196 fl_set_button(dialog_->check_sideways, sideways);
198 setEnabled(dialog_->radio_here_definitely, !wide && !sideways);
199 setEnabled(dialog_->check_force, alternatives && !sideways);
200 setEnabled(dialog_->check_top, alternatives && !sideways);
201 setEnabled(dialog_->check_bottom, alternatives && !sideways);
202 setEnabled(dialog_->check_page, alternatives && !sideways);
203 setEnabled(dialog_->check_here, alternatives && !wide && !sideways);
204 setEnabled(dialog_->check_wide, !sideways);
205 setEnabled(dialog_->radio_default, !sideways);
206 setEnabled(dialog_->radio_alternatives, !sideways);
207 setEnabled(dialog_->check_sideways, sideways_possible);
211 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
213 bool const alternatives = placement_.get() == ALTERNATIVES;
214 bool const wide = fl_get_button(dialog_->check_wide);
215 bool const sideways = fl_get_button(dialog_->check_sideways);
217 if (ob == dialog_->radio_default ||
218 ob == dialog_->radio_here_definitely ||
219 ob == dialog_->radio_alternatives) {
220 // enable check buttons only for Alternatives
221 setEnabled(dialog_->check_top, alternatives);
222 setEnabled(dialog_->check_page, alternatives);
223 // wide float doesn't allow 'here' or 'bottom' placement
224 setEnabled(dialog_->check_here, alternatives && !wide);
225 setEnabled(dialog_->check_bottom, alternatives && !wide);
227 } else if (ob == dialog_->check_wide) {
228 if (wide && placement_.get() == HERE_DEFINITELY) {
229 // wide float doesn't allow 'Here, definitely!'
231 placement_.set(dialog_->radio_default);
233 setEnabled(dialog_->check_here, alternatives && !wide);
234 setEnabled(dialog_->radio_here_definitely, !wide);
235 setEnabled(dialog_->check_bottom, alternatives && !wide);
237 } else if (ob == dialog_->check_sideways) {
238 setEnabled(dialog_->radio_default, !sideways);
239 setEnabled(dialog_->radio_alternatives, !sideways);
240 setEnabled(dialog_->radio_here_definitely, !wide && !sideways);
241 setEnabled(dialog_->check_top, alternatives && !sideways);
242 setEnabled(dialog_->check_bottom,
243 alternatives && !wide && !sideways);
244 setEnabled(dialog_->check_page, alternatives && !sideways);
245 setEnabled(dialog_->check_here, alternatives && !wide && !sideways);
246 setEnabled(dialog_->check_wide, !sideways);
249 // enable force button, if Alternatives is selected and at least
250 // one of its check buttons
251 bool const enable_force = alternatives && !sideways &&
252 (fl_get_button(dialog_->check_top) ||
253 fl_get_button(dialog_->check_bottom) ||
254 fl_get_button(dialog_->check_page) ||
255 (fl_get_button(dialog_->check_here) && !wide));
256 setEnabled(dialog_->check_force, enable_force);
258 return ButtonPolicy::SMI_VALID;
261 } // namespace frontend