]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormWrap.C
fix crash with "save as"
[lyx.git] / src / frontends / xforms / FormWrap.C
1 /**
2  * \file FormWrap.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Dekel Tsur
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 "ControlWrap.h"
19 #include "FormWrap.h"
20 #include "forms/form_wrap.h"
21 #include "Tooltips.h"
22
23 #include "support/lstrings.h"
24 #include "helper_funcs.h"
25 #include "xforms_helpers.h"
26 #include "checkedwidgets.h"
27
28 #include FORMS_H_LOCATION
29
30 typedef FormCB<ControlWrap, FormDB<FD_wrap> > base_class;
31
32 FormWrap::FormWrap()
33         : base_class(_("Wrap Options"))
34 {}
35
36
37 void FormWrap::build()
38 {
39         dialog_.reset(build_wrap(this));
40
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);
46
47         // disable for read-only documents
48         bc().addReadOnly(dialog_->input_width);
49         bc().addReadOnly(dialog_->choice_width_units);
50
51         // check validity of "length + unit" input
52         addCheckedGlueLength(bc(), dialog_->input_width);
53
54         // trigger an input event for cut&paste with middle mouse button.
55         setPrehandler(dialog_->input_width);
56
57         fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
58
59         string const choice = getStringFromVector(getLatexUnits(), "|");
60         fl_addto_choice(dialog_->choice_width_units,
61                         subst(choice, "%", "%%").c_str());
62
63         placement_.init(dialog_->radio_default, 0); // default
64         placement_.init(dialog_->radio_outer, 'p');
65         placement_.init(dialog_->radio_left,  'l');
66         placement_.init(dialog_->radio_right, 'r');
67
68         // set up the tooltips
69         string str = _("Enter width for the float.");
70         tooltips().init(dialog_->input_width, str);
71         str = _("Forces float to the right in a paragraph if the page number "
72                 "is odd, and to the left if page number is even.");
73         tooltips().init(dialog_->radio_default, str);
74         str = _("Forces float to the left in a paragraph if the pagenumber "
75                 "is odd, and to the right if page number is even.");
76         tooltips().init(dialog_->radio_outer, str);
77         str = _("Forces float to the left in the paragraph.");
78         tooltips().init(dialog_->radio_left, str);
79         str = _("Forces float to the right in the paragraph.");
80         tooltips().init(dialog_->radio_right, str);
81 }
82
83
84 void FormWrap::apply()
85 {
86         controller().params().pageWidth =
87                 LyXLength(getLengthFromWidgets(dialog_->input_width,
88                                                dialog_->choice_width_units));
89
90         char const c = static_cast<char>(placement_.get());
91         if (c)
92                 controller().params().placement = c;
93         else
94                 controller().params().placement.erase(); // default
95 }
96
97
98 void FormWrap::update()
99 {
100         LyXLength len(controller().params().pageWidth);
101         fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
102         fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
103
104         if (controller().params().placement.empty())
105                 placement_.set(dialog_->radio_default); // default
106         else
107                 placement_.set(controller().params().placement.c_str()[0]);
108 }