3 * Copyright 2000-2001 The LyX Team.
4 * See the file COPYING.
6 * \author Jürgen Vigna, jug@sad.it
12 #pragma implementation
16 #include "ControlMinipage.h"
17 #include "FormMinipage.h"
18 #include "form_minipage.h"
19 #include "support/lstrings.h"
20 #include "helper_funcs.h"
22 #include "xforms_helpers.h"
24 typedef FormCB<ControlMinipage, FormDB<FD_form_minipage> > base_class;
26 FormMinipage::FormMinipage(ControlMinipage & c)
27 : base_class(c, _("Minipage Options"))
31 void FormMinipage::build()
33 dialog_.reset(build_minipage());
35 fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
36 setPrehandler(dialog_->input_width);
38 string const choice = getStringFromVector(getLatexUnits(), "|");
39 fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str());
41 // Manage the ok, apply and cancel/close buttons
42 bc().setOK(dialog_->button_ok);
43 bc().setApply(dialog_->button_apply);
44 bc().setCancel(dialog_->button_close);
45 bc().setRestore(dialog_->button_restore);
47 bc().addReadOnly(dialog_->input_width);
48 bc().addReadOnly(dialog_->choice_width_units);
49 bc().addReadOnly(dialog_->radio_top);
50 bc().addReadOnly(dialog_->radio_middle);
51 bc().addReadOnly(dialog_->radio_bottom);
55 void FormMinipage::apply()
57 controller().params().pageWidth =
58 LyXLength(getLengthFromWidgets(dialog_->input_width,
59 dialog_->choice_width_units));
61 if (fl_get_button(dialog_->radio_top))
62 controller().params().pos = InsetMinipage::top;
63 else if (fl_get_button(dialog_->radio_middle))
64 controller().params().pos = InsetMinipage::center;
66 controller().params().pos = InsetMinipage::bottom;
70 void FormMinipage::update()
72 LyXLength len(controller().params().pageWidth);
73 fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
74 fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
76 switch (controller().params().pos) {
77 case InsetMinipage::top:
78 fl_set_button(dialog_->radio_top, 1);
80 case InsetMinipage::center:
81 fl_set_button(dialog_->radio_middle, 1);
83 case InsetMinipage::bottom:
84 fl_set_button(dialog_->radio_bottom, 1);
89 ButtonPolicy::SMInput FormMinipage::input(FL_OBJECT * ob, long)
91 ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP;
93 if (ob == dialog_->radio_top ||
94 ob == dialog_->radio_middle ||
95 ob == dialog_->radio_bottom ||
96 ob == dialog_->choice_width_units)
97 return ButtonPolicy::SMI_VALID;
99 // disallow senseless data
100 // warnings if input is senseless
101 if (ob == dialog_->input_width) {
102 string const input = getStringFromInput(dialog_->input_width);
103 bool const invalid = !isValidLength(input) && !isStrDbl(input);
105 fl_set_object_label(dialog_->text_warning,
106 _("Warning: Invalid Length!"));
107 fl_show_object(dialog_->text_warning);
108 action = ButtonPolicy::SMI_INVALID;
110 fl_hide_object(dialog_->text_warning);
111 action = ButtonPolicy::SMI_VALID;