]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormFloat.C
use exclicit temp var
[lyx.git] / src / frontends / xforms / FormFloat.C
1 /* This file is part of
2  * ====================================================== 
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2001 The LyX Team.
7  *
8  * ======================================================
9  *
10  * \file FormFloat.C
11  */
12
13 #include <config.h>
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19 #include "xformsBC.h"
20 #include "ControlFloat.h"
21 #include "FormFloat.h"
22 #include "form_float.h"
23 #include "support/lstrings.h"
24 #include "xforms_helpers.h"
25
26 typedef FormCB<ControlFloat, FormDB<FD_form_float> > base_class;
27
28 FormFloat::FormFloat(ControlFloat & c)
29         : base_class(c, _("Float Options"))
30 {}
31
32
33 // FIX: Needs to be implemented. (Lgb)
34 // A way to set to float default is missing.
35 // A way to set "force[!]" is missing.
36
37 void FormFloat::build()
38 {
39         dialog_.reset(build_float());
40
41         // Manage the ok, apply and cancel/close buttons
42         bc().setOK(dialog_->button_ok);
43         bc().setApply(dialog_->button_apply);
44         bc().setCancel(dialog_->button_cancel);
45         bc().setRestore(dialog_->button_restore);
46
47         bc().addReadOnly(dialog_->radio_top);
48         bc().addReadOnly(dialog_->radio_bottom);
49         bc().addReadOnly(dialog_->radio_page);
50         bc().addReadOnly(dialog_->radio_here);
51         bc().addReadOnly(dialog_->button_here_definitely);
52 }
53
54
55 void FormFloat::apply()
56 {
57         string placement;
58         if (fl_get_button(dialog_->button_here_definitely)) {
59                 placement += "H";
60         } else {
61                 if (fl_get_button(dialog_->radio_top)) {
62                         placement += "t";
63                 }
64                 if (fl_get_button(dialog_->radio_bottom)) {
65                         placement += "b";
66                 }
67                 if (fl_get_button(dialog_->radio_page)) {
68                         placement += "p";
69                 }
70                 if (fl_get_button(dialog_->radio_here)) {
71                         placement += "h";
72                 }
73         }
74         controller().params().placement = placement;
75 }
76
77
78 void FormFloat::update()
79 {
80         bool top = false;
81         bool bottom = false;
82         bool page = false;
83         bool here = false;
84         bool here_definitely = false;
85
86         string placement(controller().params().placement);
87         
88         if (contains(placement, "H")) {
89                 here_definitely = true;
90         } else {
91                 if (contains(placement, "t")) {
92                         top = true;
93                 }
94                 if (contains(placement, "b")) {
95                         bottom = true;
96                 }
97                 if (contains(placement, "p")) {
98                         page = true;
99                 }
100                 if (contains(placement, "h")) {
101                         here = true;
102                 }
103         }
104         fl_set_button(dialog_->radio_top, top);
105         fl_set_button(dialog_->radio_bottom, bottom);
106         fl_set_button(dialog_->radio_page, page);
107         fl_set_button(dialog_->radio_here, here);
108         fl_set_button(dialog_->button_here_definitely, here_definitely);
109         setEnabled(dialog_->button_here_definitely, controller().params().allow_here_definitely);
110 }
111
112
113 ButtonPolicy::SMInput FormFloat::input(FL_OBJECT * ob, long)
114 {
115         if (ob == dialog_->button_here_definitely) {
116                 if (fl_get_button(dialog_->button_here_definitely)) {
117                         fl_set_button(dialog_->radio_top,    false);
118                         fl_set_button(dialog_->radio_bottom, false);
119                         fl_set_button(dialog_->radio_page,   false);
120                         fl_set_button(dialog_->radio_here,   false);
121                 }
122         } else {
123                 if (fl_get_button(dialog_->button_here_definitely)) {
124                         fl_set_button(dialog_->button_here_definitely, false);
125                 }
126         }
127
128         return ButtonPolicy::SMI_VALID;
129 }