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.
13 #include "FormMinipage.h"
14 #include "ControlMinipage.h"
15 #include "forms/form_minipage.h"
17 #include "xforms_helpers.h"
20 #include "controllers/helper_funcs.h"
22 #include "support/lstrings.h"
23 #include "support/tostr.h"
25 #include "lyx_forms.h"
27 using lyx::support::getStringFromVector;
28 using lyx::support::isStrDbl;
29 using lyx::support::subst;
34 typedef FormController<ControlMinipage, FormView<FD_minipage> > base_class;
36 FormMinipage::FormMinipage(Dialog & parent)
37 : base_class(parent, _("Minipage Settings"))
41 void FormMinipage::build()
43 dialog_.reset(build_minipage(this));
45 // Allow the base class to control messages
46 setMessageWidget(dialog_->text_warning);
48 fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
49 setPrehandler(dialog_->input_width);
51 string const choice = getStringFromVector(getLatexUnits(), "|");
52 fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str());
54 // Manage the ok, apply and cancel/close buttons
55 bcview().setOK(dialog_->button_ok);
56 bcview().setApply(dialog_->button_apply);
57 bcview().setCancel(dialog_->button_close);
58 bcview().setRestore(dialog_->button_restore);
60 bcview().addReadOnly(dialog_->input_width);
61 bcview().addReadOnly(dialog_->choice_width_units);
62 bcview().addReadOnly(dialog_->radio_top);
63 bcview().addReadOnly(dialog_->radio_middle);
64 bcview().addReadOnly(dialog_->radio_bottom);
68 void FormMinipage::apply()
70 controller().params().width =
71 LyXLength(getLengthFromWidgets(dialog_->input_width,
72 dialog_->choice_width_units));
74 if (fl_get_button(dialog_->radio_top))
75 controller().params().pos = InsetMinipage::top;
76 else if (fl_get_button(dialog_->radio_middle))
77 controller().params().pos = InsetMinipage::center;
79 controller().params().pos = InsetMinipage::bottom;
83 void FormMinipage::update()
85 LyXLength len(controller().params().width);
86 fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
87 fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
89 switch (controller().params().pos) {
90 case InsetMinipage::top:
91 fl_set_button(dialog_->radio_top, 1);
93 case InsetMinipage::center:
94 fl_set_button(dialog_->radio_middle, 1);
96 case InsetMinipage::bottom:
97 fl_set_button(dialog_->radio_bottom, 1);
103 ButtonPolicy::SMInput FormMinipage::input(FL_OBJECT * ob, long)
107 ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP;
109 if (ob == dialog_->radio_top ||
110 ob == dialog_->radio_middle ||
111 ob == dialog_->radio_bottom ||
112 ob == dialog_->choice_width_units)
113 return ButtonPolicy::SMI_VALID;
115 // disallow senseless data
116 // warnings if input is senseless
117 if (ob == dialog_->input_width) {
118 string const input = getString(dialog_->input_width);
119 bool const invalid = !isValidLength(input) && !isStrDbl(input);
121 postWarning(_("Invalid Length!"));
122 action = ButtonPolicy::SMI_INVALID;
124 action = ButtonPolicy::SMI_VALID;