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