]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormFloat.C
79cbf8a13a8b20132736e9ce587555e1e033a8b2
[features.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  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "xformsBC.h"
16 #include "ControlFloat.h"
17 #include "FormFloat.h"
18 #include "forms/form_float.h"
19 #include "support/lstrings.h"
20 #include "xforms_helpers.h"
21 #include FORMS_H_LOCATION
22
23 typedef FormCB<ControlFloat, FormDB<FD_float> > base_class;
24
25 FormFloat::FormFloat(ControlFloat & c, Dialogs & d)
26         : base_class(c, d, _("Float Options"))
27 {}
28
29
30 // FIX: Needs to be implemented. (Lgb)
31 // A way to set to float default is missing.
32 // A way to set "force[!]" is missing.
33
34 void FormFloat::build()
35 {
36         dialog_.reset(build_float(this));
37
38         // Manage the ok, apply and cancel/close buttons
39         bc().setOK(dialog_->button_ok);
40         bc().setApply(dialog_->button_apply);
41         bc().setCancel(dialog_->button_close);
42         bc().setRestore(dialog_->button_restore);
43
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_here_definitely);
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_top)) {
59                         placement += "t";
60                 }
61                 if (fl_get_button(dialog_->check_bottom)) {
62                         placement += "b";
63                 }
64                 if (fl_get_button(dialog_->check_page)) {
65                         placement += "p";
66                 }
67                 if (fl_get_button(dialog_->check_here)) {
68                         placement += "h";
69                 }
70         }
71         controller().params().placement = placement;
72 }
73
74
75 void FormFloat::update()
76 {
77         bool top = false;
78         bool bottom = false;
79         bool page = false;
80         bool here = false;
81         bool here_definitely = false;
82
83         string placement(controller().params().placement);
84
85         if (contains(placement, "H")) {
86                 here_definitely = true;
87         } else {
88                 if (contains(placement, "t")) {
89                         top = true;
90                 }
91                 if (contains(placement, "b")) {
92                         bottom = true;
93                 }
94                 if (contains(placement, "p")) {
95                         page = true;
96                 }
97                 if (contains(placement, "h")) {
98                         here = true;
99                 }
100         }
101         fl_set_button(dialog_->check_top, top);
102         fl_set_button(dialog_->check_bottom, bottom);
103         fl_set_button(dialog_->check_page, page);
104         fl_set_button(dialog_->check_here, here);
105         fl_set_button(dialog_->check_here_definitely, here_definitely);
106         setEnabled(dialog_->check_here_definitely, controller().params().allow_here_definitely);
107 }
108
109
110 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
111 {
112         if (ob == dialog_->check_here_definitely) {
113                 if (fl_get_button(dialog_->check_here_definitely)) {
114                         fl_set_button(dialog_->check_top,    false);
115                         fl_set_button(dialog_->check_bottom, false);
116                         fl_set_button(dialog_->check_page,   false);
117                         fl_set_button(dialog_->check_here,   false);
118                 }
119         } else {
120                 if (fl_get_button(dialog_->check_here_definitely)) {
121                         fl_set_button(dialog_->check_here_definitely, false);
122                 }
123         }
124
125         return ButtonPolicy::SMI_VALID;
126 }