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