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 namespace lyx::support;
43 typedef FormController<ControlFloat, FormView<FD_float> > base_class;
45 FormFloat::FormFloat(Dialog & parent)
46 : base_class(parent, _("Float Settings"))
50 void FormFloat::build()
52 dialog_.reset(build_float(this));
54 // Manage the ok, apply and cancel/close buttons
55 bcview().setOK(dialog_->button_ok);
56 bcview().setApply(dialog_->button_apply);
57 bcview().setCancel(dialog_->button_close);
58 bcview().setRestore(dialog_->button_restore);
60 // disable for read-only documents
61 bcview().addReadOnly(dialog_->radio_default);
62 bcview().addReadOnly(dialog_->radio_here_definitely);
63 bcview().addReadOnly(dialog_->radio_alternatives);
64 bcview().addReadOnly(dialog_->check_top);
65 bcview().addReadOnly(dialog_->check_bottom);
66 bcview().addReadOnly(dialog_->check_page);
67 bcview().addReadOnly(dialog_->check_here);
68 bcview().addReadOnly(dialog_->check_force);
69 bcview().addReadOnly(dialog_->check_wide);
71 placement_.init(dialog_->radio_default, DOCUMENT_DEFAULTS);
72 placement_.init(dialog_->radio_here_definitely, HERE_DEFINITELY);
73 placement_.init(dialog_->radio_alternatives, ALTERNATIVES);
75 // set up the tooltips
76 string str = _("Use the document's default settings.");
77 tooltips().init(dialog_->radio_default, str);
78 str = _("Enforce placement of float here.");
79 tooltips().init(dialog_->radio_here_definitely, str);
80 str = _("Alternative suggestions for placement of float.");
81 tooltips().init(dialog_->radio_alternatives, str);
82 str = _("Try top of page.");
83 tooltips().init(dialog_->check_top, str);
84 str = _("Try bottom of page.");
85 tooltips().init(dialog_->check_bottom, str);
86 str = _("Put float on a separate page of floats.");
87 tooltips().init(dialog_->check_page, str);
88 str = _("Try float here.");
89 tooltips().init(dialog_->check_here, str);
90 str = _("Ignore internal settings. This is the \"!\" in LaTeX.");
91 tooltips().init(dialog_->check_force, str);
92 str = _("Span float over the columns.");
93 tooltips().init(dialog_->check_wide, str);
97 void FormFloat::apply()
99 bool const wide = fl_get_button(dialog_->check_wide);
102 switch (placement_.get()) {
104 if (fl_get_button(dialog_->check_force)) {
105 // Ignore internal LaTeX rules
108 if (fl_get_button(dialog_->check_top)) {
112 if (fl_get_button(dialog_->check_bottom)) {
116 if (fl_get_button(dialog_->check_page)) {
120 // ignore if wide is selected
121 if (!wide && fl_get_button(dialog_->check_here)) {
125 if (placement == "!") {
126 // ignore placement if only force is selected.
130 if (placement.length() == 0) {
131 // none of Alternatives is selected; flip to default
133 placement_.set(dialog_->radio_default);
134 setEnabled(dialog_->check_force, false);
135 setEnabled(dialog_->check_top, false);
136 setEnabled(dialog_->check_bottom, false);
137 setEnabled(dialog_->check_page, false);
138 setEnabled(dialog_->check_here, false);
142 case HERE_DEFINITELY:
146 case DOCUMENT_DEFAULTS:
147 // default, do nothing.
151 controller().params().placement = placement;
152 controller().params().wide = wide;
156 void FormFloat::update()
158 string placement(controller().params().placement);
159 bool const wide = controller().params().wide;
161 bool const here_definitely = contains(placement, "H");
163 bool const top = contains(placement, "t");
164 bool const bottom = contains(placement, "b");
165 bool const page = contains(placement, "p");
166 bool const here = contains(placement, "h");
167 bool const force = contains(placement, "!");
168 bool const alternatives = top || bottom || page || (here && !wide);
171 placement_.set(dialog_->radio_alternatives);
172 } else if (here_definitely) {
173 placement_.set(dialog_->radio_here_definitely);
175 placement_.set(dialog_->radio_default);
177 fl_set_button(dialog_->check_force, force);
178 fl_set_button(dialog_->check_top, top);
179 fl_set_button(dialog_->check_bottom, bottom);
180 fl_set_button(dialog_->check_page, page);
181 fl_set_button(dialog_->check_here, here);
182 fl_set_button(dialog_->check_wide, wide);
184 setEnabled(dialog_->radio_here_definitely, !wide);
185 setEnabled(dialog_->check_force, alternatives);
186 setEnabled(dialog_->check_top, alternatives);
187 setEnabled(dialog_->check_bottom, alternatives);
188 setEnabled(dialog_->check_page, alternatives);
189 setEnabled(dialog_->check_here, alternatives && !wide);
193 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
195 bool const alternatives = placement_.get() == ALTERNATIVES;
196 bool const wide = fl_get_button(dialog_->check_wide);
198 if (ob == dialog_->radio_default ||
199 ob == dialog_->radio_here_definitely ||
200 ob == dialog_->radio_alternatives) {
201 // enable check buttons only for Alternatives
202 setEnabled(dialog_->check_top, alternatives);
203 setEnabled(dialog_->check_bottom, alternatives);
204 setEnabled(dialog_->check_page, alternatives);
205 // wide float doesn't allow 'here' placement
206 setEnabled(dialog_->check_here, alternatives && !wide);
208 } else if (ob == dialog_->check_wide) {
209 if (wide && placement_.get() == HERE_DEFINITELY) {
210 // wide float doesn't allow 'Here, definitely!'
212 placement_.set(dialog_->radio_default);
214 setEnabled(dialog_->check_here, alternatives && !wide);
215 setEnabled(dialog_->radio_here_definitely, !wide);
218 // enable force button, if Alternatives is selected and at least
219 // one of its check buttons
220 bool const enable_force = alternatives &&
221 (fl_get_button(dialog_->check_top) ||
222 fl_get_button(dialog_->check_bottom) ||
223 fl_get_button(dialog_->check_page) ||
224 (fl_get_button(dialog_->check_here) && !wide));
225 setEnabled(dialog_->check_force, enable_force);
227 return ButtonPolicy::SMI_VALID;