]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormInclude.C
Really dull and boring header shit
[features.git] / src / frontends / xforms / FormInclude.C
1 /**
2  * \file FormInclude.C
3  * Read the file COPYING
4  *
5  * \author Alejandro Aguilar Sierra
6  * \author John Levon
7  * \author Angus Leeming 
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13 #include <algorithm>
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19 #include "xformsBC.h"
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
27
28 typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
29
30 FormInclude::FormInclude()
31         : base_class(_("Include file"))
32 {}
33
34
35 void FormInclude::build()
36 {
37         dialog_.reset(build_include(this));
38
39         fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
40         setPrehandler(dialog_->input_filename);
41
42         // Manage the ok and cancel buttons
43         bc().setOK(dialog_->button_ok);
44         bc().setCancel(dialog_->button_close);
45
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);
51 }
52
53
54 void FormInclude::update()
55 {
56         #if 0
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);
68                 return;
69         }
70         #endif
71
72         fl_set_input(dialog_->input_filename,
73                      controller().params().cparams.getContents().c_str());
74
75         string const cmdname = controller().params().cparams.getCmdName();
76
77         fl_set_button(dialog_->check_typeset,
78                       int(controller().params().noload));
79
80         if (cmdname == "input")
81                 fl_set_button(dialog_->check_preview,
82                               int(controller().params().cparams.preview()));
83         else
84                 fl_set_button(dialog_->check_preview, 0);
85
86         setEnabled(dialog_->check_preview, (cmdname == "input"));
87
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);
95         } else {
96                 fl_set_button(dialog_->check_visiblespace, 0);
97                 setEnabled(dialog_->check_visiblespace, false);
98                 setEnabled(dialog_->button_load, true);
99         }
100
101         if (cmdname.empty())
102                 fl_set_button(dialog_->radio_useinclude, 1);
103 }
104
105
106 void FormInclude::apply()
107 {
108         controller().params().noload = fl_get_button(dialog_->check_typeset);
109         controller().params().cparams
110                 .preview(fl_get_button(dialog_->check_preview));
111
112         string const file = fl_get_input(dialog_->input_filename);
113         if (controller().fileExists(file))
114                 controller().params().cparams.setContents(file);
115         else
116                 controller().params().cparams.setContents("");
117
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;
125                 else
126                         controller().params().flag = InsetInclude::VERB;
127         }
128 }
129
130
131 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
132 {
133         ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
134
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;
141                 else
142                         type = ControlInclude::INCLUDE;
143
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());
149
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)) {
153 //                      ApplyButton();
154                         controller().OKButton();
155                         controller().load(rtrim(in_name));
156                         action = ButtonPolicy::SMI_NOOP;
157                 }
158
159         } else if (ob == dialog_->radio_verbatim) {
160                 setEnabled(dialog_->check_visiblespace, true);
161                 setEnabled(dialog_->button_load, false);
162
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);
168
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;
173         }
174
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);
181         }
182
183         return action;
184 }