]> git.lyx.org Git - features.git/blobdiff - src/insets/insetert.C
skak support, John's ERT fixes, loclae blunder fix
[features.git] / src / insets / insetert.C
index 45d665cc3a4557777fe24aa491663d5b2ce2b81f..f1bef0a34f01e0646536ec8b19aecc9c97559c36 100644 (file)
@@ -238,16 +238,25 @@ void InsetERT::setFont(BufferView *, LyXFont const &, bool, bool selectall)
 }
 
 
-void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
+void InsetERT::updateStatus(BufferView * bv, bool swap) const
 {
-       InsetCollapsable::edit(bv, x, y, button);
        if (status_ != Inlined) {
                if (collapsed_) {
-                       status(0, Collapsed);
+                       status(bv, swap ? Open : Collapsed);
                } else {
-                       status(0, Open);
+                       status(bv, swap ? Collapsed : Open);
                }
        }
+}
+
+void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
+{
+       if (button == 3)
+               return;
+       InsetCollapsable::edit(bv, x, y, button);
+       updateStatus(0);
        set_latex_font(bv);
 }
 
@@ -263,13 +272,7 @@ Inset::EDITABLE InsetERT::editable() const
 void InsetERT::edit(BufferView * bv, bool front)
 {
        InsetCollapsable::edit(bv, front);
-       if (status_ != Inlined) {
-               if (collapsed_) {
-                       status(0, Collapsed);
-               } else {
-                       status(0, Open);
-               }
-       }
+       updateStatus(0);
        set_latex_font(bv);
 }
 
@@ -280,33 +283,22 @@ void InsetERT::insetButtonRelease(BufferView * bv, int x, int y, int button)
                showInsetDialog(bv);
                return;
        }
-       if ((x >= 0)  && (x < button_length) &&
-           (y >= button_top_y) &&  (y <= button_bottom_y))
-       {
-//             if (collapsed_) {
-//                     setLabel(_("ERT"));
-//             } else {
-//                     setLabel(get_new_label());
-//             }
-               if (collapsed_) {
-                       status(bv, Open);
-//                     collapsed_ = false;
-//                     inset.insetButtonRelease(bv, 0, 0, button);
-//                     inset.setUpdateStatus(bv, InsetText::FULL);
-//                     bv->updateInset(this, true);
-               } else {
-                       status(bv, Collapsed);
-//                     collapsed_ = true;
-//                     bv->unlockInset(this);
-//                     bv->updateInset(this, true);
-               }
-       } else if (!collapsed_ && (y > button_bottom_y)) {
+       if (status_ != Inlined && (x >= 0)  && (x < button_length) &&
+           (y >= button_top_y) &&  (y <= button_bottom_y)) {
+               updateStatus(bv, true);
+       } else {
                LyXFont font(LyXFont::ALL_SANE);
-               int yy = ascent(bv, font) + y -
-                   (ascent_collapsed() +
-                    descent_collapsed() +
-                    inset.ascent(bv, font));
-               inset.insetButtonRelease(bv, x, yy, button);
+               int yy = ascent(bv, font) + y - inset.ascent(bv, font);
+               // inlined is special - the text appears above 
+               // button_bottom_y
+               if (status_ == Inlined) {
+                       inset.insetButtonRelease(bv, x, yy, button);
+               } else if (!collapsed_ && (y > button_bottom_y)) {
+                       yy -= (ascent_collapsed() + descent_collapsed());
+                       inset.insetButtonRelease(bv, x, yy, button);
+               }
        }
 }
 
@@ -315,6 +307,7 @@ int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
                    bool /*free_spc*/) const
 {
        Paragraph * par = inset.paragraph();
+       int lines = 0;
        while (par) {
                Paragraph::size_type siz = par->size();
                for (Paragraph::size_type i = 0; i < siz; ++i) {
@@ -322,6 +315,7 @@ int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
                        switch (c) {
                        case Paragraph::META_NEWLINE:
                                os << '\n';
+                               ++lines;
                                break;
                        default:
                                os << c;
@@ -329,11 +323,13 @@ int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
                        }
                }
                par = par->next();
-               if (par)
+               if (par) {
                        os << "\n\n";
+                       lines += 2;
+               }
        }
        
-       return 1;
+       return lines;
 }
 
 
@@ -344,15 +340,61 @@ int InsetERT::ascii(Buffer const *,
 }
 
 
-int InsetERT::linuxdoc(Buffer const *, std::ostream &) const
+int InsetERT::linuxdoc(Buffer const *, std::ostream & os) const
 {
-       return 0;
+       Paragraph * par = inset.paragraph();
+       int lines = 0;
+       while (par) {
+               Paragraph::size_type siz = par->size();
+               for (Paragraph::size_type i = 0; i < siz; ++i) {
+                       Paragraph::value_type c = par->getChar(i);
+                       switch (c) {
+                       case Paragraph::META_NEWLINE:
+                               os << '\n';
+                               ++lines;
+                               break;
+                       default:
+                               os << c;
+                               break;
+                       }
+               }
+               par = par->next();
+               if (par) {
+                       os << "\n";
+                       lines ++;
+               }
+       }
+       
+       return lines;
 }
 
 
-int InsetERT::docbook(Buffer const *, std::ostream &) const
+int InsetERT::docbook(Buffer const *, std::ostream & os) const
 {
-       return 0;
+       Paragraph * par = inset.paragraph();
+       int lines = 0;
+       while (par) {
+               Paragraph::size_type siz = par->size();
+               for (Paragraph::size_type i = 0; i < siz; ++i) {
+                       Paragraph::value_type c = par->getChar(i);
+                       switch (c) {
+                       case Paragraph::META_NEWLINE:
+                               os << '\n';
+                               ++lines;
+                               break;
+                       default:
+                               os << c;
+                               break;
+                       }
+               }
+               par = par->next();
+               if (par) {
+                       os << "\n";
+                       lines ++;
+               }
+       }
+       
+       return lines;
 }
 
 
@@ -556,7 +598,7 @@ void InsetERT::status(BufferView * bv, ERTStatus const st) const
                        break;
                }
                if (bv)
-                       bv->updateInset(const_cast<InsetERT *>(this), true);
+                       bv->updateInset(const_cast<InsetERT *>(this), false);
        }
 }