]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormFloat.C
remove defaults stuff, let Qt handle no toolbar
[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 "insets/insetfloat.h"
23 #include "support/lstrings.h"
24 #include FORMS_H_LOCATION
25
26 namespace {
27
28 enum {
29         DOCUMENT_DEFAULTS,
30         HERE_DEFINITELY,
31         ALTERNATIVES
32 };
33
34 } // namespace anon
35
36
37 typedef FormController<ControlFloat, FormView<FD_float> > base_class;
38
39 FormFloat::FormFloat(Dialog & parent)
40         : base_class(parent, _("Float Options"))
41 {}
42
43
44 void FormFloat::build()
45 {
46         dialog_.reset(build_float(this));
47
48         // Manage the ok, apply and cancel/close buttons
49         bcview().setOK(dialog_->button_ok);
50         bcview().setApply(dialog_->button_apply);
51         bcview().setCancel(dialog_->button_close);
52         bcview().setRestore(dialog_->button_restore);
53
54         // disable for read-only documents
55         bcview().addReadOnly(dialog_->radio_default);
56         bcview().addReadOnly(dialog_->radio_here_definitely);
57         bcview().addReadOnly(dialog_->radio_alternatives);
58         bcview().addReadOnly(dialog_->check_top);
59         bcview().addReadOnly(dialog_->check_bottom);
60         bcview().addReadOnly(dialog_->check_page);
61         bcview().addReadOnly(dialog_->check_here);
62         bcview().addReadOnly(dialog_->check_force);
63         bcview().addReadOnly(dialog_->check_wide);
64
65         placement_.init(dialog_->radio_default,         DOCUMENT_DEFAULTS);
66         placement_.init(dialog_->radio_here_definitely, HERE_DEFINITELY);
67         placement_.init(dialog_->radio_alternatives,    ALTERNATIVES);
68
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);
88 }
89
90
91 void FormFloat::apply()
92 {
93         bool const wide = fl_get_button(dialog_->check_wide);
94
95         string placement;
96         switch (placement_.get()) {
97         case ALTERNATIVES:
98                 if (fl_get_button(dialog_->check_force)) {
99                         // Ignore internal LaTeX rules
100                         placement += '!';
101                 }
102                 if (fl_get_button(dialog_->check_top)) {
103                         // Top of page
104                         placement += 't';
105                 }
106                 if (fl_get_button(dialog_->check_bottom)) {
107                         // Bottom of page
108                         placement += 'b';
109                 }
110                 if (fl_get_button(dialog_->check_page)) {
111                         // Page of floats
112                         placement += 'p';
113                 }
114                 // ignore if wide is selected
115                 if (!wide && fl_get_button(dialog_->check_here)) {
116                         // Here, if possible
117                         placement += 'h';
118                 }
119                 if (placement == "!") {
120                         // ignore placement if only force is selected.
121                         placement.erase();
122                 }
123
124                 if (placement.length() == 0) {
125                         // none of Alternatives is selected; flip to default
126                         placement.erase();
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);
133                 }
134                 break;
135
136         case HERE_DEFINITELY:
137                 placement = "H";
138                 break;
139
140         case DOCUMENT_DEFAULTS:
141                 // default, do nothing.
142                 break;
143         }
144
145         controller().params().placement = placement;
146         controller().params().wide = wide;
147 }
148
149
150 void FormFloat::update()
151 {
152         string placement(controller().params().placement);
153         bool const wide = controller().params().wide;
154
155         bool const here_definitely = contains(placement, "H");
156
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);
163
164         if (alternatives) {
165                 placement_.set(dialog_->radio_alternatives);
166         } else if (here_definitely) {
167                 placement_.set(dialog_->radio_here_definitely);
168         } else {
169                 placement_.set(dialog_->radio_default);
170         }
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);
177
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);
184 }
185
186
187 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
188 {
189         bool const alternatives = placement_.get() == ALTERNATIVES;
190         bool const wide = fl_get_button(dialog_->check_wide);
191
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);
201
202         } else if (ob == dialog_->check_wide) {
203                 if (wide && placement_.get() == HERE_DEFINITELY) {
204                         // wide float doesn't allow 'Here, definitely!'
205                         // placement
206                         placement_.set(dialog_->radio_default);
207                 }
208                 setEnabled(dialog_->check_here, alternatives && !wide);
209                 setEnabled(dialog_->radio_here_definitely, !wide);
210         }
211
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);
220
221         return ButtonPolicy::SMI_VALID;
222 }