2002-03-11 17:00:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file FormParagraph.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.
|
2000-09-25 15:59:27 +00:00
|
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
2002-10-30 13:57:01 +00:00
|
|
|
|
* \author Rob Lahaye
|
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.
|
2002-03-11 17:00:41 +00:00
|
|
|
|
*/
|
2000-09-25 15:59:27 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "FormParagraph.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
|
#include "ControlParagraph.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
|
#include "forms/form_paragraph.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
|
|
|
|
|
|
#include "checkedwidgets.h"
|
|
|
|
|
#include "input_validators.h"
|
2002-10-30 13:57:01 +00:00
|
|
|
|
#include "Tooltips.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
|
#include "xforms_helpers.h"
|
|
|
|
|
#include "xformsBC.h"
|
2002-10-30 13:57:01 +00:00
|
|
|
|
|
2003-09-05 13:15:43 +00:00
|
|
|
|
#include "controllers/helper_funcs.h"
|
2002-10-30 13:57:01 +00:00
|
|
|
|
|
2002-01-04 15:14:22 +00:00
|
|
|
|
#include "lyxrc.h" // to set the deafult length values
|
2003-09-05 13:15:43 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2003-09-06 20:32:37 +00:00
|
|
|
|
#include "Spacing.h"
|
2000-09-25 15:59:27 +00:00
|
|
|
|
|
2002-01-16 16:34:03 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2003-05-13 14:36:24 +00:00
|
|
|
|
#include "support/tostr.h"
|
2002-10-30 13:57:01 +00:00
|
|
|
|
|
2003-05-14 09:17:22 +00:00
|
|
|
|
#include "lyx_forms.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2004-02-01 12:46:14 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
|
|
|
|
using boost::bind;
|
|
|
|
|
|
2002-02-18 10:08:42 +00:00
|
|
|
|
using std::remove_if;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2003-09-05 13:15:43 +00:00
|
|
|
|
using std::vector;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2000-09-25 15:59:27 +00:00
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::contains;
|
|
|
|
|
using support::getStringFromVector;
|
|
|
|
|
using support::rtrim;
|
|
|
|
|
|
|
|
|
|
namespace frontend {
|
2000-09-25 15:59:27 +00:00
|
|
|
|
|
2003-11-28 15:53:34 +00:00
|
|
|
|
namespace {
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
string defaultUnit("cm");
|
2002-03-20 17:53:39 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
} // namespace anon
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
|
typedef FormController<ControlParagraph, FormView<FD_paragraph> > base_class;
|
2002-10-30 13:57:01 +00:00
|
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
|
FormParagraph::FormParagraph(Dialog & parent)
|
2003-04-30 02:06:04 +00:00
|
|
|
|
: base_class(parent, _("Paragraph Settings"))
|
2002-10-30 13:57:01 +00:00
|
|
|
|
{}
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
void FormParagraph::build()
|
|
|
|
|
{
|
|
|
|
|
// the tabbed folder
|
|
|
|
|
dialog_.reset(build_paragraph(this));
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
|
|
|
|
// Manage the ok, apply, restore 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);
|
|
|
|
|
bcview().setRestore(dialog_->button_restore);
|
2002-06-11 16:40:18 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// disable for read-only documents
|
2003-03-10 03:13:28 +00:00
|
|
|
|
bcview().addReadOnly(dialog_->check_noindent);
|
|
|
|
|
bcview().addReadOnly(dialog_->choice_linespacing);
|
|
|
|
|
bcview().addReadOnly(dialog_->input_linespacing);
|
2002-10-30 13:57:01 +00:00
|
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
|
bcview().addReadOnly(dialog_->input_labelwidth);
|
2000-09-25 15:59:27 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// trigger an input event for cut&paste with middle mouse button.
|
|
|
|
|
setPrehandler(dialog_->input_linespacing);
|
|
|
|
|
setPrehandler(dialog_->input_labelwidth);
|
2002-03-20 18:47:43 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
fl_set_input_return(dialog_->input_labelwidth, FL_RETURN_CHANGED);
|
|
|
|
|
fl_set_input_return(dialog_->input_linespacing, FL_RETURN_CHANGED);
|
2002-03-20 17:53:39 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// limit these inputs to unsigned floats
|
|
|
|
|
fl_set_input_filter(dialog_->input_linespacing, fl_unsigned_float_filter);
|
2002-03-20 17:53:39 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// add alignment radio buttons
|
|
|
|
|
alignment_.init(dialog_->radio_align_left, LYX_ALIGN_LEFT);
|
|
|
|
|
alignment_.init(dialog_->radio_align_right, LYX_ALIGN_RIGHT);
|
|
|
|
|
alignment_.init(dialog_->radio_align_block, LYX_ALIGN_BLOCK);
|
|
|
|
|
alignment_.init(dialog_->radio_align_center, LYX_ALIGN_CENTER);
|
2002-03-20 17:53:39 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
string const linespacing = _("Default|Single|OneHalf|Double|Custom");
|
|
|
|
|
fl_addto_choice(dialog_->choice_linespacing, linespacing.c_str());
|
2002-03-20 18:47:43 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +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, '%'));
|
2002-10-30 13:57:01 +00:00
|
|
|
|
units_vec.erase(del, units_vec.end());
|
2002-03-20 18:47:43 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// set default unit for custom length
|
|
|
|
|
switch (lyxrc.default_papersize) {
|
2003-07-26 23:04:39 +00:00
|
|
|
|
case PAPER_DEFAULT:
|
|
|
|
|
case PAPER_USLETTER:
|
|
|
|
|
case PAPER_LEGALPAPER:
|
|
|
|
|
case PAPER_EXECUTIVEPAPER:
|
2002-10-30 13:57:01 +00:00
|
|
|
|
defaultUnit = "in";
|
|
|
|
|
break;
|
2003-07-26 23:04:39 +00:00
|
|
|
|
case PAPER_A3PAPER:
|
|
|
|
|
case PAPER_A4PAPER:
|
|
|
|
|
case PAPER_A5PAPER:
|
|
|
|
|
case PAPER_B5PAPER:
|
2002-10-30 13:57:01 +00:00
|
|
|
|
defaultUnit = "cm";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-03-20 18:47:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-20 17:53:39 +00:00
|
|
|
|
|
2001-08-29 12:52:41 +00:00
|
|
|
|
void FormParagraph::apply()
|
2000-10-10 01:33:42 +00:00
|
|
|
|
{
|
2003-11-28 15:53:34 +00:00
|
|
|
|
if (!form())
|
|
|
|
|
return;
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// alignment
|
|
|
|
|
LyXAlignment const alignment =
|
|
|
|
|
static_cast<LyXAlignment>(alignment_.get());
|
|
|
|
|
controller().params().align(alignment);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// label width
|
2002-03-20 17:53:39 +00:00
|
|
|
|
string const labelwidthstring =
|
2002-07-21 15:51:07 +00:00
|
|
|
|
getString(dialog_->input_labelwidth);
|
2002-06-11 16:40:18 +00:00
|
|
|
|
controller().params().labelWidthString(labelwidthstring);
|
2002-03-20 17:53:39 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// indendation
|
2002-03-20 17:53:39 +00:00
|
|
|
|
bool const noindent = fl_get_button(dialog_->check_noindent);
|
2002-06-11 16:40:18 +00:00
|
|
|
|
controller().params().noindent(noindent);
|
2002-03-20 17:53:39 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// get spacing
|
2002-03-19 21:42:50 +00:00
|
|
|
|
Spacing::Space linespacing = Spacing::Default;
|
2002-03-20 18:47:43 +00:00
|
|
|
|
string other;
|
2002-03-19 21:42:50 +00:00
|
|
|
|
switch (fl_get_choice(dialog_->choice_linespacing)) {
|
2002-03-20 18:47:43 +00:00
|
|
|
|
case 1:
|
|
|
|
|
linespacing = Spacing::Default;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
linespacing = Spacing::Single;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
linespacing = Spacing::Onehalf;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
linespacing = Spacing::Double;
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// reset to default if input is empty
|
2002-07-21 15:51:07 +00:00
|
|
|
|
other = getString(dialog_->input_linespacing);
|
2002-10-30 13:57:01 +00:00
|
|
|
|
if (!other.empty()) {
|
|
|
|
|
linespacing = Spacing::Other;
|
|
|
|
|
} else {
|
|
|
|
|
linespacing = Spacing::Default;
|
|
|
|
|
fl_set_choice(dialog_->choice_linespacing, 1);
|
|
|
|
|
}
|
2002-03-20 18:47:43 +00:00
|
|
|
|
break;
|
2002-03-19 21:42:50 +00:00
|
|
|
|
}
|
2002-03-20 18:47:43 +00:00
|
|
|
|
Spacing const spacing(linespacing, other);
|
2002-06-11 16:40:18 +00:00
|
|
|
|
controller().params().spacing(spacing);
|
2000-09-25 15:59:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-20 17:53:39 +00:00
|
|
|
|
|
2001-08-29 12:52:41 +00:00
|
|
|
|
void FormParagraph::update()
|
2000-09-25 15:59:27 +00:00
|
|
|
|
{
|
2002-03-19 21:42:50 +00:00
|
|
|
|
if (!dialog_.get())
|
|
|
|
|
return;
|
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// label width
|
|
|
|
|
string const labelwidth = controller().params().labelWidthString();
|
2002-06-11 16:40:18 +00:00
|
|
|
|
fl_set_input(dialog_->input_labelwidth, labelwidth.c_str());
|
2002-03-19 21:42:50 +00:00
|
|
|
|
setEnabled(dialog_->input_labelwidth,
|
2002-06-11 16:40:18 +00:00
|
|
|
|
labelwidth != _("Senseless with this layout!"));
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// alignment
|
|
|
|
|
alignment_.set(controller().params().align());
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// mark default alignment
|
|
|
|
|
LyXAlignment const default_alignment = controller().alignDefault();
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
string label = _("Block");
|
|
|
|
|
if (default_alignment == LYX_ALIGN_BLOCK) {
|
|
|
|
|
label += _(" (default)");
|
2002-03-19 21:42:50 +00:00
|
|
|
|
}
|
2002-10-30 13:57:01 +00:00
|
|
|
|
fl_set_object_label(dialog_->radio_align_block, label.c_str());
|
|
|
|
|
fl_set_button_shortcut(dialog_->radio_align_block, "#B", 1);
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
label = _("Center");
|
|
|
|
|
if (default_alignment == LYX_ALIGN_CENTER) {
|
|
|
|
|
label += _(" (default)");
|
|
|
|
|
}
|
|
|
|
|
fl_set_object_label(dialog_->radio_align_center, label.c_str());
|
|
|
|
|
fl_set_button_shortcut(dialog_->radio_align_center, "#C", 1);
|
|
|
|
|
|
|
|
|
|
label = _("Left");
|
|
|
|
|
if (default_alignment == LYX_ALIGN_LEFT) {
|
|
|
|
|
label += _(" (default)");
|
|
|
|
|
}
|
|
|
|
|
fl_set_object_label(dialog_->radio_align_left, label.c_str());
|
|
|
|
|
fl_set_button_shortcut(dialog_->radio_align_left, "#L", 1);
|
|
|
|
|
|
|
|
|
|
label = _("Right");
|
|
|
|
|
if (default_alignment == LYX_ALIGN_RIGHT) {
|
|
|
|
|
label = _(" (default)");
|
|
|
|
|
}
|
|
|
|
|
fl_set_object_label(dialog_->radio_align_right, label.c_str());
|
|
|
|
|
fl_set_button_shortcut(dialog_->radio_align_right, "#R", 1);
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// Ensure that there's no crud left on the screen from this change
|
|
|
|
|
// of labels.
|
|
|
|
|
fl_redraw_form(form());
|
|
|
|
|
|
|
|
|
|
LyXAlignment alignpos = controller().alignPossible();
|
|
|
|
|
setEnabled(dialog_->radio_align_block,
|
|
|
|
|
bool(alignpos & LYX_ALIGN_BLOCK));
|
|
|
|
|
setEnabled(dialog_->radio_align_center,
|
|
|
|
|
bool(alignpos & LYX_ALIGN_CENTER));
|
|
|
|
|
setEnabled(dialog_->radio_align_left,
|
|
|
|
|
bool(alignpos & LYX_ALIGN_LEFT));
|
|
|
|
|
setEnabled(dialog_->radio_align_right,
|
|
|
|
|
bool(alignpos & LYX_ALIGN_RIGHT));
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// lines, pagebreaks and indent
|
2002-03-19 21:42:50 +00:00
|
|
|
|
fl_set_button(dialog_->check_noindent,
|
2002-06-11 16:40:18 +00:00
|
|
|
|
controller().params().noindent());
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// linespacing
|
2002-06-11 16:40:18 +00:00
|
|
|
|
Spacing const space = controller().params().spacing();
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
int pos;
|
2002-03-19 21:42:50 +00:00
|
|
|
|
switch (space.getSpace()) {
|
2002-10-30 13:57:01 +00:00
|
|
|
|
case Spacing::Other:
|
|
|
|
|
pos = 5;
|
|
|
|
|
break;
|
|
|
|
|
case Spacing::Double:
|
|
|
|
|
pos = 4;
|
|
|
|
|
break;
|
|
|
|
|
case Spacing::Onehalf:
|
|
|
|
|
pos = 3;
|
|
|
|
|
break;
|
|
|
|
|
case Spacing::Single:
|
|
|
|
|
pos = 2;
|
|
|
|
|
break;
|
|
|
|
|
case Spacing::Default:
|
|
|
|
|
default:
|
|
|
|
|
pos = 1;
|
|
|
|
|
break;
|
2002-03-19 21:42:50 +00:00
|
|
|
|
}
|
2002-10-30 13:57:01 +00:00
|
|
|
|
fl_set_choice(dialog_->choice_linespacing, pos);
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
bool const spacing_other = space.getSpace() == Spacing::Other;
|
|
|
|
|
setEnabled(dialog_->input_linespacing, spacing_other);
|
|
|
|
|
if (spacing_other) {
|
2005-01-06 13:48:13 +00:00
|
|
|
|
fl_set_input(dialog_->input_linespacing,
|
|
|
|
|
space.getValueAsString().c_str());
|
2002-03-19 21:42:50 +00:00
|
|
|
|
} else {
|
|
|
|
|
fl_set_input(dialog_->input_linespacing, "");
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// no indent
|
2002-03-20 17:53:39 +00:00
|
|
|
|
fl_set_button(dialog_->check_noindent,
|
2002-06-11 16:40:18 +00:00
|
|
|
|
controller().params().noindent());
|
2002-03-20 17:53:39 +00:00
|
|
|
|
}
|
2002-03-19 21:42:50 +00:00
|
|
|
|
|
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
ButtonPolicy::SMInput FormParagraph::input(FL_OBJECT * ob, long)
|
2002-03-20 17:53:39 +00:00
|
|
|
|
{
|
2002-10-30 13:57:01 +00:00
|
|
|
|
// Enable input when custum length is choosen,
|
|
|
|
|
// disable 'keep' when no space is choosen
|
2003-11-28 15:53:34 +00:00
|
|
|
|
if (ob == dialog_->choice_linespacing) {
|
2002-10-30 13:57:01 +00:00
|
|
|
|
bool const custom_spacing =
|
|
|
|
|
fl_get_choice(dialog_->choice_linespacing) == 5;
|
|
|
|
|
setEnabled(dialog_->input_linespacing, custom_spacing);
|
|
|
|
|
}
|
2002-03-20 17:53:39 +00:00
|
|
|
|
|
2002-10-30 13:57:01 +00:00
|
|
|
|
return ButtonPolicy::SMI_VALID;
|
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|