From: Martin Vermeer Date: Tue, 7 Oct 2003 07:42:15 +0000 (+0000) Subject: The Box patch X-Git-Tag: 1.6.10~16001 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=800c0dfc384303dac86ead3d627df3d9fc0bfa88;p=features.git The Box patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7865 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/ChangeLog b/lib/ChangeLog index c1544b9cf9..64b14e9b3e 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2003-10-07 Martin Vermeer + + * ui/stdmenus.ui: The Box patch. Fancybox support, minipage, + parbox + 2003-10-06 José Matoa * lyxrevert_223.py: finish support for change tracking revert. diff --git a/lib/ui/stdmenus.ui b/lib/ui/stdmenus.ui index 365d6dd655..0fe3ee181a 100644 --- a/lib/ui/stdmenus.ui +++ b/lib/ui/stdmenus.ui @@ -101,10 +101,10 @@ Menuset OptItem "TeX Code Settings...|C" "inset-settings ert" # 'a' shortcut to match Insert entry, shouldn't clash with Table Settings OptItem "Float Settings...|a" "inset-settings float" - OptItem "Minipage Settings...|M" "inset-settings minipage" OptItem "Text Wrap Settings...|W" "inset-settings wrap" OptItem "Note Settings...|N" "inset-settings note" OptItem "Branch Settings...|B" "inset-settings branch" + OptItem "Box Settings...|x" "inset-settings box" # Hey, guess what's broken ? Surprise surprise, it's tabular stuff # This is in the Table submenu instead for now. # OptItem "Table Settings...|a" "inset-settings tabular" @@ -229,6 +229,7 @@ Menuset Submenu "Float|a" "insert_float" # YUCK Submenu "Note|N" "insert_note" + Submenu "Box" "insert_box" Submenu "Branch|B" "branches" Submenu "File|e" "insert_file" Separator @@ -243,7 +244,6 @@ Menuset Item "URL...|U" "url-insert" Item "Footnote|F" "footnote-insert" Item "Marginal Note|M" "marginalnote-insert" - Item "Minipage|p" "minipage-insert" Item "Short Title" "optional-insert" Item "TeX|X" "ert-insert" End @@ -339,6 +339,15 @@ Menuset Item "Greyed Out|G" "note-insert Greyedout" End + Menu "insert_box" + Item "Frameless|F" "box-insert Frameless" + Item "Boxed|B" "box-insert Boxed" + Item "Oval Box|O" "box-insert ovalbox" + Item "Oval Box, Thick|T" "box-insert Ovalbox" + Item "Shadow Box|S" "box-insert Shadowbox" + Item "Double Box|D" "box-insert Doublebox" + End + Menu "branches" Branches End diff --git a/po/POTFILES.in b/po/POTFILES.in index db0888f6ce..ef9083a9b7 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -18,6 +18,7 @@ src/format.C src/frontends/LyXView.C src/frontends/controllers/ControlAboutlyx.C src/frontends/controllers/ControlBibtex.C +src/frontends/controllers/ControlBox.C src/frontends/controllers/ControlDocument.C src/frontends/controllers/ControlExternal.C src/frontends/controllers/ControlGraphics.C @@ -93,6 +94,7 @@ src/frontends/xforms/FormAboutlyx.C src/frontends/xforms/FormBase.C src/frontends/xforms/FormBibitem.C src/frontends/xforms/FormBibtex.C +src/frontends/xforms/FormBox.C src/frontends/xforms/FormBranch.C src/frontends/xforms/FormChanges.C src/frontends/xforms/FormCharacter.C @@ -142,6 +144,7 @@ src/gettext.h src/importer.C src/insets/inset.C src/insets/insetbibtex.C +src/insets/insetbox.C src/insets/insetbranch.C src/insets/insetcaption.C src/insets/insetenv.C @@ -185,6 +188,7 @@ src/mathed/ref_inset.C src/paragraph.C src/paragraph_funcs.C src/rowpainter.C +src/support/path_defines.C src/text.C src/text2.C src/text3.C diff --git a/src/ChangeLog b/src/ChangeLog index 894061399f..16ecf46cb1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,13 @@ -<<<<<<< ChangeLog + +2003-10-07 Martin Vermeer + + * LaTeXFeatures.C: + * LyXAction.C: + * factory.C: + * lfuns.h: + * lyxfunc.C: + * text3.C: The Box patch. Fancybox support, minipage, parbox + 2003-10-07 Martin Vermeer * CutAndPaste.h: diff --git a/src/LaTeXFeatures.C b/src/LaTeXFeatures.C index b70b7decc3..bd891b5b76 100644 --- a/src/LaTeXFeatures.C +++ b/src/LaTeXFeatures.C @@ -189,7 +189,9 @@ char const * simplefeatures[] = { "prettyref", "float", "wasy", - "dvipost" + "dvipost", + "fancybox", + "calc" }; int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *); diff --git a/src/LyXAction.C b/src/LyXAction.C index ff0c40e1f2..c184502617 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -225,6 +225,7 @@ void LyXAction::init() { LFUN_INSET_MINIPAGE, "minipage-insert", Noop }, { LFUN_INSERT_BRANCH, "branch-insert", Noop }, { LFUN_INSERT_NOTE, "note-insert", Noop }, + { LFUN_INSERT_BOX, "box-insert", Noop }, { LFUN_GOTONOTE, "note-next", ReadOnly }, { LFUN_INSET_TOGGLE, "inset-toggle", ReadOnly }, { LFUN_DOWN_PARAGRAPH, "paragraph-down", ReadOnly }, diff --git a/src/factory.C b/src/factory.C index eca35ef59d..f02653dfbd 100644 --- a/src/factory.C +++ b/src/factory.C @@ -39,6 +39,7 @@ #include "insets/insetmarginal.h" #include "insets/insetminipage.h" #include "insets/insetnote.h" +#include "insets/insetbox.h" #include "insets/insetbranch.h" #include "insets/insetoptarg.h" #include "insets/insetref.h" @@ -82,6 +83,13 @@ InsetOld * createInset(FuncRequest const & cmd) arg = "Note"; return new InsetNote(params, arg); } + case LFUN_INSERT_BOX: + { + string arg = cmd.getArg(0); + if (arg.empty()) + arg = "Boxed"; + return new InsetBox(params, arg); + } case LFUN_INSERT_BRANCH: { string arg = cmd.getArg(0); @@ -375,6 +383,10 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf) } else if (tmptok == "Note" || tmptok == "Comment" || tmptok == "Greyedout") { inset = new InsetNote(buf.params(), tmptok); + } else if (tmptok == "Boxed" || tmptok == "ovalbox" + || tmptok == "Shadowbox" || tmptok == "Doublebox" + || tmptok == "Ovalbox" || tmptok == "Frameless") { + inset = new InsetBox(buf.params(), tmptok); } else if (tmptok == "Branch") { inset = new InsetBranch(buf.params(), string()); } else if (tmptok == "Include") { diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 59d86fefad..b5fa09f7f9 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,9 @@ +2003-10-07 Martin Vermeer + + * ControlBox.C: + * ControlBox.h: + * Makefile.am: The Box patch. Fancybox support, minipage, parbox + 2003-10-07 Martin Vermeer * BCView.h: diff --git a/src/frontends/controllers/ControlBox.C b/src/frontends/controllers/ControlBox.C new file mode 100644 index 0000000000..93e4de9582 --- /dev/null +++ b/src/frontends/controllers/ControlBox.C @@ -0,0 +1,82 @@ +/** + * \file ControlBox.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Martin Vermeer (with useful hints from Angus Leeming) + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "ControlBox.h" +#include "funcrequest.h" +#include "insets/insetbox.h" +#include "gettext.h" + + +using std::string; +using std::vector; + + +ControlBox::ControlBox(Dialog & parent) + : Dialog::Controller(parent) +{} + + +bool ControlBox::initialiseParams(string const & data) +{ + InsetBoxParams params(""); + InsetBoxMailer::string2params(data, params); + params_.reset(new InsetBoxParams(params)); + + return true; + +} + + +void ControlBox::clearParams() +{ + params_.reset(); +} + + +void ControlBox::dispatchParams() +{ + string const lfun = InsetBoxMailer::params2string(params()); + kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); +} + + +void box_gui_tokens(vector & ids, vector & gui_names) +{ + char const * const ids_[] = { + "Frameless", "Boxed", "ovalbox", + "Ovalbox", "Shadowbox", "Doublebox"}; + size_t const ids_size = sizeof(ids_) / sizeof(char *); + ids = vector(ids_, ids_ + ids_size); + gui_names.clear(); + gui_names.push_back(_("No frame drawn")); + gui_names.push_back(_("Rectangular box")); + gui_names.push_back(_("Oval box, thin")); + gui_names.push_back(_("Oval box, thick")); + gui_names.push_back(_("Shadow box")); + gui_names.push_back(_("Double box")); +} + +void box_gui_tokens_special_length(vector & ids, + vector & gui_names) +{ + char const * const ids_[] = { + "none", "height", "depth", + "totalheight", "width"}; + size_t const ids_size = sizeof(ids_) / sizeof(char *); + ids = vector(ids_, ids_ + ids_size); + gui_names.clear(); + gui_names.push_back(_("None")); + gui_names.push_back(_("Height")); + gui_names.push_back(_("Depth")); + gui_names.push_back(_("Total Height")); + gui_names.push_back(_("Width")); +} diff --git a/src/frontends/controllers/ControlBox.h b/src/frontends/controllers/ControlBox.h new file mode 100644 index 0000000000..8d9dd97c48 --- /dev/null +++ b/src/frontends/controllers/ControlBox.h @@ -0,0 +1,49 @@ +// -*- C++ -*- +/** + * \file ControlBox.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Martin Vermeer (with useful hints from Angus Leeming) + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef CONTROLBOX_H +#define CONTROLBOX_H + + +#include "Dialog.h" +#include + +class InsetBoxParams; + +class ControlBox : public Dialog::Controller { +public: + /// + ControlBox(Dialog &); + /// + virtual bool initialiseParams(std::string const & data); + /// + virtual void clearParams(); + /// + virtual void dispatchParams(); + /// + virtual bool isBufferDependent() const { return true; } + /// + InsetBoxParams & params() { return *params_.get(); } + /// + InsetBoxParams const & params() const { return *params_.get(); } + /// +private: + /// + boost::scoped_ptr params_; +}; + +/// +void box_gui_tokens(std::vector &, std::vector &); +/// +void box_gui_tokens_special_length(std::vector &, + std::vector &); + +#endif // CONTROLBOX_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 89fea1c2d9..770c03de90 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -31,6 +31,8 @@ libcontrollers_la_SOURCES= \ ControlBibtex.h \ ControlButtons.C \ ControlButtons.h \ + ControlBox.C \ + ControlBox.h \ ControlBranch.C \ ControlBranch.h \ ControlCharacter.C \ diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 3ff9055c84..6b3b4813f0 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,13 @@ +2003-10-07 Martin Vermeer + + * Dialogs.C: + * FormBox.C: + * FormBox.h: + * Makefile.am: + * forms/Makefile.am: + * forms/form_box.fd: The Box patch. Fancybox support, minipage, + parbox + 2003-10-01 Angus Leeming * FormExternal.C (updateComboChange): changes due to the diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 66d3c43dd4..71ee5280de 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -16,6 +16,7 @@ #include "ControlAboutlyx.h" #include "ControlBibtex.h" +#include "ControlBox.h" #include "ControlBranch.h" #include "ControlChanges.h" #include "ControlCitation.h" @@ -41,6 +42,7 @@ #include "FormAboutlyx.h" #include "FormBibitem.h" #include "FormBibtex.h" +#include "FormBox.h" #include "FormBranch.h" #include "FormChanges.h" #include "FormCharacter.h" @@ -109,7 +111,8 @@ FormMathsBitmap * createFormBitmap(Dialog & parent, string const & title, } -char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "branch", "changes", +char const * const dialognames[] = { +"aboutlyx", "bibitem", "bibtex", "branch", "box", "changes", "character", "citation", "error", "errorlist" , "ert", "external", "file", "float", "graphics", "include", "index", "label", "latexlog", "mathpanel", "mathaccents", "matharrows", "mathoperators", "mathrelations", "mathgreek", @@ -410,6 +413,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlNote(*dialog)); dialog->setView(new FormNote(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); + } else if (name == "box") { + dialog->setController(new ControlBox(*dialog)); + dialog->setView(new FormBox(*dialog)); + dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); } else if (name == "branch") { dialog->setController(new ControlBranch(*dialog)); dialog->setView(new FormBranch(*dialog)); diff --git a/src/frontends/xforms/FormBox.C b/src/frontends/xforms/FormBox.C new file mode 100644 index 0000000000..333e6cd927 --- /dev/null +++ b/src/frontends/xforms/FormBox.C @@ -0,0 +1,288 @@ +/** + * \file FormBox.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Jürgen Vigna (Minipage stuff) + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "FormBox.h" +#include "ControlBox.h" +#include "forms/form_box.h" +#include "controllers/ButtonPolicies.h" +#include "controllers/helper_funcs.h" +#include "support/lstrings.h" +#include "support/tostr.h" + +#include "Tooltips.h" +#include "xforms_helpers.h" +#include "xformsBC.h" + +#include "insets/insetbox.h" + +#include "lyx_forms.h" +#include "debug.h" + +#include + +using lyx::support::getStringFromVector; +using lyx::support::isStrDbl; +using lyx::support::subst; +using std::string; + + +typedef FormController > base_class; + +FormBox::FormBox(Dialog & parent) + : base_class(parent, _("Box")) +{} + + +void FormBox::build() +{ + dialog_.reset(build_box(this)); + + box_gui_tokens(ids_, gui_names_); + + for (unsigned int i = 0; i < gui_names_.size(); ++i) { + fl_addto_choice(dialog_->choice_type, gui_names_[i].c_str()); + } + + string str = _("Frameless: No border\n" + "Boxed: Rectangular\n" + "ovalbox: Oval, thin border\n" + "Ovalbox: Oval, thick border\n" + "Shadowbox: Box casting shadow\n" + "Doublebox: Double line border"); + tooltips().init(dialog_->choice_type, str); + + bcview().addReadOnly(dialog_->check_inner_box); + + str = _("The inner box may be a parbox or a minipage,\n" + "with appropriate arguments from this dialog."); + tooltips().init(dialog_->check_inner_box, str); + + bcview().addReadOnly(dialog_->radio_parbox); + bcview().addReadOnly(dialog_->radio_minipage); + + bcview().addReadOnly(dialog_->choice_pos); + fl_addto_choice(dialog_->choice_pos, _("top").c_str()); + fl_addto_choice(dialog_->choice_pos, _("middle").c_str()); + fl_addto_choice(dialog_->choice_pos, _("bottom").c_str()); + + bcview().addReadOnly(dialog_->choice_inner_pos); + fl_addto_choice(dialog_->choice_inner_pos, _("top").c_str()); + fl_addto_choice(dialog_->choice_inner_pos, _("middle").c_str()); + fl_addto_choice(dialog_->choice_inner_pos, _("bottom").c_str()); + fl_addto_choice(dialog_->choice_inner_pos, _("stretch").c_str()); + + bcview().addReadOnly(dialog_->choice_hor_pos); + fl_addto_choice(dialog_->choice_hor_pos, _("left").c_str()); + fl_addto_choice(dialog_->choice_hor_pos, _("center").c_str()); + fl_addto_choice(dialog_->choice_hor_pos, _("right").c_str()); + fl_addto_choice(dialog_->choice_hor_pos, _("stretch").c_str()); + + bcview().addReadOnly(dialog_->input_width); + bcview().addReadOnly(dialog_->choice_width_unit); + bcview().addReadOnly(dialog_->choice_special); + + box_gui_tokens_special_length(ids_spec_, gui_names_spec_); + for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) { + fl_addto_choice(dialog_->choice_special, gui_names_spec_[i].c_str()); + } + + string choice = getStringFromVector(getLatexUnits(), "|"); + fl_addto_choice(dialog_->choice_width_unit, + subst(choice, "%", "%%").c_str()); + + bcview().addReadOnly(dialog_->input_height); + bcview().addReadOnly(dialog_->choice_height_unit); + bcview().addReadOnly(dialog_->choice_height_special); + for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) { + fl_addto_choice(dialog_->choice_height_special, + gui_names_spec_[i].c_str()); + } + + choice = getStringFromVector(getLatexUnits(), "|"); + fl_addto_choice(dialog_->choice_height_unit, + subst(choice, "%", "%%").c_str()); + + bcview().setOK(dialog_->button_ok); + bcview().setApply(dialog_->button_apply); + bcview().setCancel(dialog_->button_cancel); +} + + +void FormBox::update() +{ + string type(controller().params().type); + for (unsigned int i = 0; i < gui_names_.size(); ++i) { + if (type == ids_[i]) + fl_set_choice_text(dialog_->choice_type, gui_names_[i].c_str()); + } + + fl_set_button(dialog_->check_inner_box, controller().params().inner_box); + if (controller().params().type == "Frameless") + setEnabled(dialog_->check_inner_box, false); + + char c = controller().params().pos; + fl_set_choice(dialog_->choice_pos, string("tcb").find(c, 0) + 1); + c = controller().params().inner_pos; + fl_set_choice(dialog_->choice_inner_pos, string("tcbs").find(c, 0) + 1); + c = controller().params().hor_pos; + fl_set_choice(dialog_->choice_hor_pos, string("lcrs").find(c, 0) + 1); + setEnabled(dialog_->choice_pos, controller().params().inner_box); + setEnabled(dialog_->choice_inner_pos, controller().params().inner_box); + setEnabled(dialog_->choice_hor_pos, !controller().params().inner_box); + + fl_set_button(dialog_->radio_parbox, controller().params().use_parbox); + fl_set_button(dialog_->radio_minipage, !controller().params().use_parbox); + setEnabled(dialog_->radio_parbox, controller().params().inner_box); + setEnabled(dialog_->radio_minipage, controller().params().inner_box); + + LyXLength len(controller().params().width); + fl_set_input(dialog_->input_width, tostr(len.value()).c_str()); + fl_set_choice(dialog_->choice_width_unit, len.unit() + 1); + string special(controller().params().special); + for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) { + if (special == ids_spec_[i]) + fl_set_choice_text(dialog_->choice_special, + gui_names_spec_[i].c_str()); + } + // Special width unit must be default for general units to be enabled + if(controller().params().special != "none") + setEnabled(dialog_->choice_width_unit, false); + setEnabled(dialog_->choice_special, !controller().params().inner_box); + + LyXLength ht(controller().params().height); + fl_set_input(dialog_->input_height, tostr(ht.value()).c_str()); + fl_set_choice(dialog_->choice_height_unit, ht.unit() + 1); + string const height_special(controller().params().height_special); + for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) { + if (height_special == ids_spec_[i]) + fl_set_choice_text(dialog_->choice_height_special, + gui_names_spec_[i].c_str()); + } + setEnabled(dialog_->input_height, controller().params().inner_box); + setEnabled(dialog_->choice_height_unit, controller().params().inner_box); + setEnabled(dialog_->choice_height_special, controller().params().inner_box); + // Same here + if(height_special != "none") + setEnabled(dialog_->choice_height_unit, false); +} + + +void FormBox::apply() +{ + int i = fl_get_choice(dialog_->choice_type); + controller().params().type = ids_[i - 1]; + + controller().params().inner_box = fl_get_button(dialog_->check_inner_box); + controller().params().use_parbox = + fl_get_button(dialog_->radio_parbox); + controller().params().width = + LyXLength(getLengthFromWidgets(dialog_->input_width, + dialog_->choice_width_unit)); + + controller().params().pos = + "tcb"[fl_get_choice(dialog_->choice_pos) - 1]; + controller().params().inner_pos = + "tcbs"[fl_get_choice(dialog_->choice_inner_pos) - 1]; + controller().params().hor_pos = + "lcrs"[fl_get_choice(dialog_->choice_hor_pos) - 1]; + + i = fl_get_choice(dialog_->choice_special); + controller().params().special = ids_spec_[i - 1]; + + controller().params().height = + LyXLength(getLengthFromWidgets(dialog_->input_height, + dialog_->choice_height_unit)); + i = fl_get_choice(dialog_->choice_height_special); + controller().params().height_special = ids_spec_[i - 1]; +} + +ButtonPolicy::SMInput FormBox::input(FL_OBJECT * ob, long) +{ + if (ob == dialog_->check_inner_box) { + setEnabled(dialog_->choice_pos, + fl_get_button(dialog_->check_inner_box)); + setEnabled(dialog_->radio_parbox, + fl_get_button(dialog_->check_inner_box)); + setEnabled(dialog_->radio_minipage, + fl_get_button(dialog_->check_inner_box)); + setEnabled(dialog_->choice_width_unit, true); + setEnabled(dialog_->choice_special, + !fl_get_button(dialog_->check_inner_box)); + setEnabled(dialog_->input_height, + fl_get_button(dialog_->check_inner_box)); + setEnabled(dialog_->choice_height_unit, + fl_get_button(dialog_->check_inner_box)); + setEnabled(dialog_->choice_height_special, + fl_get_button(dialog_->check_inner_box)); + setEnabled(dialog_->choice_hor_pos, + !fl_get_button(dialog_->check_inner_box)); + setEnabled(dialog_->choice_inner_pos, + fl_get_button(dialog_->check_inner_box)); + + // Reset to defaults to not confuse users: + if (fl_get_button(dialog_->check_inner_box)) + fl_set_choice(dialog_->choice_special, NONE); + else + fl_set_choice(dialog_->choice_height_special, NONE); + } + + if (ob == dialog_->choice_special || ob == dialog_->check_inner_box) + setEnabled(dialog_->choice_width_unit, + fl_get_choice(dialog_->choice_special) == NONE); + if (ob == dialog_->choice_height_special || ob == dialog_->check_inner_box) + if (fl_get_choice(dialog_->choice_height_special) != NONE) + setEnabled(dialog_->choice_height_unit, false); + else + setEnabled(dialog_->choice_height_unit, + fl_get_button(dialog_->check_inner_box)); + + // An inner box (parbox, minipage) is mandatory if no outer box + if (ob == dialog_->choice_type) { + int i = fl_get_choice(dialog_->choice_type); + if (ids_[i - 1] == "Frameless") { + setEnabled(dialog_->check_inner_box, false); + fl_set_button(dialog_->check_inner_box, true); + } else { + setEnabled(dialog_->check_inner_box, true); + } + } + // 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!")); + return ButtonPolicy::SMI_INVALID; + } + } + if (ob == dialog_->input_height) { + string const input = getString(dialog_->input_height); + bool const invalid = !isValidLength(input) && !isStrDbl(input); + if (invalid) { + postWarning(_("Invalid Length!")); + return ButtonPolicy::SMI_INVALID; + } + } + if (ob == dialog_->button_defaults) { + fl_set_button(dialog_->check_inner_box, true); + fl_set_button(dialog_->radio_parbox, false); + fl_set_input(dialog_->input_width, "100"); + fl_set_choice(dialog_->choice_width_unit, LyXLength::PCW + 1); + fl_set_choice(dialog_->choice_special, NONE); + fl_set_input(dialog_->input_height, "1"); + fl_set_choice(dialog_->choice_height_special, TOTALHEIGHT); + } + + return ButtonPolicy::SMI_VALID; +} + diff --git a/src/frontends/xforms/FormBox.h b/src/frontends/xforms/FormBox.h new file mode 100644 index 0000000000..0bdc2180a3 --- /dev/null +++ b/src/frontends/xforms/FormBox.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +/** + * \file FormBox.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef FORMBOX_H +#define FORMBOX_H + + +#include "FormDialogView.h" + + +class ControlBox; +struct FD_box; + +/** This class provides an XForms implementation of the Box Dialog. + */ +class FormBox : public FormController > { +public: + /// Constructor + FormBox(Dialog &); +private: + /// + virtual void apply(); + /// Build the dialog + virtual void build(); + /// Update dialog before showing it + virtual void update(); + /// + virtual ButtonPolicy::SMInput input( FL_OBJECT *, long); + /// + std::vector ids_; + /// + std::vector gui_names_; + /// + std::vector ids_spec_; + /// + std::vector gui_names_spec_; + /// + enum Specials { + NONE = 1, + HEIGHT, + DEPTH, + TOTALHEIGHT, + WIDTH + }; +}; + +#endif // FORMBOX_H diff --git a/src/frontends/xforms/Makefile.am b/src/frontends/xforms/Makefile.am index c6dafe8f1b..b2cd96fe97 100644 --- a/src/frontends/xforms/Makefile.am +++ b/src/frontends/xforms/Makefile.am @@ -72,6 +72,8 @@ libxforms_la_SOURCES = \ FormBibitem.h \ FormBibtex.C \ FormBibtex.h \ + FormBox.C \ + FormBox.h \ FormBrowser.C \ FormBrowser.h \ FormBranch.C \ diff --git a/src/frontends/xforms/forms/Makefile.am b/src/frontends/xforms/forms/Makefile.am index 8a835f6b8b..316f89cd20 100644 --- a/src/frontends/xforms/forms/Makefile.am +++ b/src/frontends/xforms/forms/Makefile.am @@ -12,6 +12,7 @@ noinst_LTLIBRARIES = libfdesign.la SRCS = form_aboutlyx.fd \ form_bibitem.fd \ form_bibtex.fd \ + form_box.fd \ form_browser.fd \ form_branch.fd \ form_changes.fd \ diff --git a/src/frontends/xforms/forms/form_box.fd b/src/frontends/xforms/forms/form_box.fd new file mode 100644 index 0000000000..e55f6c97d3 --- /dev/null +++ b/src/frontends/xforms/forms/form_box.fd @@ -0,0 +1,359 @@ +Magic: 13000 + +Internal Form Definition File + (do not change) + +Number of forms: 1 +Unit of measure: FL_COORD_PIXEL +SnapGrid: 7 + +=============== FORM =============== +Name: form_box +Width: 442 +Height: 379 +Number of Objects: 19 + +-------------------- +class: FL_BOX +type: UP_BOX +box: 0 0 442 379 +boxtype: FL_UP_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_CHOICE +type: NORMAL_CHOICE +box: 175 21 231 28 +boxtype: FL_FRAME_BOX +colors: FL_COL1 FL_BLACK +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Box Type|#T +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: choice_type +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: RETURN_BUTTON +box: 56 322 84 28 +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_FormDialogView_OKCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: RETURN_BUTTON +box: 147 322 98 28 +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: ^M +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_apply +callback: C_FormDialogView_ApplyCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: RETURN_BUTTON +box: 252 322 105 28 +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: ^M +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_cancel +callback: C_FormDialogView_CancelCB +argument: 0 + +-------------------- +class: FL_CHECKBUTTON +type: PUSH_BUTTON +box: 21 70 35 28 +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: Has Inner Box +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: check_inner_box +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_CHOICE +type: NORMAL_CHOICE2 +box: 315 77 91 28 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_BLACK +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Vertical Position +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: choice_pos +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_CHOICE +type: NORMAL_CHOICE2 +box: 203 210 91 28 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_BLACK +alignment: FL_ALIGN_TOP +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Width Unit +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: choice_width_unit +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_INPUT +type: NORMAL_INPUT +box: 126 210 77 28 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_TOP +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Width +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: input_width +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_CHOICE +type: NORMAL_CHOICE2 +box: 294 210 112 28 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_BLACK +alignment: FL_ALIGN_TOP +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Special +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: choice_special +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_ROUND3DBUTTON +type: RADIO_BUTTON +box: 21 112 35 28 +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: Parbox +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: radio_parbox +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_ROUND3DBUTTON +type: RADIO_BUTTON +box: 21 140 35 28 +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: Minipage +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: radio_minipage +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_FRAME +type: ENGRAVED_FRAME +box: 14 112 112 63 +boxtype: FL_NO_BOX +colors: FL_BLACK 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_CHOICE +type: NORMAL_CHOICE2 +box: 315 112 91 28 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_BLACK +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Inner Position (Vert.) +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: choice_inner_pos +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_CHOICE +type: NORMAL_CHOICE2 +box: 315 147 91 28 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_BLACK +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Horizontal Position +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: choice_hor_pos +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_INPUT +type: NORMAL_INPUT +box: 126 266 77 28 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_TOP +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Height +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: input_height +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_CHOICE +type: NORMAL_CHOICE2 +box: 203 266 91 28 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_BLACK +alignment: FL_ALIGN_TOP +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Height Unit +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: choice_height_unit +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_CHOICE +type: NORMAL_CHOICE2 +box: 294 266 112 28 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_BLACK +alignment: FL_ALIGN_TOP +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Special +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: choice_height_special +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 28 238 77 28 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: Reset +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_defaults +callback: C_FormDialogView_InputCB +argument: 0 + +============================== +create_the_forms diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 7f0ea9eb92..449a6e7afa 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,10 @@ +2003-10-07 Martin Vermeer + + * Makefile.am: + * inset.h: + * insetbox.C: + * insetbox.h: The Box patch. Fancybox support, minipage, parbox + 2003-10-02 André Pönitz * insettext.C (read): make sure there is at least one par diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index 9b29c5ed9f..dd9c775da9 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -25,6 +25,8 @@ libinsets_la_SOURCES = \ insetbibitem.h \ insetbibtex.C \ insetbibtex.h \ + insetbox.C \ + insetbox.h \ insetbranch.C \ insetbranch.h \ insetcaption.C \ diff --git a/src/insets/inset.h b/src/insets/inset.h index 670b52390e..bc653185ea 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -131,7 +131,9 @@ public: /// NEWLINE_CODE, /// - BRANCH_CODE + BRANCH_CODE, + /// + BOX_CODE }; /// diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C new file mode 100644 index 0000000000..147edf5763 --- /dev/null +++ b/src/insets/insetbox.C @@ -0,0 +1,590 @@ +/** + * \file insetbox.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Angus Leeming + * \author Martin Vermeer + * \author Jürgen Spitzmüller + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "insetbox.h" +#include "debug.h" + +#include "BufferView.h" +#include "funcrequest.h" +#include "gettext.h" +#include "LaTeXFeatures.h" +#include "LColor.h" +#include "lyxlex.h" +#include "metricsinfo.h" +#include "paragraph.h" + +#include "support/std_sstream.h" + +using std::auto_ptr; +using std::string; +using std::istringstream; +using std::ostream; +using std::ostringstream; +using std::endl; + + +namespace { + +BoxTranslator const init_boxtranslator() { + BoxTranslator translator("Boxed", InsetBox::Boxed); + translator.addPair("Frameless", InsetBox::Frameless); + translator.addPair("ovalbox", InsetBox::ovalbox); + translator.addPair("Ovalbox", InsetBox::Ovalbox); + translator.addPair("Shadowbox", InsetBox::Shadowbox); + translator.addPair("Doublebox",InsetBox::Doublebox); + return translator; +} + + +BoxTranslator const init_boxtranslator_loc() { + BoxTranslator translator(_("Boxed"), InsetBox::Boxed); + translator.addPair(_("Frameless"), InsetBox::Frameless); + translator.addPair(_("ovalbox"), InsetBox::ovalbox); + translator.addPair(_("Ovalbox"), InsetBox::Ovalbox); + translator.addPair(_("Shadowbox"), InsetBox::Shadowbox); + translator.addPair(_("Doublebox"), InsetBox::Doublebox); + return translator; +} + + +BoxTranslator const & boxtranslator() { + static BoxTranslator translator = init_boxtranslator(); + return translator; +} + + +BoxTranslator const & boxtranslator_loc() { + static BoxTranslator translator = init_boxtranslator_loc(); + return translator; +} + +} // anon + + +void InsetBox::init() +{ + setInsetName("Box"); + setButtonLabel(); +} + + +InsetBox::InsetBox(BufferParams const & bp, string const & label) + : InsetCollapsable(bp), params_(label) +{ + init(); +} + + +InsetBox::InsetBox(InsetBox const & in) + : InsetCollapsable(in), params_(in.params_) +{ + init(); +} + + +InsetBox::~InsetBox() +{ + InsetBoxMailer mailer(*this); + mailer.hideDialog(); +} + + +auto_ptr InsetBox::clone() const +{ + return auto_ptr(new InsetBox(*this)); +} + + +string const InsetBox::editMessage() const +{ + return _("Opened Box Inset"); +} + + +void InsetBox::write(Buffer const & buf, ostream & os) const +{ + params_.write(os); + InsetCollapsable::write(buf, os); +} + + +void InsetBox::read(Buffer const & buf, LyXLex & lex) +{ + params_.read(lex); + InsetCollapsable::read(buf, lex); + setButtonLabel(); +} + + +void InsetBox::setButtonLabel() +{ + LyXFont font(LyXFont::ALL_SANE); + font.decSize(); + font.decSize(); + + BoxType btype = boxtranslator().find(params_.type); + if (btype == Frameless) { + if (params_.use_parbox) + setLabel(_("Parbox")); + else + setLabel(_("Minipage")); + } else + setLabel(boxtranslator_loc().find(btype)); + + font.setColor(LColor::foreground); + setBackgroundColor(LColor::background); + setLabelFont(font); +} + + +void InsetBox::metrics(MetricsInfo & mi, Dimension & dim) const +{ + InsetCollapsable::metrics(mi, dim); + if (params_.inner_box && isOpen()) + dim.wid = mi.base.textwidth; + dim_ = dim; +} + + +bool InsetBox::showInsetDialog(BufferView * bv) const +{ + InsetBoxMailer(const_cast(*this)).showDialog(bv); + return true; +} + + +dispatch_result InsetBox::localDispatch(FuncRequest const & cmd) +{ + BufferView * bv = cmd.view(); + + switch (cmd.action) { + + case LFUN_INSET_MODIFY: { + InsetBoxMailer::string2params(cmd.argument, params_); + setButtonLabel(); + bv->updateInset(this); + return DISPATCHED; + } + case LFUN_INSET_DIALOG_UPDATE: + InsetBoxMailer(*this).updateDialog(bv); + return DISPATCHED; + + case LFUN_MOUSE_RELEASE: + if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { + InsetBoxMailer(*this).showDialog(bv); + return DISPATCHED; + } + // fallthrough: + + default: + return InsetCollapsable::localDispatch(cmd); + } +} + + +int InsetBox::latex(Buffer const & buf, ostream & os, + LatexRunParams const & runparams) const +{ + BoxType btype = boxtranslator().find(params_.type); + + string width_string = params_.width.asLatexString(); + bool stdwidth(false); + if (params_.inner_box && + (width_string.find("1.0\\columnwidth") != string::npos + || width_string.find("1.0\\textwidth") != string::npos)) { + stdwidth = true; + switch (btype) { + case Frameless: + break; + case Boxed: + width_string += " - 2\\fboxsep - 2\\fboxrule"; + break; + case ovalbox: + width_string += " - 2\\fboxsep - 0.8pt"; + break; + case Ovalbox: + width_string += " - 2\\fboxsep - 1.6pt"; + break; + case Shadowbox: + // Shadow falls outside right margin... opinions? + width_string += " - 2\\fboxsep - 2\\fboxrule"/* "-\\shadowsize"*/; + break; + case Doublebox: + width_string += " - 2\\fboxsep - 7.5\\fboxrule - 1.0pt"; + break; + } + } + + int i = 0; + os << "%\n"; + // Adapt to column/text width correctly also if paragraphs indented: + if (stdwidth) + os << "\\noindent"; + + switch (btype) { + case Frameless: + break; + case Boxed: + os << "\\framebox"; + if (!params_.inner_box) { + os << "{\\makebox"; + // Special widths, see usrguide §3.5 + if (params_.special != "none") { + os << "[" << params_.width.value() + << "\\" << params_.special << "]"; + } else + os << "[" << width_string << "]"; + if (params_.hor_pos != 'c') + os << "[" << params_.hor_pos << "]"; + } + + os << "{"; + break; + case ovalbox: + os << "\\ovalbox{"; + break; + case Ovalbox: + os << "\\Ovalbox{"; + break; + case Shadowbox: + os << "\\shadowbox{"; + break; + case Doublebox: + os << "\\doublebox{"; + break; + } + + if (params_.inner_box) { + if (params_.use_parbox) + os << "\\parbox"; + else + os << "\\begin{minipage}"; + + os << "[" << params_.pos << "]"; + if (params_.height_special == "none") { + os << "[" << params_.height.asLatexString() << "]"; + } else { + // Special heights + os << "[" << params_.height.value() + << "\\" << params_.height_special << "]"; + } + if (params_.inner_pos != params_.pos) + os << "[" << params_.inner_pos << "]"; + + os << "{" << width_string << "}"; + + if (params_.use_parbox) + os << "{"; + os << "%\n"; + i += 1; + } + + i += inset.latex(buf, os, runparams); + + if (params_.inner_box) { + if (params_.use_parbox) + os << "%\n}"; + else + os << "%\n\\end{minipage}"; + } + + switch (btype) { + case Frameless: + break; + case Boxed: + if (!params_.inner_box) + os << "}"; // for makebox + os << "}"; + break; + case ovalbox: + case Ovalbox: + case Doublebox: + case Shadowbox: + os << "}"; + break; + } + os << "%\n"; + + i += 3; + + return i; +} + + +int InsetBox::linuxdoc(Buffer const & buf, std::ostream & os) const +{ + return inset.linuxdoc(buf, os); +} + + +int InsetBox::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const +{ + return inset.docbook(buf, os, mixcont); +} + + +int InsetBox::ascii(Buffer const & buf, std::ostream & os, int ll) const +{ + int i = 0; + string const pt = params_.type; + BoxType btype = boxtranslator().find(params_.type); + switch (btype) { + case Frameless: + break; + case Boxed: + os << "["; + break; + case ovalbox: + os << "("; + break; + case Ovalbox: + os << "(("; + break; + case Shadowbox: + os << "["; + break; + case Doublebox: + os << "[["; + break; + } + + i = inset.ascii(buf, os, ll); + + switch (btype) { + case Frameless: + break; + case Boxed: + os << "]"; + break; + case ovalbox: + os << ")"; + break; + case Ovalbox: + os << "))"; + break; + case Shadowbox: + os << "]/"; + break; + case Doublebox: + os << "]]"; + break; + } + + return i; +} + + +void InsetBox::validate(LaTeXFeatures & features) const +{ + features.require("calc"); + BoxType btype = boxtranslator().find(params_.type); + switch (btype) { + case Frameless: + case Boxed: + break; + case ovalbox: + case Ovalbox: + case Shadowbox: + case Doublebox: + features.require("fancybox"); + break; + } + inset.validate(features); +} + + +InsetBoxMailer::InsetBoxMailer(InsetBox & inset) + : inset_(inset) +{ +} + + +string const InsetBoxMailer::name_ = "box"; + + +string const InsetBoxMailer::inset2string(Buffer const &) const +{ + return params2string(inset_.params()); +} + + +string const InsetBoxMailer::params2string(InsetBoxParams const & params) +{ + ostringstream data; + data << "box" << ' '; + params.write(data); + return data.str(); +} + + +void InsetBoxMailer::string2params(string const & in, + InsetBoxParams & params) +{ + params = InsetBoxParams(string()); + + if (in.empty()) + return; + + istringstream data(in); + LyXLex lex(0,0); + lex.setStream(data); + + string token; + lex.next(); + token = lex.getString(); + lex.next(); + + params.read(lex); +} + + +InsetBoxParams::InsetBoxParams(string const & label) + : type(label), + use_parbox(false), + inner_box(true), + width(LyXLength("100col%")), + special("none"), + pos('t'), + hor_pos('c'), + inner_pos('t'), + height(LyXLength("1in")), + height_special("totalheight") // default is 1\\totalheight +{} + + +void InsetBoxParams::write(ostream & os) const +{ + os << type << "\n"; + os << "position \"" << pos << "\"\n"; + os << "hor_pos \"" << hor_pos << "\"\n"; + os << "has_inner_box " << inner_box << "\n"; + os << "inner_pos \"" << inner_pos << "\"\n"; + os << "use_parbox " << use_parbox << "\n"; + os << "width \"" << width.asString() << "\"\n"; + os << "special \"" << special << "\"\n"; + os << "height \"" << height.asString() << "\"\n"; + os << "height_special \"" << height_special << "\"\n"; +} + + +void InsetBoxParams::read(LyXLex & lex) +{ + if (lex.isOK()) { + type = lex.getString(); + } + string token; + if (!lex.isOK()) + return; + lex.next(); + token = lex.getString(); + if (token == "position") { + lex.next(); + // The [0] is needed. We need the first and only char in + // this string -- MV + pos = lex.getString()[0]; + } else { + lyxerr << "InsetBox::Read: Missing 'position'-tag!" << token << endl; + lex.pushToken(token); + } + if (!lex.isOK()) + return; + lex.next(); + token = lex.getString(); + if (token == "hor_pos") { + lex.next(); + hor_pos = lex.getString()[0]; + } else { + lyxerr << "InsetBox::Read: Missing 'hor_pos'-tag!" << token << endl; + lex.pushToken(token); + } + if (!lex.isOK()) + return; + lex.next(); + token = lex.getString(); + if (token == "has_inner_box") { + lex.next(); + inner_box = lex.getInteger(); + } else { + lyxerr << "InsetBox::Read: Missing 'has_inner_box'-tag!" << endl; + lex.pushToken(token); + } + + if (!lex.isOK()) + return; + lex.next(); + token = lex.getString(); + if (token == "inner_pos") { + lex.next(); + inner_pos = lex.getString()[0]; + } else { + lyxerr << "InsetBox::Read: Missing 'inner_pos'-tag!" + << token << endl; + lex.pushToken(token); + } + if (!lex.isOK()) + return; + lex.next(); + token = lex.getString(); + if (token == "use_parbox") { + lex.next(); + use_parbox = lex.getInteger(); + } else { + lyxerr << "InsetBox::Read: Missing 'use_parbox'-tag!" << endl; + lex.pushToken(token); + } + if (!lex.isOK()) + return; + lex.next(); + token = lex.getString(); + if (token == "width") { + lex.next(); + width = LyXLength(lex.getString()); + } else { + lyxerr << "InsetBox::Read: Missing 'width'-tag!" << endl; + lex.pushToken(token); + } + if (!lex.isOK()) + return; + lex.next(); + token = lex.getString(); + if (token == "special") { + lex.next(); + special = lex.getString(); + } else { + lyxerr << "InsetBox::Read: Missing 'special'-tag!" << endl; + lex.pushToken(token); + } + if (!lex.isOK()) + return; + lex.next(); + token = lex.getString(); + if (token == "height") { + lex.next(); + height = LyXLength(lex.getString()); + } else { + lyxerr << "InsetBox::Read: Missing 'height'-tag!" << endl; + lex.pushToken(token); + } + if (!lex.isOK()) + return; + lex.next(); + token = lex.getString(); + if (token == "height_special") { + lex.next(); + height_special = lex.getString(); + } else { + lyxerr << "InsetBox::Read: Missing 'height_special'-tag!" << endl; + lex.pushToken(token); + } +} diff --git a/src/insets/insetbox.h b/src/insets/insetbox.h new file mode 100644 index 0000000000..48dbcf2366 --- /dev/null +++ b/src/insets/insetbox.h @@ -0,0 +1,148 @@ +// -*- C++ -*- +/** + * \file insetbox.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Angus Leeming + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef INSETBOX_H +#define INSETBOX_H + + +#include "insetcollapsable.h" +#include "lyxlength.h" +#include "support/translator.h" + + +struct InsetBoxParams { + /// + InsetBoxParams(std::string const &); + /// + void write(std::ostream & os) const; + /// + void read(LyXLex & lex); + /// + std::string type; + /// Use a parbox (true) or minipage (false) + bool use_parbox; + /// Do we have an inner parbox or minipage to format paragraphs to + /// columnwidth? + bool inner_box; + /// + LyXLength width; + /// "special" widths, see usrguide.dvi §3.5 + std::string special; + /// + char pos; + /// + char hor_pos; + /// + char inner_pos; + /// + LyXLength height; + /// + std::string height_special; +}; + + +/** The fbox/fancybox inset + +*/ +class InsetBox : public InsetCollapsable { +public: + /// + InsetBox(BufferParams const &, std::string const &); + /// Copy constructor + InsetBox(InsetBox const &); + /// + ~InsetBox(); + /// + virtual std::auto_ptr clone() const; + /// + std::string const editMessage() const; + /// + InsetOld::Code lyxCode() const { return InsetOld::BOX_CODE; } + /// + void write(Buffer const &, std::ostream &) const; + /// + void read(Buffer const & buf, LyXLex & lex); + /// + void setButtonLabel(); + /// + dispatch_result InsetBox::localDispatch(FuncRequest const &); + /// + void metrics(MetricsInfo &, Dimension &) const; + /// show the Box dialog + bool showInsetDialog(BufferView * bv) const; + /// + int latex(Buffer const &, std::ostream &, + LatexRunParams const &) const; + /// + int linuxdoc(Buffer const &, std::ostream &) const; + /// + int docbook(Buffer const &, std::ostream &, bool) const; + /// + int ascii(Buffer const &, std::ostream &, int) const; + /// + void validate(LaTeXFeatures &) const; + /// + InsetBoxParams const & params() const { return params_; } + /// + enum BoxType { + Frameless, + Boxed, + ovalbox, + Ovalbox, + Shadowbox, + Doublebox + }; + +private: + friend class InsetBoxParams; + + /// used by the constructors + void init(); + /// + InsetBoxParams params_; +}; + + +namespace { + +typedef Translator BoxTranslator; +BoxTranslator const & boxtranslator(); +BoxTranslator const & boxtranslator_loc(); + +} // anon + + +#include "mailinset.h" + +class InsetBoxMailer : public MailInset { +public: + /// + InsetBoxMailer(InsetBox & inset); + /// + virtual InsetBase & inset() const { return inset_; } + /// + virtual std::string const & name() const { return name_; } + /// + virtual std::string const inset2string(Buffer const &) const; + /// + static std::string const params2string(InsetBoxParams const &); + /// + static void string2params(std::string const &, InsetBoxParams &); + +private: + /// + static std::string const name_; + /// + InsetBox & inset_; +}; + +#endif // INSET_BOX_H diff --git a/src/lfuns.h b/src/lfuns.h index 4b24b321f9..cb1c7e5d85 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -323,6 +323,7 @@ enum kb_action { // 245 LFUN_INSERT_BRANCH, LFUN_INSET_DIALOG_SHOW, + LFUN_INSERT_BOX, LFUN_LASTACTION // end of the table }; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index abe1b46809..54df4a3c70 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -525,6 +525,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case InsetOld::BRANCH_CODE: disable = ev.argument != "branch"; break; + case InsetOld::BOX_CODE: + disable = ev.argument != "box"; + break; default: break; } @@ -653,6 +656,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_INSERT_NOTE: code = InsetOld::NOTE_CODE; break; + case LFUN_INSERT_BOX: + code = InsetOld::BOX_CODE; + break; case LFUN_INSERT_BRANCH: code = InsetOld::BRANCH_CODE; if (buf->params().branchlist().empty()) diff --git a/src/text3.C b/src/text3.C index b31f5cde5c..f0cae29d64 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1505,6 +1505,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd) case LFUN_INSET_CAPTION: #endif case LFUN_INSERT_NOTE: + case LFUN_INSERT_BOX: case LFUN_INSERT_BRANCH: case LFUN_INSERT_BIBITEM: case LFUN_INSET_ERT: