Ok, here an improved Note patch. Includes André's corrections and a
few of my own.

(Is there any way to get new files included in a cvs diff file?))
 
Martin
-- 
Martin Vermeer  [EMAIL PROTECTED]
Helsinki University of Technology 
Dept. of Surveying, Inst. of Geodesy
P.O. Box 1200, FIN-02015 HUT, Finland
:wq
Index: factory.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/factory.C,v
retrieving revision 1.34
diff -u -p -r1.34 factory.C
--- factory.C   2003/06/30 23:55:52     1.34
+++ factory.C   2003/07/08 10:33:53
@@ -71,7 +71,7 @@ Inset * createInset(FuncRequest const & 
                return new InsetMinipage(params);
 
        case LFUN_INSERT_NOTE:
-               return new InsetNote(params);
+               return new InsetNote(params, "Note");
 
        case LFUN_INSET_ERT:
                return new InsetERT(params);
@@ -348,8 +348,9 @@ Inset * readInset(LyXLex & lex, Buffer c
                        inset = new InsetFormula;
                } else if (tmptok == "Graphics") {
                        inset = new InsetGraphics;
-               } else if (tmptok == "Note") {
-                       inset = new InsetNote(buf.params);
+               } else if (tmptok == "Note"     || tmptok == "Comment" 
+                               || tmptok == "Greyedout") {
+                       inset = new InsetNote(buf.params, tmptok); 
                } else if (tmptok == "Include") {
                        InsetCommandParams p("Include");
                        inset = new InsetInclude(p, buf);
Index: frontends/controllers/Makefile.am
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/controllers/Makefile.am,v
retrieving revision 1.58
diff -u -p -r1.58 Makefile.am
--- frontends/controllers/Makefile.am   2003/06/21 08:50:05     1.58
+++ frontends/controllers/Makefile.am   2003/07/08 10:34:25
@@ -68,6 +68,8 @@ libcontrollers_la_SOURCES= \
        ControlMath.h \
        ControlMinipage.C \
        ControlMinipage.h \
+       ControlNote.C \
+       ControlNote.h \
        ControlParagraph.C \
        ControlParagraph.h \
        ControlPreamble.C \
Index: frontends/xforms/Dialogs.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/Dialogs.C,v
retrieving revision 1.112
diff -u -p -r1.112 Dialogs.C
--- frontends/xforms/Dialogs.C  2003/06/21 08:50:06     1.112
+++ frontends/xforms/Dialogs.C  2003/07/08 10:35:15
@@ -30,6 +30,7 @@
 #include "ControlLog.h"
 #include "ControlMath.h"
 #include "ControlMinipage.h"
+#include "ControlNote.h"
 #include "ControlParagraph.h"
 #include "ControlRef.h"
 #include "ControlShowFile.h"
@@ -60,6 +61,7 @@
 #include "FormMathsSpace.h"
 #include "FormMathsStyle.h"
 #include "FormMinipage.h"
+#include "FormNote.h"
 #include "FormParagraph.h"
 #include "FormRef.h"
 #include "FormTabular.h"
@@ -115,7 +117,7 @@ char const * const dialognames[] = { "ab
 "mathmisc", "mathdots", "mathbigoperators", "mathamsmisc",
 "mathamsarrows", "mathamsrelations", "mathamsnegatedrelations", "mathamsoperators",
 "mathdelimiter", "mathmatrix", "mathspace", "mathstyle",
-"minipage", "paragraph", "ref", "tabular", "tabularcreate", "texinfo",
+"minipage", "note", "paragraph", "ref", "tabular", "tabularcreate", "texinfo",
 
 #ifdef HAVE_LIBAIKSAURUS
 "thesaurus",
@@ -405,6 +407,10 @@ Dialog * Dialogs::build(string const & n
                dialog->setController(new ControlMinipage(*dialog));
                dialog->setView(new FormMinipage(*dialog));
                dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "note") {
+               dialog->setController(new ControlNote(*dialog));
+               dialog->setView(new FormNote(*dialog));
+               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
        } else if (name == "paragraph") {
                dialog->setController(new ControlParagraph(*dialog));
                dialog->setView(new FormParagraph(*dialog));
Index: frontends/xforms/Makefile.am
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/Makefile.am,v
retrieving revision 1.99
diff -u -p -r1.99 Makefile.am
--- frontends/xforms/Makefile.am        2003/06/21 08:50:06     1.99
+++ frontends/xforms/Makefile.am        2003/07/08 10:35:27
@@ -109,6 +109,8 @@ libxforms_la_SOURCES = \
        FormMathsStyle.h \
        FormMinipage.C \
        FormMinipage.h \
+       FormNote.C \
+       FormNote.h \
        FormParagraph.C \
        FormParagraph.h \
        FormPreamble.C \
Index: frontends/xforms/forms/Makefile.am
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/forms/Makefile.am,v
retrieving revision 1.21
diff -u -p -r1.21 Makefile.am
--- frontends/xforms/forms/Makefile.am  2003/06/21 08:50:06     1.21
+++ frontends/xforms/forms/Makefile.am  2003/07/08 10:35:31
@@ -31,6 +31,7 @@ SRCS =  form_aboutlyx.fd \
        form_maths_space.fd \
        form_maths_style.fd \
        form_minipage.fd \
+       form_note.fd \
        form_paragraph.fd \
        form_preamble.fd \
        form_preferences.fd \
Index: insets/insetnote.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/insetnote.C,v
retrieving revision 1.26
diff -u -p -r1.26 insetnote.C
--- insets/insetnote.C  2003/06/16 11:49:32     1.26
+++ insets/insetnote.C  2003/07/08 10:35:52
@@ -10,6 +10,7 @@
 
 #include <config.h>
 
+#include "Lsstream.h"
 
 #include "insetnote.h"
 #include "gettext.h"
@@ -17,6 +18,7 @@
 #include "language.h"
 #include "buffer.h"
 #include "BufferView.h"
+#include "lyxlex.h"
 #include "lyxtext.h"
 #include "insets/insettext.h"
 #include "support/LOstream.h"
@@ -28,31 +32,34 @@ using std::ostream;
 
 void InsetNote::init()
 {
-       LyXFont font(LyXFont::ALL_SANE);
-       font.decSize();
-       font.decSize();
-       font.setColor(LColor::note);
-       setLabelFont(font);
-       setBackgroundColor(LColor::notebg);
-       setLabel(_("note"));
        setInsetName("Note");
+       setButtonLabel();
 }
 
 
-InsetNote::InsetNote(BufferParams const & bp)
+InsetNote::InsetNote(BufferParams const & bp, string const & label)
        : InsetCollapsable(bp)
 {
+       params_.type = label;
        init();
+       setLabel(label);
 }
 
 
 InsetNote::InsetNote(InsetNote const & in)
-       : InsetCollapsable(in)
+       : InsetCollapsable(in), params_(in.params_)
 {
        init();
 }
 
 
+InsetNote::~InsetNote() // MV
+{
+       InsetNoteMailer mailer("note", *this);
+       mailer.hideDialog();
+}
+
+
 InsetBase * InsetNote::clone() const
 {
        return new InsetNote(*this);
@@ -67,6 +74,188 @@ string const InsetNote::editMessage() co
 
 void InsetNote::write(Buffer const * buf, ostream & os) const
 {
-       os << getInsetName() << "\n";
+       params_.write(os);
        InsetCollapsable::write(buf, os);
 }
+
+
+void InsetNote::read(Buffer const * buf, LyXLex & lex)
+{
+       InsetCollapsable::read(buf, lex);
+       setButtonLabel();
+}
+
+
+void InsetNote::setButtonLabel()
+{
+       LyXFont font(LyXFont::ALL_SANE);
+       font.decSize();
+       font.decSize();
+
+       setLabel(params_.type);
+       if (params_.type == "Note" || params_.type == "Comment") {
+               font.setColor(LColor::note);
+               setBackgroundColor(LColor::notebg);
+       } else {
+               font.setColor(LColor::red);
+               setBackgroundColor(LColor::background);
+       }
+       setLabelFont(font);
+}
+
+
+dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
+{
+       BufferView * bv = cmd.view();
+
+       switch (cmd.action) {
+       case LFUN_INSET_MODIFY:
+               {
+               InsetNoteParams params;
+               InsetNoteMailer::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 InsetCollapsable::localDispatch(cmd);
+               return UNDISPATCHED;
+       case LFUN_INSET_DIALOG_UPDATE:
+               InsetNoteMailer("note", *this).updateDialog(bv);
+               return DISPATCHED;
+       case LFUN_MOUSE_RELEASE:
+               if (cmd.button() == mouse_button::button3 && cmd.x < button_length 
+                                       && cmd.y >= button_top_y && cmd.y <= 
button_bottom_y) {
+                       InsetNoteMailer("note", *this).showDialog(bv);
+                       return DISPATCHED;
+               }
+               // fallthrough:
+       default:
+               return InsetCollapsable::localDispatch(cmd);
+       }
+}
+
+
+int InsetNote::latex(Buffer const * buf, ostream & os,
+                                               LatexRunParams const & runparams) const
+{
+       string const pt = params_.type;
+
+       int i = 0;
+       if (pt == "Comment") os << "%\n\\begin{comment}\n"; // remember to validate
+       if (pt == "Greyedout") os << "%\n\\textcolor[gray]{0.8}{";
+       if (pt != "Note") {
+               i = inset.latex(buf, os, runparams);
+       }
+       if (pt == "Comment") {
+               os << "%\n\\end{comment}\n";
+               i += 3;
+       }
+       if (pt == "Greyedout") { 
+               os << "%\n}";
+               i += 2;
+       }
+       return i;
+}
+
+
+int InsetNote::linuxdoc(Buffer const *, std::ostream &) const
+{ 
+       return 0; 
+}
+
+
+int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const
+{
+       int i = 0;
+       string const pt = params_.type;
+       // incomplete, untested - MV
+       if (pt != "Note") 
+               i = inset.docbook(buf, os, mixcont);
+       return i; 
+}
+
+
+int InsetNote::ascii(Buffer const * buf, std::ostream & os, int ll) const
+{
+       int i = 0;
+       string const pt = params_.type;
+       if (pt != "Note") {
+               os << "[";
+               i = inset.ascii(buf, os, ll);
+               os << "]";
+       }
+       return i;
+}
+
+
+void InsetNote::validate(LaTeXFeatures & features) const
+{
+       if (params_.type == "Comment") 
+               features.require("verbatim");
+       if (params_.type == "Greyedout")
+               features.require("color");
+       inset.validate(features);
+}
+
+
+
+InsetNoteMailer::InsetNoteMailer(string const & name,
+                                               InsetNote & inset)
+       : name_(name), inset_(inset)
+{
+}
+
+
+string const InsetNoteMailer::inset2string() const
+{
+       return params2string(name_, inset_.params());
+}
+
+
+string const InsetNoteMailer::params2string(string const & name,
+                               InsetNoteParams const & params)
+{
+       ostringstream data;
+       data << name << ' ';
+       params.write(data);
+       return STRCONV(data.str());
+}
+
+
+void InsetNoteMailer::string2params(string const & in,
+                                    InsetNoteParams & params)
+{
+       params = InsetNoteParams();
+
+       if (in.empty())
+               return;
+
+       istringstream data(STRCONV(in));
+       LyXLex lex(0,0);
+       lex.setStream(data);
+       params.read(lex);
+}
+
+
+void InsetNoteParams::write(ostream & os) const
+{
+       os << type << "\n";
+}
+
+
+void InsetNoteParams::read(LyXLex & lex)
+{
+       if (lex.isOK()) {
+               lex.next();
+               string token = lex.getString();
+       }
+
+       if (lex.isOK()) {
+               lex.next();
+               type = lex.getString();
+       }
+}
+
Index: insets/insetnote.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/insetnote.h,v
retrieving revision 1.22
diff -u -p -r1.22 insetnote.h
--- insets/insetnote.h  2003/06/16 11:49:32     1.22
+++ insets/insetnote.h  2003/07/08 10:35:52
@@ -15,16 +15,31 @@
 
 #include "insetcollapsable.h"
 
-/** The PostIt note inset
+  
+ struct InsetNoteParams {
+       ///
+       void write(std::ostream & os) const;
+       ///
+       void read(LyXLex & lex);
+       ///
+       string type;
+};
+ 
+ 
+/** The PostIt note inset, and other annotations
 
 */
 class InsetNote : public InsetCollapsable {
 public:
-       ///
-       InsetNote(BufferParams const &);
        ///
+
+       
+       InsetNote(BufferParams const &, string const &);
+       /// Copy constructor
        InsetNote(InsetNote const &);
        ///
+       ~InsetNote();
+       ///
        InsetBase * clone() const;
        ///
        string const editMessage() const;
@@ -33,24 +48,58 @@ public:
        ///
        void write(Buffer const *, std::ostream &) const;
        ///
+       void read(Buffer const * buf, LyXLex & lex);
+       ///
+       void setButtonLabel();
+       ///
+       dispatch_result InsetNote::localDispatch(FuncRequest const &);
+       ///
        int latex(Buffer const *, std::ostream &,
-                 LatexRunParams const &) const
-               { return 0; }
+                       LatexRunParams const &) const;
        ///
-       int linuxdoc(Buffer const *, std::ostream &) const
-               { return 0; }
+       int linuxdoc(Buffer const *, std::ostream &) const;
        ///
-       int docbook(Buffer const *, std::ostream &, bool) const
-               { return 0; }
+       int docbook(Buffer const *, std::ostream &, bool) const;
        ///
-       int ascii(Buffer const *, std::ostream &, int) const
-               { return 0; }
+       int ascii(Buffer const *, std::ostream &, int) const;
        ///
-       void validate(LaTeXFeatures &) const {}
+       void validate(LaTeXFeatures &) const;
+       ///
+       InsetNoteParams const & params() const { return params_; }
+
 private:
+       friend class InsetNoteParams;
+
        /// used by the constructors
        void init();
+       ///
+       InsetNoteParams params_;
+};
+
+#include "mailinset.h"
 
+class InsetNoteMailer : public MailInset {
+public:
+       ///
+       InsetNoteMailer(string const & name, InsetNote & inset);
+       ///
+       virtual InsetBase & inset() const { return inset_; }
+       ///
+       virtual string const & name() const { return name_; }
+       ///
+       virtual string const inset2string() const;
+       ///
+       static string const params2string(string const &, InsetNoteParams const &);
+       ///
+       static void string2params(string const &, InsetNoteParams &);
+
+private:
+       ///
+       string const name_;
+       ///
+       InsetNote & inset_;
 };
+
+
 
 #endif

/**
 * \file FormNote.C
 * This file is part of LyX, the document processor.
 * Licence details can be found in the file COPYING.
 *
 * \author Angus Leeming
 *
 * Full author contact details are available in file CREDITS
 */


#include <config.h>

#include "xformsBC.h"
#include "ControlNote.h"
#include "FormNote.h"
#include "forms/form_note.h"
#include "xforms_helpers.h" // formatted
#include "lyx_forms.h"
#include "insets/insetnote.h"
#include "debug.h"

typedef FormController<ControlNote, FormView<FD_note> > base_class;

FormNote::FormNote(Dialog & parent)
        : base_class(parent, _("Note"))
{}


void FormNote::build()
{
        dialog_.reset(build_note(this));

        fl_addto_choice(dialog_->choice_type, predefineds().c_str());

        bcview().setOK(dialog_->button_ok);
        bcview().setApply(dialog_->button_apply);
        bcview().setCancel(dialog_->button_cancel);
}


void FormNote::update()
{
        string type(controller().params().type);
        fl_set_choice_text(dialog_->choice_type, type.c_str());
}


void FormNote::apply()
{
        controller().params().type = fl_get_choice_text(dialog_->choice_type);
}

// -*- C++ -*-
/**
 * \file FormNote.h
 * This file is part of LyX, the document processor.
 * Licence details can be found in the file COPYING.
 *
 * \author Angus Leeming
 *
 * Full author contact details are available in file CREDITS
 */

#ifndef FORMNOTE_H
#define FORMNOTE_H


#include "FormDialogView.h"


class ControlNote;
struct FD_note;

/** This class provides an XForms implementation of the Note Dialog.
 */
class FormNote : public FormController<ControlNote, FormView<FD_note> > {
public:
        /// Constructor
        FormNote(Dialog &);
private:
        /// 
        virtual void apply();
        /// Build the dialog
        virtual void build();
        /// Update dialog before showing it
        virtual void update();
        ///
        string const predefineds() { return "Note|Comment|Greyedout"; }
};

#endif // FORMNOTE_H
Magic: 13000

Internal Form Definition File
    (do not change)

Number of forms: 1
Unit of measure: FL_COORD_PIXEL
SnapGrid: 7

=============== FORM ===============
Name: form_note
Width: 407
Height: 113
Number of Objects: 5

--------------------
class: FL_BOX
type: UP_BOX
box: 0 0 407 113
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: 154 21 217 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: Note 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: 49 70 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: 154 70 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: 266 70 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

==============================
create_the_forms
/**
 * \file ControlNote.C
 * This file is part of LyX, the document processor.
 * Licence details can be found in the file COPYING.
 *
 * \author Angus Leeming
 *
 * Full author contact details are available in file CREDITS
 */

#include <config.h>

#include "ControlNote.h"
#include "funcrequest.h"
#include "insets/insetnote.h"
#include "debug.h"

ControlNote::ControlNote(Dialog & parent)
        : Dialog::Controller(parent)
{}


bool ControlNote::initialiseParams(string const & data)
{
    InsetNoteParams params;
        InsetNoteMailer::string2params(data, params);
        params_.reset(new InsetNoteParams(params));
        
        return true;

}


void ControlNote::clearParams()
{
        params_.reset();
}

void ControlNote::dispatchParams()
{
        string const lfun = InsetNoteMailer::params2string(string("note"), params());
        kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
}

// -*- C++ -*-
/**
 * \file ControlNote.h
 * This file is part of LyX, the document processor.
 * Licence details can be found in the file COPYING.
 *
 * \author Angus Leeming
 *
 * Full author contact details are available in file CREDITS
 */

#ifndef CONTROLNOTE_H
#define CONTROLNOTE_H


#include "Dialog.h"
#include "debug.h"

class InsetNoteParams;

class ControlNote : public Dialog::Controller {
public:
        ///
        ControlNote(Dialog &);
        ///
        virtual bool initialiseParams(string const & data);
        ///
        virtual void clearParams();
        ///
        virtual void dispatchParams();
        ///
        virtual bool isBufferDependent() const { return true; }
        ///
        InsetNoteParams & params() { return *params_.get(); }
        ///
        InsetNoteParams const & params() const { return *params_.get(); }
        ///
private:
        ///
        boost::scoped_ptr<InsetNoteParams> params_;
};

#endif // CONTROLNOTE_H

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to