On Thu, Sep 18, 2003 at 10:51:21PM +0000, Angus Leeming spake thusly:
> 
> Martin Vermeer wrote:
> 
> > This patch adds support for rectangular frames containing one or more
> > paragraphs of text, at the width of the column, using the Note
> > infrastructure.
> > 
> > It wouldn't be too hard to extend this to fancybox support.
> > 
> > Does this look like the right thing to do?
> 
> What has this got to do with 'Note'? Derive a new InsetBoxed from 
> InsetCollapsable.
> 
> -- 
> Angus

Okay, did just that. Here is the next attempt.

- Martin 

Index: lib/ui/stdmenus.ui
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/ui/stdmenus.ui,v
retrieving revision 1.25
diff -u -p -r1.25 stdmenus.ui
--- lib/ui/stdmenus.ui  22 Aug 2003 10:37:25 -0000      1.25
+++ lib/ui/stdmenus.ui  21 Sep 2003 12:20:02 -0000
@@ -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
@@ -337,6 +338,10 @@ Menuset
                Item "LyX Note|N" "note-insert Note"
                Item "Comment|C" "note-insert Comment"
                Item "Greyed Out|G" "note-insert Greyedout"
+       End
+
+       Menu "insert_box"
+               Item "Boxed|B" "box-insert Boxed"
        End
 
        Menu "branches"
Index: src/LaTeXFeatures.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LaTeXFeatures.C,v
retrieving revision 1.96
diff -u -p -r1.96 LaTeXFeatures.C
--- src/LaTeXFeatures.C 15 Sep 2003 10:59:51 -0000      1.96
+++ src/LaTeXFeatures.C 21 Sep 2003 12:20:02 -0000
@@ -370,6 +370,10 @@ string const LaTeXFeatures::getMacros() 
        if (isRequired("lyxgreyedout"))
                macros << lyxgreyedout_def;
 
+       // Provide box fit to col width:
+       if (isRequired("fboxwidth"))
+               macros << fboxwidth_def;
+       
        // floats
        getFloatDefinitions(macros);
 
Index: src/LyXAction.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LyXAction.C,v
retrieving revision 1.182
diff -u -p -r1.182 LyXAction.C
--- src/LyXAction.C     9 Sep 2003 22:13:22 -0000       1.182
+++ src/LyXAction.C     21 Sep 2003 12:20:02 -0000
@@ -233,6 +233,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 },
Index: src/factory.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/factory.C,v
retrieving revision 1.55
diff -u -p -r1.55 factory.C
--- src/factory.C       16 Sep 2003 10:54:23 -0000      1.55
+++ src/factory.C       21 Sep 2003 12:20:02 -0000
@@ -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"
@@ -79,6 +80,13 @@ InsetOld * createInset(FuncRequest const
                                arg = "Note";
                        return new InsetNote(params, arg);
                }
+       case LFUN_INSERT_BOX:
+               {
+                       string arg = cmd.getArg(0);
+                       if (arg.empty())
+                               arg = "Box";
+                       return new InsetBox(params, arg);
+               }
        case LFUN_INSERT_BRANCH:
                {
                        string arg = cmd.getArg(0);
@@ -369,6 +377,8 @@ InsetOld * readInset(LyXLex & lex, Buffe
                } else if (tmptok == "Note"     || tmptok == "Comment"
                                || tmptok == "Greyedout") {
                        inset = new InsetNote(buf.params(), tmptok);
+               } else if (tmptok == "Boxed") {
+                       inset = new InsetBox(buf.params(), tmptok);
                } else if (tmptok == "Branch") {
                        inset = new InsetBranch(buf.params(), tmptok);
                } else if (tmptok == "Include") {
Index: src/lfuns.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lfuns.h,v
retrieving revision 1.19
diff -u -p -r1.19 lfuns.h
--- src/lfuns.h 9 Sep 2003 18:27:21 -0000       1.19
+++ src/lfuns.h 21 Sep 2003 12:20:02 -0000
@@ -323,6 +323,7 @@ enum kb_action {
        // 245
        LFUN_INSERT_BRANCH,
        LFUN_INSET_DIALOG_SHOW,
+       LFUN_INSERT_BOX,
 
        LFUN_LASTACTION                  // end of the table
 };
Index: src/lyx_sty.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_sty.C,v
retrieving revision 1.14
diff -u -p -r1.14 lyx_sty.C
--- src/lyx_sty.C       23 Aug 2003 00:16:11 -0000      1.14
+++ src/lyx_sty.C       21 Sep 2003 12:20:02 -0000
@@ -128,3 +128,10 @@ string const tabularnewline_def =
 string const lyxgreyedout_def =
        "%% The greyedout annotation environment\n"
        "\\newenvironment{lyxgreyedout}{\\color[gray]{0.8}}{}\n";
+
+       string const fboxwidth_def =
+       "\\newlength\\fboxwidth\n"
+       "\\setlength\\fboxwidth{\\columnwidth}\n"
+       "\\addtolength\\fboxwidth{-2\\fboxsep}\n"
+       "\\addtolength\\fboxwidth{-2\\fboxrule}\n";
+
Index: src/lyx_sty.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_sty.h,v
retrieving revision 1.15
diff -u -p -r1.15 lyx_sty.h
--- src/lyx_sty.h       5 Sep 2003 17:22:48 -0000       1.15
+++ src/lyx_sty.h       21 Sep 2003 12:20:02 -0000
@@ -54,5 +54,7 @@ extern string const mathcircumflex_def;
 extern string const tabularnewline_def;
 ///
 extern string const lyxgreyedout_def;
+///
+extern string const fboxwidth_def;
 
 #endif // LYX_STY_H
Index: src/lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.504
diff -u -p -r1.504 lyxfunc.C
--- src/lyxfunc.C       17 Sep 2003 16:44:51 -0000      1.504
+++ src/lyxfunc.C       21 Sep 2003 12:20:02 -0000
@@ -659,6 +659,9 @@ FuncStatus LyXFunc::getStatus(FuncReques
        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())
Index: src/text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.143
diff -u -p -r1.143 text3.C
--- src/text3.C 15 Sep 2003 10:59:54 -0000      1.143
+++ src/text3.C 21 Sep 2003 12:20:02 -0000
@@ -1505,6 +1505,7 @@ InsetOld::RESULT LyXText::dispatch(FuncR
        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:
Index: src/insets/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/Makefile.am,v
retrieving revision 1.66
diff -u -p -r1.66 Makefile.am
--- src/insets/Makefile.am      17 Aug 2003 11:28:23 -0000      1.66
+++ src/insets/Makefile.am      21 Sep 2003 12:20:03 -0000
@@ -73,6 +73,8 @@ libinsets_la_SOURCES = \
        insetnewline.h \
        insetnote.C \
        insetnote.h \
+       insetbox.C \
+       insetbox.h \
        insetoptarg.C \
        insetoptarg.h \
        insetquotes.C \
Index: src/insets/inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v
retrieving revision 1.120
diff -u -p -r1.120 inset.h
--- src/insets/inset.h  18 Sep 2003 11:48:10 -0000      1.120
+++ src/insets/inset.h  21 Sep 2003 12:20:03 -0000
@@ -130,7 +130,9 @@ public:
                ///
                NEWLINE_CODE,
                ///
-               BRANCH_CODE
+               BRANCH_CODE,
+               ///
+               BOX_CODE
        };
 
        ///
Index: src/insets/insetbox.C
===================================================================
RCS file: src/insets/insetbox.C
diff -N src/insets/insetbox.C
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/insets/insetbox.C       21 Sep 2003 12:20:03 -0000
@@ -0,0 +1,280 @@
+/**
+ * \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 <config.h>
+
+#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::istringstream;
+using std::ostream;
+using std::ostringstream;
+
+
+void InsetBox::init()
+{
+       setInsetName("Box");
+       setButtonLabel();
+}
+
+
+InsetBox::InsetBox(BufferParams const & bp, string const & label)
+       : InsetCollapsable(bp)
+{
+       params_.type = label;
+       init();
+       setButtonLabel();
+}
+
+
+InsetBox::InsetBox(InsetBox const & in)
+       : InsetCollapsable(in), params_(in.params_)
+{
+       init();
+}
+
+
+InsetBox::~InsetBox() // MV
+{
+       InsetBoxMailer mailer("box", *this);
+       mailer.hideDialog();
+}
+
+
+auto_ptr<InsetBase> InsetBox::clone() const
+{
+       return auto_ptr<InsetBase>(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)
+{
+       InsetCollapsable::read(buf, lex);
+       setButtonLabel();
+}
+
+
+void InsetBox::setButtonLabel()
+{
+       LyXFont font(LyXFont::ALL_SANE);
+       font.decSize();
+       font.decSize();
+
+       if (params_.type == "Boxed") {
+               setLabel(_("Boxed"));
+               font.setColor(LColor::foreground);
+               setBackgroundColor(LColor::background);
+       }
+       setLabelFont(font);
+}
+
+
+void InsetBox::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       InsetCollapsable::metrics(mi, dim);
+       if (params_.type == "Boxed")
+               if (isOpen())
+                       dim.wid = mi.base.textwidth;
+       dim_ = dim;
+}
+
+
+bool InsetBox::showInsetDialog(BufferView * bv) const
+{
+       InsetBoxMailer("box", const_cast<InsetBox &>(*this)).showDialog(bv);
+       return true;
+}
+
+
+dispatch_result InsetBox::localDispatch(FuncRequest const & cmd)
+{
+       BufferView * bv = cmd.view();
+
+       switch (cmd.action) {
+
+       case LFUN_INSET_MODIFY: {
+               InsetBoxParams params;
+               InsetBoxMailer::string2params(cmd.argument, params);
+               params_.type = params.type;
+               setButtonLabel();
+               bv->updateInset(this);
+               return DISPATCHED;
+       }
+
+       case LFUN_INSET_EDIT:
+               if (cmd.button() == mouse_button::button3)
+                       return UNDISPATCHED;
+               return InsetCollapsable::localDispatch(cmd);
+
+       case LFUN_INSET_DIALOG_UPDATE:
+               InsetBoxMailer("box", *this).updateDialog(bv);
+               return DISPATCHED;
+
+       case LFUN_MOUSE_RELEASE:
+               if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
+                       InsetBoxMailer("box", *this).showDialog(bv);
+                       return DISPATCHED;
+               }
+               // fallthrough:
+
+       default:
+               return InsetCollapsable::localDispatch(cmd);
+       }
+}
+
+
+int InsetBox::latex(Buffer const & buf, ostream & os,
+                                               LatexRunParams const & runparams) const
+{
+       string const pt = params_.type;
+
+       int i = 0;
+       if (pt == "Boxed") {
+               os << "%\n\\par\\fbox{\\parbox{\\fboxwidth}{%\n";
+       }
+
+       i = inset.latex(buf, os, runparams);
+
+       if (pt == "Boxed") {
+               os << "%\n}}\\par\n";
+               i += 4;
+       }
+                               
+       return i;
+}
+
+
+int InsetBox::linuxdoc(Buffer const & buf, std::ostream & os) const
+{
+       int i = 0;
+       string const pt = params_.type;
+
+       i = inset.linuxdoc(buf, os);
+       return i;
+}
+
+
+int InsetBox::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
+{
+       int i = 0;
+       string const pt = params_.type;
+
+       i = inset.docbook(buf, os, mixcont);
+
+       return i;
+}
+
+
+int InsetBox::ascii(Buffer const & buf, std::ostream & os, int ll) const
+{
+       int i = 0;
+       string const pt = params_.type;
+       if (pt == "Boxed") {
+               os << "[";
+               i = inset.ascii(buf, os, ll);
+               os << "]";
+       }
+       return i;
+}
+
+
+void InsetBox::validate(LaTeXFeatures & features) const
+{
+       if (params_.type == "Boxed") {
+               features.require("fboxwidth");
+       }
+       inset.validate(features);
+}
+
+
+
+InsetBoxMailer::InsetBoxMailer(string const & name,
+                                               InsetBox & inset)
+       : name_(name), inset_(inset)
+{
+}
+
+
+string const InsetBoxMailer::inset2string(Buffer const &) const
+{
+       return params2string(name_, inset_.params());
+}
+
+
+string const InsetBoxMailer::params2string(string const & name,
+                               InsetBoxParams const & params)
+{
+       ostringstream data;
+       data << name << ' ';
+       params.write(data);
+       return data.str();
+}
+
+
+void InsetBoxMailer::string2params(string const & in,
+                                    InsetBoxParams & params)
+{
+       params = InsetBoxParams();
+
+       if (in.empty())
+               return;
+
+       istringstream data(in);
+       LyXLex lex(0,0);
+       lex.setStream(data);
+       params.read(lex);
+}
+
+
+void InsetBoxParams::write(ostream & os) const
+{
+       os << type << "\n";
+}
+
+
+void InsetBoxParams::read(LyXLex & lex)
+{
+       if (lex.isOK()) {
+               lex.next();
+               string token = lex.getString();
+       }
+
+       if (lex.isOK()) {
+               lex.next();
+               type = lex.getString();
+       }
+}
Index: src/insets/insetbox.h
===================================================================
RCS file: src/insets/insetbox.h
diff -N src/insets/insetbox.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/insets/insetbox.h       21 Sep 2003 12:20:03 -0000
@@ -0,0 +1,108 @@
+// -*- 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"
+
+
+ struct InsetBoxParams {
+       ///
+       void write(std::ostream & os) const;
+       ///
+       void read(LyXLex & lex);
+       ///
+       string type;
+};
+
+
+/** The fbox/fancybox inset
+
+*/
+class InsetBox : public InsetCollapsable {
+public:
+       ///
+
+
+       InsetBox(BufferParams const &, string const &);
+       /// Copy constructor
+       InsetBox(InsetBox const &);
+       ///
+       ~InsetBox();
+       ///
+       virtual std::auto_ptr<InsetBase> clone() const;
+       ///
+       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 note 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_; }
+
+private:
+       friend class InsetBoxParams;
+
+       /// used by the constructors
+       void init();
+       ///
+       InsetBoxParams params_;
+};
+
+#include "mailinset.h"
+
+class InsetBoxMailer : public MailInset {
+public:
+       ///
+       InsetBoxMailer(string const & name, InsetBox & inset);
+       ///
+       virtual InsetBase & inset() const { return inset_; }
+       ///
+       virtual string const & name() const { return name_; }
+       ///
+       virtual string const inset2string(Buffer const &) const;
+       ///
+       static string const params2string(string const &, InsetBoxParams const &);
+       ///
+       static void string2params(string const &, InsetBoxParams &);
+
+private:
+       ///
+       string const name_;
+       ///
+       InsetBox & inset_;
+};
+
+#endif // INSET_BOX_H
Index: src/insets/insetnote.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetnote.C,v
retrieving revision 1.53
diff -u -p -r1.53 insetnote.C
--- src/insets/insetnote.C      16 Sep 2003 15:39:33 -0000      1.53
+++ src/insets/insetnote.C      21 Sep 2003 12:20:03 -0000
@@ -54,7 +54,7 @@ InsetNote::InsetNote(InsetNote const & i
 }
 
 
-InsetNote::~InsetNote() // MV
+InsetNote::~InsetNote()
 {
        InsetNoteMailer mailer("note", *this);
        mailer.hideDialog();

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to