*
* LyX, The Document Processor
*
- * Copyright 2000 The LyX Team.
+ * Copyright 2000-2001 The LyX Team.
*
* @author Jürgen Vigna
*
#include "buffer.h"
#include "lyxtext.h"
#include "xforms_helpers.h"
+#include "lyxrc.h" // to set the deafult length values
+#include "BufferView.h"
+#include "lyxtextclasslist.h"
+#include "Spacing.h"
+#include "ParagraphParameters.h"
+#include "input_validators.h"
+#include "helper_funcs.h"
+
+#include "support/lstrings.h"
+
+#include <functional>
-#ifdef CXX_WORKING_NAMESPACES
using Liason::setMinibuffer;
-#endif
+using SigC::slot;
+using std::vector;
+using std::bind2nd;
+using std::remove_if;
+
FormParagraph::FormParagraph(LyXView * lv, Dialogs * d)
- : FormBaseBD(lv, d, _("Paragraph Layout"))
+ : FormBaseBD(lv, d, _("Paragraph Layout")), par_(0)
{
- // let the popup be shown
+ // let the dialog be shown
// This is a permanent connection so we won't bother
// storing a copy because we won't be disconnecting.
- d->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
+ d->showParagraph.connect(slot(this, &FormParagraph::show));
}
-void FormParagraph::redraw()
+void FormParagraph::connect()
+{
+ cp_ = d_->updateParagraph
+ .connect(slot(this, &FormParagraph::changedParagraph));
+ FormBaseBD::connect();
+}
+
+
+void FormParagraph::disconnect()
+{
+ cp_.disconnect();
+ FormBaseBD::disconnect();
+}
+
+
+Paragraph const * FormParagraph::getCurrentParagraph() const
+{
+ return lv_->view()->getLyXText()->cursor.par();
+}
+
+
+void FormParagraph::changedParagraph()
{
- if( form() && form()->visible )
- fl_redraw_form( form() );
- else
+ /// Record the paragraph
+ Paragraph const * const p = getCurrentParagraph();
+ if (p == 0 || p == par_)
return;
+#ifdef WITH_WARNINGS
+#warning Please someone of you GUII people have a look at this!
+#endif
+ // shouldn't we chage the par_ pointer too?
+ // anyway for me the below function does just nothing!
+ // (Jug 20020108)
- FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
- if (outer_form && outer_form->visible)
- fl_redraw_form( outer_form );
+ // For now don't bother checking if the params are different,
+ // just activate the Apply button
+ bc().valid();
+}
+
+
+void FormParagraph::redraw()
+{
+ if (form() && form()->visible)
+ fl_redraw_form(form());
}
void FormParagraph::build()
{
// the tabbed folder
- dialog_.reset(build_tabbed_paragraph());
-
- // Workaround dumb xforms sizing bug
- minw_ = form()->w;
- minh_ = form()->h;
+ dialog_.reset(build_paragraph());
- // Manage the ok, apply, restore and cancel/close buttons
- bc_.setOK(dialog_->button_ok);
- bc_.setApply(dialog_->button_apply);
- bc_.setCancel(dialog_->button_cancel);
- bc_.setUndoAll(dialog_->button_restore);
- bc_.refresh();
-
- // the general paragraph data form
- general_.reset(build_paragraph_general());
-
- fl_addto_choice(general_->choice_space_above,
+ fl_addto_choice(dialog_->choice_space_above,
_(" None | Defskip | Smallskip "
"| Medskip | Bigskip | VFill | Length "));
- fl_addto_choice(general_->choice_space_below,
+ fl_addto_choice(dialog_->choice_space_below,
_(" None | Defskip | Smallskip "
"| Medskip | Bigskip | VFill | Length "));
- fl_set_input_return(general_->input_space_above, FL_RETURN_CHANGED);
- fl_set_input_return(general_->input_space_below, FL_RETURN_CHANGED);
- fl_set_input_return(general_->input_labelwidth, FL_RETURN_CHANGED);
-
- bc_.addReadOnly (general_->radio_align_right);
- bc_.addReadOnly (general_->radio_align_left);
- bc_.addReadOnly (general_->radio_align_block);
- bc_.addReadOnly (general_->radio_align_center);
- bc_.addReadOnly (general_->check_lines_top);
- bc_.addReadOnly (general_->check_lines_bottom);
- bc_.addReadOnly (general_->check_pagebreaks_top);
- bc_.addReadOnly (general_->check_pagebreaks_bottom);
- bc_.addReadOnly (general_->choice_space_above);
- bc_.addReadOnly (general_->input_space_above);
- bc_.addReadOnly (general_->check_space_above);
- bc_.addReadOnly (general_->choice_space_below);
- bc_.addReadOnly (general_->input_space_below);
- bc_.addReadOnly (general_->check_space_below);
- bc_.addReadOnly (general_->check_noindent);
- bc_.addReadOnly (general_->input_labelwidth);
-
- // the document class form
- extra_.reset(build_paragraph_extra());
-
- fl_set_input_return(extra_->input_pextra_width, FL_RETURN_CHANGED);
- fl_set_input_return(extra_->input_pextra_widthp, FL_RETURN_CHANGED);
-
- bc_.addReadOnly (extra_->radio_pextra_indent);
- bc_.addReadOnly (extra_->radio_pextra_minipage);
- bc_.addReadOnly (extra_->radio_pextra_floatflt);
- bc_.addReadOnly (extra_->radio_pextra_hfill);
- bc_.addReadOnly (extra_->radio_pextra_startmp);
-
- // now make them fit together
- fl_addto_tabfolder(dialog_->tabbed_folder,_("General"), general_->form);
- fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"), extra_->form);
+ fl_addto_choice(dialog_->choice_linespacing,
+ _(" Default | Single | OneHalf | Double | Other "));
+
+ fl_set_input_return(dialog_->input_space_above, FL_RETURN_CHANGED);
+ fl_set_input_return(dialog_->input_space_below, FL_RETURN_CHANGED);
+ fl_set_input_return(dialog_->input_labelwidth, FL_RETURN_CHANGED);
+ fl_set_input_return(dialog_->input_linespacing, FL_RETURN_CHANGED);
+ fl_set_input_filter(dialog_->input_linespacing, fl_unsigned_float_filter);
+
+ // Create the contents of the unit choices
+ // Don't include the "%" terms...
+#warning A bit dangerous... (Lgb)
+ vector<string> units_vec = getLatexUnits();
+#if 0
+ for (vector<string>::iterator it = units_vec.begin();
+ it != units_vec.end(); ++it) {
+ if (contains(*it, "%"))
+ it = units_vec.erase(it, it+1) - 1;
+ }
+#else
+ // Something similar to this is a better way to erase
+ vector<string>::iterator del =
+ remove_if(units_vec.begin(), units_vec.end(),
+ bind2nd(contains_functor(), "%"));
+ units_vec.erase(del, units_vec.end());
+#endif
+
+ string units = getStringFromVector(units_vec, "|");
+
+ fl_addto_choice(dialog_->choice_value_space_above, units.c_str());
+ fl_addto_choice(dialog_->choice_value_space_below, units.c_str());
+
+ // Manage the ok, apply, restore and cancel/close buttons
+ bc_.setOK(dialog_->button_ok);
+ bc_.setApply(dialog_->button_apply);
+ bc_.setCancel(dialog_->button_cancel);
+ bc_.setRestore(dialog_->button_restore);
+
+ bc_.addReadOnly (dialog_->group_radio_alignment);
+ // bc_.addReadOnly (dialog_->radio_align_right);
+ // bc_.addReadOnly (dialog_->radio_align_left);
+ // bc_.addReadOnly (dialog_->radio_align_block);
+ // bc_.addReadOnly (dialog_->radio_align_center);
+ bc_.addReadOnly (dialog_->check_lines_top);
+ bc_.addReadOnly (dialog_->check_lines_bottom);
+ bc_.addReadOnly (dialog_->check_pagebreaks_top);
+ bc_.addReadOnly (dialog_->check_pagebreaks_bottom);
+ bc_.addReadOnly (dialog_->choice_space_above);
+ bc_.addReadOnly (dialog_->input_space_above);
+ bc_.addReadOnly (dialog_->check_space_above);
+ bc_.addReadOnly (dialog_->choice_space_below);
+ bc_.addReadOnly (dialog_->input_space_below);
+ bc_.addReadOnly (dialog_->check_space_below);
+ bc_.addReadOnly (dialog_->choice_linespacing);
+ bc_.addReadOnly (dialog_->input_linespacing);
+ bc_.addReadOnly (dialog_->check_noindent);
+ bc_.addReadOnly (dialog_->input_labelwidth);
}
if (!lv_->view()->available() || !dialog_.get())
return;
- general_apply();
- extra_apply();
-
- lv_->view()->update(lv_->view()->text,
- BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
- lv_->buffer()->markDirty();
- setMinibuffer(lv_, _("Paragraph layout set"));
-}
-
-
-void FormParagraph::update()
-{
- if (!dialog_.get())
- return;
-
- general_update();
- extra_update();
- bc_.readOnly(lv_->buffer()->isReadonly());
-}
-
-
-void FormParagraph::general_apply()
-{
VSpace space_top, space_bottom;
LyXAlignment align;
string labelwidthstring;
// If a vspace kind is "Length" but there's no text in
// the input field, reset the kind to "None".
- if ((fl_get_choice (general_->choice_space_above) == 7) &&
- !*(fl_get_input (general_->input_space_above)))
+ if ((fl_get_choice (dialog_->choice_space_above) == 7) &&
+ !*(fl_get_input (dialog_->input_space_above)))
{
- fl_set_choice (general_->choice_space_above, 1);
+ fl_set_choice (dialog_->choice_space_above, 1);
}
- if ((fl_get_choice (general_->choice_space_below) == 7) &&
- !*(fl_get_input (general_->input_space_below)))
+ if ((fl_get_choice (dialog_->choice_space_below) == 7) &&
+ !*(fl_get_input (dialog_->input_space_below)))
{
- fl_set_choice (general_->choice_space_below, 1);
+ fl_set_choice (dialog_->choice_space_below, 1);
}
- bool line_top = fl_get_button(general_->check_lines_top);
- bool line_bottom = fl_get_button(general_->check_lines_bottom);
- bool pagebreak_top = fl_get_button(general_->check_pagebreaks_top);
- bool pagebreak_bottom = fl_get_button(general_->check_pagebreaks_bottom);
+ bool line_top = fl_get_button(dialog_->check_lines_top);
+ bool line_bottom = fl_get_button(dialog_->check_lines_bottom);
+ bool pagebreak_top = fl_get_button(dialog_->check_pagebreaks_top);
+ bool pagebreak_bottom = fl_get_button(dialog_->check_pagebreaks_bottom);
- switch (fl_get_choice (general_->choice_space_above)) {
+ switch (fl_get_choice (dialog_->choice_space_above)) {
case 1:
space_top = VSpace(VSpace::NONE);
break;
space_top = VSpace(VSpace::VFILL);
break;
case 7:
+ {
+ string const length =
+ getLengthFromWidgets(dialog_->input_space_above,
+ dialog_->choice_value_space_above);
space_top =
- VSpace(LyXGlueLength(fl_get_input(general_->input_space_above)));
+ VSpace(LyXGlueLength(length));
break;
}
- if (fl_get_button (general_->check_space_above))
+ }
+
+ if (fl_get_button (dialog_->check_space_above))
space_top.setKeep (true);
- switch (fl_get_choice (general_->choice_space_below)) {
+ switch (fl_get_choice (dialog_->choice_space_below)) {
case 1:
space_bottom = VSpace(VSpace::NONE);
break;
space_bottom = VSpace(VSpace::VFILL);
break;
case 7:
- space_bottom =
- VSpace(LyXGlueLength(fl_get_input(general_->input_space_below)));
+ string const length =
+ getLengthFromWidgets(dialog_->input_space_below,
+ dialog_->choice_value_space_below);
+ space_bottom = VSpace(LyXGlueLength(length));
break;
}
- if (fl_get_button (general_->check_space_below))
+ if (fl_get_button (dialog_->check_space_below))
space_bottom.setKeep (true);
- if (fl_get_button(general_->radio_align_left))
+ if (fl_get_button(dialog_->radio_align_left))
align = LYX_ALIGN_LEFT;
- else if (fl_get_button(general_->radio_align_right))
+ else if (fl_get_button(dialog_->radio_align_right))
align = LYX_ALIGN_RIGHT;
- else if (fl_get_button(general_->radio_align_center))
+ else if (fl_get_button(dialog_->radio_align_center))
align = LYX_ALIGN_CENTER;
else
align = LYX_ALIGN_BLOCK;
- labelwidthstring = fl_get_input(general_->input_labelwidth);
- noindent = fl_get_button(general_->check_noindent);
-
- LyXText * text = 0;
- if (lv_->view()->theLockingInset())
- text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
- if (!text)
- text = lv_->view()->text;
- text->SetParagraph(lv_->view(), line_top, line_bottom, pagebreak_top,
- pagebreak_bottom, space_top, space_bottom, align,
- labelwidthstring, noindent);
-}
+ labelwidthstring = fl_get_input(dialog_->input_labelwidth);
+ noindent = fl_get_button(dialog_->check_noindent);
+ Spacing::Space linespacing = Spacing::Default;
+ string other_linespacing;
+ switch (fl_get_choice(dialog_->choice_linespacing)) {
+ 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:
+ linespacing = Spacing::Other;
+ other_linespacing = fl_get_input(dialog_->input_linespacing);
+ break;
+ }
+ Spacing const spacing(linespacing, other_linespacing);
+ LyXText * text(lv_->view()->getLyXText());
+ text->setParagraph(lv_->view(), line_top, line_bottom, pagebreak_top,
+ pagebreak_bottom, space_top, space_bottom, spacing,
+ align, labelwidthstring, noindent);
-void FormParagraph::extra_apply()
-{
- char const * width = fl_get_input(extra_->input_pextra_width);
- char const * widthp = fl_get_input(extra_->input_pextra_widthp);
- LyXText * text = lv_->view()->text;
- int type = LyXParagraph::PEXTRA_NONE;
- LyXParagraph::MINIPAGE_ALIGNMENT
- alignment = LyXParagraph::MINIPAGE_ALIGN_TOP;
- bool
- hfill = false,
- start_minipage = false;
-
- if (fl_get_button(extra_->radio_pextra_indent)) {
- type = LyXParagraph::PEXTRA_INDENT;
- } else if (fl_get_button(extra_->radio_pextra_minipage)) {
- type = LyXParagraph::PEXTRA_MINIPAGE;
- hfill = fl_get_button(extra_->radio_pextra_hfill);
- start_minipage = fl_get_button(extra_->radio_pextra_startmp);
- if (fl_get_button(extra_->radio_pextra_top))
- alignment = LyXParagraph::MINIPAGE_ALIGN_TOP;
- else if (fl_get_button(extra_->radio_pextra_middle))
- alignment = LyXParagraph::MINIPAGE_ALIGN_MIDDLE;
- else if (fl_get_button(extra_->radio_pextra_bottom))
- alignment = LyXParagraph::MINIPAGE_ALIGN_BOTTOM;
- } else if (fl_get_button(extra_->radio_pextra_floatflt)) {
- type = LyXParagraph::PEXTRA_FLOATFLT;
- }
- text->SetParagraphExtraOpt(lv_->view(), type, width, widthp, alignment,
- hfill, start_minipage);
+
+ // Actually apply these settings
+ lv_->view()->update(text,
+ BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
+ lv_->buffer()->markDirty();
+ setMinibuffer(lv_, _("Paragraph layout set"));
}
-void FormParagraph::general_update()
+void FormParagraph::update()
{
- if (!general_.get())
+ if (!dialog_.get())
return;
+ // Do this first; some objects may be de/activated subsequently.
+ bc_.readOnly(lv_->buffer()->isReadonly());
+
Buffer * buf = lv_->view()->buffer();
- LyXText * text = 0;
- if (lv_->view()->theLockingInset())
- text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
- if (!text)
- text = lv_->view()->text;
+ /// Record the paragraph
+ par_ = getCurrentParagraph();
+
+ fl_set_input(dialog_->input_labelwidth,
+ par_->getLabelWidthString().c_str());
+ setEnabled(dialog_->input_labelwidth,
+ (par_->getLabelWidthString() != _("Senseless with this layout!")));
- fl_set_input(general_->input_labelwidth,
- text->cursor.par()->GetLabelWidthString().c_str());
- fl_set_button(general_->radio_align_right, 0);
- fl_set_button(general_->radio_align_left, 0);
- fl_set_button(general_->radio_align_center, 0);
- fl_set_button(general_->radio_align_block, 0);
+ fl_set_button(dialog_->radio_align_right, 0);
+ fl_set_button(dialog_->radio_align_left, 0);
+ fl_set_button(dialog_->radio_align_center, 0);
+ fl_set_button(dialog_->radio_align_block, 0);
- int align = text->cursor.par()->GetAlign();
+ LyXTextClass const & tclass = textclasslist[buf->params.textclass];
+
+ int align = par_->getAlign();
if (align == LYX_ALIGN_LAYOUT)
- align = textclasslist.Style(buf->params.textclass,
- text->cursor.par()->GetLayout()).align;
-
+ align = tclass[par_->layout()].align;
+
switch (align) {
case LYX_ALIGN_RIGHT:
- fl_set_button(general_->radio_align_right, 1);
+ fl_set_button(dialog_->radio_align_right, 1);
break;
case LYX_ALIGN_LEFT:
- fl_set_button(general_->radio_align_left, 1);
+ fl_set_button(dialog_->radio_align_left, 1);
break;
case LYX_ALIGN_CENTER:
- fl_set_button(general_->radio_align_center, 1);
+ fl_set_button(dialog_->radio_align_center, 1);
break;
default:
- fl_set_button(general_->radio_align_block, 1);
+ fl_set_button(dialog_->radio_align_block, 1);
break;
}
-#ifndef NEW_INSETS
- fl_set_button(general_->check_lines_top,
- text->cursor.par()->FirstPhysicalPar()->params.lineTop());
-
- fl_set_button(general_->check_lines_bottom,
- text->cursor.par()->FirstPhysicalPar()->params.lineBottom());
-
- fl_set_button(general_->check_pagebreaks_top,
- text->cursor.par()->FirstPhysicalPar()->params.pagebreakTop());
+ LyXAlignment alignpos = tclass[par_->layout()].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));
- fl_set_button(general_->check_pagebreaks_bottom,
- text->cursor.par()->FirstPhysicalPar()->params.pagebreakBottom());
- fl_set_button(general_->check_noindent,
- text->cursor.par()->FirstPhysicalPar()->params.noindent());
-#else
- fl_set_button(general_->check_lines_top,
- text->cursor.par()->params.lineTop());
- fl_set_button(general_->check_lines_bottom,
- text->cursor.par()->params.lineBottom());
- fl_set_button(general_->check_pagebreaks_top,
- text->cursor.par()->params.pagebreakTop());
- fl_set_button(general_->check_pagebreaks_bottom,
- text->cursor.par()->params.pagebreakBottom());
- fl_set_button(general_->check_noindent,
- text->cursor.par()->params.noindent());
-#endif
- fl_set_input (general_->input_space_above, "");
+ // no inset-text-owned paragraph may have pagebreaks
+ setEnabled(dialog_->check_pagebreaks_top, !par_->inInset());
+ setEnabled(dialog_->check_pagebreaks_bottom, !par_->inInset());
+
+ fl_set_button(dialog_->check_lines_top,
+ par_->params().lineTop());
+ fl_set_button(dialog_->check_lines_bottom,
+ par_->params().lineBottom());
+ fl_set_button(dialog_->check_pagebreaks_top,
+ par_->params().pagebreakTop());
+ fl_set_button(dialog_->check_pagebreaks_bottom,
+ par_->params().pagebreakBottom());
+ fl_set_button(dialog_->check_noindent,
+ par_->params().noindent());
+
+ int linespacing;
+ Spacing const space = par_->params().spacing();
+
+ switch (space.getSpace()) {
+ default: linespacing = 1; break;
+ case Spacing::Single: linespacing = 2; break;
+ case Spacing::Onehalf: linespacing = 3; break;
+ case Spacing::Double: linespacing = 4; break;
+ case Spacing::Other: linespacing = 5; break;
+ }
+
+ fl_set_choice(dialog_->choice_linespacing, linespacing);
+ if (space.getSpace() == Spacing::Other) {
+ string const sp = tostr(space.getValue());
+ fl_set_input(dialog_->input_linespacing, sp.c_str());
+ setEnabled(dialog_->input_linespacing, true);
+ } else {
+ fl_set_input(dialog_->input_linespacing, "");
+ setEnabled(dialog_->input_linespacing, false);
+ }
-#ifndef NEW_INSETS
- switch (text->cursor.par()->FirstPhysicalPar()->params.spaceTop().kind()) {
-#else
- switch (text->cursor.par()->params.spaceTop().kind()) {
-#endif
+ fl_set_input (dialog_->input_space_above, "");
+ setEnabled(dialog_->input_space_above, false);
+ setEnabled(dialog_->choice_value_space_above, false);
+ switch (par_->params().spaceTop().kind()) {
case VSpace::NONE:
- fl_set_choice (general_->choice_space_above, 1);
+ fl_set_choice (dialog_->choice_space_above, 1);
break;
case VSpace::DEFSKIP:
- fl_set_choice (general_->choice_space_above, 2);
+ fl_set_choice (dialog_->choice_space_above, 2);
break;
case VSpace::SMALLSKIP:
- fl_set_choice (general_->choice_space_above, 3);
+ fl_set_choice (dialog_->choice_space_above, 3);
break;
case VSpace::MEDSKIP:
- fl_set_choice (general_->choice_space_above, 4);
+ fl_set_choice (dialog_->choice_space_above, 4);
break;
case VSpace::BIGSKIP:
- fl_set_choice (general_->choice_space_above, 5);
+ fl_set_choice (dialog_->choice_space_above, 5);
break;
case VSpace::VFILL:
- fl_set_choice (general_->choice_space_above, 6);
+ fl_set_choice (dialog_->choice_space_above, 6);
break;
case VSpace::LENGTH:
- fl_set_choice (general_->choice_space_above, 7);
-#ifndef NEW_INSETS
- fl_set_input(general_->input_space_above,
- text->cursor.par()->FirstPhysicalPar()->
- params.spaceTop().length().asString().c_str());
-#else
- fl_set_input(general_->input_space_above, text->cursor.par()->
- params.spaceTop().length().asString().c_str());
-#endif
+ {
+ fl_set_choice (dialog_->choice_space_above, 7);
+ setEnabled(dialog_->input_space_above, true);
+ setEnabled(dialog_->choice_value_space_above, true);
+ bool const metric = lyxrc.default_papersize > 3;
+ string const default_unit = metric ? "cm" : "in";
+ string const length = par_->params().spaceTop().length().asString();
+ updateWidgetsFromLengthString(dialog_->input_space_above,
+ dialog_->choice_value_space_above,
+ length, default_unit);
break;
}
-#ifndef NEW_INSETS
- fl_set_button(general_->check_space_above,
- text->cursor.par()->FirstPhysicalPar()->
- params.spaceTop().keep());
- fl_set_input(general_->input_space_below, "");
- switch (text->cursor.par()->FirstPhysicalPar()->
- params.spaceBottom().kind()) {
-#else
- fl_set_button (general_->check_space_above,
- text->cursor.par()->params.spaceTop().keep());
- fl_set_input (general_->input_space_below, "");
- switch (text->cursor.par()->params.spaceBottom().kind()) {
-#endif
+ }
+
+ fl_set_button (dialog_->check_space_above,
+ par_->params().spaceTop().keep());
+ fl_set_input (dialog_->input_space_below, "");
+
+ setEnabled(dialog_->input_space_below, false);
+ setEnabled(dialog_->choice_value_space_below, false);
+ switch (par_->params().spaceBottom().kind()) {
case VSpace::NONE:
- fl_set_choice (general_->choice_space_below, 1);
+ fl_set_choice (dialog_->choice_space_below, 1);
break;
case VSpace::DEFSKIP:
- fl_set_choice (general_->choice_space_below, 2);
+ fl_set_choice (dialog_->choice_space_below, 2);
break;
case VSpace::SMALLSKIP:
- fl_set_choice (general_->choice_space_below, 3);
+ fl_set_choice (dialog_->choice_space_below, 3);
break;
case VSpace::MEDSKIP:
- fl_set_choice (general_->choice_space_below, 4);
+ fl_set_choice (dialog_->choice_space_below, 4);
break;
case VSpace::BIGSKIP:
- fl_set_choice (general_->choice_space_below, 5);
+ fl_set_choice (dialog_->choice_space_below, 5);
break;
case VSpace::VFILL:
- fl_set_choice (general_->choice_space_below, 6);
+ fl_set_choice (dialog_->choice_space_below, 6);
break;
case VSpace::LENGTH:
- fl_set_choice (general_->choice_space_below, 7);
-#ifndef NEW_INSETS
- fl_set_input(general_->input_space_below,
- text->cursor.par()->FirstPhysicalPar()->
- params.spaceBottom().length().asString().c_str());
+ {
+ fl_set_choice (dialog_->choice_space_below, 7);
+ setEnabled(dialog_->input_space_below, true);
+ setEnabled(dialog_->choice_value_space_below, true);
+ bool const metric = lyxrc.default_papersize > 3;
+ string const default_unit = metric ? "cm" : "in";
+ string const length =
+ par_->params().spaceBottom().length().asString();
+ updateWidgetsFromLengthString(dialog_->input_space_below,
+ dialog_->choice_value_space_below,
+ length, default_unit);
break;
}
- fl_set_button(general_->check_space_below,
- text->cursor.par()->FirstPhysicalPar()->
- params.spaceBottom().keep());
- fl_set_button(general_->check_noindent,
- text->cursor.par()->FirstPhysicalPar()->params.noindent());
-
- bool const enable = (!text->cursor.par()->FirstPhysicalPar()->InInset());
-
- setEnabled(general_->check_pagebreaks_top, enable);
- setEnabled(general_->check_pagebreaks_bottom, enable);
-
- if (!enable) {
- fl_set_button(general_->check_pagebreaks_top, 0);
- fl_set_button(general_->check_pagebreaks_bottom, 0);
- }
-
-#else
- fl_set_input(general_->input_space_below, text->cursor.par()->
- params.spaceBottom().length().asString().c_str());
- break;
}
- fl_set_button(general_->check_space_below,
- text->cursor.par()->params.spaceBottom().keep());
- fl_set_button(general_->check_noindent,
- text->cursor.par()->params.noindent());
-#endif
-}
-
-
-void FormParagraph::extra_update()
-{
- if (!lv_->view()->available() || !extra_.get())
- return;
- LyXParagraph * par = lv_->view()->text->cursor.par();
-
- setEnabled(extra_->input_pextra_width, true);
- setEnabled(extra_->input_pextra_widthp, true);
-
- fl_set_input(extra_->input_pextra_width,
- par->params.pextraWidth().c_str());
- fl_set_input(extra_->input_pextra_widthp,
- par->params.pextraWidthp().c_str());
- switch (par->params.pextraAlignment()) {
- case LyXParagraph::MINIPAGE_ALIGN_TOP:
- fl_set_button(extra_->radio_pextra_top, 1);
- break;
- case LyXParagraph::MINIPAGE_ALIGN_MIDDLE:
- fl_set_button(extra_->radio_pextra_middle, 1);
- break;
- case LyXParagraph::MINIPAGE_ALIGN_BOTTOM:
- fl_set_button(extra_->radio_pextra_bottom, 1);
- break;
- }
- fl_set_button(extra_->radio_pextra_hfill,
- par->params.pextraHfill());
- fl_set_button(extra_->radio_pextra_startmp,
- par->params.pextraStartMinipage());
- if (par->params.pextraType() == LyXParagraph::PEXTRA_INDENT) {
- fl_set_button(extra_->radio_pextra_indent, 1);
- fl_set_button(extra_->radio_pextra_minipage, 0);
- fl_set_button(extra_->radio_pextra_floatflt, 0);
- setEnabled(extra_->radio_pextra_top, false);
- setEnabled(extra_->radio_pextra_middle, false);
- setEnabled(extra_->radio_pextra_bottom, false);
- input(extra_->radio_pextra_indent, 0);
- } else if (par->params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE) {
- fl_set_button(extra_->radio_pextra_indent, 0);
- fl_set_button(extra_->radio_pextra_minipage, 1);
- fl_set_button(extra_->radio_pextra_floatflt, 0);
- setEnabled(extra_->radio_pextra_top, true);
- setEnabled(extra_->radio_pextra_middle, true);
- setEnabled(extra_->radio_pextra_bottom, true);
- input(extra_->radio_pextra_minipage, 0);
- } else if (par->params.pextraType() == LyXParagraph::PEXTRA_FLOATFLT) {
- fl_set_button(extra_->radio_pextra_indent, 0);
- fl_set_button(extra_->radio_pextra_minipage, 0);
- fl_set_button(extra_->radio_pextra_floatflt, 1);
- setEnabled(extra_->radio_pextra_top, false);
- setEnabled(extra_->radio_pextra_middle, false);
- setEnabled(extra_->radio_pextra_bottom, false);
- input(extra_->radio_pextra_floatflt, 0);
- } else {
- fl_set_button(extra_->radio_pextra_indent, 0);
- fl_set_button(extra_->radio_pextra_minipage, 0);
- fl_set_button(extra_->radio_pextra_floatflt, 0);
- setEnabled(extra_->input_pextra_width, false);
- setEnabled(extra_->input_pextra_widthp, false);
- setEnabled(extra_->radio_pextra_top, false);
- setEnabled(extra_->radio_pextra_middle, false);
- setEnabled(extra_->radio_pextra_bottom, false);
- input(0, 0);
- }
- fl_hide_object(dialog_->text_warning);
+ fl_set_button(dialog_->check_space_below,
+ par_->params().spaceBottom().keep());
+ fl_set_button(dialog_->check_noindent,
+ par_->params().noindent());
}
bool FormParagraph::input(FL_OBJECT * ob, long)
{
- bool ret = true;
+ bool valid = true;
fl_hide_object(dialog_->text_warning);
// First check the buttons which are exclusive and you have to
// check only the actuall de/activated button.
//
- // general form first
- //
// "Synchronize" the choices and input fields, making it
// impossible to commit senseless data.
- if (fl_get_choice (general_->choice_space_above) != 7)
- fl_set_input (general_->input_space_above, "");
-
- if (fl_get_choice (general_->choice_space_below) != 7)
- fl_set_input (general_->input_space_below, "");
-
- //
- // then the extra form
- //
- if (ob == extra_->radio_pextra_indent) {
- bool const enable = (fl_get_button(extra_->radio_pextra_indent) != 0);
-
- if (enable) {
- fl_set_button(extra_->radio_pextra_minipage, 0);
- fl_set_button(extra_->radio_pextra_floatflt, 0);
- }
-
- setEnabled(extra_->input_pextra_width, enable);
- setEnabled(extra_->input_pextra_widthp, enable);
-
- setEnabled(extra_->radio_pextra_top, false);
- setEnabled(extra_->radio_pextra_middle, false);
- setEnabled(extra_->radio_pextra_bottom, false);
- setEnabled(extra_->radio_pextra_hfill, false);
- setEnabled(extra_->radio_pextra_startmp, false);
-
- } else if (ob == extra_->radio_pextra_minipage) {
- bool const enable = (fl_get_button(extra_->radio_pextra_minipage) != 0);
-
- if (enable) {
- fl_set_button(extra_->radio_pextra_indent, 0);
- fl_set_button(extra_->radio_pextra_floatflt, 0);
- }
-
- setEnabled(extra_->input_pextra_width, enable);
- setEnabled(extra_->input_pextra_widthp, enable);
- setEnabled(extra_->radio_pextra_top, enable);
- setEnabled(extra_->radio_pextra_middle, enable);
- setEnabled(extra_->radio_pextra_bottom, enable);
- setEnabled(extra_->radio_pextra_hfill, enable);
- setEnabled(extra_->radio_pextra_startmp, enable);
- } else if (ob == extra_->radio_pextra_floatflt) {
- bool const enable = (fl_get_button(extra_->radio_pextra_floatflt) != 0);
-
- if (enable) {
- fl_set_button(extra_->radio_pextra_indent, 0);
- fl_set_button(extra_->radio_pextra_minipage, 0);
- }
-
- setEnabled(extra_->input_pextra_width, enable);
- setEnabled(extra_->input_pextra_widthp, enable);
-
- setEnabled(extra_->radio_pextra_top, false);
- setEnabled(extra_->radio_pextra_middle, false);
- setEnabled(extra_->radio_pextra_bottom, false);
- setEnabled(extra_->radio_pextra_hfill, false);
- setEnabled(extra_->radio_pextra_startmp, false);
+ if (ob == dialog_->choice_space_above) {
+ if (fl_get_choice (dialog_->choice_space_above) != 7) {
+ fl_set_input (dialog_->input_space_above, "");
+ setEnabled (dialog_->input_space_above, false);
+ setEnabled (dialog_->choice_value_space_above, false);
+ } else {
+ setEnabled (dialog_->input_space_above, !lv_->buffer()->isReadonly());
+ setEnabled (dialog_->choice_value_space_above, !lv_->buffer()->isReadonly());
+ bool const metric = lyxrc.default_papersize > 3;
+ int const default_unit = metric ? 8 : 9;
+ if (strip(fl_get_input(dialog_->input_space_above)).empty())
+ fl_set_choice(dialog_->choice_value_space_above,
+ default_unit);
+ }
}
-
+ if (ob == dialog_->choice_space_below) {
+ if (fl_get_choice (dialog_->choice_space_below) != 7) {
+ fl_set_input (dialog_->input_space_below, "");
+ setEnabled (dialog_->input_space_below, false);
+ setEnabled (dialog_->choice_value_space_below, false);
+ } else {
+ setEnabled (dialog_->input_space_below, !lv_->buffer()->isReadonly());
+ setEnabled (dialog_->choice_value_space_below, !lv_->buffer()->isReadonly());
+ bool const metric = lyxrc.default_papersize > 3;
+ int const default_unit = metric ? 8 : 9;
+ if (strip(fl_get_input(dialog_->input_space_below)).empty())
+ fl_set_choice(dialog_->choice_value_space_below,
+ default_unit);
+ }
+ }
+
//
- // first the general form
+ // warnings if input is senseless
//
- string input = fl_get_input (general_->input_space_above);
+ string input = fl_get_input (dialog_->input_space_above);
bool invalid = false;
-
- if (fl_get_choice(general_->choice_space_above)==7)
- invalid = !input.empty() && !isValidGlueLength(input);
- input = fl_get_input (general_->input_space_below);
+ if (fl_get_choice(dialog_->choice_space_above)==7)
+ invalid = !input.empty() && !isValidGlueLength(input) && !isStrDbl(input);
- if (fl_get_choice(general_->choice_space_below)==7)
- invalid = invalid || (!input.empty() && !isValidGlueLength(input));
-
- if (ob == general_->input_space_above || ob == general_->input_space_below) {
- if (invalid) {
+ input = fl_get_input (dialog_->input_space_below);
+
+ if (fl_get_choice(dialog_->choice_space_below)==7)
+ invalid = invalid
+ || (!input.empty() && !isValidGlueLength(input) && !isStrDbl(input));
+
+ if (ob == dialog_->input_space_above || ob == dialog_->input_space_below) {
+ if (invalid) {
fl_set_object_label(dialog_->text_warning,
_("Warning: Invalid Length (valid example: 10mm)"));
fl_show_object(dialog_->text_warning);
}
}
- //
- // then the extra form
- //
- int n = fl_get_button(extra_->radio_pextra_indent) +
- fl_get_button(extra_->radio_pextra_minipage) +
- fl_get_button(extra_->radio_pextra_floatflt);
- string s1 = fl_get_input(extra_->input_pextra_width);
- string s2 = fl_get_input(extra_->input_pextra_widthp);
- if (!n) { // no button pressed both should be deactivated now
- setEnabled(extra_->input_pextra_width, false);
- setEnabled(extra_->input_pextra_widthp, false);
- fl_hide_object(dialog_->text_warning);
- } else if (s1.empty() && s2.empty()) {
- setEnabled(extra_->input_pextra_width, true);
- setEnabled(extra_->input_pextra_widthp, true);
- fl_hide_object(dialog_->text_warning);
- ret = false;
- } else if (!s1.empty()) { // LyXLength parameter
- setEnabled(extra_->input_pextra_width, true);
- setEnabled(extra_->input_pextra_widthp, false);
- if (!isValidLength(s1)) {
- fl_set_object_label(dialog_->text_warning,
- _("Warning: Invalid Length (valid example: 10mm)"));
- fl_show_object(dialog_->text_warning);
- ret = false;
- }
- } else { // !s2.empty() % parameter
- setEnabled(extra_->input_pextra_width, false);
- setEnabled(extra_->input_pextra_widthp, true);
- if ((lyx::atoi(s2) < 0 ) || (lyx::atoi(s2) > 100)) {
- ret = false;
- fl_set_object_label(dialog_->text_warning,
- _("Warning: Invalid percent value (0-100)"));
- fl_show_object(dialog_->text_warning);
- }
+ if (fl_get_choice (dialog_->choice_linespacing) == 5)
+ setEnabled (dialog_->input_linespacing, true);
+ else {
+ setEnabled (dialog_->input_linespacing, false);
+ fl_set_input (dialog_->input_linespacing, "");
}
- return ret;
-}
+ double spacing(strToDbl(fl_get_input(dialog_->input_linespacing)));
+
+ if (fl_get_choice (dialog_->choice_linespacing) == 5
+ && int(spacing) == 0)
+ valid = false;
+
+ return valid;
+}