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 namespace lyx::support;
30 typedef FormController<ControlMinipage, FormView<FD_minipage> > base_class;
32 FormMinipage::FormMinipage(Dialog & parent)
33 : base_class(parent, _("Minipage Settings"))
37 void FormMinipage::build()
39 dialog_.reset(build_minipage(this));
41 // Allow the base class to control messages
42 setMessageWidget(dialog_->text_warning);
44 fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
45 setPrehandler(dialog_->input_width);
47 string const choice = getStringFromVector(getLatexUnits(), "|");
48 fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str());
50 // Manage the ok, apply and cancel/close buttons
51 bcview().setOK(dialog_->button_ok);
52 bcview().setApply(dialog_->button_apply);
53 bcview().setCancel(dialog_->button_close);
54 bcview().setRestore(dialog_->button_restore);
56 bcview().addReadOnly(dialog_->input_width);
57 bcview().addReadOnly(dialog_->choice_width_units);
58 bcview().addReadOnly(dialog_->radio_top);
59 bcview().addReadOnly(dialog_->radio_middle);
60 bcview().addReadOnly(dialog_->radio_bottom);
64 void FormMinipage::apply()
66 controller().params().width =
67 LyXLength(getLengthFromWidgets(dialog_->input_width,
68 dialog_->choice_width_units));
70 if (fl_get_button(dialog_->radio_top))
71 controller().params().pos = InsetMinipage::top;
72 else if (fl_get_button(dialog_->radio_middle))
73 controller().params().pos = InsetMinipage::center;
75 controller().params().pos = InsetMinipage::bottom;
79 void FormMinipage::update()
81 LyXLength len(controller().params().width);
82 fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
83 fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
85 switch (controller().params().pos) {
86 case InsetMinipage::top:
87 fl_set_button(dialog_->radio_top, 1);
89 case InsetMinipage::center:
90 fl_set_button(dialog_->radio_middle, 1);
92 case InsetMinipage::bottom:
93 fl_set_button(dialog_->radio_bottom, 1);
99 ButtonPolicy::SMInput FormMinipage::input(FL_OBJECT * ob, long)
103 ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP;
105 if (ob == dialog_->radio_top ||
106 ob == dialog_->radio_middle ||
107 ob == dialog_->radio_bottom ||
108 ob == dialog_->choice_width_units)
109 return ButtonPolicy::SMI_VALID;
111 // disallow senseless data
112 // warnings if input is senseless
113 if (ob == dialog_->input_width) {
114 string const input = getString(dialog_->input_width);
115 bool const invalid = !isValidLength(input) && !isStrDbl(input);
117 postWarning(_("Invalid Length!"));
118 action = ButtonPolicy::SMI_INVALID;
120 action = ButtonPolicy::SMI_VALID;