]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormFloat.C
handle Wide attribute of floats in their dialog (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  */
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         bc().addReadOnly(dialog_->check_wide);
50 }
51
52
53 void FormFloat::apply()
54 {
55         string placement;
56         if (fl_get_button(dialog_->check_here_definitely)) {
57                 placement += "H";
58         } else {
59                 if (fl_get_button(dialog_->check_top)) {
60                         placement += "t";
61                 }
62                 if (fl_get_button(dialog_->check_bottom)) {
63                         placement += "b";
64                 }
65                 if (fl_get_button(dialog_->check_page)) {
66                         placement += "p";
67                 }
68                 if (fl_get_button(dialog_->check_here)) {
69                         placement += "h";
70                 }
71         }
72         controller().params().placement = placement;
73         controller().params().wide = fl_get_button(dialog_->check_wide);
74 }
75
76
77 void FormFloat::update()
78 {
79         bool top = false;
80         bool bottom = false;
81         bool page = false;
82         bool here = false;
83         bool here_definitely = false;
84
85         string placement(controller().params().placement);
86
87         if (contains(placement, "H")) {
88                 here_definitely = true;
89         } else {
90                 if (contains(placement, "t")) {
91                         top = true;
92                 }
93                 if (contains(placement, "b")) {
94                         bottom = true;
95                 }
96                 if (contains(placement, "p")) {
97                         page = true;
98                 }
99                 if (contains(placement, "h")) {
100                         here = true;
101                 }
102         }
103         fl_set_button(dialog_->check_top, top);
104         fl_set_button(dialog_->check_bottom, bottom);
105         fl_set_button(dialog_->check_page, page);
106         fl_set_button(dialog_->check_here, here);
107         fl_set_button(dialog_->check_here_definitely, here_definitely);
108         setEnabled(dialog_->check_here_definitely, !controller().params().wide);
109         fl_set_button(dialog_->check_wide, controller().params().wide);
110 }
111
112
113 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
114 {
115         if (ob == dialog_->check_here_definitely) {
116                 if (fl_get_button(dialog_->check_here_definitely)) {
117                         fl_set_button(dialog_->check_top,    false);
118                         fl_set_button(dialog_->check_bottom, false);
119                         fl_set_button(dialog_->check_page,   false);
120                         fl_set_button(dialog_->check_here,   false);
121                 }
122         } else {
123                 if (fl_get_button(dialog_->check_here_definitely)) {
124                         fl_set_button(dialog_->check_here_definitely, false);
125                 }
126         }
127         if (ob == dialog_->check_wide) {
128                 if (fl_get_button(dialog_->check_wide)) {
129                         fl_set_button(dialog_->check_here_definitely, false);
130                         setEnabled(dialog_->check_here_definitely, false);
131                 }
132                 else
133                         setEnabled(dialog_->check_here_definitely, true);
134         }
135
136         return ButtonPolicy::SMI_VALID;
137 }