2003-11-28 15:53:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file FormVSpace.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
* \author Rob Lahaye
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "FormVSpace.h"
|
|
|
|
|
#include "ControlVSpace.h"
|
|
|
|
|
#include "forms/form_vspace.h"
|
|
|
|
|
|
|
|
|
|
#include "checkedwidgets.h"
|
|
|
|
|
#include "input_validators.h"
|
|
|
|
|
#include "Tooltips.h"
|
|
|
|
|
#include "xforms_helpers.h"
|
|
|
|
|
#include "xformsBC.h"
|
|
|
|
|
|
|
|
|
|
#include "controllers/helper_funcs.h"
|
|
|
|
|
|
|
|
|
|
#include "lyxrc.h" // to set the deafult length values
|
|
|
|
|
#include "Spacing.h"
|
|
|
|
|
#include "vspace.h"
|
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
#include "support/tostr.h"
|
|
|
|
|
|
|
|
|
|
#include "lyx_forms.h"
|
|
|
|
|
|
2004-02-01 12:46:14 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
|
|
|
|
using boost::bind;
|
|
|
|
|
|
2003-11-28 15:53:34 +00:00
|
|
|
|
using std::remove_if;
|
|
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
using std::string;
|
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::contains;
|
|
|
|
|
using support::getStringFromVector;
|
|
|
|
|
using support::rtrim;
|
|
|
|
|
|
|
|
|
|
namespace frontend {
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
string defaultUnit("cm");
|
|
|
|
|
|
|
|
|
|
void validateVSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length)
|
|
|
|
|
{
|
|
|
|
|
// Paranoia check!
|
|
|
|
|
BOOST_ASSERT(choice_type && choice_type->objclass == FL_CHOICE &&
|
|
|
|
|
input_length && input_length->objclass == FL_INPUT);
|
|
|
|
|
|
2003-12-01 14:16:27 +00:00
|
|
|
|
if (fl_get_choice(choice_type) != 6)
|
2003-11-28 15:53:34 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// If a vspace kind is "Length" but there's no text in
|
2003-12-01 14:16:27 +00:00
|
|
|
|
// the input field, insert nothing.
|
2003-11-28 15:53:34 +00:00
|
|
|
|
string const input = rtrim(getString(input_length));
|
|
|
|
|
if (input.empty())
|
2003-12-01 14:16:27 +00:00
|
|
|
|
return;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VSpace const setVSpaceFromWidgets(FL_OBJECT * choice_type,
|
|
|
|
|
FL_OBJECT * input_length,
|
2003-11-29 20:13:51 +00:00
|
|
|
|
FL_OBJECT * choice_length,
|
|
|
|
|
bool keep)
|
2003-11-28 15:53:34 +00:00
|
|
|
|
{
|
|
|
|
|
// Paranoia check!
|
|
|
|
|
BOOST_ASSERT(choice_type && choice_type->objclass == FL_CHOICE &&
|
|
|
|
|
input_length && input_length->objclass == FL_INPUT &&
|
|
|
|
|
choice_length && choice_length->objclass == FL_CHOICE);
|
|
|
|
|
|
2003-12-01 21:24:18 +00:00
|
|
|
|
VSpace space;
|
2003-11-29 20:13:51 +00:00
|
|
|
|
|
2003-11-28 15:53:34 +00:00
|
|
|
|
switch (fl_get_choice(choice_type)) {
|
|
|
|
|
case 1:
|
2003-11-29 20:13:51 +00:00
|
|
|
|
space = VSpace(VSpace::DEFSKIP);
|
|
|
|
|
break;
|
2003-12-01 14:16:27 +00:00
|
|
|
|
case 2:
|
2003-11-29 20:13:51 +00:00
|
|
|
|
space = VSpace(VSpace::SMALLSKIP);
|
|
|
|
|
break;
|
2003-12-01 14:16:27 +00:00
|
|
|
|
case 3:
|
2003-11-29 20:13:51 +00:00
|
|
|
|
space = VSpace(VSpace::MEDSKIP);
|
|
|
|
|
break;
|
2003-12-01 14:16:27 +00:00
|
|
|
|
case 4:
|
2003-11-29 20:13:51 +00:00
|
|
|
|
space = VSpace(VSpace::BIGSKIP);
|
|
|
|
|
break;
|
2003-12-01 14:16:27 +00:00
|
|
|
|
case 5:
|
2003-11-29 20:13:51 +00:00
|
|
|
|
space = VSpace(VSpace::VFILL);
|
|
|
|
|
break;
|
2003-12-01 14:16:27 +00:00
|
|
|
|
case 6:
|
2003-11-29 20:13:51 +00:00
|
|
|
|
space = VSpace(LyXGlueLength(
|
|
|
|
|
getLengthFromWidgets(input_length, choice_length)));
|
|
|
|
|
break;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-29 20:13:51 +00:00
|
|
|
|
space.setKeep(keep);
|
|
|
|
|
return space;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setWidgetsFromVSpace(VSpace const & space,
|
|
|
|
|
FL_OBJECT * choice_type,
|
|
|
|
|
FL_OBJECT * input_length,
|
2003-11-29 20:13:51 +00:00
|
|
|
|
FL_OBJECT * choice_length,
|
|
|
|
|
FL_OBJECT * check_keep)
|
2003-11-28 15:53:34 +00:00
|
|
|
|
{
|
|
|
|
|
// Paranoia check!
|
|
|
|
|
BOOST_ASSERT(choice_type && choice_type->objclass == FL_CHOICE &&
|
|
|
|
|
input_length && input_length->objclass == FL_INPUT &&
|
2003-11-29 20:13:51 +00:00
|
|
|
|
choice_length && choice_length->objclass == FL_CHOICE &&
|
|
|
|
|
check_keep && check_keep->objclass == FL_CHECKBUTTON);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
|
|
int pos = 1;
|
|
|
|
|
switch (space.kind()) {
|
|
|
|
|
case VSpace::DEFSKIP:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
pos = 1;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::SMALLSKIP:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
pos = 2;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::MEDSKIP:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
pos = 3;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::BIGSKIP:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
pos = 4;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::VFILL:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
pos = 5;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::LENGTH:
|
2003-12-01 14:16:27 +00:00
|
|
|
|
pos = 6;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
fl_set_choice(choice_type, pos);
|
2003-11-29 20:13:51 +00:00
|
|
|
|
fl_set_button(check_keep, space.keep());
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
|
|
bool const custom_vspace = space.kind() == VSpace::LENGTH;
|
|
|
|
|
if (custom_vspace) {
|
|
|
|
|
string const length = space.length().asString();
|
|
|
|
|
updateWidgetsFromLengthString(input_length, choice_length,
|
|
|
|
|
length, defaultUnit);
|
|
|
|
|
} else {
|
|
|
|
|
fl_set_input(input_length, "");
|
|
|
|
|
fl_set_choice_text(choice_length, defaultUnit.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef FormController<ControlVSpace, FormView<FD_vspace> > base_class;
|
|
|
|
|
|
|
|
|
|
FormVSpace::FormVSpace(Dialog & parent)
|
|
|
|
|
: base_class(parent, _("VSpace Settings"))
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FormVSpace::build()
|
|
|
|
|
{
|
|
|
|
|
// the tabbed folder
|
|
|
|
|
dialog_.reset(build_vspace(this));
|
|
|
|
|
|
|
|
|
|
// Manage the ok, apply, restore and cancel/close buttons
|
|
|
|
|
bcview().setOK(dialog_->button_ok);
|
|
|
|
|
bcview().setApply(dialog_->button_apply);
|
|
|
|
|
bcview().setCancel(dialog_->button_close);
|
|
|
|
|
bcview().setRestore(dialog_->button_restore);
|
|
|
|
|
|
|
|
|
|
// disable for read-only documents
|
|
|
|
|
bcview().addReadOnly(dialog_->choice_space);
|
|
|
|
|
bcview().addReadOnly(dialog_->input_space);
|
2003-11-28 17:38:39 +00:00
|
|
|
|
bcview().addReadOnly(dialog_->choice_unit_space);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
2003-11-28 17:38:39 +00:00
|
|
|
|
// check validity of "length + unit" input.
|
2003-11-29 20:13:51 +00:00
|
|
|
|
// If invalid, the label of input_space is displayed in red.
|
2003-11-28 15:53:34 +00:00
|
|
|
|
addCheckedGlueLength(bcview(),
|
|
|
|
|
dialog_->input_space,
|
2003-11-29 20:13:51 +00:00
|
|
|
|
dialog_->input_space);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
|
|
// trigger an input event for cut&paste with middle mouse button.
|
|
|
|
|
setPrehandler(dialog_->input_space);
|
|
|
|
|
|
|
|
|
|
fl_set_input_return(dialog_->input_space, FL_RETURN_CHANGED);
|
|
|
|
|
|
2003-11-28 17:38:39 +00:00
|
|
|
|
string const spacing =
|
2003-12-01 14:16:27 +00:00
|
|
|
|
_("DefSkip|SmallSkip|MedSkip|BigSkip|VFill|Length");
|
2003-11-28 17:38:39 +00:00
|
|
|
|
fl_addto_choice(dialog_->choice_space, spacing.c_str());
|
|
|
|
|
|
2003-11-28 15:53:34 +00:00
|
|
|
|
// Create the contents of the unit choices; don't include the "%" terms.
|
|
|
|
|
vector<string> units_vec = getLatexUnits();
|
|
|
|
|
vector<string>::iterator del =
|
|
|
|
|
remove_if(units_vec.begin(), units_vec.end(),
|
2004-02-01 12:46:14 +00:00
|
|
|
|
bind(contains<char>, _1, '%'));
|
2003-11-28 15:53:34 +00:00
|
|
|
|
units_vec.erase(del, units_vec.end());
|
|
|
|
|
|
|
|
|
|
string const units = getStringFromVector(units_vec, "|");
|
|
|
|
|
fl_addto_choice(dialog_->choice_unit_space, units.c_str());
|
|
|
|
|
|
|
|
|
|
// set up the tooltips
|
|
|
|
|
string str = _("Additional vertical space.");
|
|
|
|
|
tooltips().init(dialog_->choice_space, str);
|
|
|
|
|
|
|
|
|
|
// set default unit for custom length
|
|
|
|
|
switch (lyxrc.default_papersize) {
|
|
|
|
|
case PAPER_DEFAULT:
|
|
|
|
|
case PAPER_USLETTER:
|
|
|
|
|
case PAPER_LEGALPAPER:
|
|
|
|
|
case PAPER_EXECUTIVEPAPER:
|
|
|
|
|
defaultUnit = "in";
|
|
|
|
|
break;
|
|
|
|
|
case PAPER_A3PAPER:
|
|
|
|
|
case PAPER_A4PAPER:
|
|
|
|
|
case PAPER_A5PAPER:
|
|
|
|
|
case PAPER_B5PAPER:
|
|
|
|
|
defaultUnit = "cm";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FormVSpace::apply()
|
|
|
|
|
{
|
|
|
|
|
// If a vspace choice is "Length" but there's no text in
|
2003-12-01 14:16:27 +00:00
|
|
|
|
// the input field, insert nothing.
|
2003-11-28 15:53:34 +00:00
|
|
|
|
validateVSpaceWidgets(dialog_->choice_space, dialog_->input_space);
|
|
|
|
|
|
|
|
|
|
VSpace const space =
|
|
|
|
|
setVSpaceFromWidgets(dialog_->choice_space,
|
|
|
|
|
dialog_->input_space,
|
2003-11-29 20:13:51 +00:00
|
|
|
|
dialog_->choice_unit_space,
|
|
|
|
|
fl_get_button(dialog_->check_keep));
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
|
|
controller().params() = space;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FormVSpace::update()
|
|
|
|
|
{
|
|
|
|
|
setWidgetsFromVSpace(controller().params(),
|
|
|
|
|
dialog_->choice_space,
|
|
|
|
|
dialog_->input_space,
|
2003-11-29 20:13:51 +00:00
|
|
|
|
dialog_->choice_unit_space,
|
|
|
|
|
dialog_->check_keep);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
2003-11-28 17:38:39 +00:00
|
|
|
|
bool const custom_length =
|
2003-12-01 14:16:27 +00:00
|
|
|
|
fl_get_choice(dialog_->choice_space) == 6;
|
2003-11-28 17:38:39 +00:00
|
|
|
|
setEnabled(dialog_->input_space, custom_length);
|
|
|
|
|
setEnabled(dialog_->choice_unit_space, custom_length);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ButtonPolicy::SMInput FormVSpace::input(FL_OBJECT * ob, long)
|
|
|
|
|
{
|
2003-12-05 02:42:41 +00:00
|
|
|
|
// Enable input when custom length is chosen,
|
|
|
|
|
// disable 'keep' when no space is chosen
|
2003-11-28 15:53:34 +00:00
|
|
|
|
if (ob == dialog_->choice_space) {
|
|
|
|
|
bool const custom_length =
|
2003-12-01 14:16:27 +00:00
|
|
|
|
fl_get_choice(dialog_->choice_space) == 6;
|
2003-11-28 17:38:39 +00:00
|
|
|
|
setEnabled(dialog_->input_space, custom_length);
|
|
|
|
|
setEnabled(dialog_->choice_unit_space, custom_length);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
return ButtonPolicy::SMI_VALID;
|
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|