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
17 #include "ControlFloat.h"
18 #include "FormFloat.h"
19 #include "forms/form_float.h"
21 #include "xforms_helpers.h"
22 #include "insets/insetfloat.h"
23 #include "support/lstrings.h"
24 #include FORMS_H_LOCATION
37 typedef FormController<ControlFloat, FormView<FD_float> > base_class;
39 FormFloat::FormFloat(Dialog & parent)
40 : base_class(parent, _("Float Options"))
44 void FormFloat::build()
46 dialog_.reset(build_float(this));
48 // Manage the ok, apply and cancel/close buttons
49 bc().setOK(dialog_->button_ok);
50 bc().setApply(dialog_->button_apply);
51 bc().setCancel(dialog_->button_close);
52 bc().setRestore(dialog_->button_restore);
54 // disable for read-only documents
55 bc().addReadOnly(dialog_->radio_default);
56 bc().addReadOnly(dialog_->radio_here_definitely);
57 bc().addReadOnly(dialog_->radio_alternatives);
58 bc().addReadOnly(dialog_->check_top);
59 bc().addReadOnly(dialog_->check_bottom);
60 bc().addReadOnly(dialog_->check_page);
61 bc().addReadOnly(dialog_->check_here);
62 bc().addReadOnly(dialog_->check_force);
63 bc().addReadOnly(dialog_->check_wide);
65 placement_.init(dialog_->radio_default, DOCUMENT_DEFAULTS);
66 placement_.init(dialog_->radio_here_definitely, HERE_DEFINITELY);
67 placement_.init(dialog_->radio_alternatives, ALTERNATIVES);
69 // set up the tooltips
70 string str = _("Use the document's default settings.");
71 tooltips().init(dialog_->radio_default, str);
72 str = _("Enforce placement of float here.");
73 tooltips().init(dialog_->radio_here_definitely, str);
74 str = _("Alternative suggestions for placement of float.");
75 tooltips().init(dialog_->radio_alternatives, str);
76 str = _("Try top of page.");
77 tooltips().init(dialog_->check_top, str);
78 str = _("Try bottom of page.");
79 tooltips().init(dialog_->check_bottom, str);
80 str = _("Put float on a separate page of floats.");
81 tooltips().init(dialog_->check_page, str);
82 str = _("Try float here.");
83 tooltips().init(dialog_->check_here, str);
84 str = _("Ignore internal settings. This is the \"!\" in LaTeX.");
85 tooltips().init(dialog_->check_force, str);
86 str = _("Span float over the columns.");
87 tooltips().init(dialog_->check_wide, str);
91 void FormFloat::apply()
93 bool const wide = fl_get_button(dialog_->check_wide);
96 switch (placement_.get()) {
98 if (fl_get_button(dialog_->check_force)) {
99 // Ignore internal LaTeX rules
102 if (fl_get_button(dialog_->check_top)) {
106 if (fl_get_button(dialog_->check_bottom)) {
110 if (fl_get_button(dialog_->check_page)) {
114 // ignore if wide is selected
115 if (!wide && fl_get_button(dialog_->check_here)) {
119 if (placement == "!") {
120 // ignore placement if only force is selected.
124 if (placement.length() == 0) {
125 // none of Alternatives is selected; flip to default
127 placement_.set(dialog_->radio_default);
128 setEnabled(dialog_->check_force, false);
129 setEnabled(dialog_->check_top, false);
130 setEnabled(dialog_->check_bottom, false);
131 setEnabled(dialog_->check_page, false);
132 setEnabled(dialog_->check_here, false);
136 case HERE_DEFINITELY:
140 case DOCUMENT_DEFAULTS:
141 // default, do nothing.
145 controller().params().placement = placement;
146 controller().params().wide = wide;
150 void FormFloat::update()
152 string placement(controller().params().placement);
153 bool const wide = controller().params().wide;
155 bool const here_definitely = contains(placement, "H");
157 bool const top = contains(placement, "t");
158 bool const bottom = contains(placement, "b");
159 bool const page = contains(placement, "p");
160 bool const here = contains(placement, "h");
161 bool const force = contains(placement, "!");
162 bool const alternatives = top || bottom || page || (here && !wide);
165 placement_.set(dialog_->radio_alternatives);
166 } else if (here_definitely) {
167 placement_.set(dialog_->radio_here_definitely);
169 placement_.set(dialog_->radio_default);
171 fl_set_button(dialog_->check_force, force);
172 fl_set_button(dialog_->check_top, top);
173 fl_set_button(dialog_->check_bottom, bottom);
174 fl_set_button(dialog_->check_page, page);
175 fl_set_button(dialog_->check_here, here);
176 fl_set_button(dialog_->check_wide, wide);
178 setEnabled(dialog_->radio_here_definitely, !wide);
179 setEnabled(dialog_->check_force, alternatives);
180 setEnabled(dialog_->check_top, alternatives);
181 setEnabled(dialog_->check_bottom, alternatives);
182 setEnabled(dialog_->check_page, alternatives);
183 setEnabled(dialog_->check_here, alternatives && !wide);
187 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
189 bool const alternatives = placement_.get() == ALTERNATIVES;
190 bool const wide = fl_get_button(dialog_->check_wide);
192 if (ob == dialog_->radio_default ||
193 ob == dialog_->radio_here_definitely ||
194 ob == dialog_->radio_alternatives) {
195 // enable check buttons only for Alternatives
196 setEnabled(dialog_->check_top, alternatives);
197 setEnabled(dialog_->check_bottom, alternatives);
198 setEnabled(dialog_->check_page, alternatives);
199 // wide float doesn't allow 'here' placement
200 setEnabled(dialog_->check_here, alternatives && !wide);
202 } else if (ob == dialog_->check_wide) {
203 if (wide && placement_.get() == HERE_DEFINITELY) {
204 // wide float doesn't allow 'Here, definitely!'
206 placement_.set(dialog_->radio_default);
208 setEnabled(dialog_->check_here, alternatives && !wide);
209 setEnabled(dialog_->radio_here_definitely, !wide);
212 // enable force button, if Alternatives is selected and at least
213 // one of its check buttons
214 bool const enable_force = alternatives &&
215 (fl_get_button(dialog_->check_top) ||
216 fl_get_button(dialog_->check_bottom) ||
217 fl_get_button(dialog_->check_page) ||
218 (fl_get_button(dialog_->check_here) && !wide));
219 setEnabled(dialog_->check_force, enable_force);
221 return ButtonPolicy::SMI_VALID;