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