3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
18 #include "ControlWrap.h"
20 #include "forms/form_wrap.h"
21 #include "support/lstrings.h"
22 #include "helper_funcs.h"
24 #include "xforms_helpers.h"
25 #include FORMS_H_LOCATION
27 typedef FormCB<ControlWrap, FormDB<FD_wrap> > base_class;
30 : base_class(_("Wrap Options"))
34 void FormWrap::build()
36 dialog_.reset(build_wrap(this));
38 // Allow the base class to control messages
39 setMessageWidget(dialog_->text_warning);
41 fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
42 setPrehandler(dialog_->input_width);
44 string const choice = getStringFromVector(getLatexUnits(), "|");
45 fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str());
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);
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_outer);
58 bc().addReadOnly(dialog_->radio_default);
62 void FormWrap::apply()
64 controller().params().pageWidth =
65 LyXLength(getLengthFromWidgets(dialog_->input_width,
66 dialog_->choice_width_units));
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_outer))
73 controller().params().placement = "p";
75 controller().params().placement.erase();
79 void FormWrap::update()
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);
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_outer, 1);
92 fl_set_button(dialog_->radio_default, 1);
96 ButtonPolicy::SMInput FormWrap::input(FL_OBJECT * ob, long)
100 ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP;
102 if (ob == dialog_->radio_left ||
103 ob == dialog_->radio_right ||
104 ob == dialog_->radio_outer ||
105 ob == dialog_->radio_default ||
106 ob == dialog_->choice_width_units)
107 return ButtonPolicy::SMI_VALID;
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);
115 postWarning(_("Invalid Length!"));
116 action = ButtonPolicy::SMI_INVALID;
118 action = ButtonPolicy::SMI_VALID;