]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormWrap.C
Yet more dialog tweaking from Rob.
[lyx.git] / src / frontends / xforms / FormWrap.C
1 /**
2  * \file FormWrap.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Dekel Tsur
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "xformsBC.h"
18 #include "ControlWrap.h"
19 #include "FormWrap.h"
20 #include "forms/form_wrap.h"
21 #include "support/lstrings.h"
22 #include "helper_funcs.h"
23 #include "debug.h"
24 #include "xforms_helpers.h"
25 #include FORMS_H_LOCATION
26
27 typedef FormCB<ControlWrap, FormDB<FD_wrap> > base_class;
28
29 FormWrap::FormWrap()
30         : base_class(_("Wrap Options"))
31 {}
32
33
34 void FormWrap::build()
35 {
36         dialog_.reset(build_wrap(this));
37
38         // Allow the base class to control messages
39         setMessageWidget(dialog_->text_warning);
40
41         fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
42         setPrehandler(dialog_->input_width);
43
44         string const choice = getStringFromVector(getLatexUnits(), "|");
45         fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str());
46
47         // Manage the ok, apply and cancel/close buttons
48         bc().setOK(dialog_->button_ok);
49         bc().setApply(dialog_->button_apply);
50         bc().setCancel(dialog_->button_close);
51         bc().setRestore(dialog_->button_restore);
52
53         bc().addReadOnly(dialog_->input_width);
54         bc().addReadOnly(dialog_->choice_width_units);
55         bc().addReadOnly(dialog_->radio_left);
56         bc().addReadOnly(dialog_->radio_right);
57         bc().addReadOnly(dialog_->radio_inner);
58         bc().addReadOnly(dialog_->radio_default);
59 }
60
61
62 void FormWrap::apply()
63 {
64         controller().params().pageWidth =
65                 LyXLength(getLengthFromWidgets(dialog_->input_width,
66                                                dialog_->choice_width_units));
67
68         if (fl_get_button(dialog_->radio_left))
69                 controller().params().placement = "l";
70         else if (fl_get_button(dialog_->radio_right))
71                 controller().params().placement = "r";
72         else if (fl_get_button(dialog_->radio_inner))
73                 controller().params().placement = "p";
74         else
75                 controller().params().placement.erase();
76 }
77
78
79 void FormWrap::update()
80 {
81         LyXLength len(controller().params().pageWidth);
82         fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
83         fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
84
85         if (controller().params().placement == "l")
86                 fl_set_button(dialog_->radio_left, 1);
87         else if (controller().params().placement == "r")
88                 fl_set_button(dialog_->radio_right, 1);
89         else if (controller().params().placement == "p")
90                 fl_set_button(dialog_->radio_inner, 1);
91         else
92                 fl_set_button(dialog_->radio_default, 1);
93 }
94
95
96 ButtonPolicy::SMInput FormWrap::input(FL_OBJECT * ob, long)
97 {
98         clearMessage();
99
100         ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP;
101
102         if (ob == dialog_->radio_left ||
103             ob == dialog_->radio_right ||
104             ob == dialog_->radio_inner ||
105             ob == dialog_->radio_default ||
106             ob == dialog_->choice_width_units)
107                 return ButtonPolicy::SMI_VALID;
108
109         // disallow senseless data
110         // warnings if input is senseless
111         if (ob == dialog_->input_width) {
112                 string const input = getString(dialog_->input_width);
113                 bool const invalid = !isValidLength(input) && !isStrDbl(input);
114                 if (invalid) {
115                         postWarning(_("Invalid Length!"));
116                         action = ButtonPolicy::SMI_INVALID;
117                 } else {
118                         action = ButtonPolicy::SMI_VALID;
119                 }
120         }
121
122         return action;
123 }