]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormFloat.C
Move the float dialog to the new scheme.
[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
16 #include "xformsBC.h"
17 #include "ControlFloat.h"
18 #include "FormFloat.h"
19 #include "forms/form_float.h"
20 #include "Tooltips.h"
21 #include "xforms_helpers.h"
22 #include "support/lstrings.h"
23 #include FORMS_H_LOCATION
24
25 namespace {
26
27 enum {
28         DOCUMENT_DEFAULTS,
29         HERE_DEFINITELY,
30         ALTERNATIVES
31 };
32
33 } // namespace anon
34
35
36 typedef FormController<ControlFloat, FormView<FD_float> > base_class;
37
38 FormFloat::FormFloat(Dialog & parent)
39         : base_class(parent, _("Float Options"))
40 {}
41
42
43 void FormFloat::build()
44 {
45         dialog_.reset(build_float(this));
46
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);
52
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);
63
64         placement_.init(dialog_->radio_default,         DOCUMENT_DEFAULTS);
65         placement_.init(dialog_->radio_here_definitely, HERE_DEFINITELY);
66         placement_.init(dialog_->radio_alternatives,    ALTERNATIVES);
67
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);
87 }
88
89
90 void FormFloat::apply()
91 {
92         bool const wide = fl_get_button(dialog_->check_wide);
93
94         string placement;
95         switch (placement_.get()) {
96         case ALTERNATIVES:
97                 if (fl_get_button(dialog_->check_force)) {
98                         // Ignore internal LaTeX rules
99                         placement += '!';
100                 }
101                 if (fl_get_button(dialog_->check_top)) {
102                         // Top of page
103                         placement += 't';
104                 }
105                 if (fl_get_button(dialog_->check_bottom)) {
106                         // Bottom of page
107                         placement += 'b';
108                 }
109                 if (fl_get_button(dialog_->check_page)) {
110                         // Page of floats
111                         placement += 'p';
112                 }
113                 // ignore if wide is selected
114                 if (!wide && fl_get_button(dialog_->check_here)) {
115                         // Here, if possible
116                         placement += 'h';
117                 }
118                 if (placement == "!") {
119                         // ignore placement if only force is selected.
120                         placement.erase();
121                 }
122
123                 if (placement.length() == 0) {
124                         // none of Alternatives is selected; flip to default
125                         placement.erase();
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);
132                 }
133                 break;
134
135         case HERE_DEFINITELY:
136                 placement = "H";
137                 break;
138
139         case DOCUMENT_DEFAULTS:
140                 // default, do nothing.
141                 break;
142         }
143
144         controller().params().placement = placement;
145         controller().params().wide = wide;
146 }
147
148
149 void FormFloat::update()
150 {
151         string placement(controller().params().placement);
152         bool const wide = controller().params().wide;
153
154         bool const here_definitely = contains(placement, "H");
155
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);
162
163         if (alternatives) {
164                 placement_.set(dialog_->radio_alternatives);
165         } else if (here_definitely) {
166                 placement_.set(dialog_->radio_here_definitely);
167         } else {
168                 placement_.set(dialog_->radio_default);
169         }
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);
176
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);
183 }
184
185
186 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
187 {
188         bool const alternatives = placement_.get() == ALTERNATIVES;
189         bool const wide = fl_get_button(dialog_->check_wide);
190
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);
200
201         } else if (ob == dialog_->check_wide) {
202                 if (wide && placement_.get() == HERE_DEFINITELY) {
203                         // wide float doesn't allow 'Here, definitely!'
204                         // placement
205                         placement_.set(dialog_->radio_default);
206                 }
207                 setEnabled(dialog_->check_here, alternatives && !wide);
208                 setEnabled(dialog_->radio_here_definitely, !wide);
209         }
210
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);
219
220         return ButtonPolicy::SMI_VALID;
221 }