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 namespace grfx = lyx::graphics;
37 typedef FormController<ControlExternal, FormView<FD_external> > base_class;
39 FormExternal::FormExternal(Dialog & parent)
40 : base_class(parent, _("External Material"))
44 void FormExternal::apply()
46 InsetExternal::Params params = controller().params();
48 params.filename = fl_get_input(dialog_->input_filename);
50 int const choice = fl_get_choice(dialog_->choice_template) - 1;
51 params.templatename = controller().getTemplate(choice).lyxName;
53 params.lyxscale = strToInt(getString(dialog_->input_lyxscale));
54 if (params.lyxscale == 0)
55 params.lyxscale = 100;
57 switch (fl_get_choice(dialog_->choice_display)) {
59 params.display = grfx::NoDisplay;
62 params.display = grfx::ColorDisplay;
65 params.display = grfx::GrayscaleDisplay;
68 params.display = grfx::MonochromeDisplay;
71 params.display = grfx::DefaultDisplay;
74 controller().setParams(params);
78 void FormExternal::build()
80 dialog_.reset(build_external(this));
83 ' ' + getStringFromVector(controller().getTemplates(), " | ") + ' ';
84 fl_addto_choice(dialog_->choice_template, choice.c_str());
86 fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
88 // Disable for read-only documents.
89 bcview().addReadOnly(dialog_->input_filename);
90 bcview().addReadOnly(dialog_->button_browse);
92 // Trigger an input event for cut&paste with middle mouse button.
93 setPrehandler(dialog_->input_filename);
95 // Activate ok/apply immediately upon input.
96 fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
97 fl_set_input_return(dialog_->input_lyxscale, FL_RETURN_CHANGED);
99 fl_set_input_filter(dialog_->input_lyxscale, fl_unsigned_int_filter);
101 string const display_List =
102 _("Default|Monochrome|Grayscale|Color|Do not display");
103 fl_addto_choice(dialog_->choice_display, display_List.c_str());
105 // Set up the tooltips.
106 string str = _("The file you want to insert.");
107 tooltips().init(dialog_->input_filename, str);
108 str = _("Browse the directories.");
109 tooltips().init(dialog_->button_browse, str);
111 str = _("Scale the image to inserted percentage value.");
112 tooltips().init(dialog_->input_lyxscale, str);
113 str = _("Select display mode for this image.");
114 tooltips().init(dialog_->choice_display, str);
116 // Manage the ok, apply and cancel/close buttons
117 bcview().setOK(dialog_->button_ok);
118 bcview().setApply(dialog_->button_apply);
119 bcview().setCancel(dialog_->button_close);
123 void FormExternal::update()
125 InsetExternal::Params const & params = controller().params();
127 fl_set_input(dialog_->input_filename, params.filename.c_str());
129 int ID = controller().getTemplateNumber(params.templatename);
131 fl_set_choice(dialog_->choice_template, ID+1);
135 fl_set_input(dialog_->input_lyxscale, tostr(params.lyxscale).c_str());
137 switch (params.display) {
138 case grfx::NoDisplay:
139 fl_set_choice(dialog_->choice_display, 5);
141 case grfx::ColorDisplay:
142 fl_set_choice(dialog_->choice_display, 4);
144 case grfx::GrayscaleDisplay:
145 fl_set_choice(dialog_->choice_display, 3);
147 case grfx::MonochromeDisplay:
148 fl_set_choice(dialog_->choice_display, 2);
150 case grfx::DefaultDisplay:
151 fl_set_choice(dialog_->choice_display, 1);
156 ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
158 ButtonPolicy::SMInput result = ButtonPolicy::SMI_VALID;
159 if (ob == dialog_->choice_template) {
161 // set to the chosen template
164 } else if (ob == dialog_->button_browse) {
166 string const in_name = fl_get_input(dialog_->input_filename);
167 string const out_name = controller().Browse(in_name);
168 fl_set_input(dialog_->input_filename, out_name.c_str());
170 } else if (ob == dialog_->button_edit) {
171 controller().editExternal();
172 result = ButtonPolicy::SMI_NOOP;
179 void FormExternal::updateComboChange()
181 int const choice = fl_get_choice(dialog_->choice_template) - 1;
182 ExternalTemplate templ = controller().getTemplate(choice);
184 // Update the help text
185 fl_clear_browser(dialog_->browser_helptext);
186 fl_addto_browser(dialog_->browser_helptext, templ.helpText.c_str());
187 fl_set_browser_topline(dialog_->browser_helptext, 0);