Port wrap dialog to the new scheme.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6357 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-03-05 23:19:45 +00:00
parent fafd0dae3a
commit 80a4567bc2
26 changed files with 304 additions and 205 deletions

View File

@ -1,3 +1,8 @@
2003-03-05 Angus Leeming <leeming@lyx.org>
* Dialogs.h: remove showWrap.
* guiapi.[Ch]: remove gui_ShowWrap.
2003-03-05 Angus Leeming <leeming@lyx.org>
* Dialogs.h: remove showFloat.

View File

@ -23,7 +23,6 @@ class Dialog;
class InsetBase;
class LyXView;
class InsetWrap;
class InsetGraphics;
class InsetInfo;
class InsetMinipage;
@ -86,8 +85,6 @@ public:
void showDocument();
/// show the contents of a file.
void showFile(string const &);
///
void showWrap(InsetWrap *);
/// show all forked child processes
void showForks();
///

View File

@ -1,5 +1,7 @@
2003-03-05 Angus Leeming <leeming@lyx.org>
* ControlWrap.[Ch]: rewrite to use the Dialog-based scheme.
* ControlFloat.[Ch]: move insetfloat.h into the .C file.
* ControlFloat.[Ch]: rewrite to use the Dialog-based scheme.

View File

@ -10,38 +10,33 @@
#include <config.h>
#include "ControlWrap.h"
#include "BufferView.h"
#include "buffer.h"
#include "funcrequest.h"
#include "lyxlength.h"
#include "insets/insetwrap.h"
ControlWrap::ControlWrap(LyXView & lv, Dialogs & d)
: ControlInset<InsetWrap, WrapParams>(lv, d)
ControlWrap::ControlWrap(Dialog & parent)
: Dialog::Controller(parent)
{}
void ControlWrap::applyParamsToInset()
void ControlWrap::initialiseParams(string const & data)
{
inset()->pageWidth(params().pageWidth);
inset()->placement(params().placement);
bufferview()->updateInset(inset(), true);
InsetWrapParams params;
InsetWrapMailer::string2params(data, params);
params_.reset(new InsetWrapParams(params));
}
void ControlWrap::applyParamsNoInset()
{}
WrapParams const ControlWrap::getParams(InsetWrap const & inset)
void ControlWrap::clearParams()
{
return WrapParams(inset);
params_.reset();
}
WrapParams::WrapParams(InsetWrap const & inset)
: pageWidth(inset.pageWidth()),
placement(inset.placement())
{}
void ControlWrap::dispatchParams()
{
string const lfun = InsetWrapMailer::params2string("wrap", params());
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
}

View File

@ -12,58 +12,29 @@
#ifndef CONTROLWRAP_H
#define CONTROLWRAP_H
#include "Dialog.h"
#include "ControlInset.h"
#include "lyxlength.h"
class InsetWrapParams;
// needed to instatiate inset->hideDialog in ControlInset
#include "insets/insetwrap.h"
class InsetWrap;
///
struct WrapParams {
///
WrapParams() {}
///
WrapParams(InsetWrap const &);
///
LyXLength pageWidth;
///
string placement;
};
inline
bool operator==(WrapParams const & p1, WrapParams const & p2)
{
return p1.pageWidth == p2.pageWidth && p1.placement == p2.placement;
}
inline
bool operator!=(WrapParams const & p1, WrapParams const & p2)
{
return !(p1 == p2);
}
/** A controller for Minipage dialogs.
*/
class ControlWrap : public ControlInset<InsetWrap, WrapParams> {
class ControlWrap : public Dialog::Controller {
public:
///
ControlWrap(LyXView &, Dialogs &);
private:
/// Dispatch the changed parameters to the kernel.
virtual void applyParamsToInset();
ControlWrap(Dialog &);
///
virtual void applyParamsNoInset();
/// get the parameters from the string passed to createInset.
virtual WrapParams const getParams(string const &)
{ return WrapParams(); }
/// get the parameters from the inset passed to showInset.
virtual WrapParams const getParams(InsetWrap const &);
virtual void initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
///
InsetWrapParams & params() { return *params_.get(); }
///
InsetWrapParams const & params() const { return *params_.get(); }
private:
///
boost::scoped_ptr<InsetWrapParams> params_;
};
#endif

View File

@ -51,12 +51,6 @@ void gui_ShowFile(string const & f, Dialogs & d)
}
void gui_ShowWrap(InsetWrap * iw, Dialogs & d)
{
d.showWrap(iw);
}
void gui_ShowForks(Dialogs & d)
{
d.showForks();

View File

@ -16,7 +16,6 @@
#include "LString.h"
class Dialogs;
class InsetWrap;
class InsetGraphics;
class InsetMinipage;
class InsetTabular;
@ -50,7 +49,6 @@ void gui_ShowTabularCreate(Dialogs &);
void gui_ShowTexinfo(Dialogs &);
void gui_ShowThesaurus(string const &, Dialogs &);
void gui_ShowVCLogFile(Dialogs &);
void gui_ShowWrap(InsetWrap *, Dialogs &);
} // extern "C"

View File

@ -1,3 +1,13 @@
2003-03-05 Angus Leeming <leeming@lyx.org>
* QWrap.[Ch]: changes to use the new Dialog-based scheme.
* Dialogs.C:
* Dialogs2.C:
* Dialogs_impl.h: remove wrap dialog.
* Dialogs3.C: add wrap dialog.
2003-03-05 Angus Leeming <leeming@lyx.org>
* QFloat.[Ch]: changes to use the new Dialog-based scheme.

View File

@ -48,6 +48,5 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d)
thesaurus(lv, d),
#endif
vclogfile(lv, d),
wrap(lv, d)
vclogfile(lv, d)
{}

View File

@ -179,9 +179,3 @@ void Dialogs::showVCLogFile()
{
pimpl_->vclogfile.controller().show();
}
void Dialogs::showWrap(InsetWrap * iw)
{
pimpl_->wrap.controller().showInset(iw);
}

View File

@ -26,6 +26,7 @@
#include "ControlRef.h"
#include "ControlToc.h"
#include "ControlUrl.h"
#include "ControlWrap.h"
#include "QBibitem.h"
#include "QBibitemDialog.h"
@ -55,6 +56,8 @@
#include "QTocDialog.h"
#include "QURL.h"
#include "QURLDialog.h"
#include "QWrap.h"
#include "QWrapDialog.h"
#include "Qt2BC.h"
#include "ButtonController.h"
@ -78,7 +81,7 @@ namespace {
char const * const dialognames[] = { "bibitem", "bibtex", "citation",
"error", "ert", "external", "float",
"include", "index", "label", "ref",
"toc", "url" };
"toc", "url", "wrap" };
char const * const * const end_dialognames =
dialognames + (sizeof(dialognames) / sizeof(char *));
@ -166,6 +169,10 @@ Dialog * Dialogs::build(string const & name)
dialog->setController(new ControlUrl(*dialog));
dialog->setView(new QURL(*dialog));
dialog->setButtonController(new NoRepeatedApplyReadOnlyBC);
} else if (name == "wrap") {
dialog->setController(new ControlWrap(*dialog));
dialog->setView(new QWrap(*dialog));
dialog->setButtonController(new NoRepeatedApplyReadOnlyBC);
}
return dialog;

View File

@ -34,7 +34,6 @@
#include "ControlTabular.h"
#include "ControlTexinfo.h"
#include "ControlVCLog.h"
#include "ControlWrap.h"
#include "QAbout.h"
#include "QAboutDialog.h"
@ -84,8 +83,6 @@
#include "QVCLog.h"
#include "QVCLogDialog.h"
#include "QWrap.h"
#include "QWrapDialog.h"
#include "Qt2BC.h"
@ -150,9 +147,6 @@ ThesaurusDialog;
typedef GUI<ControlVCLog, QVCLog, OkCancelPolicy, Qt2BC>
VCLogFileDialog;
typedef GUI<ControlWrap, QWrap, NoRepeatedApplyReadOnlyPolicy, Qt2BC>
WrapDialog;
struct Dialogs::Impl {
Impl(LyXView & lv, Dialogs & d);
@ -180,7 +174,6 @@ struct Dialogs::Impl {
#endif
VCLogFileDialog vclogfile;
WrapDialog wrap;
};
#endif // DIALOGS_IMPL_H

View File

@ -10,7 +10,6 @@
#include <config.h>
#include "debug.h"
#include "qt_helpers.h"
#include "support/lstrings.h"
@ -22,15 +21,18 @@
#include "Qt2BC.h"
#include "lengthcombo.h"
#include "insets/insetwrap.h"
#include <qpushbutton.h>
#include <qcombobox.h>
#include <qlineedit.h>
typedef Qt2CB<ControlWrap, Qt2DB<QWrapDialog> > base_class;
typedef QController<ControlWrap, QView<QWrapDialog> > base_class;
QWrap::QWrap()
: base_class(qt_("LyX: Text-wrapping Settings"))
QWrap::QWrap(Dialog & parent)
: base_class(parent, qt_("LyX: Text-wrapping Settings"))
{
}
@ -57,9 +59,9 @@ void QWrap::apply()
if (dialog_->widthED->text().isEmpty())
unit = LyXLength::UNIT_NONE;
WrapParams & params = controller().params();
InsetWrapParams & params = controller().params();
params.pageWidth = LyXLength(value, unit);
params.width = LyXLength(value, unit);
switch (dialog_->valignCO->currentItem()) {
case 0:
@ -92,9 +94,9 @@ string const numtostr(double val) {
void QWrap::update_contents()
{
WrapParams & params = controller().params();
InsetWrapParams & params = controller().params();
LyXLength len(params.pageWidth);
LyXLength len(params.width);
dialog_->widthED->setText(toqstr(numtostr(len.value())));
dialog_->unitsLC->setCurrentItem(len.unit());

View File

@ -13,19 +13,18 @@
#define QWRAP_H
#include "Qt2Base.h"
#include "QDialogView.h"
class ControlWrap;
class QWrapDialog;
class QWrap
: public Qt2CB<ControlWrap, Qt2DB<QWrapDialog> >
{
class QWrap : public QController<ControlWrap, QView<QWrapDialog> > {
public:
friend class QWrapDialog;
QWrap();
QWrap(Dialog &);
private:
/// Apply changes
virtual void apply();

View File

@ -1,3 +1,14 @@
2003-03-05 Angus Leeming <leeming@lyx.org>
* FormWrap.[Ch]:
* forms/form_wrap.fd: changes to use the new Dialog-based scheme.
* Dialogs.C:
* Dialogs2.C:
* Dialogs_impl.h: remove wrap dialog.
* Dialogs3.C: add wrap dialog.
2003-03-05 Angus Leeming <leeming@lyx.org>
* FormFloat.[Ch]:

View File

@ -51,6 +51,5 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d)
thesaurus(lv, d),
#endif
vclogfile(lv, d),
wrap(lv, d)
vclogfile(lv, d)
{}

View File

@ -178,9 +178,3 @@ void Dialogs::showVCLogFile()
{
pimpl_->vclogfile.controller().show();
}
void Dialogs::showWrap(InsetWrap * iw)
{
pimpl_->wrap.controller().showInset(iw);
}

View File

@ -65,6 +65,10 @@
#include "FormUrl.h"
#include "forms/form_url.h"
#include "ControlWrap.h"
#include "FormWrap.h"
#include "forms/form_wrap.h"
#include "xformsBC.h"
#include "ButtonController.h"
@ -92,7 +96,7 @@ namespace {
char const * const dialognames[] = { "bibitem", "bibtex", "citation",
"error", "ert", "external", "float",
"include", "index", "label", "ref",
"toc", "url" };
"toc", "url", "wrap" };
char const * const * const end_dialognames =
dialognames + (sizeof(dialognames) / sizeof(char *));
@ -178,6 +182,10 @@ Dialog * Dialogs::build(string const & name)
dialog->setController(new ControlUrl(*dialog));
dialog->setView(new FormUrl(*dialog));
dialog->setButtonController(new NoRepeatedApplyReadOnlyBC);
} else if (name == "wrap") {
dialog->setController(new ControlWrap(*dialog));
dialog->setView(new FormWrap(*dialog));
dialog->setButtonController(new NoRepeatedApplyReadOnlyBC);
}
return dialog;

View File

@ -108,11 +108,6 @@
#include "ControlVCLog.h"
#include "FormVCLog.h"
#include "ControlWrap.h"
#include "FormWrap.h"
#include "forms/form_wrap.h"
typedef GUI<ControlAboutlyx, FormAboutlyx, OkCancelPolicy, xformsBC>
AboutlyxDialog;
@ -181,9 +176,6 @@ ThesaurusDialog;
typedef GUI<ControlVCLog, FormVCLog, OkCancelPolicy, xformsBC>
VCLogFileDialog;
typedef GUI<ControlWrap, FormWrap, NoRepeatedApplyReadOnlyPolicy, xformsBC>
WrapDialog;
struct Dialogs::Impl {
Impl(LyXView & lv, Dialogs & d);
@ -213,7 +205,6 @@ struct Dialogs::Impl {
#endif
VCLogFileDialog vclogfile;
WrapDialog wrap;
};
#endif // DIALOGS_IMPL_H

View File

@ -10,24 +10,24 @@
#include <config.h>
#include "xformsBC.h"
#include "ControlWrap.h"
#include "FormWrap.h"
#include "forms/form_wrap.h"
#include "Tooltips.h"
#include "support/lstrings.h"
#include "helper_funcs.h"
#include "xforms_helpers.h"
#include "checkedwidgets.h"
#include "insets/insetwrap.h"
#include "support/lstrings.h"
#include FORMS_H_LOCATION
typedef FormCB<ControlWrap, FormDB<FD_wrap> > base_class;
typedef FormController<ControlWrap, FormView<FD_wrap> > base_class;
FormWrap::FormWrap()
: base_class(_("Wrap Options"))
FormWrap::FormWrap(Dialog & parent)
: base_class(parent, _("Wrap Options"))
{}
@ -80,26 +80,29 @@ void FormWrap::build()
void FormWrap::apply()
{
controller().params().pageWidth =
InsetWrapParams & params = controller().params();
params.width =
LyXLength(getLengthFromWidgets(dialog_->input_width,
dialog_->choice_width_units));
char const c = static_cast<char>(placement_.get());
if (c)
controller().params().placement = c;
params.placement = c;
else
controller().params().placement.erase(); // default
params.placement.erase(); // default
}
void FormWrap::update()
{
LyXLength len(controller().params().pageWidth);
InsetWrapParams const & params = controller().params();
LyXLength len(params.width);
fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
if (controller().params().placement.empty())
if (params.placement.empty())
placement_.set(dialog_->radio_default); // default
else
placement_.set(controller().params().placement.c_str()[0]);
placement_.set(params.placement.c_str()[0]);
}

View File

@ -13,7 +13,7 @@
#define FORMWRAP_H
#include "FormBase.h"
#include "FormDialogView.h"
#include "RadioButtonGroup.h"
class ControlWrap;
@ -23,10 +23,10 @@ struct FD_wrap;
Dialog.
*/
class FormWrap
: public FormCB<ControlWrap, FormDB<FD_wrap> > {
: public FormController<ControlWrap, FormView<FD_wrap> > {
public:
///
FormWrap();
FormWrap(Dialog &);
private:
/// Set the Params variable for the Controller.
virtual void apply();

View File

@ -64,7 +64,7 @@ shortcut:
resize: FL_RESIZE_X
gravity: FL_West FL_NoGravity
name: input_width
callback: C_FormBaseInputCB
callback: C_FormDialogView_InputCB
argument: 0
--------------------
@ -82,7 +82,7 @@ shortcut:
resize: FL_RESIZE_X
gravity: FL_NoGravity FL_NoGravity
name: choice_width_units
callback: C_FormBaseInputCB
callback: C_FormDialogView_InputCB
argument: 0
--------------------
@ -118,7 +118,7 @@ shortcut:
resize: FL_RESIZE_NONE
gravity: FL_NoGravity FL_NoGravity
name: radio_left
callback: C_FormBaseInputCB
callback: C_FormDialogView_InputCB
argument: 0
--------------------
@ -136,7 +136,7 @@ shortcut:
resize: FL_RESIZE_NONE
gravity: FL_NoGravity FL_NoGravity
name: radio_right
callback: C_FormBaseInputCB
callback: C_FormDialogView_InputCB
argument: 0
--------------------
@ -154,7 +154,7 @@ shortcut:
resize: FL_RESIZE_NONE
gravity: FL_NoGravity FL_NoGravity
name: radio_outer
callback: C_FormBaseInputCB
callback: C_FormDialogView_InputCB
argument: 0
--------------------
@ -172,7 +172,7 @@ shortcut:
resize: FL_RESIZE_NONE
gravity: FL_NoGravity FL_NoGravity
name: radio_default
callback: C_FormBaseInputCB
callback: C_FormDialogView_InputCB
argument: 0
--------------------
@ -208,7 +208,7 @@ shortcut:
resize: FL_RESIZE_NONE
gravity: FL_SouthEast FL_SouthEast
name: button_close
callback: C_FormBaseCancelCB
callback: C_FormDialogView_CancelCB
argument: 0
--------------------
@ -226,7 +226,7 @@ shortcut:
resize: FL_RESIZE_NONE
gravity: FL_SouthEast FL_SouthEast
name: button_apply
callback: C_FormBaseApplyCB
callback: C_FormDialogView_ApplyCB
argument: 0
--------------------
@ -244,7 +244,7 @@ shortcut: ^M
resize: FL_RESIZE_NONE
gravity: FL_SouthEast FL_SouthEast
name: button_ok
callback: C_FormBaseOKCB
callback: C_FormDialogView_OKCB
argument: 0
--------------------
@ -262,7 +262,7 @@ shortcut:
resize: FL_RESIZE_NONE
gravity: FL_SouthWest FL_SouthWest
name: button_restore
callback: C_FormBaseRestoreCB
callback: C_FormDialogView_RestoreCB
argument: 0
==============================

View File

@ -1,3 +1,8 @@
2003-03-05 Angus Leeming <leeming@lyx.org>
* insetwrap.[Ch]: define a new class InsetWrapMailer and use
it to communicate with the frontend dialogs.
2003-03-05 Angus Leeming <leeming@lyx.org>
* insetcollapsable.C (draw): cache the BufferView.

View File

@ -17,7 +17,6 @@
#include "insetcollapsable.h"
#include "toc.h"
class Painter;
struct InsetFloatParams {
///
@ -46,10 +45,8 @@ public:
InsetFloat(InsetFloat const &, bool same_id = false);
///
~InsetFloat();
///
virtual dispatch_result localDispatch(FuncRequest const & cmd);
///
void write(Buffer const * buf, std::ostream & os) const;
///

View File

@ -10,22 +10,25 @@
#include <config.h>
#include "insetwrap.h"
#include "gettext.h"
#include "lyxfont.h"
#include "BufferView.h"
#include "lyxtext.h"
#include "insets/insettext.h"
#include "support/LOstream.h"
#include "support/lstrings.h"
#include "LaTeXFeatures.h"
#include "debug.h"
#include "insettext.h"
#include "buffer.h"
#include "BufferView.h"
#include "debug.h"
#include "funcrequest.h"
#include "FloatList.h"
#include "gettext.h"
#include "LaTeXFeatures.h"
#include "lyxfont.h"
#include "lyxlex.h"
#include "lyxtext.h"
#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
#include "lyxlex.h"
#include "FloatList.h"
#include "support/LOstream.h"
#include "support/lstrings.h"
using std::ostream;
using std::endl;
@ -49,7 +52,7 @@ string floatname(string const & type, BufferParams const & bp)
InsetWrap::InsetWrap(BufferParams const & bp, string const & type)
: InsetCollapsable(bp), width_(50, LyXLength::PCW)
: InsetCollapsable(bp)
{
string lab(_("wrap: "));
lab += floatname(type, bp);
@ -59,7 +62,8 @@ InsetWrap::InsetWrap(BufferParams const & bp, string const & type)
font.decSize();
font.setColor(LColor::collapsable);
setLabelFont(font);
Type_ = type;
params_.type = type;
params_.width = LyXLength(50, LyXLength::PCW);
setInsetName(type);
LyXTextClass const & tclass = bp.getLyXTextClass();
if (tclass.hasLayout(caplayout))
@ -68,39 +72,61 @@ InsetWrap::InsetWrap(BufferParams const & bp, string const & type)
InsetWrap::InsetWrap(InsetWrap const & in, bool same_id)
: InsetCollapsable(in, same_id), Type_(in.Type_),
Placement_(in.Placement_), width_(in.width_)
: InsetCollapsable(in, same_id), params_(in.params_)
{}
InsetWrap::~InsetWrap()
{
hideDialog();
InsetWrapMailer mailer(*this);
mailer.hideDialog();
}
void InsetWrap::write(Buffer const * buf, ostream & os) const
dispatch_result InsetWrap::localDispatch(FuncRequest const & cmd)
{
Inset::RESULT result = UNDISPATCHED;
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetWrapParams params;
InsetWrapMailer::string2params(cmd.argument, params);
params_.placement = params.placement;
params_.width = params.width;
cmd.view()->updateInset(this, true);
result = DISPATCHED;
}
break;
default:
result = InsetCollapsable::localDispatch(cmd);
}
return result;
}
void InsetWrapParams::write(ostream & os) const
{
os << "Wrap " // getInsetName()
<< Type_ << '\n';
<< type << '\n';
if (!Placement_.empty()) {
os << "placement " << Placement_ << "\n";
if (!placement.empty()) {
os << "placement " << placement << "\n";
}
os << "width \"" << width_.asString() << "\"\n";
InsetCollapsable::write(buf, os);
os << "width \"" << width.asString() << "\"\n";
}
void InsetWrap::read(Buffer const * buf, LyXLex & lex)
void InsetWrapParams::read(LyXLex & lex)
{
if (lex.isOK()) {
lex.next();
string token = lex.getString();
if (token == "placement") {
lex.next();
Placement_ = lex.getString();
placement = lex.getString();
} else {
// take countermeasures
lex.pushToken(token);
@ -111,7 +137,7 @@ void InsetWrap::read(Buffer const * buf, LyXLex & lex)
string token = lex.getString();
if (token == "width") {
lex.next();
width_ = LyXLength(lex.getString());
width = LyXLength(lex.getString());
} else {
lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
<< endl;
@ -119,6 +145,19 @@ void InsetWrap::read(Buffer const * buf, LyXLex & lex)
lex.pushToken(token);
}
}
}
void InsetWrap::write(Buffer const * buf, ostream & os) const
{
params_.write(os);
InsetCollapsable::write(buf, os);
}
void InsetWrap::read(Buffer const * buf, LyXLex & lex)
{
params_.read(lex);
InsetCollapsable::read(buf, lex);
}
@ -145,24 +184,24 @@ string const InsetWrap::editMessage() const
int InsetWrap::latex(Buffer const * buf,
ostream & os, bool fragile, bool fp) const
{
os << "\\begin{floating" << Type_ << '}';
if (!Placement_.empty()) {
os << '[' << Placement_ << ']';
os << "\\begin{floating" << params_.type << '}';
if (!params_.placement.empty()) {
os << '[' << params_.placement << ']';
}
os << '{' << width_.asLatexString() << "}%\n";
os << '{' << params_.width.asLatexString() << "}%\n";
int const i = inset.latex(buf, os, fragile, fp);
os << "\\end{floating" << Type_ << "}%\n";
os << "\\end{floating" << params_.type << "}%\n";
return i + 2;
}
int InsetWrap::docbook(Buffer const * buf, ostream & os, bool mixcont) const
{
os << '<' << Type_ << '>';
os << '<' << params_.type << '>';
int const i = inset.docbook(buf, os, mixcont);
os << "</" << Type_ << '>';
os << "</" << params_.type << '>';
return i;
}
@ -188,7 +227,7 @@ int InsetWrap::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
static_cast<UpdatableInset*>(owner())->getMaxWidth(bv, inset) < 0) {
return -1;
}
if (!width_.zero()) {
if (!params_.width.zero()) {
int const ww1 = latexTextWidth(bv);
int const ww2 = InsetCollapsable::getMaxWidth(bv, inset);
if (ww2 > 0 && ww2 < ww1) {
@ -203,26 +242,26 @@ int InsetWrap::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
int InsetWrap::latexTextWidth(BufferView * bv) const
{
return width_.inPixels(InsetCollapsable::latexTextWidth(bv));
return params_.width.inPixels(InsetCollapsable::latexTextWidth(bv));
}
string const & InsetWrap::type() const
{
return Type_;
return params_.type;
}
LyXLength const & InsetWrap::pageWidth() const
{
return width_;
return params_.width;
}
void InsetWrap::pageWidth(LyXLength const & ll)
{
if (ll != width_) {
width_ = ll;
if (ll != params_.width) {
params_.width = ll;
need_update = FULL;
}
}
@ -230,20 +269,22 @@ void InsetWrap::pageWidth(LyXLength const & ll)
void InsetWrap::placement(string const & p)
{
Placement_ = p;
params_.placement = p;
}
string const & InsetWrap::placement() const
{
return Placement_;
return params_.placement;
}
bool InsetWrap::showInsetDialog(BufferView * bv) const
{
if (!inset.showInsetDialog(bv)) {
bv->owner()->getDialogs().showWrap(const_cast<InsetWrap *>(this));
InsetWrap * tmp = const_cast<InsetWrap *>(this);
InsetWrapMailer mailer(*tmp);
mailer.showDialog();
}
return true;
}
@ -267,3 +308,51 @@ void InsetWrap::addToToc(toc::TocList & toclist, Buffer const * buf) const
tmp = tmp->next();
}
}
InsetWrapMailer::InsetWrapMailer(InsetWrap & inset)
: name_("wrap"), inset_(inset)
{}
string const InsetWrapMailer::inset2string() const
{
return params2string(name(), inset_.params());
}
void InsetWrapMailer::string2params(string const & in,
InsetWrapParams & params)
{
params = InsetWrapParams();
string name;
string body = split(in, name, ' ');
if (name != "wrap" || body.empty())
return;
// This is part of the inset proper that is usually swallowed
// by Buffer::readInset
body = split(body, name, '\n');
if (!prefixIs(name, "Wrap "))
return;
istringstream data(body);
LyXLex lex(0,0);
lex.setStream(data);
params.read(lex);
}
string const
InsetWrapMailer::params2string(string const & name,
InsetWrapParams const & params)
{
ostringstream data;
data << name << ' ';
params.write(data);
return data.str();
}

View File

@ -16,13 +16,24 @@
#include "toc.h"
#include "lyxlength.h"
#include <boost/signals/signal0.hpp>
class Painter;
struct InsetWrapParams {
///
void write(std::ostream &) const;
///
void read(LyXLex &);
///
string type;
///
string placement;
///
LyXLength width;
};
/** The wrap inset
*/
*/
class InsetWrap : public InsetCollapsable {
public:
///
@ -32,6 +43,8 @@ public:
///
~InsetWrap();
///
virtual dispatch_result localDispatch(FuncRequest const & cmd);
///
void write(Buffer const * buf, std::ostream & os) const;
///
void read(Buffer const * buf, LyXLex & lex);
@ -66,16 +79,39 @@ public:
///
bool showInsetDialog(BufferView *) const;
///
boost::signal0<void> hideDialog;
///
int latexTextWidth(BufferView *) const;
///
InsetWrapParams const & params() const { return params_; }
private:
///
string Type_;
InsetWrapParams params_;
};
#include "mailinset.h"
class InsetWrapMailer : public MailInset {
public:
///
string Placement_;
InsetWrapMailer(InsetWrap & inset);
///
LyXLength width_;
virtual Inset & inset() const { return inset_; }
///
virtual string const & name() const { return name_; }
///
virtual string const inset2string() const;
///
static void string2params(string const &, InsetWrapParams &);
///
static string const params2string(string const & name,
InsetWrapParams const &);
private:
///
string const name_;
///
InsetWrap & inset_;
};
#endif