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 "support/tostr.h"
28 #include "support/lstrings.h"
29 #include "lyx_forms.h"
31 typedef FormController<ControlExternal, FormView<FD_external> > base_class;
33 FormExternal::FormExternal(Dialog & parent)
34 : base_class(parent, _("External Material"))
38 void FormExternal::apply()
40 InsetExternal::Params params = controller().params();
42 params.filename = fl_get_input(dialog_->input_filename);
44 int const choice = fl_get_choice(dialog_->choice_template) - 1;
45 params.templ = controller().getTemplate(choice);
47 params.lyxscale = strToInt(getString(dialog_->input_lyxscale));
48 if (params.lyxscale == 0)
49 params.lyxscale = 100;
51 switch (fl_get_choice(dialog_->choice_display)) {
53 params.display = grfx::NoDisplay;
56 params.display = grfx::ColorDisplay;
59 params.display = grfx::GrayscaleDisplay;
62 params.display = grfx::MonochromeDisplay;
65 params.display = grfx::DefaultDisplay;
68 controller().setParams(params);
72 void FormExternal::build()
74 dialog_.reset(build_external(this));
77 ' ' + getStringFromVector(controller().getTemplates(), " | ") + ' ';
78 fl_addto_choice(dialog_->choice_template, choice.c_str());
80 fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
82 // Disable for read-only documents.
83 bcview().addReadOnly(dialog_->input_filename);
84 bcview().addReadOnly(dialog_->button_browse);
86 // Trigger an input event for cut&paste with middle mouse button.
87 setPrehandler(dialog_->input_filename);
89 // Activate ok/apply immediately upon input.
90 fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
91 fl_set_input_return(dialog_->input_lyxscale, FL_RETURN_CHANGED);
93 fl_set_input_filter(dialog_->input_lyxscale, fl_unsigned_int_filter);
95 string const display_List =
96 _("Default|Monochrome|Grayscale|Color|Do not display");
97 fl_addto_choice(dialog_->choice_display, display_List.c_str());
99 // Set up the tooltips.
100 string str = _("The file you want to insert.");
101 tooltips().init(dialog_->input_filename, str);
102 str = _("Browse the directories.");
103 tooltips().init(dialog_->button_browse, str);
105 str = _("Scale the image to inserted percentage value.");
106 tooltips().init(dialog_->input_lyxscale, str);
107 str = _("Select display mode for this image.");
108 tooltips().init(dialog_->choice_display, str);
110 // Manage the ok, apply and cancel/close buttons
111 bcview().setOK(dialog_->button_ok);
112 bcview().setApply(dialog_->button_apply);
113 bcview().setCancel(dialog_->button_close);
117 void FormExternal::update()
119 InsetExternal::Params const & params = controller().params();
121 fl_set_input(dialog_->input_filename, params.filename.c_str());
123 int ID = controller().getTemplateNumber(params.templ.lyxName);
125 fl_set_choice(dialog_->choice_template, ID+1);
129 fl_set_input(dialog_->input_lyxscale, tostr(params.lyxscale).c_str());
131 switch (params.display) {
132 case grfx::NoDisplay:
133 fl_set_choice(dialog_->choice_display, 5);
135 case grfx::ColorDisplay:
136 fl_set_choice(dialog_->choice_display, 4);
138 case grfx::GrayscaleDisplay:
139 fl_set_choice(dialog_->choice_display, 3);
141 case grfx::MonochromeDisplay:
142 fl_set_choice(dialog_->choice_display, 2);
144 case grfx::DefaultDisplay:
145 fl_set_choice(dialog_->choice_display, 1);
150 ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
152 if (ob == dialog_->choice_template) {
154 // set to the chosen template
155 int const choice = fl_get_choice(dialog_->choice_template) - 1;
156 InsetExternal::Params params = controller().params();
157 params.templ = controller().getTemplate(choice);
158 controller().setParams(params);
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();
172 return ButtonPolicy::SMI_VALID;
176 void FormExternal::updateComboChange()
178 // Update the help text
179 fl_clear_browser(dialog_->browser_helptext);
180 fl_addto_browser(dialog_->browser_helptext,
181 controller().params().templ.helpText.c_str());
182 fl_set_browser_topline(dialog_->browser_helptext, 0);