2002-03-11 17:00:41 +00:00
|
|
|
/**
|
2001-03-30 09:51:46 +00:00
|
|
|
* \file FormExternal.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-11 17:00:41 +00:00
|
|
|
*
|
2001-03-30 09:51:46 +00:00
|
|
|
* \author Asger Alstrup
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author John Levon
|
2002-11-27 10:30:28 +00:00
|
|
|
* \author Angus Leeming
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-03-12 12:47:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "FormExternal.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
#include "ControlExternal.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include "forms/form_external.h"
|
2003-06-04 09:16:29 +00:00
|
|
|
|
|
|
|
#include "input_validators.h"
|
|
|
|
#include "Tooltips.h"
|
|
|
|
#include "xforms_helpers.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
#include "xformsBC.h"
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2003-06-11 14:30:04 +00:00
|
|
|
#include "insets/ExternalTemplate.h"
|
|
|
|
|
2002-04-15 12:05:07 +00:00
|
|
|
#include "support/lstrings.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
#include "support/tostr.h"
|
|
|
|
|
2003-05-14 09:17:22 +00:00
|
|
|
#include "lyx_forms.h"
|
2002-04-15 12:05:07 +00:00
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::getStringFromVector;
|
|
|
|
using lyx::support::strToInt;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2003-09-05 13:15:43 +00:00
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
typedef FormController<ControlExternal, FormView<FD_external> > base_class;
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
FormExternal::FormExternal(Dialog & parent)
|
2003-04-30 02:06:04 +00:00
|
|
|
: base_class(parent, _("External Material"))
|
2001-03-30 09:51:46 +00:00
|
|
|
{}
|
2001-03-12 12:47:07 +00:00
|
|
|
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
void FormExternal::apply()
|
2001-03-12 12:47:07 +00:00
|
|
|
{
|
2003-03-05 11:30:35 +00:00
|
|
|
InsetExternal::Params params = controller().params();
|
|
|
|
|
2003-07-23 09:17:04 +00:00
|
|
|
string const buffer_path = kernel().bufferFilepath();
|
|
|
|
params.filename.set(getString(dialog_->input_filename), buffer_path);
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2002-10-24 13:39:59 +00:00
|
|
|
int const choice = fl_get_choice(dialog_->choice_template) - 1;
|
2003-09-25 10:49:13 +00:00
|
|
|
params.settemplate(controller().getTemplate(choice).lyxName);
|
2003-03-05 11:30:35 +00:00
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
params.lyxscale = strToInt(getString(dialog_->input_lyxscale));
|
|
|
|
if (params.lyxscale == 0)
|
|
|
|
params.lyxscale = 100;
|
|
|
|
|
|
|
|
switch (fl_get_choice(dialog_->choice_display)) {
|
|
|
|
case 5:
|
2003-07-21 21:30:57 +00:00
|
|
|
params.display = lyx::graphics::NoDisplay;
|
2003-06-04 09:16:29 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2003-07-21 21:30:57 +00:00
|
|
|
params.display = lyx::graphics::ColorDisplay;
|
2003-06-04 09:16:29 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2003-07-21 21:30:57 +00:00
|
|
|
params.display = lyx::graphics::GrayscaleDisplay;
|
2003-06-04 09:16:29 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2003-07-21 21:30:57 +00:00
|
|
|
params.display = lyx::graphics::MonochromeDisplay;
|
2003-06-04 09:16:29 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2003-07-21 21:30:57 +00:00
|
|
|
params.display = lyx::graphics::DefaultDisplay;
|
2003-06-04 09:16:29 +00:00
|
|
|
}
|
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
controller().setParams(params);
|
2001-03-12 12:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
void FormExternal::build()
|
2001-03-12 12:47:07 +00:00
|
|
|
{
|
2002-06-13 13:43:51 +00:00
|
|
|
dialog_.reset(build_external(this));
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
string const choice =
|
2002-11-27 10:30:28 +00:00
|
|
|
' ' + getStringFromVector(controller().getTemplates(), " | ") + ' ';
|
2001-03-30 09:51:46 +00:00
|
|
|
fl_addto_choice(dialog_->choice_template, choice.c_str());
|
2002-03-11 18:24:31 +00:00
|
|
|
|
|
|
|
fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
|
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
// Disable for read-only documents.
|
|
|
|
bcview().addReadOnly(dialog_->input_filename);
|
|
|
|
bcview().addReadOnly(dialog_->button_browse);
|
|
|
|
|
|
|
|
// Trigger an input event for cut&paste with middle mouse button.
|
2002-03-11 18:24:31 +00:00
|
|
|
setPrehandler(dialog_->input_filename);
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
// Activate ok/apply immediately upon input.
|
|
|
|
fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return(dialog_->input_lyxscale, FL_RETURN_CHANGED);
|
|
|
|
|
|
|
|
fl_set_input_filter(dialog_->input_lyxscale, fl_unsigned_int_filter);
|
|
|
|
|
|
|
|
string const display_List =
|
|
|
|
_("Default|Monochrome|Grayscale|Color|Do not display");
|
|
|
|
fl_addto_choice(dialog_->choice_display, display_List.c_str());
|
|
|
|
|
|
|
|
// Set up the tooltips.
|
|
|
|
string str = _("The file you want to insert.");
|
|
|
|
tooltips().init(dialog_->input_filename, str);
|
|
|
|
str = _("Browse the directories.");
|
|
|
|
tooltips().init(dialog_->button_browse, str);
|
|
|
|
|
|
|
|
str = _("Scale the image to inserted percentage value.");
|
|
|
|
tooltips().init(dialog_->input_lyxscale, str);
|
|
|
|
str = _("Select display mode for this image.");
|
|
|
|
tooltips().init(dialog_->choice_display, str);
|
|
|
|
|
|
|
|
// Manage the ok, apply and cancel/close buttons
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().setOK(dialog_->button_ok);
|
|
|
|
bcview().setApply(dialog_->button_apply);
|
|
|
|
bcview().setCancel(dialog_->button_close);
|
2001-03-12 12:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
void FormExternal::update()
|
2001-03-12 12:47:07 +00:00
|
|
|
{
|
2001-03-30 09:51:46 +00:00
|
|
|
InsetExternal::Params const & params = controller().params();
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2003-07-23 09:17:04 +00:00
|
|
|
string const buffer_path = kernel().bufferFilepath();
|
|
|
|
string const name = params.filename.outputFilename(buffer_path);
|
|
|
|
fl_set_input(dialog_->input_filename, name.c_str());
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2003-09-25 10:49:13 +00:00
|
|
|
int ID = controller().getTemplateNumber(params.templatename());
|
2003-05-23 10:40:18 +00:00
|
|
|
if (ID < 0) ID = 0;
|
|
|
|
fl_set_choice(dialog_->choice_template, ID+1);
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
updateComboChange();
|
2003-06-04 09:16:29 +00:00
|
|
|
|
|
|
|
fl_set_input(dialog_->input_lyxscale, tostr(params.lyxscale).c_str());
|
|
|
|
|
|
|
|
switch (params.display) {
|
2003-07-21 21:30:57 +00:00
|
|
|
case lyx::graphics::NoDisplay:
|
2003-06-04 09:16:29 +00:00
|
|
|
fl_set_choice(dialog_->choice_display, 5);
|
|
|
|
break;
|
2003-07-21 21:30:57 +00:00
|
|
|
case lyx::graphics::ColorDisplay:
|
2003-06-04 09:16:29 +00:00
|
|
|
fl_set_choice(dialog_->choice_display, 4);
|
|
|
|
break;
|
2003-07-21 21:30:57 +00:00
|
|
|
case lyx::graphics::GrayscaleDisplay:
|
2003-06-04 09:16:29 +00:00
|
|
|
fl_set_choice(dialog_->choice_display, 3);
|
|
|
|
break;
|
2003-07-21 21:30:57 +00:00
|
|
|
case lyx::graphics::MonochromeDisplay:
|
2003-06-04 09:16:29 +00:00
|
|
|
fl_set_choice(dialog_->choice_display, 2);
|
|
|
|
break;
|
2003-07-21 21:30:57 +00:00
|
|
|
case lyx::graphics::DefaultDisplay:
|
2003-06-04 09:16:29 +00:00
|
|
|
fl_set_choice(dialog_->choice_display, 1);
|
|
|
|
}
|
2001-03-12 12:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
|
2001-03-12 12:47:07 +00:00
|
|
|
{
|
2003-06-12 08:32:34 +00:00
|
|
|
ButtonPolicy::SMInput result = ButtonPolicy::SMI_VALID;
|
2001-03-30 09:51:46 +00:00
|
|
|
if (ob == dialog_->choice_template) {
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
// set to the chosen template
|
|
|
|
updateComboChange();
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
} else if (ob == dialog_->button_browse) {
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
string const in_name = fl_get_input(dialog_->input_filename);
|
|
|
|
string const out_name = controller().Browse(in_name);
|
|
|
|
fl_set_input(dialog_->input_filename, out_name.c_str());
|
2001-03-12 12:47:07 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
} else if (ob == dialog_->button_edit) {
|
|
|
|
controller().editExternal();
|
2003-06-12 08:32:34 +00:00
|
|
|
result = ButtonPolicy::SMI_NOOP;
|
2001-03-12 12:47:07 +00:00
|
|
|
}
|
|
|
|
|
2003-06-12 08:32:34 +00:00
|
|
|
return result;
|
2001-03-12 12:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormExternal::updateComboChange()
|
|
|
|
{
|
2003-06-10 11:00:53 +00:00
|
|
|
int const choice = fl_get_choice(dialog_->choice_template) - 1;
|
2003-10-01 10:16:00 +00:00
|
|
|
lyx::external::Template templ = controller().getTemplate(choice);
|
2003-06-10 11:00:53 +00:00
|
|
|
|
2001-03-12 12:47:07 +00:00
|
|
|
// Update the help text
|
2003-09-23 17:04:25 +00:00
|
|
|
string const txt = formatted(templ.helpText,
|
|
|
|
dialog_->browser_helptext->w - 20);
|
2001-03-12 12:47:07 +00:00
|
|
|
fl_clear_browser(dialog_->browser_helptext);
|
2003-09-23 17:04:25 +00:00
|
|
|
fl_addto_browser(dialog_->browser_helptext, txt.c_str());
|
2001-03-12 12:47:07 +00:00
|
|
|
fl_set_browser_topline(dialog_->browser_helptext, 0);
|
|
|
|
}
|