]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormFloat.C
Yet more dialog tweaking from Rob.
[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 Juergen Spitzmueller j.spitzmueller@gmx.de
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "xformsBC.h"
19 #include "ControlFloat.h"
20 #include "FormFloat.h"
21 #include "forms/form_float.h"
22 #include "support/lstrings.h"
23 #include "xforms_helpers.h"
24 #include FORMS_H_LOCATION
25
26 typedef FormCB<ControlFloat, FormDB<FD_float> > base_class;
27
28 FormFloat::FormFloat()
29         : base_class(_("Float Options"))
30 {}
31
32
33 void FormFloat::build()
34 {
35         dialog_.reset(build_float(this));
36
37         // Manage the ok, apply and cancel/close buttons
38         bc().setOK(dialog_->button_ok);
39         bc().setApply(dialog_->button_apply);
40         bc().setCancel(dialog_->button_close);
41         bc().setRestore(dialog_->button_restore);
42
43         bc().addReadOnly(dialog_->check_default);
44         bc().addReadOnly(dialog_->check_top);
45         bc().addReadOnly(dialog_->check_bottom);
46         bc().addReadOnly(dialog_->check_page);
47         bc().addReadOnly(dialog_->check_here);
48         bc().addReadOnly(dialog_->check_force);
49         bc().addReadOnly(dialog_->check_here_definitely);
50         bc().addReadOnly(dialog_->check_wide);
51 }
52
53
54 void FormFloat::apply()
55 {
56         string placement;
57         if (fl_get_button(dialog_->check_here_definitely)) {
58                 placement += "H";
59         } else {
60                 if (fl_get_button(dialog_->check_force)) {
61                         placement += "!";
62                 }
63                 if (fl_get_button(dialog_->check_here)) {
64                         placement += "h";
65                 }
66                 if (fl_get_button(dialog_->check_top)) {
67                         placement += "t";
68                 }
69                 if (fl_get_button(dialog_->check_bottom)) {
70                         placement += "b";
71                 }
72                 if (fl_get_button(dialog_->check_page)) {
73                         placement += "p";
74                 }
75
76         }
77         controller().params().placement = placement;
78         controller().params().wide = fl_get_button(dialog_->check_wide);
79 }
80
81
82 void FormFloat::update()
83 {
84         bool def_placement = false;
85         bool top = false;
86         bool bottom = false;
87         bool page = false;
88         bool here = false;
89         bool force = false;
90         bool here_definitely = false;
91
92         string placement(controller().params().placement);
93
94         if (placement.empty()) {
95                 def_placement = true;
96
97         } else if (contains(placement, "H")) {
98                 here_definitely = true;
99
100         } else {
101                 if (contains(placement, "!")) {
102                         force = true;
103                 }
104                 if (contains(placement, "t")) {
105                         top = true;
106                 }
107                 if (contains(placement, "b")) {
108                         bottom = true;
109                 }
110                 if (contains(placement, "p")) {
111                         page = true;
112                 }
113                 if (contains(placement, "h")) {
114                         here = true;
115                 }
116         }
117         fl_set_button(dialog_->check_default, def_placement);
118         fl_set_button(dialog_->check_top, top);
119         fl_set_button(dialog_->check_bottom, bottom);
120         fl_set_button(dialog_->check_page, page);
121         fl_set_button(dialog_->check_here, here);
122         fl_set_button(dialog_->check_force, force);
123         fl_set_button(dialog_->check_here_definitely, here_definitely);
124         setEnabled(dialog_->check_here_definitely, !controller().params().wide 
125                         && !def_placement);
126         if (controller().params().wide) {
127                         fl_set_button(dialog_->check_here, false);
128                         fl_set_button(dialog_->check_bottom, false);
129         }
130         setEnabled(dialog_->check_here, !controller().params().wide && !def_placement);
131         setEnabled(dialog_->check_bottom, !controller().params().wide && !def_placement);
132         fl_set_button(dialog_->check_wide, controller().params().wide);
133         setEnabled(dialog_->check_top, !def_placement);
134         setEnabled(dialog_->check_page, !def_placement);
135         setEnabled(dialog_->check_force, top || bottom || page || here);
136 }
137
138
139 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
140 {
141         bool const def_place = fl_get_button(dialog_->check_default);
142         bool const wide_float = fl_get_button(dialog_->check_wide);
143         // with wide floats, h[ere] is not allowed
144         // b[ottom] is allowed (only) for figure* in multicolumn, don't
145         // disallow it therefore
146         bool const wide_options = (fl_get_button(dialog_->check_top)
147                                         || fl_get_button(dialog_->check_bottom)
148                                         || fl_get_button(dialog_->check_page));
149         // The !-option is only allowed together with h, t, b, or p
150         // We have to take this into account
151         bool const standard_options = (wide_options || fl_get_button(dialog_->check_here));
152         
153         if (ob == dialog_->check_default) {
154                 if (def_place) {
155                         fl_set_button(dialog_->check_top, false);
156                         fl_set_button(dialog_->check_bottom,  false);
157                         fl_set_button(dialog_->check_page, false);
158                         fl_set_button(dialog_->check_here, false);
159                         fl_set_button(dialog_->check_force, false);
160                         fl_set_button(dialog_->check_here_definitely, false);
161                         }
162                 setEnabled(dialog_->check_top, !def_place);
163                 setEnabled(dialog_->check_bottom, !def_place);
164                 setEnabled(dialog_->check_page, !def_place);
165                 setEnabled(dialog_->check_here, !def_place && !wide_float);
166                 setEnabled(dialog_->check_force, !def_place && standard_options);
167                 setEnabled(dialog_->check_here_definitely, !def_place && !wide_float);
168
169         } else if (ob == dialog_->check_wide) {
170                 if (wide_float) {
171                         fl_set_button(dialog_->check_here_definitely, false);
172                         fl_set_button(dialog_->check_here, false);
173                         if (!wide_options) {
174                                 fl_set_button(dialog_->check_force, false);
175                                 setEnabled(dialog_->check_force, false);
176                         }
177                 }
178                 setEnabled(dialog_->check_here, !def_place && !wide_float);
179                 setEnabled(dialog_->check_force, !def_place && wide_options);
180                 setEnabled(dialog_->check_here_definitely, !def_place && !wide_float);
181
182         } else if (ob == dialog_->check_here_definitely) {
183                 if (fl_get_button(dialog_->check_here_definitely)) {
184                         fl_set_button(dialog_->check_top,    false);
185                         fl_set_button(dialog_->check_bottom, false);
186                         fl_set_button(dialog_->check_page,   false);
187                         fl_set_button(dialog_->check_here,   false);
188                         fl_set_button(dialog_->check_force,   false);
189                         setEnabled(dialog_->check_force, false);
190                 }
191
192         } else if (ob == dialog_->check_here || ob == dialog_->check_top
193                 || ob == dialog_->check_bottom || ob == dialog_->check_page) {
194                 if (!standard_options)
195                         fl_set_button(dialog_->check_force, false);
196                 else
197                         fl_set_button(dialog_->check_here_definitely, false);
198                 setEnabled(dialog_->check_force, standard_options);
199
200         }
201
202         return ButtonPolicy::SMI_VALID;
203 }