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"
29 using lyx::support::contains;
45 typedef FormController<ControlFloat, FormView<FD_float> > base_class;
47 FormFloat::FormFloat(Dialog & parent)
48 : base_class(parent, _("Float Settings"))
52 void FormFloat::build()
54 dialog_.reset(build_float(this));
56 // Manage the ok, apply and cancel/close buttons
57 bcview().setOK(dialog_->button_ok);
58 bcview().setApply(dialog_->button_apply);
59 bcview().setCancel(dialog_->button_close);
60 bcview().setRestore(dialog_->button_restore);
62 // disable for read-only documents
63 bcview().addReadOnly(dialog_->radio_default);
64 bcview().addReadOnly(dialog_->radio_here_definitely);
65 bcview().addReadOnly(dialog_->radio_alternatives);
66 bcview().addReadOnly(dialog_->check_top);
67 bcview().addReadOnly(dialog_->check_bottom);
68 bcview().addReadOnly(dialog_->check_page);
69 bcview().addReadOnly(dialog_->check_here);
70 bcview().addReadOnly(dialog_->check_force);
71 bcview().addReadOnly(dialog_->check_wide);
72 bcview().addReadOnly(dialog_->check_sideways);
74 placement_.init(dialog_->radio_default, DOCUMENT_DEFAULTS);
75 placement_.init(dialog_->radio_here_definitely, HERE_DEFINITELY);
76 placement_.init(dialog_->radio_alternatives, ALTERNATIVES);
78 // set up the tooltips
79 string str = _("Use the document's default settings.");
80 tooltips().init(dialog_->radio_default, str);
81 str = _("Enforce placement of float here.");
82 tooltips().init(dialog_->radio_here_definitely, str);
83 str = _("Alternative suggestions for placement of float.");
84 tooltips().init(dialog_->radio_alternatives, str);
85 str = _("Try top of page.");
86 tooltips().init(dialog_->check_top, str);
87 str = _("Try bottom of page.");
88 tooltips().init(dialog_->check_bottom, str);
89 str = _("Put float on a separate page of floats.");
90 tooltips().init(dialog_->check_page, str);
91 str = _("Try float here.");
92 tooltips().init(dialog_->check_here, str);
93 str = _("Ignore internal settings. This is the \"!\" in LaTeX.");
94 tooltips().init(dialog_->check_force, str);
95 str = _("Span float over the columns.");
96 tooltips().init(dialog_->check_wide, str);
97 str = _("Rotate the float sideways by 90 degs.");
98 tooltips().init(dialog_->check_sideways, str);
102 void FormFloat::apply()
104 bool const wide = fl_get_button(dialog_->check_wide);
105 bool const sideways = fl_get_button(dialog_->check_sideways);
108 switch (placement_.get()) {
110 if (fl_get_button(dialog_->check_force)) {
111 // Ignore internal LaTeX rules
114 if (fl_get_button(dialog_->check_top)) {
118 if (fl_get_button(dialog_->check_bottom)) {
122 if (fl_get_button(dialog_->check_page)) {
126 // ignore if wide is selected
127 if (!wide && fl_get_button(dialog_->check_here)) {
131 if (placement == "!") {
132 // ignore placement if only force is selected.
136 if (placement.length() == 0) {
137 // none of Alternatives is selected; flip to default
139 placement_.set(dialog_->radio_default);
140 setEnabled(dialog_->check_force, false);
141 setEnabled(dialog_->check_top, false);
142 setEnabled(dialog_->check_bottom, false);
143 setEnabled(dialog_->check_page, false);
144 setEnabled(dialog_->check_here, false);
148 case HERE_DEFINITELY:
152 case DOCUMENT_DEFAULTS:
153 // default, do nothing.
157 controller().params().placement = placement;
158 controller().params().wide = wide;
159 controller().params().sideways = sideways;
163 void FormFloat::update()
165 string placement(controller().params().placement);
166 bool const wide = controller().params().wide;
167 bool const sideways = controller().params().sideways;
168 bool const sideways_possible = (controller().params().type == "figure"
169 || controller().params().type == "table");
171 bool const here_definitely = contains(placement, 'H');
173 bool const top = contains(placement, 't');
174 bool const bottom = contains(placement, 'b');
175 bool const page = contains(placement, 'p');
176 bool const here = contains(placement, 'h');
177 bool const force = contains(placement, '!');
178 bool const alternatives = top || bottom || page || (here && !wide);
181 placement_.set(dialog_->radio_alternatives);
182 } else if (here_definitely) {
183 placement_.set(dialog_->radio_here_definitely);
185 placement_.set(dialog_->radio_default);
187 fl_set_button(dialog_->check_force, force);
188 fl_set_button(dialog_->check_top, top);
189 fl_set_button(dialog_->check_bottom, bottom);
190 fl_set_button(dialog_->check_page, page);
191 fl_set_button(dialog_->check_here, here);
192 fl_set_button(dialog_->check_wide, wide);
193 fl_set_button(dialog_->check_sideways, sideways);
195 setEnabled(dialog_->radio_here_definitely, !wide && !sideways);
196 setEnabled(dialog_->check_force, alternatives && !sideways);
197 setEnabled(dialog_->check_top, alternatives && !sideways);
198 setEnabled(dialog_->check_bottom, alternatives && !sideways);
199 setEnabled(dialog_->check_page, alternatives && !sideways);
200 setEnabled(dialog_->check_here, alternatives && !wide && !sideways);
201 setEnabled(dialog_->check_wide, !sideways);
202 setEnabled(dialog_->radio_default, !sideways);
203 setEnabled(dialog_->radio_alternatives, !sideways);
204 setEnabled(dialog_->check_sideways, sideways_possible);
208 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
210 bool const alternatives = placement_.get() == ALTERNATIVES;
211 bool const wide = fl_get_button(dialog_->check_wide);
212 bool const sideways = fl_get_button(dialog_->check_sideways);
214 if (ob == dialog_->radio_default ||
215 ob == dialog_->radio_here_definitely ||
216 ob == dialog_->radio_alternatives) {
217 // enable check buttons only for Alternatives
218 setEnabled(dialog_->check_top, alternatives);
219 setEnabled(dialog_->check_page, alternatives);
220 // wide float doesn't allow 'here' or 'bottom' placement
221 setEnabled(dialog_->check_here, alternatives && !wide);
222 setEnabled(dialog_->check_bottom, alternatives && !wide);
224 } else if (ob == dialog_->check_wide) {
225 if (wide && placement_.get() == HERE_DEFINITELY) {
226 // wide float doesn't allow 'Here, definitely!'
228 placement_.set(dialog_->radio_default);
230 setEnabled(dialog_->check_here, alternatives && !wide);
231 setEnabled(dialog_->radio_here_definitely, !wide);
232 setEnabled(dialog_->check_bottom, alternatives && !wide);
234 } else if (ob == dialog_->check_sideways) {
235 setEnabled(dialog_->radio_default, !sideways);
236 setEnabled(dialog_->radio_alternatives, !sideways);
237 setEnabled(dialog_->radio_here_definitely, !wide && !sideways);
238 setEnabled(dialog_->check_top, alternatives && !sideways);
239 setEnabled(dialog_->check_bottom,
240 alternatives && !wide && !sideways);
241 setEnabled(dialog_->check_page, alternatives && !sideways);
242 setEnabled(dialog_->check_here, alternatives && !wide && !sideways);
243 setEnabled(dialog_->check_wide, !sideways);
246 // enable force button, if Alternatives is selected and at least
247 // one of its check buttons
248 bool const enable_force = alternatives && !sideways &&
249 (fl_get_button(dialog_->check_top) ||
250 fl_get_button(dialog_->check_bottom) ||
251 fl_get_button(dialog_->check_page) ||
252 (fl_get_button(dialog_->check_here) && !wide));
253 setEnabled(dialog_->check_force, enable_force);
255 return ButtonPolicy::SMI_VALID;