From bc56bb9ffadbdf457153547851986cf867d22aa1 Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Tue, 10 Sep 2002 10:18:58 +0000 Subject: [PATCH] Add insetwrap. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5247 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ui/default.ui | 1 + src/ChangeLog | 4 + src/LyXAction.C | 7 +- src/buffer.C | 5 + src/commandtags.h | 1 + src/factory.C | 7 + src/frontends/Dialogs.h | 3 + src/frontends/controllers/ControlFloat.h | 2 - src/frontends/controllers/ControlWrap.C | 55 ++++ src/frontends/controllers/ControlWrap.h | 72 ++++++ src/frontends/controllers/Makefile.am | 2 + src/frontends/guiapi.C | 4 + src/frontends/guiapi.h | 2 + src/frontends/xforms/Dialogs.C | 3 +- src/frontends/xforms/Dialogs2.C | 6 + src/frontends/xforms/Dialogs_impl.h | 8 + src/frontends/xforms/FormWrap.C | 123 +++++++++ src/frontends/xforms/FormWrap.h | 43 ++++ src/frontends/xforms/Makefile.am | 2 + src/frontends/xforms/forms/Makefile.am | 1 + src/frontends/xforms/forms/form_wrap.fd | 304 +++++++++++++++++++++++ src/insets/Makefile.am | 2 + src/insets/inset.h | 2 + src/insets/insetwrap.C | 231 +++++++++++++++++ src/insets/insetwrap.h | 81 ++++++ src/lyxfunc.C | 3 + src/text2.C | 4 +- src/text3.C | 1 + 28 files changed, 972 insertions(+), 7 deletions(-) create mode 100644 src/frontends/controllers/ControlWrap.C create mode 100644 src/frontends/controllers/ControlWrap.h create mode 100644 src/frontends/xforms/FormWrap.C create mode 100644 src/frontends/xforms/FormWrap.h create mode 100644 src/frontends/xforms/forms/form_wrap.fd create mode 100644 src/insets/insetwrap.C create mode 100644 src/insets/insetwrap.h diff --git a/lib/ui/default.ui b/lib/ui/default.ui index f10987b2d3..a6de103448 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -250,6 +250,7 @@ Menuset Menu "insert_floats" FloatInsert + Item "Floatflt Figure" "wrap-insert figure" End Menu "insert_toc" diff --git a/src/ChangeLog b/src/ChangeLog index c55f71f2a6..d22d3c724b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2002-09-10 Dekel Tsur + + * many files: Add insetwrap. + 2002-09-09 John Levon * text2.C: remove confusing and awkward depth wraparound diff --git a/src/LyXAction.C b/src/LyXAction.C index b42c04528c..a12086705f 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -196,12 +196,13 @@ void LyXAction::init() { LFUN_FILE_INSERT_ASCII, "file-insert-ascii", _("Insert ASCII files as lines"), Noop }, { LFUN_FILE_INSERT_ASCII_PARA, "file-insert-ascii-para", _("Insert ASCII file as a paragraph"), Noop }, { LFUN_FILE_NEW, "file-new", "", NoBuffer }, - { LFUN_FILE_OPEN, "file-open", _("Open a file"), NoBuffer }, + { LFUN_FILE_OPEN, "file-open", N_("Open a file"), NoBuffer }, { LFUN_MENUSEARCH, "find-replace", N_("Find & Replace"), ReadOnly }, - { LFUN_INSET_FLOAT, "float-insert", "Insert a Float", Noop }, + { LFUN_INSET_FLOAT, "float-insert", N_("Insert a Float"), Noop }, { LFUN_INSET_WIDE_FLOAT, "float-wide-insert", - "Insert a wide Float", Noop }, + N_("Insert a wide Float"), Noop }, + { LFUN_INSET_WRAP, "wrap-insert", N_("Insert a Wrap"), Noop }, { LFUN_BOLD, "font-bold", N_("Toggle bold"), Noop }, { LFUN_CODE, "font-code", N_("Toggle code style"), Noop }, { LFUN_DEFAULT, "font-default", N_("Default font style"), diff --git a/src/buffer.C b/src/buffer.C index 7538be4e6d..610f3dd2cd 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -75,6 +75,7 @@ #include "insets/insetoptarg.h" #include "insets/insetminipage.h" #include "insets/insetfloat.h" +#include "insets/insetwrap.h" #include "insets/insettabular.h" #if 0 #include "insets/insettheorem.h" @@ -1116,6 +1117,10 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par, lex.next(); string tmptok = lex.getString(); inset = new InsetFloat(params, tmptok); + } else if (tmptok == "Wrap") { + lex.next(); + string tmptok = lex.getString(); + inset = new InsetWrap(params, tmptok); #if 0 } else if (tmptok == "List") { inset = new InsetList; diff --git a/src/commandtags.h b/src/commandtags.h index 1ef2827646..fd6692bee9 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -289,6 +289,7 @@ enum kb_action { LFUN_MOUSE_DOUBLE, // André 9 Aug 2002 LFUN_MOUSE_TRIPLE, // André 9 Aug 2002 LFUN_EDIT, // André 16 Aug 2002 + LFUN_INSET_WRAP, // Dekel 7 Apr 2002 LFUN_LASTACTION /* this marks the end of the table */ }; diff --git a/src/factory.C b/src/factory.C index 11d0832578..520da4ba22 100644 --- a/src/factory.C +++ b/src/factory.C @@ -23,6 +23,7 @@ #include "insets/insettext.h" #include "insets/insettoc.h" #include "insets/inseturl.h" +#include "insets/insetwrap.h" #include "frontends/Dialogs.h" #include "frontends/LyXView.h" @@ -74,6 +75,12 @@ Inset * createInset(FuncRequest const & cmd) lyxerr << "Non-existent float type: " << cmd.argument << endl; return 0; + case LFUN_INSET_WRAP: + if (cmd.argument == "figure") + return new InsetWrap(params, cmd.argument); + lyxerr << "Non-existent floatflt type: " << cmd.argument << endl; + return 0; + case LFUN_INDEX_INSERT: { string entry = cmd.argument; if (entry.empty()) diff --git a/src/frontends/Dialogs.h b/src/frontends/Dialogs.h index 1cb3b30a2d..cb8a929dd4 100644 --- a/src/frontends/Dialogs.h +++ b/src/frontends/Dialogs.h @@ -30,6 +30,7 @@ class InsetError; class InsetERT; class InsetExternal; class InsetFloat; +class InsetWrap; class InsetGraphics; class InsetInclude; class InsetInfo; @@ -109,6 +110,8 @@ public: void showFile(string const &); /// void showFloat(InsetFloat *); + /// + void showWrap(InsetWrap *); /// show all forked child processes void showForks(); /// diff --git a/src/frontends/controllers/ControlFloat.h b/src/frontends/controllers/ControlFloat.h index d6e6891072..3319163ab8 100644 --- a/src/frontends/controllers/ControlFloat.h +++ b/src/frontends/controllers/ControlFloat.h @@ -12,8 +12,6 @@ #ifndef CONTROLFLOAT_H #define CONTROLFLOAT_H -#include - #ifdef __GNUG__ #pragma interface #endif diff --git a/src/frontends/controllers/ControlWrap.C b/src/frontends/controllers/ControlWrap.C new file mode 100644 index 0000000000..41b6c83e16 --- /dev/null +++ b/src/frontends/controllers/ControlWrap.C @@ -0,0 +1,55 @@ +/** + * \file ControlWrap.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Dekel Tsur + * + * Full author contact details are available in file CREDITS + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "ControlWrap.h" +#include "BufferView.h" +#include "buffer.h" + + +ControlWrap::ControlWrap(LyXView & lv, Dialogs & d) + : ControlInset(lv, d) +{} + + + +void ControlWrap::applyParamsToInset() +{ + inset()->pageWidth(params().pageWidth); + inset()->placement(params().placement); + bufferview()->updateInset(inset(), true); + +} + + +void ControlWrap::applyParamsNoInset() +{} + + +WrapParams const ControlWrap::getParams(InsetWrap const & inset) +{ + return WrapParams(inset); +} + + +WrapParams::WrapParams() + : placement("") +{} + + +WrapParams::WrapParams(InsetWrap const & inset) + : pageWidth(inset.pageWidth()), + placement(inset.placement()) +{} diff --git a/src/frontends/controllers/ControlWrap.h b/src/frontends/controllers/ControlWrap.h new file mode 100644 index 0000000000..df42b3abad --- /dev/null +++ b/src/frontends/controllers/ControlWrap.h @@ -0,0 +1,72 @@ +// -*- C++ -*- +/** + * \file ControlWrap.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Dekel Tsur + * + * Full author contact details are available in file CREDITS + */ + +#ifndef CONTROLWRAP_H +#define CONTROLWRAP_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "ControlInset.h" +#include "lyxlength.h" + +// 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 { +public: + /// + ControlWrap(LyXView &, Dialogs &); +private: + /// Dispatch the changed parameters to the kernel. + virtual void applyParamsToInset(); + /// + 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 &); +}; + +#endif diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index a00d438b8d..158ca0b5a1 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -50,6 +50,8 @@ libcontrollers_la_SOURCES= \ ControlExternal.h \ ControlFloat.C \ ControlFloat.h \ + ControlWrap.C \ + ControlWrap.h \ ControlForks.C \ ControlForks.h \ ControlGraphics.C \ diff --git a/src/frontends/guiapi.C b/src/frontends/guiapi.C index 400015f7ef..28338a5cfa 100644 --- a/src/frontends/guiapi.C +++ b/src/frontends/guiapi.C @@ -103,6 +103,10 @@ extern "C" { d.showFloat(ifl); } + void gui_ShowWrap(InsetWrap * iw, Dialogs & d) + { + d.showWrap(iw); + } void gui_ShowForks(Dialogs & d) { diff --git a/src/frontends/guiapi.h b/src/frontends/guiapi.h index b5f4c803d2..69c85ebe7c 100644 --- a/src/frontends/guiapi.h +++ b/src/frontends/guiapi.h @@ -24,6 +24,7 @@ class InsetError; class InsetERT; class InsetExternal; class InsetFloat; +class InsetWrap; class InsetGraphics; class InsetInclude; class InsetMinipage; @@ -45,6 +46,7 @@ extern "C" { void gui_ShowExternal(InsetExternal *, Dialogs &); void gui_ShowFile(string const &, Dialogs &); void gui_ShowFloat(InsetFloat *, Dialogs &); + void gui_ShowWrap(InsetWrap *, Dialogs &); void gui_ShowForks(Dialogs &); void gui_ShowGraphics(InsetGraphics *, Dialogs &); void gui_ShowInclude(InsetInclude *, Dialogs &); diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 2c570a1a45..c79539325a 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -81,5 +81,6 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) toc(lv, d), url(lv, d), - vclogfile(lv, d) + vclogfile(lv, d), + wrap(lv, d) {} diff --git a/src/frontends/xforms/Dialogs2.C b/src/frontends/xforms/Dialogs2.C index 9ed8e939ca..740badd8d3 100644 --- a/src/frontends/xforms/Dialogs2.C +++ b/src/frontends/xforms/Dialogs2.C @@ -284,3 +284,9 @@ void Dialogs::showVCLogFile() { pimpl_->vclogfile.controller().show(); } + + +void Dialogs::showWrap(InsetWrap * iw) +{ + pimpl_->wrap.controller().showInset(iw); +} diff --git a/src/frontends/xforms/Dialogs_impl.h b/src/frontends/xforms/Dialogs_impl.h index 345d66b95a..f552ee3055 100644 --- a/src/frontends/xforms/Dialogs_impl.h +++ b/src/frontends/xforms/Dialogs_impl.h @@ -169,6 +169,10 @@ #include "ControlVCLog.h" #include "FormVCLog.h" +#include "ControlWrap.h" +#include "FormWrap.h" +#include "forms/form_wrap.h" + typedef GUI AboutlyxDialog; @@ -267,6 +271,9 @@ UrlDialog; typedef GUI VCLogFileDialog; +typedef GUI +WrapDialog; + struct Dialogs::Impl { Impl(LyXView & lv, Dialogs & d); @@ -307,6 +314,7 @@ struct Dialogs::Impl { TocDialog toc; UrlDialog url; VCLogFileDialog vclogfile; + WrapDialog wrap; }; #endif // DIALOGS_IMPL_H diff --git a/src/frontends/xforms/FormWrap.C b/src/frontends/xforms/FormWrap.C new file mode 100644 index 0000000000..17f99ef5b7 --- /dev/null +++ b/src/frontends/xforms/FormWrap.C @@ -0,0 +1,123 @@ +/** + * \file FormWrap.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Dekel Tsur + * + * Full author contact details are available in file CREDITS + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "xformsBC.h" +#include "ControlWrap.h" +#include "FormWrap.h" +#include "forms/form_wrap.h" +#include "support/lstrings.h" +#include "helper_funcs.h" +#include "debug.h" +#include "xforms_helpers.h" +#include FORMS_H_LOCATION + +typedef FormCB > base_class; + +FormWrap::FormWrap() + : base_class(_("Wrap Options")) +{} + + +void FormWrap::build() +{ + dialog_.reset(build_wrap(this)); + + // Allow the base class to control messages + setMessageWidget(dialog_->text_warning); + + fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED); + setPrehandler(dialog_->input_width); + + string const choice = getStringFromVector(getLatexUnits(), "|"); + fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str()); + + // Manage the ok, apply and cancel/close buttons + bc().setOK(dialog_->button_ok); + bc().setApply(dialog_->button_apply); + bc().setCancel(dialog_->button_close); + bc().setRestore(dialog_->button_restore); + + bc().addReadOnly(dialog_->input_width); + bc().addReadOnly(dialog_->choice_width_units); + bc().addReadOnly(dialog_->radio_left); + bc().addReadOnly(dialog_->radio_right); + bc().addReadOnly(dialog_->radio_inner); + bc().addReadOnly(dialog_->radio_default); +} + + +void FormWrap::apply() +{ + controller().params().pageWidth = + LyXLength(getLengthFromWidgets(dialog_->input_width, + dialog_->choice_width_units)); + + if (fl_get_button(dialog_->radio_left)) + controller().params().placement = "l"; + else if (fl_get_button(dialog_->radio_right)) + controller().params().placement = "r"; + else if (fl_get_button(dialog_->radio_inner)) + controller().params().placement = "p"; + else + controller().params().placement.erase(); +} + + +void FormWrap::update() +{ + LyXLength len(controller().params().pageWidth); + 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 == "l") + fl_set_button(dialog_->radio_left, 1); + else if (controller().params().placement == "r") + fl_set_button(dialog_->radio_right, 1); + else if (controller().params().placement == "p") + fl_set_button(dialog_->radio_inner, 1); + else + fl_set_button(dialog_->radio_default, 1); +} + + +ButtonPolicy::SMInput FormWrap::input(FL_OBJECT * ob, long) +{ + clearMessage(); + + ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP; + + if (ob == dialog_->radio_left || + ob == dialog_->radio_right || + ob == dialog_->radio_inner || + ob == dialog_->radio_default || + ob == dialog_->choice_width_units) + return ButtonPolicy::SMI_VALID; + + // disallow senseless data + // warnings if input is senseless + if (ob == dialog_->input_width) { + string const input = getString(dialog_->input_width); + bool const invalid = !isValidLength(input) && !isStrDbl(input); + if (invalid) { + postWarning(_("Invalid Length!")); + action = ButtonPolicy::SMI_INVALID; + } else { + action = ButtonPolicy::SMI_VALID; + } + } + + return action; +} diff --git a/src/frontends/xforms/FormWrap.h b/src/frontends/xforms/FormWrap.h new file mode 100644 index 0000000000..2e1a16c290 --- /dev/null +++ b/src/frontends/xforms/FormWrap.h @@ -0,0 +1,43 @@ +// -*- C++ -*- +/** + * \file FormMinipage.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Dekel Tsur + * + * Full author contact details are available in file CREDITS + */ + +#ifndef FORMWRAP_H +#define FORMWRAP_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "FormBase.h" + +class ControlWrap; +struct FD_wrap; + +/** This class provides an XForms implementation of the Wrap + Dialog. + */ +class FormWrap + : public FormCB > { +public: + /// + FormWrap(); +private: + /// Set the Params variable for the Controller. + virtual void apply(); + /// Build the dialog. + virtual void build(); + /// Update dialog before/whilst showing it. + virtual void update(); + /// Filter the inputs on callback from xforms + virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); +}; + +#endif // FORMWRAP_H diff --git a/src/frontends/xforms/Makefile.am b/src/frontends/xforms/Makefile.am index 93dbf037ae..2193c969a3 100644 --- a/src/frontends/xforms/Makefile.am +++ b/src/frontends/xforms/Makefile.am @@ -85,6 +85,8 @@ libxforms_la_SOURCES = \ FormExternal.h \ FormFloat.C \ FormFloat.h \ + FormWrap.C \ + FormWrap.h \ FormForks.C \ FormForks.h \ FormGraphics.C \ diff --git a/src/frontends/xforms/forms/Makefile.am b/src/frontends/xforms/forms/Makefile.am index 1fe63fa9e0..1dd0be27fc 100644 --- a/src/frontends/xforms/forms/Makefile.am +++ b/src/frontends/xforms/forms/Makefile.am @@ -19,6 +19,7 @@ SRCS = form_aboutlyx.fd \ form_external.fd \ form_filedialog.fd \ form_float.fd \ + form_wrap.fd \ form_forks.fd \ form_graphics.fd \ form_include.fd \ diff --git a/src/frontends/xforms/forms/form_wrap.fd b/src/frontends/xforms/forms/form_wrap.fd new file mode 100644 index 0000000000..132dcc2da2 --- /dev/null +++ b/src/frontends/xforms/forms/form_wrap.fd @@ -0,0 +1,304 @@ +Magic: 13000 + +Internal Form Definition File + (do not change) + +Number of forms: 1 +Unit of measure: FL_COORD_PIXEL + +=============== FORM =============== +Name: form_wrap +Width: 430 +Height: 200 +Number of Objects: 16 + +-------------------- +class: FL_BOX +type: FLAT_BOX +box: 0 0 430 200 +boxtype: FL_FLAT_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: +callback: +argument: + +-------------------- +class: FL_LABELFRAME +type: ENGRAVED_FRAME +box: 20 20 200 60 +boxtype: FL_NO_BOX +colors: FL_BLACK FL_COL1 +alignment: FL_ALIGN_TOP_LEFT +style: FL_BOLD_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Width +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: +callback: +argument: + +-------------------- +class: FL_LABELFRAME +type: ENGRAVED_FRAME +box: 240 20 180 130 +boxtype: FL_NO_BOX +colors: FL_BLACK FL_COL1 +alignment: FL_ALIGN_TOP_LEFT +style: FL_BOLD_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Placement +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: +callback: +argument: + +-------------------- +class: FL_INPUT +type: NORMAL_INPUT +box: 30 30 110 30 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: input_width +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_CHOICE +type: NORMAL_CHOICE +box: 150 30 60 30 +boxtype: FL_FRAME_BOX +colors: FL_COL1 FL_BLACK +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: choice_width_units +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BEGIN_GROUP +type: 0 +box: 0 0 0 0 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: +callback: +argument: + +-------------------- +class: FL_ROUND3DBUTTON +type: RADIO_BUTTON +box: 249 30 152 30 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Left|#L +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: radio_left +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_ROUND3DBUTTON +type: RADIO_BUTTON +box: 249 60 152 30 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Right|#R +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: radio_right +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_ROUND3DBUTTON +type: RADIO_BUTTON +box: 249 90 152 30 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Inner|#I +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: radio_inner +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_ROUND3DBUTTON +type: RADIO_BUTTON +box: 250 120 152 30 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Default (outer)|#D +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: radio_default +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_END_GROUP +type: 0 +box: 0 0 0 0 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: +callback: +argument: + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 330 160 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Cancel|^[ +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_close +callback: C_FormBaseCancelCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 230 160 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Apply|#A +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_apply +callback: C_FormBaseApplyCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: RETURN_BUTTON +box: 130 160 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: OK +shortcut: ^M +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_ok +callback: C_FormBaseOKCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 10 160 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Restore|#R +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_restore +callback: C_FormBaseRestoreCB +argument: 0 + +-------------------- +class: FL_TEXT +type: NORMAL_TEXT +box: 20 90 210 30 +boxtype: FL_FLAT_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_LEFT|FL_ALIGN_INSIDE +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: text_warning +callback: +argument: + +============================== +create_the_forms diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index e755ca7b05..a187d28d67 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -39,6 +39,8 @@ libinsets_la_SOURCES = \ insetexternal.h \ insetfloat.h \ insetfloat.C \ + insetwrap.h \ + insetwrap.C \ insetfloatlist.C \ insetfloatlist.h \ insetfoot.C \ diff --git a/src/insets/inset.h b/src/insets/inset.h index 4f7467838b..54459c5e6c 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -93,6 +93,8 @@ public: /// FLOAT_CODE, /// + WRAP_CODE, + /// MINIPAGE_CODE, /// SPECIALCHAR_CODE, // 25 diff --git a/src/insets/insetwrap.C b/src/insets/insetwrap.C new file mode 100644 index 0000000000..ae39aac22b --- /dev/null +++ b/src/insets/insetwrap.C @@ -0,0 +1,231 @@ +/** + * \file insetwrap.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Dekel Tsur + * + * Full author contact details are available in file CREDITS + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#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 "buffer.h" +#include "frontends/LyXView.h" +#include "frontends/Dialogs.h" +#include "lyxlex.h" + +using std::ostream; +using std::endl; + + +InsetWrap::InsetWrap(BufferParams const & bp, string const & type) + : InsetCollapsable(bp), width_(50, LyXLength::PCW) +{ + string lab(_("wrap")); + lab += type; + setLabel(lab); + LyXFont font(LyXFont::ALL_SANE); + font.decSize(); + font.decSize(); + font.setColor(LColor::collapsable); + setLabelFont(font); + Type_ = type; + setInsetName(type); +} + + +InsetWrap::InsetWrap(InsetWrap const & in, bool same_id) + : InsetCollapsable(in, same_id), Type_(in.Type_), + Placement_(in.Placement_), width_(in.width_) +{} + + +InsetWrap::~InsetWrap() +{ + hideDialog(); +} + + +void InsetWrap::write(Buffer const * buf, ostream & os) const +{ + os << "Wrap " // getInsetName() + << Type_ << '\n'; + + if (!Placement_.empty()) { + os << "placement " << Placement_ << "\n"; + } + os << "width \"" << width_.asString() << "\"\n"; + + InsetCollapsable::write(buf, os); +} + + +void InsetWrap::read(Buffer const * buf, LyXLex & lex) +{ + if (lex.isOK()) { + lex.next(); + string token = lex.getString(); + if (token == "placement") { + lex.next(); + Placement_ = lex.getString(); + } else { + // take countermeasures + lex.pushToken(token); + } + } + if (lex.isOK()) { + lex.next(); + string token = lex.getString(); + if (token == "width") { + lex.next(); + width_ = LyXLength(lex.getString()); + } else { + lyxerr << "InsetWrap::Read:: Missing 'width'-tag!" + << endl; + // take countermeasures + lex.pushToken(token); + } + } + InsetCollapsable::read(buf, lex); +} + + +void InsetWrap::validate(LaTeXFeatures & features) const +{ + features.require("floatflt"); + InsetCollapsable::validate(features); +} + + +Inset * InsetWrap::clone(Buffer const &, bool same_id) const +{ + return new InsetWrap(*const_cast(this), same_id); +} + + +string const InsetWrap::editMessage() const +{ + return _("Opened Wrap Inset"); +} + + +int InsetWrap::latex(Buffer const * buf, + ostream & os, bool fragile, bool fp) const +{ + os << "\\begin{floating" << Type_ << "}"; + if (!Placement_.empty()) { + os << "[" << Placement_ << "]"; + } + os << "{" << width_.asLatexString() << "}%\n"; + + int const i = inset.latex(buf, os, fragile, fp); + + os << "\\end{floating" << Type_ << "}%\n"; + return i + 2; +} + + +int InsetWrap::docbook(Buffer const * buf, ostream & os, bool mixcont) const +{ + os << "<" << Type_ << ">"; + int const i = inset.docbook(buf, os, mixcont); + os << ""; + + return i; +} + + +bool InsetWrap::insetAllowed(Inset::Code code) const +{ + switch(code) { + case FLOAT_CODE: + case FOOT_CODE: + case MARGIN_CODE: + return false; + default: + return InsetCollapsable::insetAllowed(code); + } +} + +int InsetWrap::getMaxWidth(BufferView * bv, UpdatableInset const * inset) + const +{ + if (owner() && + static_cast(owner())->getMaxWidth(bv, inset) < 0) { + return -1; + } + if (!width_.zero()) { + int ww1 = latexTextWidth(bv); + int ww2 = InsetCollapsable::getMaxWidth(bv, inset); + if (ww2 > 0 && ww2 < ww1) { + return ww2; + } + return ww1; + } + // this should not happen! + return InsetCollapsable::getMaxWidth(bv, inset); +} + + +int InsetWrap::latexTextWidth(BufferView * bv) const +{ + return width_.inPixels(InsetCollapsable::latexTextWidth(bv), + bv->text->defaultHeight()); +} + + +string const & InsetWrap::type() const +{ + return Type_; +} + + +LyXLength const & InsetWrap::pageWidth() const +{ + return width_; +} + + +void InsetWrap::pageWidth(LyXLength const & ll) +{ + if (ll != width_) { + width_ = ll; + need_update = FULL; + } +} + + +void InsetWrap::placement(string const & p) +{ + Placement_ = p; +} + + +string const & InsetWrap::placement() const +{ + return Placement_; +} + + +bool InsetWrap::showInsetDialog(BufferView * bv) const +{ + if (!inset.showInsetDialog(bv)) { + bv->owner()->getDialogs().showWrap(const_cast(this)); + } + return true; +} diff --git a/src/insets/insetwrap.h b/src/insets/insetwrap.h new file mode 100644 index 0000000000..4ddc3e8b41 --- /dev/null +++ b/src/insets/insetwrap.h @@ -0,0 +1,81 @@ +/** + * \file insetwrap.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Dekel Tsur + * + * Full author contact details are available in file CREDITS + */ + +#ifndef InsetWrap_H +#define InsetWrap_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "insetcollapsable.h" +#include "lyxlength.h" + +#include + +class Painter; + +/** The wrap inset + +*/ +class InsetWrap : public InsetCollapsable { +public: + /// + InsetWrap(BufferParams const &, string const &); + /// + InsetWrap(InsetWrap const &, bool same_id = false); + /// + ~InsetWrap(); + /// + void write(Buffer const * buf, std::ostream & os) const; + /// + void read(Buffer const * buf, LyXLex & lex); + /// + void validate(LaTeXFeatures & features) const; + /// + Inset * clone(Buffer const &, bool same_id = false) const; + /// + Inset::Code lyxCode() const { return Inset::WRAP_CODE; } + /// + int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; + /// + int docbook(Buffer const *, std::ostream &, bool mixcont) const; + /// + string const editMessage() const; + /// + bool insetAllowed(Inset::Code) const; + /// + int getMaxWidth(BufferView *, UpdatableInset const *) const; + /// + string const & type() const; + /// + LyXLength const & pageWidth() const; + /// + void pageWidth(LyXLength const &); + /// + void placement(string const & p); + /// + string const & placement() const; + /// + bool showInsetDialog(BufferView *) const; + /// + boost::signal0 hideDialog; + /// + int latexTextWidth(BufferView *) const; +private: + /// + string Type_; + /// + string Placement_; + /// + LyXLength width_; +}; + +#endif diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 968c5225ca..8e08ed42c3 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -493,6 +493,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_INSET_WIDE_FLOAT: code = Inset::FLOAT_CODE; break; + case LFUN_INSET_WRAP: + code == Inset::WRAP_CODE; + break; case LFUN_FLOAT_LIST: code = Inset::FLOAT_LIST_CODE; break; diff --git a/src/text2.C b/src/text2.C index e8e261b991..075fcc6a58 100644 --- a/src/text2.C +++ b/src/text2.C @@ -39,6 +39,7 @@ #include "insets/insetspecialchar.h" #include "insets/insettext.h" #include "insets/insetfloat.h" +#include "insets/insetwrap.h" #include "support/LAssert.h" #include "support/textutils.h" @@ -1315,7 +1316,8 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const while (tmppar && tmppar->inInset() // the single '=' is intended below && (in = tmppar->inInset()->owner())) { - if (in->lyxCode() == Inset::FLOAT_CODE) { + if (in->lyxCode() == Inset::FLOAT_CODE || + in->lyxCode() == Inset::WRAP_CODE) { isOK = true; break; } else { diff --git a/src/text3.C b/src/text3.C index 3abab9fc69..eae7919996 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1577,6 +1577,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) case LFUN_INSET_MINIPAGE: case LFUN_INSET_OPTARG: case LFUN_INSET_WIDE_FLOAT: + case LFUN_INSET_WRAP: case LFUN_TABULAR_INSERT: case LFUN_INDEX_INSERT: case LFUN_INDEX_PRINT: -- 2.39.5