3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS
16 #include "ControlExternal.h"
17 #include "FormExternal.h"
18 #include "forms/form_external.h"
20 #include "helper_funcs.h"
21 #include "input_validators.h"
23 #include "xforms_helpers.h"
27 #include "insets/ExternalTemplate.h"
29 #include "support/tostr.h"
30 #include "support/lstrings.h"
31 #include "lyx_forms.h"
33 using namespace lyx::support;
35 typedef FormController<ControlExternal, FormView<FD_external> > base_class;
37 FormExternal::FormExternal(Dialog & parent)
38 : base_class(parent, _("External Material"))
42 void FormExternal::apply()
44 InsetExternal::Params params = controller().params();
46 params.filename = fl_get_input(dialog_->input_filename);
48 int const choice = fl_get_choice(dialog_->choice_template) - 1;
49 params.templatename = controller().getTemplate(choice).lyxName;
51 params.lyxscale = strToInt(getString(dialog_->input_lyxscale));
52 if (params.lyxscale == 0)
53 params.lyxscale = 100;
55 switch (fl_get_choice(dialog_->choice_display)) {
57 params.display = grfx::NoDisplay;
60 params.display = grfx::ColorDisplay;
63 params.display = grfx::GrayscaleDisplay;
66 params.display = grfx::MonochromeDisplay;
69 params.display = grfx::DefaultDisplay;
72 controller().setParams(params);
76 void FormExternal::build()
78 dialog_.reset(build_external(this));
81 ' ' + getStringFromVector(controller().getTemplates(), " | ") + ' ';
82 fl_addto_choice(dialog_->choice_template, choice.c_str());
84 fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
86 // Disable for read-only documents.
87 bcview().addReadOnly(dialog_->input_filename);
88 bcview().addReadOnly(dialog_->button_browse);
90 // Trigger an input event for cut&paste with middle mouse button.
91 setPrehandler(dialog_->input_filename);
93 // Activate ok/apply immediately upon input.
94 fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
95 fl_set_input_return(dialog_->input_lyxscale, FL_RETURN_CHANGED);
97 fl_set_input_filter(dialog_->input_lyxscale, fl_unsigned_int_filter);
99 string const display_List =
100 _("Default|Monochrome|Grayscale|Color|Do not display");
101 fl_addto_choice(dialog_->choice_display, display_List.c_str());
103 // Set up the tooltips.
104 string str = _("The file you want to insert.");
105 tooltips().init(dialog_->input_filename, str);
106 str = _("Browse the directories.");
107 tooltips().init(dialog_->button_browse, str);
109 str = _("Scale the image to inserted percentage value.");
110 tooltips().init(dialog_->input_lyxscale, str);
111 str = _("Select display mode for this image.");
112 tooltips().init(dialog_->choice_display, str);
114 // Manage the ok, apply and cancel/close buttons
115 bcview().setOK(dialog_->button_ok);
116 bcview().setApply(dialog_->button_apply);
117 bcview().setCancel(dialog_->button_close);
121 void FormExternal::update()
123 InsetExternal::Params const & params = controller().params();
125 fl_set_input(dialog_->input_filename, params.filename.c_str());
127 int ID = controller().getTemplateNumber(params.templatename);
129 fl_set_choice(dialog_->choice_template, ID+1);
133 fl_set_input(dialog_->input_lyxscale, tostr(params.lyxscale).c_str());
135 switch (params.display) {
136 case grfx::NoDisplay:
137 fl_set_choice(dialog_->choice_display, 5);
139 case grfx::ColorDisplay:
140 fl_set_choice(dialog_->choice_display, 4);
142 case grfx::GrayscaleDisplay:
143 fl_set_choice(dialog_->choice_display, 3);
145 case grfx::MonochromeDisplay:
146 fl_set_choice(dialog_->choice_display, 2);
148 case grfx::DefaultDisplay:
149 fl_set_choice(dialog_->choice_display, 1);
154 ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
156 ButtonPolicy::SMInput result = ButtonPolicy::SMI_VALID;
157 if (ob == dialog_->choice_template) {
159 // set to the chosen template
162 } else if (ob == dialog_->button_browse) {
164 string const in_name = fl_get_input(dialog_->input_filename);
165 string const out_name = controller().Browse(in_name);
166 fl_set_input(dialog_->input_filename, out_name.c_str());
168 } else if (ob == dialog_->button_edit) {
169 controller().editExternal();
170 result = ButtonPolicy::SMI_NOOP;
177 void FormExternal::updateComboChange()
179 int const choice = fl_get_choice(dialog_->choice_template) - 1;
180 ExternalTemplate templ = controller().getTemplate(choice);
182 // Update the help text
183 fl_clear_browser(dialog_->browser_helptext);
184 fl_addto_browser(dialog_->browser_helptext, templ.helpText.c_str());
185 fl_set_browser_topline(dialog_->browser_helptext, 0);