]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetERT.cpp
Fix text frame drawing.
[lyx.git] / src / insets / InsetERT.cpp
index f87b1c7b35b379f0d6154e2a0ed924d6efebb7b7..9a3e4eb320ac9537c62a2d62267b287376b0202c 100644 (file)
 #include "Color.h"
 #include "LyXAction.h"
 #include "Lexer.h"
-#include "LyXTextClass.h"
+#include "TextClass.h"
 #include "MetricsInfo.h"
 #include "ParagraphParameters.h"
 #include "Paragraph.h"
 
-#include "frontends/Alert.h"
+#include "frontends/alert.h"
 
 #include <sstream>
 
@@ -43,7 +43,6 @@ using support::token;
 using std::endl;
 using std::min;
 
-using std::auto_ptr;
 using std::istringstream;
 using std::ostream;
 using std::ostringstream;
@@ -53,22 +52,17 @@ using std::string;
 void InsetERT::init()
 {
        setButtonLabel();
-
-       LyXFont font(LyXFont::ALL_SANE);
-       font.decSize();
-       font.decSize();
-       font.setColor(Color::latex);
-       setLabelFont(font);
-       text_.current_font.setLanguage(latex_language);
-       text_.real_current_font.setLanguage(latex_language);
-
-       setInsetName(from_ascii("ERT"));
+       setLabelFont(layout_.labelfont);
+       // FIXME: what to do with those?
+       //text_.current_font.setLanguage(latex_language);
+       //text_.real_current_font.setLanguage(latex_language);
 }
 
 
 InsetERT::InsetERT(BufferParams const & bp, CollapseStatus status)
        : InsetCollapsable(bp, status)
 {
+       setLayout(bp);
        init();
 }
 
@@ -80,9 +74,9 @@ InsetERT::InsetERT(InsetERT const & in)
 }
 
 
-auto_ptr<InsetBase> InsetERT::doClone() const
+Inset * InsetERT::clone() const
 {
-       return auto_ptr<InsetBase>(new InsetERT(*this));
+       return new InsetERT(*this);
 }
 
 
@@ -91,7 +85,7 @@ InsetERT::InsetERT(BufferParams const & bp,
                   Language const *, string const & contents, CollapseStatus status)
        : InsetCollapsable(bp, status)
 {
-       LyXFont font(LyXFont::ALL_INHERIT, latex_language);
+       Font font(Font::ALL_INHERIT, latex_language);
        paragraphs().begin()->insert(0, contents, font);
 
        // the init has to be after the initialization of the paragraph
@@ -125,7 +119,7 @@ void InsetERT::read(Buffer const & buf, Lexer & lex)
        // inherits the language from the last position of the existing text.
        // As a side effect this makes us also robust against bugs in LyX
        // that might lead to font changes in ERT in .lyx files.
-       LyXFont font(LyXFont::ALL_INHERIT, latex_language);
+       Font font(Font::ALL_INHERIT, latex_language);
        ParagraphList::iterator par = paragraphs().begin();
        ParagraphList::iterator const end = paragraphs().end();
        while (par != end) {
@@ -172,7 +166,7 @@ int InsetERT::latex(Buffer const &, odocstream & os,
 
 
 int InsetERT::plaintext(Buffer const &, odocstream &,
-                        OutputParams const &) const
+                       OutputParams const &) const
 {
        return 0; // do not output TeX code
 }
@@ -205,8 +199,17 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
        //lyxerr << "\nInsetERT::doDispatch (begin): cmd: " << cmd << endl;
        switch (cmd.action) {
 
+       case LFUN_MOUSE_PRESS:
+               if (cmd.button() != mouse_button::button3)
+                       InsetCollapsable::doDispatch(cur, cmd);
+               else
+                       // This makes the cursor leave the
+                       // inset when it collapses on mouse-3
+                       cur.undispatched();
+               break;
+
        case LFUN_QUOTE_INSERT: {
-               // We need to bypass the fancy quotes in LyXText
+               // We need to bypass the fancy quotes in Text
                FuncRequest f(LFUN_SELF_INSERT, "\"");
                dispatch(cur, f);
                break;
@@ -227,9 +230,9 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
                // FIXME: Change only the pasted paragraphs
 
                BufferParams const & bp = cur.buffer().params();
-               LyXLayout_ptr const layout =
-                       bp.getLyXTextClass().defaultLayout();
-               LyXFont font = layout->font;
+               LayoutPtr const layout =
+                       bp.getTextClass().defaultLayout();
+               Font font = layout->font;
                // ERT contents has always latex_language
                font.setLanguage(latex_language);
                ParagraphList::iterator const end = paragraphs().end();
@@ -252,8 +255,9 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
                // start of an existing paragraph get the buffer language
                // and not latex_language, so we take this brute force
                // approach.
-               text_.current_font.setLanguage(latex_language);
-               text_.real_current_font.setLanguage(latex_language);
+               // FIXME: what to do with those?
+               //text_.current_font.setLanguage(latex_language);
+               //text_.real_current_font.setLanguage(latex_language);
 
                InsetCollapsable::doDispatch(cur, cmd);
                break;
@@ -352,6 +356,7 @@ bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
                case LFUN_URL_INSERT:
                case LFUN_FLOAT_LIST:
                case LFUN_INSET_INSERT:
+               case LFUN_PARAGRAPH_PARAMS:
                case LFUN_PARAGRAPH_PARAMS_APPLY:
                case LFUN_PARAGRAPH_UPDATE:
                case LFUN_NOMENCL_INSERT:
@@ -387,11 +392,14 @@ bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
 void InsetERT::setButtonLabel()
 {
        // FIXME UNICODE
-       setLabel(isOpen() ?  _("ERT") : getNewLabel(_("ERT")));
+       if (decoration() == Classic)
+               setLabel(isOpen() ? _("ERT") : getNewLabel(_("ERT")));
+       else
+               setLabel(getNewLabel(_("ERT")));
 }
 
 
-bool InsetERT::insetAllowed(InsetBase::Code /* code */) const
+bool InsetERT::insetAllowed(Inset::Code /* code */) const
 {
        return false;
 }
@@ -399,7 +407,7 @@ bool InsetERT::insetAllowed(InsetBase::Code /* code */) const
 
 bool InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       LyXFont tmpfont = mi.base.font;
+       Font tmpfont = mi.base.font;
        getDrawFont(mi.base.font);
        mi.base.font.realize(tmpfont);
        InsetCollapsable::metrics(mi, dim);
@@ -412,9 +420,10 @@ bool InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetERT::draw(PainterInfo & pi, int x, int y) const
 {
-       LyXFont tmpfont = pi.base.font;
+       Font tmpfont = pi.base.font;
        getDrawFont(pi.base.font);
        pi.base.font.realize(tmpfont);
+       const_cast<InsetERT &>(*this).setButtonLabel();
        InsetCollapsable::draw(pi, x, y);
        pi.base.font = tmpfont;
 }
@@ -427,11 +436,10 @@ bool InsetERT::showInsetDialog(BufferView * bv) const
 }
 
 
-void InsetERT::getDrawFont(LyXFont & font) const
+void InsetERT::getDrawFont(Font & font) const
 {
-       font = LyXFont(LyXFont::ALL_INHERIT, latex_language);
-       font.setFamily(LyXFont::TYPEWRITER_FAMILY);
-       font.setColor(Color::latex);
+       font = Font(Font::ALL_INHERIT, latex_language);
+       font.realize(layout_.font);
 }