/**
* \file FormExternal.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author unknown
+ * \author Asger Alstrup
* \author John Levon
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#include <utility>
-#include FORMS_H_LOCATION
+#include "FormExternal.h"
+#include "forms/form_external.h"
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include "checkedwidgets.h"
+#include "input_validators.h"
+#include "Tooltips.h"
+#include "xforms_helpers.h"
+#include "xformsBC.h"
-#include "debug.h"
-#include "gettext.h"
-#include "support/LAssert.h"
-#include "lyx_gui_misc.h"
-#include "Dialogs.h"
-#include "LyXView.h"
-#include "buffer.h"
-#include "FormExternal.h"
-#include "form_external.h"
-#include "frontends/FileDialog.h"
-#include "LString.h"
-#include "support/filetools.h"
-
-using std::pair;
-using std::make_pair;
-using std::endl;
-using SigC::slot;
-
-FormExternal::FormExternal(LyXView * lv, Dialogs * d)
- : FormBaseBD(lv, d, _("Edit external file")),
- inset_(0), ih_(0)
-{
- d->showExternal.connect(slot(this, &FormExternal::showInset));
-}
+#include "controllers/ControlExternal.h"
+#include "lengthcommon.h"
+#include "lyxrc.h"
-extern "C" void ExternalTemplateCB(FL_OBJECT * ob, long data)
-{
- FormExternal::templateCB(ob, data);
-}
+#include "insets/ExternalTemplate.h"
+#include "insets/insetexternal.h"
+#include "support/lstrings.h"
+#include "support/lyxlib.h"
+#include "support/tostr.h"
-extern "C" void ExternalBrowseCB(FL_OBJECT * ob, long data)
-{
- FormExternal::browseCB(ob, data);
-}
+#include "lyx_forms.h"
+namespace external = lyx::external;
-extern "C" void ExternalEditCB(FL_OBJECT * ob, long data)
-{
- FormExternal::editCB(ob, data);
-}
+using lyx::support::bformat;
+using lyx::support::float_equal;
+using lyx::support::getStringFromVector;
+using lyx::support::isStrDbl;
+using lyx::support::strToDbl;
+using lyx::support::strToInt;
+using lyx::support::token;
+using lyx::support::trim;
+using std::find;
+using std::string;
+using std::vector;
-extern "C" void ExternalViewCB(FL_OBJECT * ob, long data)
-{
- FormExternal::viewCB(ob, data);
-}
+namespace {
-extern "C" void ExternalUpdateCB(FL_OBJECT * ob, long data)
+LyXLength::UNIT defaultUnit()
{
- FormExternal::updateCB(ob, data);
+ LyXLength::UNIT default_unit = LyXLength::CM;
+ switch (lyxrc.default_papersize) {
+ case PAPER_USLETTER:
+ case PAPER_LEGALPAPER:
+ case PAPER_EXECUTIVEPAPER:
+ default_unit = LyXLength::IN;
+ break;
+ default:
+ break;
+ }
+ return default_unit;
}
-FL_FORM * FormExternal::form() const
+void setDisplay(FL_OBJECT * displayCB, FL_OBJECT * showCO, FL_OBJECT * scaleED,
+ external::DisplayType display, unsigned int scale,
+ bool read_only)
{
- if (dialog_.get())
- return dialog_->form;
- return 0;
-}
+ BOOST_ASSERT(displayCB && displayCB->objclass == FL_CHECKBUTTON);
+ BOOST_ASSERT(showCO && showCO->objclass == FL_CHOICE);
+ BOOST_ASSERT(scaleED && scaleED->objclass == FL_INPUT);
+
+ int item = 1;
+ switch (display) {
+ case external::DefaultDisplay:
+ item = 1;
+ break;
+ case external::MonochromeDisplay:
+ item = 2;
+ break;
+ case external::GrayscaleDisplay:
+ item = 3;
+ break;
+ case external::ColorDisplay:
+ item = 4;
+ break;
+ case external::PreviewDisplay:
+ item = 5;
+ break;
+ case external::NoDisplay:
+ item = 1;
+ break;
+ }
+ fl_set_choice(showCO, item);
-void FormExternal::connect()
-{
- u_ = d_->updateBufferDependent.
- connect(slot(this, &FormExternal::updateSlot));
- h_ = d_->hideBufferDependent.
- connect(slot(this, &FormExternal::hide));
- FormBaseDeprecated::connect();
+ bool const no_display = display == lyx::external::NoDisplay;
+ setEnabled(showCO, !no_display && !read_only);
+
+ fl_set_button(displayCB, !no_display);
+
+ fl_set_input(scaleED, tostr(scale).c_str());
+ setEnabled(scaleED, !no_display && !read_only);
}
-void FormExternal::disconnect()
+void getDisplay(external::DisplayType & display,
+ unsigned int & scale,
+ FL_OBJECT * displayCB,
+ FL_OBJECT * showCO,
+ FL_OBJECT * scaleED)
{
- inset_ = 0;
- ih_.disconnect();
- FormBaseBD::disconnect();
+ BOOST_ASSERT(displayCB && displayCB->objclass == FL_CHECKBUTTON);
+ BOOST_ASSERT(showCO && showCO->objclass == FL_CHOICE);
+ BOOST_ASSERT(scaleED && scaleED->objclass == FL_INPUT);
+
+ switch (fl_get_choice(showCO)) {
+ case 1:
+ display = external::DefaultDisplay;
+ break;
+ case 2:
+ display = external::MonochromeDisplay;
+ break;
+ case 3:
+ display = external::GrayscaleDisplay;
+ break;
+ case 4:
+ display = external::ColorDisplay;
+ break;
+ case 5:
+ display = external::PreviewDisplay;
+ break;
+ }
+
+ if (!fl_get_button(displayCB))
+ display = external::NoDisplay;
+
+ scale = strToInt(getString(scaleED));
}
-void FormExternal::updateSlot(bool switched)
+void setRotation(FL_OBJECT * angleED, FL_OBJECT * originCO,
+ external::RotationData const & data)
{
- if (switched)
- hide();
- else
- update();
+ BOOST_ASSERT(angleED && angleED->objclass == FL_INPUT);
+ BOOST_ASSERT(originCO && originCO->objclass == FL_CHOICE);
+
+ fl_set_choice(originCO, 1 + int(data.origin()));
+ fl_set_input(angleED, tostr(data.angle()).c_str());
}
-void FormExternal::showInset(InsetExternal * inset)
+void getRotation(external::RotationData & data,
+ FL_OBJECT * angleED, FL_OBJECT * originCO)
{
- Assert(inset);
-
- // If connected to another inset, disconnect from it.
- if (inset_)
- ih_.disconnect();
+ BOOST_ASSERT(angleED && angleED->objclass == FL_INPUT);
+ BOOST_ASSERT(originCO && originCO->objclass == FL_CHOICE);
- inset_ = inset;
- params_ = inset_->params();
+ typedef external::RotationData::OriginType OriginType;
- ih_ = inset->hideDialog.connect(slot(this, &FormExternal::hide));
- show();
+ data.origin(static_cast<OriginType>(fl_get_choice(originCO) - 1));
+ data.angle(strToDbl(getString(angleED)));
}
-void FormExternal::build()
+void setSize(FL_OBJECT * widthED, FL_OBJECT * widthUnitCO,
+ FL_OBJECT * heightED, FL_OBJECT * heightUnitCO,
+ FL_OBJECT * aspectratioCB,
+ external::ResizeData const & data)
{
- dialog_.reset(build_external());
+ BOOST_ASSERT(widthED && widthED->objclass == FL_INPUT);
+ BOOST_ASSERT(widthUnitCO && widthUnitCO->objclass == FL_CHOICE);
+ BOOST_ASSERT(heightED && heightED->objclass == FL_INPUT);
+ BOOST_ASSERT(heightUnitCO && heightUnitCO->objclass == FL_CHOICE);
+ BOOST_ASSERT(aspectratioCB &&
+ aspectratioCB->objclass == FL_CHECKBUTTON);
+
+ bool using_scale = data.usingScale();
+ double scale = data.scale;
+ if (data.no_resize()) {
+ // Everything is zero, so default to this!
+ using_scale = true;
+ scale = 100;
+ }
- fl_addto_choice(dialog_->choice_template,
- getTemplatesComboString().c_str());
+ if (using_scale) {
+ fl_set_input(widthED, tostr(scale).c_str());
+ fl_set_choice(widthUnitCO, 1);
+ } else {
+ fl_set_input(widthED, tostr(data.width.value()).c_str());
+ // Because 'Scale' is position 1...
+ // Note also that width cannot be zero here, so
+ // we don't need to worry about the default unit.
+ fl_set_choice(widthUnitCO, data.width.unit() + 2);
+ }
+
+ string const h = data.height.zero() ? string() : data.height.asString();
+ LyXLength::UNIT default_unit = data.width.zero() ?
+ defaultUnit() : data.width.unit();
+ updateWidgetsFromLengthString(heightED, heightUnitCO,
+ h, stringFromUnit(default_unit));
- bc_.setOK(dialog_->button_ok);
- bc_.setCancel(dialog_->button_cancel);
- bc_.refresh();
+ setEnabled(heightED, !using_scale);
+ setEnabled(heightUnitCO, !using_scale);
- bc_.addReadOnly(dialog_->input_filename);
- bc_.addReadOnly(dialog_->button_filenamebrowse);
- bc_.addReadOnly(dialog_->input_parameters);
+ fl_set_button(aspectratioCB, data.keepAspectRatio);
+
+ bool const disable_aspectRatio = using_scale ||
+ data.width.zero() || data.height.zero();
+ setEnabled(aspectratioCB, !disable_aspectRatio);
}
-string const FormExternal::getTemplatesComboString() const
+void getSize(external::ResizeData & data,
+ FL_OBJECT * widthED, FL_OBJECT * widthUnitCO,
+ FL_OBJECT * heightED, FL_OBJECT * heightUnitCO,
+ FL_OBJECT * aspectratioCB)
{
- string result;
- bool first = true;
- ExternalTemplateManager::Templates::const_iterator i1, i2;
- i1 = ExternalTemplateManager::get().getTemplates().begin();
- i2 = ExternalTemplateManager::get().getTemplates().end();
- for (; i1 != i2; ++i1) {
- if (!first)
- result += "|";
+ BOOST_ASSERT(widthED && widthED->objclass == FL_INPUT);
+ BOOST_ASSERT(widthUnitCO && widthUnitCO->objclass == FL_CHOICE);
+ BOOST_ASSERT(heightED && heightED->objclass == FL_INPUT);
+ BOOST_ASSERT(heightUnitCO && heightUnitCO->objclass == FL_CHOICE);
+ BOOST_ASSERT(aspectratioCB &&
+ aspectratioCB->objclass == FL_CHECKBUTTON);
+
+ string const width = getString(widthED);
+
+ if (fl_get_choice(widthUnitCO) > 1) {
+ // Subtract one, because scale is 1.
+ int const unit = fl_get_choice(widthUnitCO) - 1;
+
+ LyXLength w;
+ if (isValidLength(width, &w))
+ data.width = w;
+ else if (isStrDbl(width))
+ data.width = LyXLength(strToDbl(width),
+ static_cast<LyXLength::UNIT>(unit));
else
- first = false;
+ data.width = LyXLength();
+
+ data.scale = 0.0;
- result += (*i1).second.lyxName;
+ } else {
+ // scaling instead of a width
+ data.scale = strToDbl(width);
+ data.width = LyXLength();
}
- return result;
+
+ data.height = LyXLength(getLengthFromWidgets(heightED, heightUnitCO));
+
+ data.keepAspectRatio = fl_get_button(aspectratioCB);
}
-int FormExternal::getTemplateComboNumber(string const & name) const
+void setCrop(FL_OBJECT * clipCB,
+ FL_OBJECT * xlED, FL_OBJECT * ybED,
+ FL_OBJECT * xrED, FL_OBJECT * ytED,
+ external::ClipData const & data)
{
- int i = 1;
- ExternalTemplateManager::Templates::const_iterator i1, i2;
- i1 = ExternalTemplateManager::get().getTemplates().begin();
- i2 = ExternalTemplateManager::get().getTemplates().end();
- for (; i1 != i2; ++i1) {
- if (i1->second.lyxName == name)
- return i;
- ++i;
- }
- // we can get here if a LyX document has a template not installed
- // on this machine.
- return 0;
+ BOOST_ASSERT(clipCB && clipCB->objclass == FL_CHECKBUTTON);
+ BOOST_ASSERT(xlED && xlED->objclass == FL_INPUT);
+ BOOST_ASSERT(ybED && ybED->objclass == FL_INPUT);
+ BOOST_ASSERT(xrED && xrED->objclass == FL_INPUT);
+ BOOST_ASSERT(ytED && ytED->objclass == FL_INPUT);
+
+ fl_set_button(clipCB, data.clip);
+ lyx::graphics::BoundingBox const & bbox = data.bbox;
+ fl_set_input(xlED, tostr(bbox.xl).c_str());
+ fl_set_input(ybED, tostr(bbox.yb).c_str());
+ fl_set_input(xrED, tostr(bbox.xr).c_str());
+ fl_set_input(ytED, tostr(bbox.yt).c_str());
+}
+
+
+void getCrop(external::ClipData & data,
+ FL_OBJECT * clipCB,
+ FL_OBJECT * xlED, FL_OBJECT * ybED,
+ FL_OBJECT * xrED, FL_OBJECT * ytED,
+ bool bb_changed)
+{
+ BOOST_ASSERT(clipCB && clipCB->objclass == FL_CHECKBUTTON);
+ BOOST_ASSERT(xlED && xlED->objclass == FL_INPUT);
+ BOOST_ASSERT(ybED && ybED->objclass == FL_INPUT);
+ BOOST_ASSERT(xrED && xrED->objclass == FL_INPUT);
+ BOOST_ASSERT(ytED && ytED->objclass == FL_INPUT);
+
+ data.clip = fl_get_button(clipCB);
+
+ if (!bb_changed)
+ return;
+
+ data.bbox.xl = strToInt(getString(xlED));
+ data.bbox.yb = strToInt(getString(ybED));
+ data.bbox.xr = strToInt(getString(xrED));
+ data.bbox.yt = strToInt(getString(ytED));
}
-ExternalTemplate FormExternal::getTemplate(int i) const
+void getExtra(external::ExtraData & data,
+ FormExternal::MapType const & extra)
{
- ExternalTemplateManager::Templates::const_iterator i1;
- i1 = ExternalTemplateManager::get().getTemplates().begin();
- for (int n = 1; n < i; ++n)
- ++i1;
+ typedef FormExternal::MapType MapType;
+ MapType::const_iterator it = extra.begin();
+ MapType::const_iterator const end = extra.end();
+ for (; it != end; ++it)
+ data.set(it->first, trim(it->second));
+}
+
+} // namespace anon
+
- return (*i1).second;
+typedef FormController<ControlExternal, FormView<FD_external> > base_class;
+
+FormExternal::FormExternal(Dialog & parent)
+ : base_class(parent, _("External Material"))
+{}
+
+
+void FormExternal::build()
+{
+ dialog_.reset(build_external(this));
+ file_.reset(build_external_file(this));
+ lyxview_.reset(build_external_lyxview(this));
+ rotate_.reset(build_external_rotate(this));
+ scale_.reset(build_external_scale(this));
+ crop_.reset(build_external_crop(this));
+ options_.reset(build_external_options(this));
+
+ bcview().setOK(dialog_->button_ok);
+ bcview().setApply(dialog_->button_apply);
+ bcview().setCancel(dialog_->button_close);
+
+ bcview().addReadOnly(file_->input_file);
+ bcview().addReadOnly(file_->button_browse);
+ bcview().addReadOnly(file_->button_edit);
+ bcview().addReadOnly(file_->choice_template);
+ bcview().addReadOnly(file_->check_draft);
+
+ bcview().addReadOnly(lyxview_->check_show);
+ bcview().addReadOnly(lyxview_->choice_show);
+ bcview().addReadOnly(lyxview_->input_displayscale);
+
+ bcview().addReadOnly(rotate_->input_angle);
+ bcview().addReadOnly(rotate_->choice_origin);
+
+ bcview().addReadOnly(scale_->input_width);
+ bcview().addReadOnly(scale_->choice_width);
+ bcview().addReadOnly(scale_->input_height);
+ bcview().addReadOnly(scale_->choice_height);
+ bcview().addReadOnly(scale_->check_aspectratio);
+
+ bcview().addReadOnly(crop_->check_bbox);
+ bcview().addReadOnly(crop_->button_get_bbox);
+ bcview().addReadOnly(crop_->input_xr);
+ bcview().addReadOnly(crop_->input_yt);
+ bcview().addReadOnly(crop_->input_xl);
+ bcview().addReadOnly(crop_->input_yb);
+
+ bcview().addReadOnly(options_->choice_option);
+ bcview().addReadOnly(options_->input_option);
+
+ // initial setting
+// addCheckedPositiveFloat(bcview(), scale_->input_width);
+ // As I haven't written addCheckedPositiveFloat, we default to
+ // always checking that it is a valide LyXLength, even when
+ // I'm 'scaling'. No harm done, just not as strict as it might be.
+ addCheckedLyXLength(bcview(), scale_->input_width);
+ addCheckedLyXLength(bcview(), scale_->input_height);
+
+// addCheckedPositiveFloat(bcview(), input_displayscale);
+ fl_set_input_filter(lyxview_->input_displayscale,
+ fl_unsigned_int_filter);
+
+ fl_set_input_filter(crop_->input_xr, fl_unsigned_int_filter);
+ fl_set_input_filter(crop_->input_yt, fl_unsigned_int_filter);
+ fl_set_input_filter(crop_->input_xl, fl_unsigned_int_filter);
+ fl_set_input_filter(crop_->input_yb, fl_unsigned_int_filter);
+
+ fl_set_input_return(file_->input_file, FL_RETURN_CHANGED);
+ fl_set_input_return(lyxview_->input_displayscale, FL_RETURN_CHANGED);
+ fl_set_input_return(rotate_->input_angle, FL_RETURN_CHANGED);
+ fl_set_input_return(scale_->input_width, FL_RETURN_CHANGED);
+ fl_set_input_return(scale_->input_height, FL_RETURN_CHANGED);
+ fl_set_input_return(crop_->input_xr, FL_RETURN_CHANGED);
+ fl_set_input_return(crop_->input_yt, FL_RETURN_CHANGED);
+ fl_set_input_return(crop_->input_xl, FL_RETURN_CHANGED);
+ fl_set_input_return(crop_->input_yb, FL_RETURN_CHANGED);
+ fl_set_input_return(options_->input_option, FL_RETURN_CHANGED);
+
+ // Trigger an input event for cut&paste with middle mouse button.
+ setPrehandler(file_->input_file);
+ setPrehandler(lyxview_->input_displayscale);
+ setPrehandler(rotate_->input_angle);
+ setPrehandler(scale_->input_width);
+ setPrehandler(scale_->input_height);
+ setPrehandler(crop_->input_xr);
+ setPrehandler(crop_->input_yt);
+ setPrehandler(crop_->input_xl);
+ setPrehandler(crop_->input_yb);
+ setPrehandler(options_->input_option);
+
+ string const choice =
+ ' ' + getStringFromVector(controller().getTemplates(), " | ") +
+ ' ';
+ fl_addto_choice(file_->choice_template, choice.c_str());
+
+ string const display_list =
+ _("Default|Monochrome|Grayscale|Color|Preview");
+ fl_addto_choice(lyxview_->choice_show, display_list.c_str());
+
+ // Fill the origins combo
+ typedef vector<external::RotationDataType> Origins;
+ Origins const & all_origins = external::all_origins();
+ for (Origins::size_type i = 0; i != all_origins.size(); ++i)
+ fl_addto_choice(rotate_->choice_origin,
+ external::origin_gui_str(i).c_str());
+
+ string const width_list = bformat(_("Scale%%%%|%1$s"),
+ choice_Length_All);
+ fl_addto_choice(scale_->choice_width, width_list.c_str());
+
+ fl_addto_choice(scale_->choice_height, choice_Length_All.c_str());
+
+ // Set up the tooltips.
+ string str = _("The file you want to insert.");
+ tooltips().init(file_->input_file, str);
+ str = _("Browse the directories.");
+ tooltips().init(file_->button_browse, str);
+
+ str = _("Scale the image to inserted percentage value.");
+ tooltips().init(lyxview_->input_displayscale, str);
+ str = _("Select display mode for this image.");
+ tooltips().init(options_->choice_option, str);
+
+ // Stack tabs
+ tabmap_[FILETAB] =
+ fl_addto_tabfolder(dialog_->tabfolder, _("File").c_str(),
+ file_->form);
+
+ tabmap_[LYXVIEWTAB] =
+ fl_addto_tabfolder(dialog_->tabfolder, _("LyX View").c_str(),
+ lyxview_->form);
+ tabmap_[ROTATETAB] =
+ fl_addto_tabfolder(dialog_->tabfolder, _("Rotate").c_str(),
+ rotate_->form);
+ tabmap_[SCALETAB] =
+ fl_addto_tabfolder(dialog_->tabfolder, _("Scale").c_str(),
+ scale_->form);
+ tabmap_[CROPTAB] =
+ fl_addto_tabfolder(dialog_->tabfolder, _("Crop").c_str(),
+ crop_->form);
+ tabmap_[OPTIONSTAB] =
+ fl_addto_tabfolder(dialog_->tabfolder, _("Options").c_str(),
+ options_->form);
}
void FormExternal::update()
{
- fl_set_input(dialog_->input_filename, params_.filename.c_str());
- fl_set_input(dialog_->input_parameters, params_.parameters.c_str());
+ fl_set_folder_bynumber(dialog_->tabfolder, 1);
+ InsetExternalParams const & params = controller().params();
+
+ string const buffer_path = kernel().bufferFilepath();
+ string const name = params.filename.outputFilename(buffer_path);
+ fl_set_input(file_->input_file, name.c_str());
- fl_set_choice(dialog_->choice_template, getTemplateComboNumber(params_.templ.lyxName));
+ int ID = controller().getTemplateNumber(params.templatename());
+ if (ID < 0) ID = 0;
+ fl_set_choice(file_->choice_template, ID+1);
updateComboChange();
- bc_.valid();
+ fl_set_button(file_->check_draft, params.draft);
+
+ setDisplay(lyxview_->check_show, lyxview_->choice_show,
+ lyxview_->input_displayscale,
+ params.display, params.lyxscale,
+ kernel().isBufferReadonly());
+
+ setRotation(rotate_->input_angle, rotate_->choice_origin,
+ params.rotationdata);
+
+ setSize(scale_->input_width, scale_->choice_width,
+ scale_->input_height, scale_->choice_height,
+ scale_->check_aspectratio,
+ params.resizedata);
+
+ setCrop(crop_->check_bbox,
+ crop_->input_xl, crop_->input_yb,
+ crop_->input_xr, crop_->input_yt,
+ params.clipdata);
+ controller().bbChanged(!params.clipdata.bbox.empty());
}
void FormExternal::updateComboChange()
{
+ namespace external = lyx::external;
+
+ int const choice = fl_get_choice(file_->choice_template) - 1;
+ external::Template templ = controller().getTemplate(choice);
+
// Update the help text
- fl_clear_browser(dialog_->browser_helptext);
- fl_addto_browser(dialog_->browser_helptext, params_.templ.helpText.c_str());
- fl_set_browser_topline(dialog_->browser_helptext, 0);
+ string const txt = formatted(templ.helpText,
+ file_->browser_template->w - 20);
+ fl_clear_browser(file_->browser_template);
+ fl_addto_browser(file_->browser_template, txt.c_str());
+ fl_set_browser_topline(file_->browser_template, 0);
+
+ // Ascertain which (if any) transformations the template supports
+ // and disable tabs hosting unsupported transforms.
+ typedef vector<external::TransformID> TransformIDs;
+ TransformIDs const transformIds = templ.transformIds;
+ TransformIDs::const_iterator tr_begin = transformIds.begin();
+ TransformIDs::const_iterator const tr_end = transformIds.end();
+
+ tabmap_[FILETAB];
+ tabmap_[LYXVIEWTAB];
+ tabmap_[ROTATETAB];
+ tabmap_[SCALETAB];
+ tabmap_[CROPTAB];
+ tabmap_[OPTIONSTAB];
+
+ bool found = find(tr_begin, tr_end, external::Rotate) != tr_end;
+ setEnabled(tabmap_[ROTATETAB], found);
+
+ found = find(tr_begin, tr_end, external::Resize) != tr_end;
+ setEnabled(tabmap_[SCALETAB], found);
+
+ found = find(tr_begin, tr_end, external::Clip) != tr_end;
+ setEnabled(tabmap_[CROPTAB], found);
+
+ found = find(tr_begin, tr_end, external::Extra) != tr_end;
+ setEnabled(tabmap_[OPTIONSTAB], found);
+
+ if (!found)
+ return;
- if (params_.templ.automaticProduction) {
- fl_deactivate_object(dialog_->button_update);
- fl_set_object_lcol(dialog_->button_update, FL_INACTIVE);
- } else {
- fl_activate_object(dialog_->button_update);
- fl_set_object_lcol(dialog_->button_update, FL_BLACK);
+ // Ascertain whether the template has any formats supporting
+ // the 'Extra' option
+ FL_OBJECT * const ob_input = options_->input_option;
+ FL_OBJECT * const ob_choice = options_->choice_option;
+ extra_.clear();
+ fl_set_input(ob_input, "");
+ fl_clear_choice(ob_choice);
+
+ external::Template::Formats::const_iterator it = templ.formats.begin();
+ external::Template::Formats::const_iterator end = templ.formats.end();
+ for (; it != end; ++it) {
+ if (it->second.option_transformers.find(external::Extra) ==
+ it->second.option_transformers.end())
+ continue;
+ string const format = it->first;
+ string const opt = controller().params().extradata.get(format);
+ fl_addto_choice(ob_choice, format.c_str());
+ extra_[format] = opt;
}
-}
+ bool const enabled = fl_get_choice_maxitems(ob_choice) > 0;
-bool FormExternal::input(FL_OBJECT *, long)
-{
- // FIXME: anything to do here ?
- return true;
+ setEnabled(tabmap_[OPTIONSTAB], enabled);
+ setEnabled(ob_input, enabled && !kernel().isBufferReadonly());
+ setEnabled(ob_choice, enabled);
+
+ if (enabled) {
+ fl_set_choice(ob_choice, 1);
+ string const format = fl_get_choice_text(ob_choice);
+ fl_set_input(ob_input, extra_[format].c_str());
+ }
}
void FormExternal::apply()
{
- Assert(inset_);
+ InsetExternalParams params = controller().params();
- if (lv_->buffer()->isReadonly())
- return;
+ string const buffer_path = kernel().bufferFilepath();
+ params.filename.set(getString(file_->input_file), buffer_path);
- params_.filename = fl_get_input(dialog_->input_filename);
- params_.parameters = fl_get_input(dialog_->input_parameters);
- params_.templ = getTemplate(fl_get_choice(dialog_->choice_template));
+ int const choice = fl_get_choice(file_->choice_template) - 1;
+ params.settemplate(controller().getTemplate(choice).lyxName);
- inset_->setFromParams(params_);
- lv_->view()->updateInset(inset_, true);
-}
+ params.draft = fl_get_button(file_->check_draft);
+ getDisplay(params.display, params.lyxscale,
+ lyxview_->check_show, lyxview_->choice_show,
+ lyxview_->input_displayscale);
-void FormExternal::templateCB(FL_OBJECT * ob, long)
-{
- FormExternal * form = static_cast<FormExternal*>(ob->form->u_vdata);
+ if (isActive(tabmap_[ROTATETAB]))
+ getRotation(params.rotationdata,
+ rotate_->input_angle, rotate_->choice_origin);
+
+ if (isActive(tabmap_[SCALETAB]))
+ getSize(params.resizedata,
+ scale_->input_width, scale_->choice_width,
+ scale_->input_height, scale_->choice_height,
+ scale_->check_aspectratio);
- // set to the chosen template
- form->params_.templ = form->getTemplate(fl_get_choice(form->dialog_->choice_template));
+ if (isActive(tabmap_[CROPTAB]))
+ getCrop(params.clipdata,
+ crop_->check_bbox,
+ crop_->input_xl, crop_->input_yb,
+ crop_->input_xr, crop_->input_yt,
+ controller().bbChanged());
- form->updateComboChange();
+ if (isActive(tabmap_[OPTIONSTAB]))
+ getExtra(params.extradata, extra_);
+
+ controller().setParams(params);
}
-void FormExternal::browseCB(FL_OBJECT * ob, long)
+ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
{
- FormExternal * form = static_cast<FormExternal*>(ob->form->u_vdata);
-
- static string current_path;
- static int once = 0;
-
- string p = fl_get_input(form->dialog_->input_filename);
- string buf = MakeAbsPath(form->lv_->buffer()->fileName());
- string buf2 = OnlyPath(buf);
-
- if (!p.empty()) {
- buf = MakeAbsPath(p, buf2);
- buf = OnlyPath(buf);
- } else {
- buf = OnlyPath(form->lv_->buffer()->fileName());
- }
-
- FileDialog fileDlg(form->lv_, _("Select external file"),
- LFUN_SELECT_FILE_SYNC,
- make_pair(string(_("Document")), string(buf)));
-
- /// Determine the template file extension
- ExternalTemplate const & et = form->params_.templ;
-
- string regexp = et.fileRegExp;
- if (regexp.empty())
- regexp = "*";
-
- // FIXME: a temporary hack until the FileDialog interface is updated
- regexp += "|";
-
- while (1) {
- string const path = (once) ? current_path : buf;
- FileDialog::Result result = fileDlg.Select(path, regexp, fl_get_input(form->dialog_->input_filename));
-
- if (result.second.empty())
- return;
-
- string p = result.second;
-
- buf = MakeRelPath(p, buf2);
- current_path = OnlyPath(p);
- once = 1;
-
- if (contains(p, "#") || contains(p, "~") || contains(p, "$")
- || contains(p, "%")) {
- WriteAlert(_("Filename can't contain any "
- "of these characters:"),
- // xgettext:no-c-format
- _("'#', '~', '$' or '%'."));
- } else
- break;
+ ButtonPolicy::SMInput result = ButtonPolicy::SMI_VALID;
+
+ if (ob == file_->choice_template) {
+
+ // set to the chosen template
+ updateComboChange();
+
+ } else if (ob == file_->button_browse) {
+
+ string const in_name = fl_get_input(file_->input_file);
+
+ int const choice = fl_get_choice(file_->choice_template) - 1;
+ string const template_name =
+ controller().getTemplate(choice).lyxName;
+ string const out_name =
+ controller().browse(in_name, template_name);
+ fl_set_input(file_->input_file, out_name.c_str());
+
+ } else if (ob == file_->button_edit) {
+ controller().editExternal();
+ result = ButtonPolicy::SMI_NOOP;
+
+ } else if (ob == lyxview_->check_show) {
+
+ bool const checked = fl_get_button(ob);
+ setEnabled(lyxview_->choice_show, checked);
+ setEnabled(lyxview_->input_displayscale, checked);
+
+ } else if (ob == crop_->button_get_bbox) {
+
+ getBB();
+
+ } else if (ob == scale_->input_width ||
+ ob == scale_->input_height) {
+
+ setEnabled(scale_->check_aspectratio,
+ activateAspectratio());
+
+ } else if (ob == scale_->choice_width) {
+
+ widthUnitChanged();
+
+ } else if (ob == crop_->input_xr ||
+ ob == crop_->input_yt ||
+ ob == crop_->input_xl ||
+ ob == crop_->input_yb) {
+
+ controller().bbChanged(true);
+
+ } else if (ob == options_->input_option) {
+
+ string const format =
+ fl_get_choice_text(options_->choice_option);
+ extra_[format] = getString(options_->input_option);
+
+ } else if (ob == options_->choice_option) {
+
+ string const format =
+ fl_get_choice_text(options_->choice_option);
+ fl_set_input(options_->input_option, extra_[format].c_str());
+ result = ButtonPolicy::SMI_NOOP;
}
- fl_set_input(form->dialog_->input_filename, buf.c_str());
+ return result;
}
-void FormExternal::editCB(FL_OBJECT * ob, long)
+bool FormExternal::activateAspectratio() const
{
- FormExternal * form = static_cast<FormExternal*>(ob->form->u_vdata);
+ if (fl_get_choice(scale_->choice_width) == 1)
+ return false;
+
+ string const wstr = getString(scale_->input_width);
+ if (wstr.empty())
+ return false;
+ bool const wIsDbl = isStrDbl(wstr);
+ if (wIsDbl && float_equal(strToDbl(wstr), 0.0, 0.05))
+ return false;
+ LyXLength l;
+ if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
+ return false;
+
+ string const hstr = getString(scale_->input_height);
+ if (hstr.empty())
+ return false;
+ bool const hIsDbl = isStrDbl(hstr);
+ if (hIsDbl && float_equal(strToDbl(hstr), 0.0, 0.05))
+ return false;
+ if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
+ return false;
- form->apply();
- form->inset_->editExternal();
+ return true;
}
-void FormExternal::viewCB(FL_OBJECT * ob, long)
+void FormExternal::getBB()
{
- FormExternal * form = static_cast<FormExternal*>(ob->form->u_vdata);
-
- form->apply();
- form->inset_->viewExternal();
+ fl_set_input(crop_->input_xl, "0");
+ fl_set_input(crop_->input_yb, "0");
+ fl_set_input(crop_->input_xr, "0");
+ fl_set_input(crop_->input_yt, "0");
+
+ string const filename = getString(file_->input_file);
+ if (filename.empty())
+ return;
+
+ string const bb = controller().readBB(filename);
+ if (bb.empty())
+ return;
+
+ fl_set_input(crop_->input_xl, token(bb, ' ', 0).c_str());
+ fl_set_input(crop_->input_yb, token(bb, ' ', 1).c_str());
+ fl_set_input(crop_->input_xr, token(bb, ' ', 2).c_str());
+ fl_set_input(crop_->input_yt, token(bb, ' ', 3).c_str());
+
+ controller().bbChanged(false);
}
-void FormExternal::updateCB(FL_OBJECT * ob, long)
+void FormExternal::widthUnitChanged()
{
- FormExternal * form = static_cast<FormExternal*>(ob->form->u_vdata);
-
- form->apply();
- form->inset_->updateExternal();
+ if (fl_get_choice(scale_->choice_width) == 1)
+ return;
+
+ bool useHeight = fl_get_choice(scale_->choice_width) > 1;
+
+// if (useHeight)
+// widthED->setValidator(unsignedLengthValidator(widthED));
+// else
+// widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
+
+ setEnabled(scale_->input_height, useHeight);
+ setEnabled(scale_->choice_height, useHeight);
}