1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
10 * \file FormMinipage.C
11 * \author Jürgen Vigna, jug@sad.it
17 #pragma implementation
21 #include "ControlMinipage.h"
22 #include "FormMinipage.h"
23 #include "form_minipage.h"
24 #include "support/lstrings.h"
25 #include "helper_funcs.h"
27 #include "xforms_helpers.h"
29 typedef FormCB<ControlMinipage, FormDB<FD_form_minipage> > base_class;
31 FormMinipage::FormMinipage(ControlMinipage & c)
32 : base_class(c, _("Minipage Options"))
36 void FormMinipage::build()
38 dialog_.reset(build_minipage());
40 fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
42 string const choice = getStringFromVector(getLatexUnits(), "|");
43 fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str());
45 // Manage the ok, apply and cancel/close buttons
46 bc().setOK(dialog_->button_ok);
47 bc().setApply(dialog_->button_apply);
48 bc().setCancel(dialog_->button_cancel);
49 bc().setRestore(dialog_->button_restore);
51 bc().addReadOnly(dialog_->input_width);
52 bc().addReadOnly(dialog_->choice_width_units);
53 bc().addReadOnly(dialog_->group_alignment);
54 bc().addReadOnly(dialog_->radio_top);
55 bc().addReadOnly(dialog_->radio_middle);
56 bc().addReadOnly(dialog_->radio_bottom);
60 void FormMinipage::apply()
62 controller().params().pageWidth =
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().pageWidth);
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);
94 ButtonPolicy::SMInput FormMinipage::input(FL_OBJECT * ob, long)
96 ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP;
98 if (ob == dialog_->radio_top ||
99 ob == dialog_->radio_middle ||
100 ob == dialog_->radio_bottom ||
101 ob == dialog_->choice_width_units)
102 return ButtonPolicy::SMI_VALID;
104 // disallow senseless data
105 // warnings if input is senseless
106 if (ob == dialog_->input_width) {
107 string const input = getStringFromInput(dialog_->input_width);
108 bool const invalid = !isValidLength(input) && !isStrDbl(input);
110 fl_set_object_label(dialog_->text_warning,
111 _("Warning: Invalid Length!"));
112 fl_show_object(dialog_->text_warning);
113 action = ButtonPolicy::SMI_INVALID;
115 fl_hide_object(dialog_->text_warning);
116 action = ButtonPolicy::SMI_VALID;