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 #include "ControlMinipage.h"
15 #include "FormMinipage.h"
16 #include "forms/form_minipage.h"
17 #include "support/lstrings.h"
18 #include "support/tostr.h"
19 #include "helper_funcs.h"
21 #include "xforms_helpers.h"
22 #include "lyx_forms.h"
24 using namespace lyx::support;
26 typedef FormController<ControlMinipage, FormView<FD_minipage> > base_class;
28 FormMinipage::FormMinipage(Dialog & parent)
29 : base_class(parent, _("Minipage Settings"))
33 void FormMinipage::build()
35 dialog_.reset(build_minipage(this));
37 // Allow the base class to control messages
38 setMessageWidget(dialog_->text_warning);
40 fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
41 setPrehandler(dialog_->input_width);
43 string const choice = getStringFromVector(getLatexUnits(), "|");
44 fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str());
46 // Manage the ok, apply and cancel/close buttons
47 bcview().setOK(dialog_->button_ok);
48 bcview().setApply(dialog_->button_apply);
49 bcview().setCancel(dialog_->button_close);
50 bcview().setRestore(dialog_->button_restore);
52 bcview().addReadOnly(dialog_->input_width);
53 bcview().addReadOnly(dialog_->choice_width_units);
54 bcview().addReadOnly(dialog_->radio_top);
55 bcview().addReadOnly(dialog_->radio_middle);
56 bcview().addReadOnly(dialog_->radio_bottom);
60 void FormMinipage::apply()
62 controller().params().width =
63 LyXLength(getLengthFromWidgets(dialog_->input_width,
64 dialog_->choice_width_units));
66 if (fl_get_button(dialog_->radio_top))
67 controller().params().pos = InsetMinipage::top;
68 else if (fl_get_button(dialog_->radio_middle))
69 controller().params().pos = InsetMinipage::center;
71 controller().params().pos = InsetMinipage::bottom;
75 void FormMinipage::update()
77 LyXLength len(controller().params().width);
78 fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
79 fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
81 switch (controller().params().pos) {
82 case InsetMinipage::top:
83 fl_set_button(dialog_->radio_top, 1);
85 case InsetMinipage::center:
86 fl_set_button(dialog_->radio_middle, 1);
88 case InsetMinipage::bottom:
89 fl_set_button(dialog_->radio_bottom, 1);
95 ButtonPolicy::SMInput FormMinipage::input(FL_OBJECT * ob, long)
99 ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP;
101 if (ob == dialog_->radio_top ||
102 ob == dialog_->radio_middle ||
103 ob == dialog_->radio_bottom ||
104 ob == dialog_->choice_width_units)
105 return ButtonPolicy::SMI_VALID;
107 // disallow senseless data
108 // warnings if input is senseless
109 if (ob == dialog_->input_width) {
110 string const input = getString(dialog_->input_width);
111 bool const invalid = !isValidLength(input) && !isStrDbl(input);
113 postWarning(_("Invalid Length!"));
114 action = ButtonPolicy::SMI_INVALID;
116 action = ButtonPolicy::SMI_VALID;