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 "support/lstrings.h"
23 #include FORMS_H_LOCATION
36 typedef FormController<ControlFloat, FormView<FD_float> > base_class;
38 FormFloat::FormFloat(Dialog & parent)
39 : base_class(parent, _("Float Options"))
43 void FormFloat::build()
45 dialog_.reset(build_float(this));
47 // Manage the ok, apply and cancel/close buttons
48 bc().setOK(dialog_->button_ok);
49 bc().setApply(dialog_->button_apply);
50 bc().setCancel(dialog_->button_close);
51 bc().setRestore(dialog_->button_restore);
53 // disable for read-only documents
54 bc().addReadOnly(dialog_->radio_default);
55 bc().addReadOnly(dialog_->radio_here_definitely);
56 bc().addReadOnly(dialog_->radio_alternatives);
57 bc().addReadOnly(dialog_->check_top);
58 bc().addReadOnly(dialog_->check_bottom);
59 bc().addReadOnly(dialog_->check_page);
60 bc().addReadOnly(dialog_->check_here);
61 bc().addReadOnly(dialog_->check_force);
62 bc().addReadOnly(dialog_->check_wide);
64 placement_.init(dialog_->radio_default, DOCUMENT_DEFAULTS);
65 placement_.init(dialog_->radio_here_definitely, HERE_DEFINITELY);
66 placement_.init(dialog_->radio_alternatives, ALTERNATIVES);
68 // set up the tooltips
69 string str = _("Use the document's default settings.");
70 tooltips().init(dialog_->radio_default, str);
71 str = _("Enforce placement of float here.");
72 tooltips().init(dialog_->radio_here_definitely, str);
73 str = _("Alternative suggestions for placement of float.");
74 tooltips().init(dialog_->radio_alternatives, str);
75 str = _("Try top of page.");
76 tooltips().init(dialog_->check_top, str);
77 str = _("Try bottom of page.");
78 tooltips().init(dialog_->check_bottom, str);
79 str = _("Put float on a separate page of floats.");
80 tooltips().init(dialog_->check_page, str);
81 str = _("Try float here.");
82 tooltips().init(dialog_->check_here, str);
83 str = _("Ignore internal settings. This is the \"!\" in LaTeX.");
84 tooltips().init(dialog_->check_force, str);
85 str = _("Span float over the columns.");
86 tooltips().init(dialog_->check_wide, str);
90 void FormFloat::apply()
92 bool const wide = fl_get_button(dialog_->check_wide);
95 switch (placement_.get()) {
97 if (fl_get_button(dialog_->check_force)) {
98 // Ignore internal LaTeX rules
101 if (fl_get_button(dialog_->check_top)) {
105 if (fl_get_button(dialog_->check_bottom)) {
109 if (fl_get_button(dialog_->check_page)) {
113 // ignore if wide is selected
114 if (!wide && fl_get_button(dialog_->check_here)) {
118 if (placement == "!") {
119 // ignore placement if only force is selected.
123 if (placement.length() == 0) {
124 // none of Alternatives is selected; flip to default
126 placement_.set(dialog_->radio_default);
127 setEnabled(dialog_->check_force, false);
128 setEnabled(dialog_->check_top, false);
129 setEnabled(dialog_->check_bottom, false);
130 setEnabled(dialog_->check_page, false);
131 setEnabled(dialog_->check_here, false);
135 case HERE_DEFINITELY:
139 case DOCUMENT_DEFAULTS:
140 // default, do nothing.
144 controller().params().placement = placement;
145 controller().params().wide = wide;
149 void FormFloat::update()
151 string placement(controller().params().placement);
152 bool const wide = controller().params().wide;
154 bool const here_definitely = contains(placement, "H");
156 bool const top = contains(placement, "t");
157 bool const bottom = contains(placement, "b");
158 bool const page = contains(placement, "p");
159 bool const here = contains(placement, "h");
160 bool const force = contains(placement, "!");
161 bool const alternatives = top || bottom || page || (here && !wide);
164 placement_.set(dialog_->radio_alternatives);
165 } else if (here_definitely) {
166 placement_.set(dialog_->radio_here_definitely);
168 placement_.set(dialog_->radio_default);
170 fl_set_button(dialog_->check_force, force);
171 fl_set_button(dialog_->check_top, top);
172 fl_set_button(dialog_->check_bottom, bottom);
173 fl_set_button(dialog_->check_page, page);
174 fl_set_button(dialog_->check_here, here);
175 fl_set_button(dialog_->check_wide, wide);
177 setEnabled(dialog_->radio_here_definitely, !wide);
178 setEnabled(dialog_->check_force, alternatives);
179 setEnabled(dialog_->check_top, alternatives);
180 setEnabled(dialog_->check_bottom, alternatives);
181 setEnabled(dialog_->check_page, alternatives);
182 setEnabled(dialog_->check_here, alternatives && !wide);
186 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
188 bool const alternatives = placement_.get() == ALTERNATIVES;
189 bool const wide = fl_get_button(dialog_->check_wide);
191 if (ob == dialog_->radio_default ||
192 ob == dialog_->radio_here_definitely ||
193 ob == dialog_->radio_alternatives) {
194 // enable check buttons only for Alternatives
195 setEnabled(dialog_->check_top, alternatives);
196 setEnabled(dialog_->check_bottom, alternatives);
197 setEnabled(dialog_->check_page, alternatives);
198 // wide float doesn't allow 'here' placement
199 setEnabled(dialog_->check_here, alternatives && !wide);
201 } else if (ob == dialog_->check_wide) {
202 if (wide && placement_.get() == HERE_DEFINITELY) {
203 // wide float doesn't allow 'Here, definitely!'
205 placement_.set(dialog_->radio_default);
207 setEnabled(dialog_->check_here, alternatives && !wide);
208 setEnabled(dialog_->radio_here_definitely, !wide);
211 // enable force button, if Alternatives is selected and at least
212 // one of its check buttons
213 bool const enable_force = alternatives &&
214 (fl_get_button(dialog_->check_top) ||
215 fl_get_button(dialog_->check_bottom) ||
216 fl_get_button(dialog_->check_page) ||
217 (fl_get_button(dialog_->check_here) && !wide));
218 setEnabled(dialog_->check_force, enable_force);
220 return ButtonPolicy::SMI_VALID;