]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormInclude.C
* Baruch's GuiBC template.
[lyx.git] / src / frontends / xforms / FormInclude.C
1 /**
2  * \file FormInclude.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author John Levon, moz@compsoc.man.ac.uk
8  * \author Angus Leeming, a.leeming@.ac.uk
9  */
10
11 #include <config.h>
12 #include <algorithm>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "xformsBC.h"
19 #include "ControlInclude.h"
20 #include "FormInclude.h"
21 #include "form_include.h"
22 #include "insets/insetinclude.h"
23 #include "xforms_helpers.h" // setEnabled
24 #include "support/lstrings.h" // compare
25
26 typedef FormCB<ControlInclude, FormDB<FD_form_include> > base_class;
27
28 FormInclude::FormInclude(ControlInclude & c)
29         : base_class(c, _("Include file"))
30 {}
31
32
33 void FormInclude::build()
34 {
35         dialog_.reset(build_include());
36
37         // Manage the ok and cancel buttons
38         bc().setOK(dialog_->button_ok);
39         bc().setCancel(dialog_->button_cancel);
40         bc().refresh();
41
42         bc().addReadOnly(dialog_->button_browse);
43         bc().addReadOnly(dialog_->check_verbatim);
44         bc().addReadOnly(dialog_->check_typeset);
45         bc().addReadOnly(dialog_->check_useinput);
46         bc().addReadOnly(dialog_->check_useinclude);
47 }
48
49
50 void FormInclude::update()
51 {
52         if (controller().params().noload) {
53                 fl_set_input(dialog_->input_filename, "");
54                 fl_set_button(dialog_->check_typeset, 0);
55                 fl_set_button(dialog_->check_useinput, 0);
56                 fl_set_button(dialog_->check_useinclude, 1);
57                 fl_set_button(dialog_->check_verbatim, 0);
58                 fl_set_button(dialog_->check_visiblespace, 0);
59                 fl_deactivate_object(dialog_->check_visiblespace);
60                 fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
61                 return;
62         }
63
64         fl_set_input(dialog_->input_filename,
65                      controller().params().cparams.getContents().c_str());
66
67         string const cmdname = controller().params().cparams.getCmdName();
68
69         fl_set_button(dialog_->check_typeset,
70                       int(controller().params().noload));
71
72         fl_set_button(dialog_->check_useinput, cmdname == "input");
73         fl_set_button(dialog_->check_useinclude, cmdname == "include");
74         if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
75                 fl_set_button(dialog_->check_verbatim, 1);
76                 fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
77                 setEnabled(dialog_->check_visiblespace, true);
78         } else {
79                 fl_set_button(dialog_->check_visiblespace, 0);
80                 setEnabled(dialog_->check_visiblespace, false);
81         }
82  
83         if (cmdname.empty())
84                 fl_set_button(dialog_->check_useinclude, 1);
85 }
86
87
88 void FormInclude::apply()
89 {
90         controller().params().noload = fl_get_button(dialog_->check_typeset);
91
92         controller().params().cparams.
93                 setContents(fl_get_input(dialog_->input_filename));
94
95         if (fl_get_button(dialog_->check_useinput))
96                 controller().params().flag = InsetInclude::INPUT;
97         else if (fl_get_button(dialog_->check_useinclude))
98                 controller().params().flag = InsetInclude::INCLUDE;
99         else if (fl_get_button(dialog_->check_verbatim)) {
100                 if (fl_get_button(dialog_->check_visiblespace))
101                         controller().params().flag = InsetInclude::VERBAST;
102                 else
103                         controller().params().flag = InsetInclude::VERB;
104         }
105 }
106
107
108 ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
109 {
110         if (ob == dialog_->button_browse) {
111                 ControlInclude::Type type;
112                 if (fl_get_button(dialog_->check_useinput))
113                         type = ControlInclude::INPUT;
114                 else if (fl_get_button(dialog_->check_verbatim))
115                         type = ControlInclude::VERBATIM;
116                 else
117                         type = ControlInclude::INCLUDE;
118
119                 string const in_name  = fl_get_input(dialog_->input_filename);
120                 fl_freeze_form(form()); 
121                 string const out_name = controller().Browse(in_name, type);
122                 fl_set_input(dialog_->input_filename, out_name.c_str());
123                 fl_unfreeze_form(form()); 
124
125                 return ButtonPolicy::SMI_VALID;
126         }
127
128         if (ob == dialog_->button_load) {
129                 if (compare(fl_get_input(dialog_->input_filename),"")) {
130                         ApplyButton();
131                         return ButtonPolicy::SMI_NOOP;
132                 }
133         }
134
135         if (ob == dialog_->check_verbatim) {
136                 setEnabled(dialog_->check_visiblespace, true);
137
138         } else if (ob == dialog_->check_useinclude ||
139                    ob == dialog_->check_useinput) {
140                 fl_set_button(dialog_->check_visiblespace, 0);
141                 setEnabled(dialog_->check_visiblespace, false);
142         }
143         
144         return ButtonPolicy::SMI_VALID;
145 }