]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetERT.cpp
* src/paragraph_funcs.cpp (breakParagraph): change parameter 'flag' to
[lyx.git] / src / insets / InsetERT.cpp
index dc343c60e31c7db6bb4d48e49cfc1ca4bb1022bf..1fe2af0af8db88a67729d13930a09de1f96457e2 100644 (file)
@@ -23,6 +23,7 @@
 #include "FuncStatus.h"
 #include "gettext.h"
 #include "Language.h"
+#include "Layout.h"
 #include "Color.h"
 #include "LyXAction.h"
 #include "Lexer.h"
@@ -43,7 +44,6 @@ using support::token;
 using std::endl;
 using std::min;
 
-using std::auto_ptr;
 using std::istringstream;
 using std::ostream;
 using std::ostringstream;
@@ -53,19 +53,17 @@ using std::string;
 void InsetERT::init()
 {
        setButtonLabel();
-       Font font(Font::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);
+       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();
 }
 
@@ -77,9 +75,9 @@ InsetERT::InsetERT(InsetERT const & in)
 }
 
 
-auto_ptr<Inset> InsetERT::doClone() const
+Inset * InsetERT::clone() const
 {
-       return auto_ptr<Inset>(new InsetERT(*this));
+       return new InsetERT(*this);
 }
 
 
@@ -169,7 +167,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
 }
@@ -199,11 +197,23 @@ int InsetERT::docbook(Buffer const &, odocstream & os,
 
 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
+       BufferParams const & bp = cur.buffer().params();
+       LayoutPtr const layout =
+                       bp.getTextClass().defaultLayout();
        //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;
@@ -223,9 +233,6 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
                // attributes.
                // FIXME: Change only the pasted paragraphs
 
-               BufferParams const & bp = cur.buffer().params();
-               Layout_ptr const layout =
-                       bp.getTextClass().defaultLayout();
                Font font = layout->font;
                // ERT contents has always latex_language
                font.setLanguage(latex_language);
@@ -249,9 +256,10 @@ 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);
-
+               cur.current_font = layout->font;
+               cur.real_current_font = layout->font;
+               cur.current_font.setLanguage(latex_language);
+               cur.real_current_font.setLanguage(latex_language);
                InsetCollapsable::doDispatch(cur, cmd);
                break;
        }
@@ -294,7 +302,7 @@ bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
                case LFUN_FLOAT_WIDE_INSERT:
                case LFUN_WRAP_INSERT:
                case LFUN_FONT_BOLD:
-               case LFUN_FONT_CODE:
+               case LFUN_FONT_TYPEWRITER:
                case LFUN_FONT_DEFAULT:
                case LFUN_FONT_EMPH:
                case LFUN_FONT_FREE_APPLY:
@@ -333,7 +341,7 @@ bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
                case LFUN_MENU_OPEN:
                case LFUN_MENU_SEPARATOR_INSERT:
                case LFUN_BRANCH_INSERT:
-               case LFUN_CHARSTYLE_INSERT:
+               case LFUN_FLEX_INSERT:
                case LFUN_NOTE_INSERT:
                case LFUN_BOX_INSERT:
                case LFUN_NOTE_NEXT:
@@ -349,6 +357,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:
@@ -384,7 +393,10 @@ 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")));
 }
 
 
@@ -394,16 +406,13 @@ bool InsetERT::insetAllowed(Inset::Code /* code */) const
 }
 
 
-bool InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        Font tmpfont = mi.base.font;
        getDrawFont(mi.base.font);
        mi.base.font.realize(tmpfont);
        InsetCollapsable::metrics(mi, dim);
        mi.base.font = tmpfont;
-       bool const changed = dim_ != dim;
-       dim_ = dim;
-       return changed;
 }
 
 
@@ -412,6 +421,7 @@ void InsetERT::draw(PainterInfo & pi, int x, int y) const
        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,8 +437,7 @@ bool InsetERT::showInsetDialog(BufferView * bv) const
 void InsetERT::getDrawFont(Font & font) const
 {
        font = Font(Font::ALL_INHERIT, latex_language);
-       font.setFamily(Font::TYPEWRITER_FAMILY);
-       font.setColor(Color::latex);
+       font.realize(layout_.font);
 }