]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormFloat.C
Strip out another 180 #includes.
[lyx.git] / src / frontends / xforms / FormFloat.C
1 /**
2  * \file FormFloat.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jürgen Spitzmüller
8  * \author Rob Lahaye
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "FormFloat.h"
16 #include "ControlFloat.h"
17 #include "forms/form_float.h"
18
19 #include "Tooltips.h"
20 #include "xforms_helpers.h"
21 #include "xformsBC.h"
22
23 #include "insets/insetfloat.h"
24
25 #include "support/lstrings.h"
26
27 #include "lyx_forms.h"
28
29 using namespace lyx::support;
30
31
32 namespace {
33
34 enum {
35         DOCUMENT_DEFAULTS,
36         HERE_DEFINITELY,
37         ALTERNATIVES
38 };
39
40 } // namespace anon
41
42
43 typedef FormController<ControlFloat, FormView<FD_float> > base_class;
44
45 FormFloat::FormFloat(Dialog & parent)
46         : base_class(parent, _("Float Settings"))
47 {}
48
49
50 void FormFloat::build()
51 {
52         dialog_.reset(build_float(this));
53
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);
59
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);
70
71         placement_.init(dialog_->radio_default,         DOCUMENT_DEFAULTS);
72         placement_.init(dialog_->radio_here_definitely, HERE_DEFINITELY);
73         placement_.init(dialog_->radio_alternatives,    ALTERNATIVES);
74
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);
94 }
95
96
97 void FormFloat::apply()
98 {
99         bool const wide = fl_get_button(dialog_->check_wide);
100
101         string placement;
102         switch (placement_.get()) {
103         case ALTERNATIVES:
104                 if (fl_get_button(dialog_->check_force)) {
105                         // Ignore internal LaTeX rules
106                         placement += '!';
107                 }
108                 if (fl_get_button(dialog_->check_top)) {
109                         // Top of page
110                         placement += 't';
111                 }
112                 if (fl_get_button(dialog_->check_bottom)) {
113                         // Bottom of page
114                         placement += 'b';
115                 }
116                 if (fl_get_button(dialog_->check_page)) {
117                         // Page of floats
118                         placement += 'p';
119                 }
120                 // ignore if wide is selected
121                 if (!wide && fl_get_button(dialog_->check_here)) {
122                         // Here, if possible
123                         placement += 'h';
124                 }
125                 if (placement == "!") {
126                         // ignore placement if only force is selected.
127                         placement.erase();
128                 }
129
130                 if (placement.length() == 0) {
131                         // none of Alternatives is selected; flip to default
132                         placement.erase();
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);
139                 }
140                 break;
141
142         case HERE_DEFINITELY:
143                 placement = "H";
144                 break;
145
146         case DOCUMENT_DEFAULTS:
147                 // default, do nothing.
148                 break;
149         }
150
151         controller().params().placement = placement;
152         controller().params().wide = wide;
153 }
154
155
156 void FormFloat::update()
157 {
158         string placement(controller().params().placement);
159         bool const wide = controller().params().wide;
160
161         bool const here_definitely = contains(placement, "H");
162
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);
169
170         if (alternatives) {
171                 placement_.set(dialog_->radio_alternatives);
172         } else if (here_definitely) {
173                 placement_.set(dialog_->radio_here_definitely);
174         } else {
175                 placement_.set(dialog_->radio_default);
176         }
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);
183
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);
190 }
191
192
193 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
194 {
195         bool const alternatives = placement_.get() == ALTERNATIVES;
196         bool const wide = fl_get_button(dialog_->check_wide);
197
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);
207
208         } else if (ob == dialog_->check_wide) {
209                 if (wide && placement_.get() == HERE_DEFINITELY) {
210                         // wide float doesn't allow 'Here, definitely!'
211                         // placement
212                         placement_.set(dialog_->radio_default);
213                 }
214                 setEnabled(dialog_->check_here, alternatives && !wide);
215                 setEnabled(dialog_->radio_here_definitely, !wide);
216         }
217
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);
226
227         return ButtonPolicy::SMI_VALID;
228 }