]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormFloat.C
simple ws changes only
[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 lyx::support::contains;
30
31 using std::string;
32
33
34 namespace {
35
36 enum {
37         DOCUMENT_DEFAULTS,
38         HERE_DEFINITELY,
39         ALTERNATIVES
40 };
41
42 } // namespace anon
43
44
45 typedef FormController<ControlFloat, FormView<FD_float> > base_class;
46
47 FormFloat::FormFloat(Dialog & parent)
48         : base_class(parent, _("Float Settings"))
49 {}
50
51
52 void FormFloat::build()
53 {
54         dialog_.reset(build_float(this));
55
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);
61
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);
73
74         placement_.init(dialog_->radio_default,         DOCUMENT_DEFAULTS);
75         placement_.init(dialog_->radio_here_definitely, HERE_DEFINITELY);
76         placement_.init(dialog_->radio_alternatives,    ALTERNATIVES);
77
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);
99 }
100
101
102 void FormFloat::apply()
103 {
104         bool const wide = fl_get_button(dialog_->check_wide);
105         bool const sideways = fl_get_button(dialog_->check_sideways);
106
107         string placement;
108         switch (placement_.get()) {
109         case ALTERNATIVES:
110                 if (fl_get_button(dialog_->check_force)) {
111                         // Ignore internal LaTeX rules
112                         placement += '!';
113                 }
114                 if (fl_get_button(dialog_->check_top)) {
115                         // Top of page
116                         placement += 't';
117                 }
118                 if (fl_get_button(dialog_->check_bottom)) {
119                         // Bottom of page
120                         placement += 'b';
121                 }
122                 if (fl_get_button(dialog_->check_page)) {
123                         // Page of floats
124                         placement += 'p';
125                 }
126                 // ignore if wide is selected
127                 if (!wide && fl_get_button(dialog_->check_here)) {
128                         // Here, if possible
129                         placement += 'h';
130                 }
131                 if (placement == "!") {
132                         // ignore placement if only force is selected.
133                         placement.erase();
134                 }
135
136                 if (placement.length() == 0) {
137                         // none of Alternatives is selected; flip to default
138                         placement.erase();
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);
145                 }
146                 break;
147
148         case HERE_DEFINITELY:
149                 placement = "H";
150                 break;
151
152         case DOCUMENT_DEFAULTS:
153                 // default, do nothing.
154                 break;
155         }
156
157         controller().params().placement = placement;
158         controller().params().wide = wide;
159         controller().params().sideways = sideways;
160 }
161
162
163 void FormFloat::update()
164 {
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");
170
171         bool const here_definitely = contains(placement, 'H');
172
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);
179
180         if (alternatives) {
181                 placement_.set(dialog_->radio_alternatives);
182         } else if (here_definitely) {
183                 placement_.set(dialog_->radio_here_definitely);
184         } else {
185                 placement_.set(dialog_->radio_default);
186         }
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);
194
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);
205 }
206
207
208 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
209 {
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);
213
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);
223
224         } else if (ob == dialog_->check_wide) {
225                 if (wide && placement_.get() == HERE_DEFINITELY) {
226                         // wide float doesn't allow 'Here, definitely!'
227                         // placement
228                         placement_.set(dialog_->radio_default);
229                 }
230                 setEnabled(dialog_->check_here, alternatives && !wide);
231                 setEnabled(dialog_->radio_here_definitely, !wide);
232                 setEnabled(dialog_->check_bottom, alternatives && !wide);
233
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);
244         }
245
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);
254
255         return ButtonPolicy::SMI_VALID;
256 }