]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetnote.C
Enable convertDefault.sh to run even if its executable bit is not set.
[lyx.git] / src / insets / insetnote.C
index ce4188331e10514399765663d45c9dfc1acda6e8..ad66b0f92c8f430cd9c70545ecfd6a0cbf8759a6 100644 (file)
@@ -4,8 +4,10 @@
  * 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
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
@@ -13,6 +15,7 @@
 #include "Lsstream.h"
 
 #include "insetnote.h"
+#include "metricsinfo.h"
 #include "gettext.h"
 #include "lyxfont.h"
 #include "language.h"
@@ -41,7 +44,7 @@ InsetNote::InsetNote(BufferParams const & bp, string const & label)
 {
        params_.type = label;
        init();
-       setLabel(label);
+       setButtonLabel();
 }
 
 
@@ -71,14 +74,14 @@ string const InsetNote::editMessage() const
 }
 
 
-void InsetNote::write(Buffer const * buf, ostream & os) const
+void InsetNote::write(Buffer const & buf, ostream & os) const
 {
        params_.write(os);
        InsetCollapsable::write(buf, os);
 }
 
 
-void InsetNote::read(Buffer const * buf, LyXLex & lex)
+void InsetNote::read(Buffer const & buf, LyXLex & lex)
 {
        InsetCollapsable::read(buf, lex);
        setButtonLabel();
@@ -91,18 +94,35 @@ void InsetNote::setButtonLabel()
        font.decSize();
        font.decSize();
 
-       setLabel(params_.type);
-       if (params_.type == "Note" || params_.type == "Comment") {
+       if (params_.type == "Note") {
+               setLabel(_("LyX Note"));
                font.setColor(LColor::note);
                setBackgroundColor(LColor::notebg);
+       } else if (params_.type == "Comment") {
+               setLabel(_("Comment"));
+               font.setColor(LColor::comment);
+               setBackgroundColor(LColor::commentbg);
        } else {
-               font.setColor(LColor::red);
-               setBackgroundColor(LColor::background);
+               setLabel(_("Greyed Out"));
+               font.setColor(LColor::greyedout);
+               setBackgroundColor(LColor::greyedoutbg);
        }
        setLabelFont(font);
 }
 
 
+void InsetNote::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       InsetCollapsable::metrics(mi, dim);
+       // Contrary to Greyedout, these cannot be construed as part of the
+       // running text: make them stand on their own
+       if (params_.type == "Note" || params_.type == "Comment")
+               if (!collapsed_)
+                       dim.wid = mi.base.textwidth;
+       dim_ = dim;
+}
+
+
 bool InsetNote::showInsetDialog(BufferView * bv) const
 {
        InsetNoteMailer("note", const_cast<InsetNote &>(*this)).showDialog(bv);
@@ -115,61 +135,66 @@ dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
        BufferView * bv = cmd.view();
 
        switch (cmd.action) {
-       case LFUN_INSET_MODIFY:
-               {
+
+       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;
+               if (cmd.button() == mouse_button::button3)
+                       return UNDISPATCHED;
+               return InsetCollapsable::localDispatch(cmd);
+
        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) {
+               if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
                        InsetNoteMailer("note", *this).showDialog(bv);
                        return DISPATCHED;
                }
                // fallthrough:
+
        default:
                return InsetCollapsable::localDispatch(cmd);
        }
 }
 
 
-int InsetNote::latex(Buffer const * buf, ostream & os,
+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
+                // verbatim
+               os << "%\n\\begin{comment}\n";
        else if (pt == "Greyedout")
-               os << "%\n\\color[gray]{0.8}";
+                // we roll our own macro
+               os << "%\n\\begin{lyxgreyedout}\n";
 
        if (pt != "Note")
                i = inset.latex(buf, os, runparams);
 
        if (pt == "Comment") {
                os << "%\n\\end{comment}\n";
-               i += 3;
+               i += 4;
        } else if (pt == "Greyedout") {
-               os << "\\normalcolor%\n}";
-               i += 2;
-       }
+               os << "%\n\\end{lyxgreyedout}\n";
+               i += 4;
+       } 
        return i;
 }
 
 
-int InsetNote::linuxdoc(Buffer const * buf, std::ostream & os) const
+int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os) const
 {
        string const pt = params_.type;
 
@@ -188,7 +213,7 @@ int InsetNote::linuxdoc(Buffer const * buf, std::ostream & os) const
 }
 
 
-int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const
+int InsetNote::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
 {
        string const pt = params_.type;
 
@@ -207,7 +232,7 @@ int InsetNote::docbook(Buffer const * buf, std::ostream & os, bool mixcont) cons
 }
 
 
-int InsetNote::ascii(Buffer const * buf, std::ostream & os, int ll) const
+int InsetNote::ascii(Buffer const & buf, std::ostream & os, int ll) const
 {
        int i = 0;
        string const pt = params_.type;
@@ -224,8 +249,10 @@ void InsetNote::validate(LaTeXFeatures & features) const
 {
        if (params_.type == "Comment")
                features.require("verbatim");
-       if (params_.type == "Greyedout")
+       if (params_.type == "Greyedout") {
                features.require("color");
+               features.require("lyxgreyedout");
+       }
        inset.validate(features);
 }