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