]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMinipage.C
Really dull and boring header shit
[lyx.git] / src / frontends / xforms / FormMinipage.C
1 /**
2  * \file FormMinipage.C
3  * See the file COPYING.
4  *
5  * \author Jürgen Vigna
6  *
7  * Full author contact details are available in file CREDITS
8  */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "xformsBC.h"
17 #include "ControlMinipage.h"
18 #include "FormMinipage.h"
19 #include "forms/form_minipage.h"
20 #include "support/lstrings.h"
21 #include "helper_funcs.h"
22 #include "debug.h"
23 #include "xforms_helpers.h"
24 #include FORMS_H_LOCATION
25
26 typedef FormCB<ControlMinipage, FormDB<FD_minipage> > base_class;
27
28 FormMinipage::FormMinipage()
29         : base_class(_("Minipage Options"))
30 {}
31
32
33 void FormMinipage::build()
34 {
35         dialog_.reset(build_minipage(this));
36
37         // Allow the base class to control messages
38         setMessageWidget(dialog_->text_warning);
39
40         fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
41         setPrehandler(dialog_->input_width);
42
43         string const choice = getStringFromVector(getLatexUnits(), "|");
44         fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str());
45
46         // Manage the ok, apply and cancel/close buttons
47         bc().setOK(dialog_->button_ok);
48         bc().setApply(dialog_->button_apply);
49         bc().setCancel(dialog_->button_close);
50         bc().setRestore(dialog_->button_restore);
51
52         bc().addReadOnly(dialog_->input_width);
53         bc().addReadOnly(dialog_->choice_width_units);
54         bc().addReadOnly(dialog_->radio_top);
55         bc().addReadOnly(dialog_->radio_middle);
56         bc().addReadOnly(dialog_->radio_bottom);
57 }
58
59
60 void FormMinipage::apply()
61 {
62         controller().params().pageWidth =
63                 LyXLength(getLengthFromWidgets(dialog_->input_width,
64                                                dialog_->choice_width_units));
65
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;
70         else
71                 controller().params().pos = InsetMinipage::bottom;
72 }
73
74
75 void FormMinipage::update()
76 {
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);
80
81         switch (controller().params().pos) {
82         case InsetMinipage::top:
83                 fl_set_button(dialog_->radio_top, 1);
84                 break;
85         case InsetMinipage::center:
86                 fl_set_button(dialog_->radio_middle, 1);
87                 break;
88         case InsetMinipage::bottom:
89                 fl_set_button(dialog_->radio_bottom, 1);
90                 break;
91         }
92 }
93
94
95 ButtonPolicy::SMInput FormMinipage::input(FL_OBJECT * ob, long)
96 {
97         clearMessage();
98
99         ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP;
100
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;
106
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);
112                 if (invalid) {
113                         postWarning(_("Invalid Length!"));
114                         action = ButtonPolicy::SMI_INVALID;
115                 } else {
116                         action = ButtonPolicy::SMI_VALID;
117                 }
118         }
119
120         return action;
121 }