3 * Read the file COPYING
5 * \author Alejandro Aguilar Sierra
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS
16 #pragma implementation
20 #include "ControlInclude.h"
21 #include "FormInclude.h"
22 #include "forms/form_include.h"
23 #include "insets/insetinclude.h"
24 #include "xforms_helpers.h" // setEnabled
25 #include "support/lstrings.h" // strip
26 #include FORMS_H_LOCATION
28 typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
30 FormInclude::FormInclude()
31 : base_class(_("Include file"))
35 void FormInclude::build()
37 dialog_.reset(build_include(this));
39 fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
40 setPrehandler(dialog_->input_filename);
42 // Manage the ok and cancel buttons
43 bc().setOK(dialog_->button_ok);
44 bc().setCancel(dialog_->button_close);
46 bc().addReadOnly(dialog_->button_browse);
47 bc().addReadOnly(dialog_->radio_verbatim);
48 bc().addReadOnly(dialog_->check_typeset);
49 bc().addReadOnly(dialog_->radio_useinput);
50 bc().addReadOnly(dialog_->radio_useinclude);
54 void FormInclude::update()
57 // I believe this is not needed.
58 // Anyway, it is plain wrong (JSpitzm 3/7/02)
59 if (controller().params().noload) {
60 fl_set_input(dialog_->input_filename, "");
61 fl_set_button(dialog_->check_typeset, 0);
62 fl_set_button(dialog_->radio_useinput, 0);
63 fl_set_button(dialog_->radio_useinclude, 1);
64 fl_set_button(dialog_->radio_verbatim, 0);
65 fl_set_button(dialog_->check_visiblespace, 0);
66 fl_deactivate_object(dialog_->check_visiblespace);
67 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
72 fl_set_input(dialog_->input_filename,
73 controller().params().cparams.getContents().c_str());
75 string const cmdname = controller().params().cparams.getCmdName();
77 fl_set_button(dialog_->check_typeset,
78 int(controller().params().noload));
80 if (cmdname == "input")
81 fl_set_button(dialog_->check_preview,
82 int(controller().params().cparams.preview()));
84 fl_set_button(dialog_->check_preview, 0);
86 setEnabled(dialog_->check_preview, (cmdname == "input"));
88 fl_set_button(dialog_->radio_useinput, cmdname == "input");
89 fl_set_button(dialog_->radio_useinclude, cmdname == "include");
90 if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
91 fl_set_button(dialog_->radio_verbatim, 1);
92 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
93 setEnabled(dialog_->check_visiblespace, true);
94 setEnabled(dialog_->button_load, false);
96 fl_set_button(dialog_->check_visiblespace, 0);
97 setEnabled(dialog_->check_visiblespace, false);
98 setEnabled(dialog_->button_load, true);
102 fl_set_button(dialog_->radio_useinclude, 1);
106 void FormInclude::apply()
108 controller().params().noload = fl_get_button(dialog_->check_typeset);
109 controller().params().cparams
110 .preview(fl_get_button(dialog_->check_preview));
112 string const file = fl_get_input(dialog_->input_filename);
113 if (controller().fileExists(file))
114 controller().params().cparams.setContents(file);
116 controller().params().cparams.setContents("");
118 if (fl_get_button(dialog_->radio_useinput))
119 controller().params().flag = InsetInclude::INPUT;
120 else if (fl_get_button(dialog_->radio_useinclude))
121 controller().params().flag = InsetInclude::INCLUDE;
122 else if (fl_get_button(dialog_->radio_verbatim)) {
123 if (fl_get_button(dialog_->check_visiblespace))
124 controller().params().flag = InsetInclude::VERBAST;
126 controller().params().flag = InsetInclude::VERB;
131 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
133 ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
135 if (ob == dialog_->button_browse) {
136 ControlInclude::Type type;
137 if (fl_get_button(dialog_->radio_useinput))
138 type = ControlInclude::INPUT;
139 else if (fl_get_button(dialog_->radio_verbatim))
140 type = ControlInclude::VERBATIM;
142 type = ControlInclude::INCLUDE;
144 string const in_name = fl_get_input(dialog_->input_filename);
145 fl_freeze_form(form());
146 string const out_name = controller().Browse(in_name, type);
147 fl_set_input(dialog_->input_filename, out_name.c_str());
148 fl_unfreeze_form(form());
150 } else if (ob == dialog_->button_load) {
151 string const in_name = fl_get_input(dialog_->input_filename);
152 if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
154 controller().OKButton();
155 controller().load(rtrim(in_name));
156 action = ButtonPolicy::SMI_NOOP;
159 } else if (ob == dialog_->radio_verbatim) {
160 setEnabled(dialog_->check_visiblespace, true);
161 setEnabled(dialog_->button_load, false);
163 } else if (ob == dialog_->radio_useinclude ||
164 ob == dialog_->radio_useinput) {
165 fl_set_button(dialog_->check_visiblespace, 0);
166 setEnabled(dialog_->check_visiblespace, false);
167 setEnabled(dialog_->button_load, true);
169 } else if (ob == dialog_->input_filename) {
170 string const in_name = fl_get_input(dialog_->input_filename);
171 if (rtrim(in_name).empty())
172 action = ButtonPolicy::SMI_INVALID;
175 if (ob == dialog_->radio_useinput) {
176 setEnabled(dialog_->check_preview, true);
177 } else if (ob == dialog_->radio_verbatim ||
178 ob == dialog_->radio_useinclude) {
179 fl_set_button(dialog_->check_preview, 0);
180 setEnabled(dialog_->check_preview, false);