]> git.lyx.org Git - features.git/commitdiff
All changes I made to have text-insets working. Look at the Changelog
authorJürgen Vigna <jug@sad.it>
Fri, 25 Feb 2000 12:06:15 +0000 (12:06 +0000)
committerJürgen Vigna <jug@sad.it>
Fri, 25 Feb 2000 12:06:15 +0000 (12:06 +0000)
for more details.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@571 a592a061-630c-0410-9148-cb99ea01b6c8

48 files changed:
ChangeLog
po/POTFILES.in
src/BufferView.C
src/BufferView.h
src/BufferView2.C
src/LyXAction.C
src/buffer.C
src/commandtags.h
src/insets/Makefile.am
src/insets/figinset.C
src/insets/figinset.h
src/insets/inset.C
src/insets/insetbib.C
src/insets/insetbib.h
src/insets/inseterror.C
src/insets/inseterror.h
src/insets/insetert.C [new file with mode: 0644]
src/insets/insetert.h [new file with mode: 0644]
src/insets/insetinclude.C
src/insets/insetinclude.h
src/insets/insetindex.C
src/insets/insetindex.h
src/insets/insetinfo.C
src/insets/insetinfo.h
src/insets/insetloa.h
src/insets/insetparent.C
src/insets/insetparent.h
src/insets/insetref.C
src/insets/insetref.h
src/insets/insettext.C [new file with mode: 0644]
src/insets/insettext.h [new file with mode: 0644]
src/insets/insettoc.C
src/insets/insettoc.h
src/insets/inseturl.C
src/insets/inseturl.h
src/insets/lyxinset.h
src/lyx_cb.C
src/lyxfunc.C
src/lyxparagraph.h
src/lyxtext.h
src/mathed/formula.C
src/mathed/formula.h
src/mathed/formulamacro.C
src/mathed/formulamacro.h
src/mathed/math_defs.h
src/mathed/math_symbols.C
src/text.C
src/text2.C

index f83550dca532b5d96e30d62b224dffc61a2bd92c..290bdde8e70b605c96b8a754ce8fdd42daaf2358 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2000-02-24  Juergen Vigna  <jug@sad.it>
+
+       * src/buffer.C:
+       * src/commandtags.h: 
+       * src/LyXAction.C:
+       * src/lyxfunc.C: added code for LFUN_INSET_ERT and LFUN_INSET_TEXT
+
+       * src/BufferView.h
+       * src/BufferView.C
+       * src/BufferView2.C: added/updated code for various inset-functions
+
+       * src/insets/insetert.[Ch]: added implementation of InsetERT
+
+       * src/insets/insettext.[Ch]: added implementation of InsetText
+
+       * src/insets/inset.C (Edit): added "unsigned int button" parameter
+       (draw): added preliminary code for inset scrolling not finshed yet
+
+       * src/insets/inset.C (LocalDispatch): changed arg parameter to string
+       as it is in lyxfunc.C now
+
+       * src/insets/lyxinset.h: Added functions for text-insets
+
 2000-02-22  Lars Gullik Bjønnes  <larsbj@lyx.org>
 
        * src/lyx_cb.C src/UpdateInset.[Ch]: move the updateinsetlist into
index 7f6a48b17b17199b317390536da7731df82bc297..ea2a66716e3b48630867cc652db55f71d9bbc1a9 100644 (file)
@@ -29,6 +29,7 @@ src/insets/form_url.C
 src/insets/insetbib.C
 src/insets/inseterror.C
 src/insets/inseterror.h
+src/insets/insetert.C
 src/insets/insetinclude.C
 src/insets/insetindex.C
 src/insets/insetinfo.C
@@ -38,6 +39,7 @@ src/insets/insetlof.h
 src/insets/insetlot.h
 src/insets/insetparent.h
 src/insets/insetref.C
+src/insets/insettext.C
 src/insets/insettoc.h
 src/insets/inseturl.C
 src/insets/inseturl.h
index 94d7e5532db5a55147781d7b374331a58daad9b8..b4624ee8a7d656e15d234c25f343752d4295837b 100644 (file)
@@ -736,7 +736,7 @@ void BufferView::workAreaButtonPress(int xpos, int ypos, unsigned int button)
                selection_possible = false;
                owner_->updateLayoutChoice();
                owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
-               inset_hit->Edit(this, xpos, ypos);
+               inset_hit->Edit(this, xpos, ypos, button);
                return;
        } 
        
@@ -870,7 +870,7 @@ void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
                }
 
                owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
-               inset_hit->Edit(this, x, y);
+               inset_hit->Edit(this, x, y, button);
                return;
        }
 
@@ -946,7 +946,7 @@ void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
                            textclasslist
                            .TextClass(buffer_->
                                       params.textclass).defaultfont())) {
-               text->cursor.par->bibkey->Edit(this, 0, 0);
+               text->cursor.par->bibkey->Edit(this, 0, 0, 0);
        }
 
        return;
@@ -1025,7 +1025,6 @@ Inset * BufferView::checkInsetHit(int & x, int & y)
        return 0;
 }
 
-
 void BufferView::workAreaExpose()
 {
        // this is a hack to ensure that we only call this through
@@ -1427,7 +1426,7 @@ void BufferView::insetSleep()
 void BufferView::insetWakeup()
 {
        if (the_locking_inset && inset_slept) {
-               the_locking_inset->Edit(this, slx, sly);
+               the_locking_inset->Edit(this, slx, sly, 0);
                inset_slept = false;
        }
 }
@@ -1462,6 +1461,18 @@ bool BufferView::active() const
 }
 
 
+Painter & BufferView::getPainter() const
+{
+    return workarea->getPainter();
+}
+
+
+unsigned short BufferView::paperWidth() const
+{
+    return text->paperWidth();
+}
+
+
 bool BufferView::belowMouse() const 
 {
        return workarea->belowMouse();
index 0f43d9fa1416630da974624ed265f7c0617b094c..b07ef0935da5919ef232f1a279907bab826f8dde 100644 (file)
@@ -41,6 +41,8 @@ public:
        ///
        Painter & painter();
        ///
+       Painter & getPainter() const;
+       ///
        void buffer(Buffer * b);
        ///
        void resize(int, int, int, int);
@@ -83,8 +85,12 @@ public:
        */
        LyXText * text;
        ///
+       unsigned short paperWidth() const;
+       ///
        UpdatableInset * the_locking_inset;
        ///
+       void updateInset(Inset * inset, bool mark_dirty);
+       ///
        bool inset_slept;
        ///
        int slx;
@@ -264,8 +270,6 @@ private:
        ///
        UpdateInset updatelist;
 public:
-       ///
-       void updateInset(Inset *, bool);
        ///
        void pushIntoUpdateList(Inset * i) {
                updatelist.push(i);
index ea2aa084fad2f6cc756eb17ef8c1c5e42fb07ac5..edd0a38e2400639877606b91546a9127c4583e05 100644 (file)
@@ -237,7 +237,7 @@ void BufferView::open_new_inset(UpdatableInset * new_inset)
        insertInset(new_inset);
        text->CursorLeft();
        update(1);
-       new_inset->Edit(this, 0, 0);
+       new_inset->Edit(this, 0, 0, 0);
 }
 
 /* This is also a buffer property (ale) */
@@ -360,7 +360,7 @@ void BufferView::insertNote()
 {
        InsetInfo * new_inset = new InsetInfo();
        insertInset(new_inset);
-       new_inset->Edit(this, 0, 0);
+       new_inset->Edit(this, 0, 0, 0);
 }
 
 
@@ -684,6 +684,7 @@ void BufferView::replaceWord(string const & replacestring)
 // End of spellchecker stuff
 
 
+
 /* these functions return 1 if an error occured, 
    otherwise 0 */
 int BufferView::lockInset(UpdatableInset * inset)
@@ -756,16 +757,31 @@ void BufferView::updateInset(Inset * inset, bool mark_dirty)
                return;
 
        // first check for locking insets
-       if (the_locking_inset == inset) {
-               if (text->UpdateInset(inset)){
-                       update();
-                       if (mark_dirty){
-                               if (buffer()->isLyxClean())
-                                       owner()->getMiniBuffer()->setTimer(4);
-                               buffer()->markDirty();
+       if (the_locking_inset) {
+               if (the_locking_inset == inset) {
+                       if (text->UpdateInset(inset)){
+                               update();
+                               if (mark_dirty){
+                                       if (buffer()->isLyxClean())
+                                               owner()->getMiniBuffer()->
+                                                       setTimer(4);
+                                       buffer()->markDirty();
+                               }
+                               updateScrollbar();
+                               return;
+                       }
+               } else if (the_locking_inset->UpdateInsetInInset(this,inset)) {
+                       if (text->UpdateInset(the_locking_inset)) {
+                               update();
+                               if (mark_dirty){
+                                       if (buffer()->isLyxClean())
+                                               owner()->getMiniBuffer()->
+                                                       setTimer(4);
+                                       buffer()->markDirty();
+                               }
+                               updateScrollbar();
+                               return;
                        }
-                       updateScrollbar();
-                       return;
                }
        }
   
index 52a41787c122fce84dbcc47ae012dbc57d2439d1..7f0ba2f873393833c7e932f3c103637add8c81d3 100644 (file)
@@ -177,6 +177,8 @@ void LyXAction::init()
                { LFUN_GOTOERROR, "error-next", N_("Go to next error"), Noop },
                { LFUN_REMOVEERRORS, "error-remove-all",
                  N_("Remove all error boxes"), ReadOnly },
+               { LFUN_INSET_ERT, "ert-inset-insert",
+                 N_("Insert a new ERT Inset"), Noop },
                { LFUN_FIGURE, "figure-insert", N_("Insert Figure"), Noop },
                { LFUN_FILE_INSERT, "file-insert", "", Noop },
                { LFUN_FILE_INSERT_ASCII, "file-insert-ascii", "", Noop },
@@ -330,6 +332,8 @@ void LyXAction::init()
                { LFUN_TABINSERT, "tab-insert", "", Noop },
                { LFUN_TABLE, "table-insert", N_("Insert Table"), Noop },
                { LFUN_TEX, "tex-mode", N_("Toggle TeX style"), Noop },
+               { LFUN_INSET_TEXT, "text-inset-insert",
+                 N_("Insert a new Text Inset"), Noop },
                { LFUN_TOC_INSERT, "toc-insert",
                  N_("Insert table of contents"), Noop },
                { LFUN_TOCVIEW, "toc-view",
index 131a716971cfc5e51dc71f8e40f0b993c8d14107..6c4495db6b3f3c2056c7a1697b7b8939c8f68347 100644 (file)
@@ -73,6 +73,8 @@ using std::setw;
 #include "insets/insetparent.h"
 #include "insets/insetspecialchar.h"
 #include "insets/figinset.h"
+#include "insets/insettext.h"
+#include "insets/insetert.h"
 #include "support/filetools.h"
 #include "support/path.h"
 #include "LaTeX.h"
@@ -745,6 +747,20 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                                par->InsertInset(pos, inset);
                                par->SetFont(pos, font);
                                ++pos;
+                       } else if (tmptok == "ERT") {
+                               inset = new InsetERT(this);
+                               inset->Read(lex);
+                               par->InsertChar(pos, LyXParagraph::META_INSET); 
+                               par->InsertInset(pos, inset);
+                               par->SetFont(pos, font);
+                               ++pos;
+                       } else if (tmptok == "Text") {
+                               inset = new InsetText(this);
+                               inset->Read(lex);
+                               par->InsertChar(pos, LyXParagraph::META_INSET); 
+                               par->InsertInset(pos, inset);
+                               par->SetFont(pos, font);
+                               ++pos;
                        } else if (tmptok == "LatexCommand") {
                                InsetCommand inscmd;
                                inscmd.Read(lex);
index bafd6ffde3da21a1be0c77684d7a4c11133144c9..b0c2f7ffee36c1519875c1dcc20b88738b429c23 100644 (file)
@@ -240,6 +240,8 @@ enum kb_action {
        LFUN_SAVEPREFERENCES,           // Lgb 991127
        LFUN_DATE_INSERT,               // jdblair 20000131
        LFUN_RTL,                       // Dekel 20000203
+       LFUN_INSET_TEXT,                // Jug 20000214
+       LFUN_INSET_ERT,                 // Jug 20000218
        LFUN_LASTACTION  /* this marks the end of the table */
 };
 
index cb0e3b132fcc3d9b0e6c1095456f60fcf012c71c..e7fc7eaa1695fa345633d6b0ac82a1f2637ba969 100644 (file)
@@ -17,6 +17,8 @@ libinsets_la_SOURCES = \
        insetcommand.h \
        inseterror.C \
        inseterror.h \
+       insetert.C \
+       insetert.h \
        insetinclude.C \
        insetinclude.h \
        insetindex.C \
@@ -41,6 +43,8 @@ libinsets_la_SOURCES = \
        insetref.h \
        insetspecialchar.C \
        insetspecialchar.h \
+       insettext.C \
+       insettext.h \
        insettoc.C \
        insettoc.h \
        inseturl.C \
index 0210ef4511f3acb44a752b76d0527be0750443e0..854caea8c6623ca4873bfd6b7a39e6123769ef86 100644 (file)
@@ -1036,8 +1036,7 @@ int InsetFig::width(Painter &, LyXFont const &) const
 }
 
 
-void InsetFig::draw(Painter & pain, LyXFont const & f,
-                   int baseline, float & x) const
+void InsetFig::draw(Painter & pain, LyXFont const & f, int baseline, float & x) const
 {
        LyXFont font(f);
        
@@ -1241,7 +1240,7 @@ bool InsetFig::Deletable() const
 }
 
 
-void InsetFig::Edit(BufferView * bv, int, int)
+void InsetFig::Edit(BufferView * bv, int, int, unsigned int)
 {
        lyxerr.debug() << "Editing InsetFig." << endl;
        Regenerate();
index 10e0c19205fdd40599dc4e5f522957725a09f1cb..1ee86e042ac3c23946b9419725a1395b35985ecd 100644 (file)
@@ -49,9 +49,9 @@ public:
        void Validate(LaTeXFeatures & features) const;
 
        /// what appears in the minibuffer when opening
-       char const * EditMessage() const { return _("Opened figure"); }
+       const char * EditMessage() const { return _("Opened figure"); }
        ///
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView *, int, int, unsigned int);
        ///
        unsigned char Editable() const;
        ///
index e924c636ff4ea8ac9122ad7dc6f4c7e7fc0452b4..628f853aae602fd8c454ce512e4988c2f6f6ed66 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "lyxinset.h"
 #include "debug.h"
+#include "BufferView.h"
 #include "support/lstrings.h"
 
 /* Insets default methods */
@@ -49,7 +50,7 @@ bool Inset::AutoDelete() const
 }
 
 
-void Inset::Edit(BufferView *, int, int)
+void Inset::Edit(BufferView *, int, int, unsigned int)
 {
 }
 
@@ -105,3 +106,48 @@ unsigned char UpdatableInset::Editable() const
 void UpdatableInset::ToggleInsetCursor(BufferView *)
 {
 }
+
+void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int)
+{
+    LyXFont
+       font;
+//    bview = bv;
+    scx = 0;
+
+    mx_scx=abs((width(bv->getPainter(), font) - bv->paperWidth())/2);
+}
+
+
+void UpdatableInset::draw(Painter &, LyXFont const &,
+                         int baseline, float & x) const
+{
+    if (scx) x += float(scx);
+    top_x = int(x);
+    top_baseline = baseline;
+}
+
+
+void UpdatableInset::SetFont(LyXFont const &, bool )
+{
+}
+
+///  An updatable inset could handle lyx editing commands
+#ifdef SCROLL_INSET
+UpdatableInset::RESULT UpdatableInset::LocalDispatch(BufferView *, 
+                                                    int action, string arg) 
+#else
+UpdatableInset::RESULT UpdatableInset::LocalDispatch(BufferView *, int, string)
+#endif
+{
+#ifdef SCROLL_INSET
+    if (action==LFUN_SCROLL_INSET)
+       {
+           float xx;
+           sscanf(arg.c_str(), "%f", &xx);     
+           scroll(xx);
+
+           return DISPATCHED;
+       }
+#endif
+    return UNDISPATCHED; 
+}
index 4898652810f4fe19373f4d06badbb878f1615741..dd34a47a2222afbf9f26610a10ac967ec5aa20d6 100644 (file)
@@ -156,7 +156,7 @@ InsetCitation::~InsetCitation()
 }
 
 
-void InsetCitation::Edit(BufferView * bv, int, int)
+void InsetCitation::Edit(BufferView * bv, int, int, unsigned int)
 {
        if(bv->buffer()->isReadonly())
                WarnReadonly(bv->buffer()->fileName());
@@ -265,7 +265,7 @@ string InsetBibKey::getScreenLabel() const
   upwards?
   (Joacim 1998-03-04)
 */
-void InsetBibKey::Edit(BufferView * bv, int, int)
+void InsetBibKey::Edit(BufferView * bv, int, int, unsigned int)
 {
        if(bv->buffer()->isReadonly())
                WarnReadonly(bv->buffer()->fileName());
@@ -419,7 +419,7 @@ string InsetBibtex::getKeys(char delim)
 
 
 // BibTeX should have its own dialog. This is provisional.
-void InsetBibtex::Edit(BufferView *, int, int)
+void InsetBibtex::Edit(BufferView *, int, int, unsigned int)
 {
        if (!bibitem_form) {
                bibitem_form = create_form_bibitem_form();
index e9072295994bddec9be1c7e1867999f2b227aabe..b8a0d1760e85b3e0938c3f80d97915255ee172f6 100644 (file)
@@ -18,8 +18,7 @@
 
 #include "insetcommand.h"
 
-// Created by Alejandro 970222
-
+class Buffer;
 
 /** Used to insert citations  
  */
@@ -38,7 +37,7 @@ public:
        ///
        string getScreenLabel()const;
         ///
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView *, int x, int y, unsigned int button);
         ///
        unsigned char Editable() const {
                return 1;
@@ -77,7 +76,7 @@ public:
        ///
        virtual string getScreenLabel() const;
         ///
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView *, int x, int y, unsigned int button);
        ///
        unsigned char Editable() const {
                return 1;
@@ -126,7 +125,7 @@ public:
        ///
        string getScreenLabel() const;
        ///
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView *, int x, int y, unsigned int button);
        /// 
        int Latex(ostream &, signed char) const;
        ///
index a3d2928b58e26789394b2c7ecc2aad4e700b60c3..d41ad691db05da746c36cfa1f5033b36db4cb18c 100644 (file)
@@ -155,7 +155,7 @@ extern "C" void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data)
 }
 
 
-void InsetError::Edit(BufferView *, int, int)
+void InsetError::Edit(BufferView *, int, int, unsigned int)
 {
        static int ow = 400, oh = 240;
 
index f3b14341e005868a23dc366da1a8af45cdcb182b..4fe255658633ca6d7ee0763695e8817cc6883941 100644 (file)
@@ -41,8 +41,7 @@ public:
        ///
        int width(Painter &, LyXFont const & font) const;
        ///
-       void draw(Painter &, LyXFont const & font,
-                 int baseline, float & x) const;
+       void draw(Painter &, LyXFont const & font, int baseline, float & x) const;
        ///
        void Write(ostream &) const;
        ///
@@ -58,9 +57,9 @@ public:
        ///
        bool AutoDelete() const;
        /// what appears in the minibuffer when opening
-       char const * EditMessage() const {return _("Opened error");}
+       const char * EditMessage() const {return _("Opened error");}
        ///
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView *, int x, int y, unsigned int button);
        ///
        unsigned char Editable() const;
        ///
diff --git a/src/insets/insetert.C b/src/insets/insetert.C
new file mode 100644 (file)
index 0000000..83a9a81
--- /dev/null
@@ -0,0 +1,191 @@
+/* This file is part of
+ * ======================================================
+ * 
+ *           LyX, The Document Processor
+ *      
+ *          Copyright (C) 1998 The LyX Team.
+ *
+ *======================================================*/
+
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "insetert.h"
+#include "gettext.h"
+#include "lyxfont.h"
+#include "Painter.h"
+#include "lyx_gui_misc.h"
+
+
+InsetERT::InsetERT(Buffer * bf): InsetText(bf)
+{
+       closed = true;
+       nomotion = false;
+}
+
+
+InsetERT * InsetERT::Clone() const
+{
+    InsetERT * result = new InsetERT(buffer);
+    return result;
+}
+
+
+void InsetERT::Write(ostream & os) const
+{
+    os << "ERT\n";
+    WriteParagraphData(os);
+}
+
+
+int InsetERT::ascent_closed(Painter & pain, LyXFont const & f) const
+{
+       int width, ascent, descent;
+       LyXFont font(LyXFont::ALL_SANE);
+       font.setSize(f.size());
+       font.decSize();
+       font.decSize();
+       pain.buttonText(0, 0, _("ERT"), font, false, width, ascent, descent);
+       return ascent;
+}
+
+
+int InsetERT::descent_closed(Painter & pain, LyXFont const & f) const
+{
+       int width, ascent, descent;
+       LyXFont font(LyXFont::ALL_SANE);
+       font.setSize(f.size());
+       font.decSize();
+       font.decSize();
+       pain.buttonText(0, 0, _("ERT"), font, false, width, ascent, descent);
+       return descent;
+}
+
+
+int InsetERT::width_closed(Painter & pain, LyXFont const & f) const
+{
+       int width, ascent, descent;
+       LyXFont font(LyXFont::ALL_SANE);
+       font.setSize(f.size());
+       font.decSize();
+       font.decSize();
+       pain.buttonText(TEXT_TO_INSET_OFFSET, 0, _("ERT"), font, false,
+                       width, ascent, descent);
+       return width + (2*TEXT_TO_INSET_OFFSET);
+}
+
+
+int InsetERT::ascent(Painter & pain, LyXFont const & font) const
+{
+    if (closed) 
+       return ascent_closed(pain, font);
+    else 
+       return InsetText::ascent(pain, font);
+}
+
+
+int InsetERT::descent(Painter & pain, LyXFont const & font) const
+{
+
+    if (closed) 
+       return descent_closed(pain, font);
+    else 
+       return InsetText::descent(pain, font);
+}
+
+
+int InsetERT::width(Painter & pain, LyXFont const & font) const
+{
+    if (closed) 
+       return width_closed(pain, font);
+    else 
+       return InsetText::width(pain, font);
+}
+
+
+void InsetERT::draw_closed(Painter & pain, LyXFont const & f,
+                          int baseline, float & x) const
+{
+       LyXFont font(LyXFont::ALL_SANE);
+       font.setSize(f.size());
+       font.decSize();
+       font.decSize();
+       font.setColor(LColor::ert);
+       int width;
+       pain.buttonText(int(x)+TEXT_TO_INSET_OFFSET, baseline, _("ERT"), font,
+                       true, width);
+       x += width + (2*TEXT_TO_INSET_OFFSET);
+}
+
+
+void InsetERT::draw(Painter & pain, LyXFont const & f, int baseline, float & x) const
+{
+    if (closed) {
+       top_x = int(x);
+       top_baseline = baseline;
+       draw_closed(pain, f, baseline, x);
+    } else {
+       InsetText::draw(pain, f, baseline, x);
+    }
+//    resetPos(bv);
+}
+
+
+void InsetERT::InsetButtonRelease(BufferView * bv, int x, int y, int button)
+{
+    nomotion = false;
+    InsetText::InsetButtonRelease(bv, x, y, button);
+}
+
+
+void InsetERT::InsetButtonPress(BufferView * bv, int x, int y, int button)
+{
+    nomotion = false;
+    InsetText::InsetButtonPress(bv, x, y, button);
+}
+
+
+void InsetERT::InsetMotionNotify(BufferView * bv, int x, int y, int button)
+{
+    if (nomotion)
+       return;
+    InsetText::InsetMotionNotify(bv, x, y, button);
+}
+
+
+void InsetERT::Edit(BufferView * bv, int x, int y, unsigned int button)
+{
+    closed = false;
+    nomotion = true;
+    LyXFont font(LyXFont::ALL_SANE);
+    font.setLatex (LyXFont::ON);
+    InsetText::Edit(bv, (x > (width_closed(bv->getPainter(),font)-5) ?
+                    width(bv->getPainter(), font) : 0), y, button);
+    real_current_font = current_font = font;
+    bv->updateInset(this, false);
+}
+
+
+void InsetERT::InsetUnlock(BufferView * bv)
+{
+    closed = true;
+    InsetText::InsetUnlock(bv);
+    bv->updateInset(this, false);
+}
+
+
+bool InsetERT::InsertInset(Inset *)
+{
+    return false;
+}
+
+
+void InsetERT::SetFont(LyXFont const &, bool)
+{
+    WriteAlert(_("Impossible Operation!"),
+              _("Not permitted to change font-types inside ERT-insets!"),
+              _("Sorry."));
+}
diff --git a/src/insets/insetert.h b/src/insets/insetert.h
new file mode 100644 (file)
index 0000000..76bf317
--- /dev/null
@@ -0,0 +1,86 @@
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ * 
+ *           LyX, The Document Processor
+ *
+ *           Copyright (C) 1998 The LyX Team.
+ *
+ *======================================================
+ */
+// The pristine updatable inset: Text
+
+
+#ifndef INSETERT_H
+#define INSETERT_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "insettext.h"
+
+class Painter;
+
+/** A colapsable text inset
+  
+  To write full ert (including styles and other insets) in a given
+  space. 
+*/
+class InsetERT : public InsetText {
+public:
+    ///
+    InsetERT(Buffer *);
+    ///
+    //     InsetERT(InsetERT const &, Buffer *);
+    ///
+    ~InsetERT() {}
+    ///
+    InsetERT * Clone() const;
+    ///
+    //    void Read(LyXLex &);
+    ///
+    void Write(ostream &) const;
+    ///
+    int ascent(Painter &, LyXFont const &) const;
+    ///
+    int descent(Painter &, LyXFont const &) const;
+    ///
+    int width(Painter &, LyXFont const & f) const;
+    ///
+    void draw(Painter & pain, const LyXFont &, int , float &) const;
+    ///
+    //LString EditMessage() const;
+    ///
+    void InsetButtonRelease(BufferView *, int, int, int);
+    ///
+    void InsetButtonPress(BufferView *, int, int, int);
+    ///
+    void InsetMotionNotify(BufferView *, int, int, int);
+    ///
+    void Edit(BufferView *, int, int, unsigned int);
+    ///
+    void InsetUnlock(BufferView *);
+    ///
+    bool InsertInset(Inset *);
+    ///
+    void SetFont(LyXFont const &, bool toggleall);
+
+protected:
+    ///
+    int ascent_closed(Painter &, LyXFont const &) const;
+    ///
+    int descent_closed(Painter &, LyXFont const &) const;
+    ///
+    int width_closed(Painter &, LyXFont const & f) const;
+    ///
+    void draw_closed(Painter & pain, const LyXFont &, int , float &) const;
+
+private:
+    ///
+    bool
+        closed,
+       nomotion;
+};
+
+#endif
index 4a447b29d683060d7b5abca7ec8eb8d451763d8d..b9fdd55e03e7e8d46e0f9847ab9c354194f9f839 100644 (file)
@@ -226,7 +226,7 @@ Inset * InsetInclude::Clone() const
 }
 
 
-void InsetInclude::Edit(BufferView * bv, int, int)
+void InsetInclude::Edit(BufferView * bv, int, int, unsigned int)
 {
        if(bv->buffer()->isReadonly())
                WarnReadonly(bv->buffer()->fileName());
index 6b0fb58438a94794c6896418c385b87159177817..0cd817b2f2782d4b53d3020a9ac609cb0a7fd743 100644 (file)
@@ -47,7 +47,7 @@ public:
        /// This returns the list of bibkeys on the child buffer
        string getKeys(char delim) const;
        ///
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView *, int x, int y, unsigned int button);
        ///
        unsigned char Editable() const
        {
index dd187d63eba89528375c0544fd4e0f1605477b55..03e844d5d5021a270962d923aea1780bfa19b1aa 100644 (file)
@@ -85,7 +85,7 @@ InsetIndex::~InsetIndex()
 }
 
 
-void InsetIndex::Edit(BufferView * bv, int, int)
+void InsetIndex::Edit(BufferView * bv, int, int, unsigned int)
 {
        if(bv->buffer()->isReadonly())
                WarnReadonly(bv->buffer()->fileName());
index 152dd6597d401780eec385d05473fe122a9f45fa..b4905bf0b06950ecd14e9016be271f4d5b08a0db 100644 (file)
@@ -37,7 +37,7 @@ public:
        ///
        Inset * Clone() const { return new InsetIndex(contents);}
        ///
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView *, int, int, unsigned int);
        ///
        unsigned char Editable() const
        {
@@ -59,7 +59,7 @@ public:
        /// Updates needed features for this inset.
        void Validate(LaTeXFeatures & features) const;
        ///
-       void Edit(BufferView *, int, int) {}
+       void Edit(BufferView *, int, int, unsigned int) {}
        ///
        unsigned char Editable() const{
                return 1;
index 2e0978f3562d4b0f6068977afe8ac89c20259bcf..848285ee59e78d1772450a13eae5de529434f4f7 100644 (file)
@@ -180,7 +180,7 @@ extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
 }
 
 
-void InsetInfo::Edit(BufferView * bv, int, int)
+void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
 {
        static int ow = -1, oh;
 
index 422b531f763f43dbd2a3d935710cc13613518fe8..20ffaf207cbea591c91e979c1ce428c89b53c874 100644 (file)
@@ -57,9 +57,9 @@ public:
        ///
        int DocBook(string & file) const;
        /// what appears in the minibuffer when opening
-       char const * EditMessage() const {return _("Opened note");}
+       const char * EditMessage() const {return _("Opened note");}
        ///
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView *, int, int, unsigned int);
        ///
        unsigned char Editable() const;
        ///
index 27757f4a00da0f6504d4a6c11584d92ce8807994..49ca447356a696a01683386310831eb69c0699a4 100644 (file)
@@ -19,7 +19,7 @@
 #include "insetcommand.h"
 #include "gettext.h"
 
-// Created by Bernhard 970807
+class Buffer;
 
 /** Used to insert table of algorithms
  */
index cca6c089bd3b5b959f083ed66480e49aef9c083a..0fd046ddabfbb9911a184b2281c8794ea12b0509 100644 (file)
@@ -35,10 +35,10 @@ InsetParent::InsetParent(string const & fn, Buffer * owner)
 }
 
 
-void InsetParent::Edit(BufferView * bv, int, int)
+void InsetParent::Edit(BufferView * bv, int, int, unsigned int)
 {    
-       bv->owner()->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, 
-                                           getContents().c_str());
+       bv->owner()->getLyXFunc()->
+               Dispatch(LFUN_CHILDOPEN, getContents().c_str());
 }
 
 
index 1e7ab372071ddae45ccf623bf2d07227c434ee40..2e863c1deab46702289576f0dbc701b6a8378ba9 100644 (file)
@@ -17,7 +17,8 @@
 
 #include "insetcommand.h"
 #include "gettext.h"
-// Created by asierra 970813
+
+class Buffer;
 
 /** Reference to the parent document.
 
@@ -41,7 +42,7 @@ public:
                return string(_("Parent:")) + getContents();
        }
         ///
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView *, int, int, unsigned int);
         ///
        unsigned char Editable() const {
                return 1;
index b4a7c2408cccfc02044d7b75fdc5b8c0ca2df01a..79dd93287286e8ba33968288c41b360511dfa465 100644 (file)
@@ -43,10 +43,10 @@ InsetRef::InsetRef(InsetCommand const & inscmd, Buffer * bf)
 }
 
 
-void InsetRef::Edit(BufferView * bv, int, int)
+void InsetRef::Edit(BufferView * bv, int, int, unsigned int)
 {
-        bv->owner()->getLyXFunc()
-               ->Dispatch(LFUN_REFGOTO, getContents().c_str());
+        bv->owner()->getLyXFunc()->
+               Dispatch(LFUN_REFGOTO, getContents().c_str());
 }
 
 
index fe4e71487c833c3ab36a3320637dda8d8c5bed28..3644753e2316efea6cbedba294ba9fe865c78a14 100644 (file)
@@ -45,7 +45,7 @@ public:
        ///
        Inset::Code LyxCode() const { return Inset::REF_CODE; }
        ///
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView *, int, int, unsigned int);
        ///
        unsigned char Editable() const {
                return 1;
diff --git a/src/insets/insettext.C b/src/insets/insettext.C
new file mode 100644 (file)
index 0000000..c0da234
--- /dev/null
@@ -0,0 +1,1466 @@
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ * 
+ *           LyX, The Document Processor
+ *
+ *           Copyright (C) 1998 The LyX Team.
+ *
+ * ======================================================
+ */
+
+#include <config.h>
+
+#include <fstream>
+using std::ifstream;
+
+#include <cstdlib>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "insettext.h"
+#include "lyxlex.h"
+#include "debug.h"
+#include "lyxfont.h"
+#include "lyxlex.h"
+#include "commandtags.h"
+#include "buffer.h"
+#include "LyXView.h"
+#include "BufferView.h"
+#include "support/textutils.h"
+#include "layout.h"
+#include "insetlatexaccent.h"
+#include "insetquotes.h"
+#include "mathed/formulamacro.h"
+#include "figinset.h"
+#include "insetinfo.h"
+#include "insetinclude.h"
+#include "insetbib.h"
+#include "insetcommand.h"
+#include "insetindex.h"
+#include "insetlabel.h"
+#include "insetref.h"
+//#include "insettabular.h"
+#include "insetert.h"
+#include "insetspecialchar.h"
+#include "LaTeXFeatures.h"
+#include "Painter.h"
+#include "lyx_gui_misc.h"
+#include "support/LAssert.h"
+
+extern unsigned char getCurrentTextClass(Buffer *);
+
+InsetText::InsetText(Buffer * buf)
+{
+    par = new LyXParagraph();
+    the_locking_inset = 0;
+    buffer = buf;
+    cursor_visible = false;
+    maxWidth = old_x = -1;
+    actpos = selection_start = selection_end = 0;
+    interline_space = 1;
+    no_selection = false;
+    init_inset = true;
+}
+
+
+InsetText::InsetText(InsetText const & ins, Buffer * buf)
+{
+    par = new LyXParagraph(ins.par);
+    the_locking_inset = 0;
+    buffer = buf;
+    cursor_visible = false;
+    maxWidth = old_x = -1;
+    actpos = selection_start = selection_end = 0;
+    interline_space = 1;
+    no_selection = false;
+    init_inset = true;
+}
+
+
+InsetText::~InsetText()
+{
+    delete par;
+}
+
+
+InsetText * InsetText::Clone() const
+{
+    InsetText * t = new InsetText(*this, buffer);
+    return t;
+}
+
+
+void InsetText::Write(ostream & os) const
+{
+    os << "Text\n";
+    WriteParagraphData(os);
+}
+
+
+void InsetText::WriteParagraphData(ostream &os) const
+{
+    LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
+    LyXFont font2;
+    int column = 0;
+    char c = 0;
+
+    for (int i = 0; i < par->Last(); ++i) {
+        // Write font changes
+        font2 = par->GetFontSettings(i);
+        if (font2 != font1) {
+            font2.lyxWriteChanges(font1, os);
+            column = 0;
+            font1 = font2;
+        }
+        c = par->GetChar(i);
+        // A newline before tags
+        if (column > 0 &&
+            (c == LyXParagraph::META_INSET ||
+             c == LyXParagraph::META_NEWLINE ||
+             c == '\\')) {
+            os << "\n";
+            column = 0;
+        }
+       
+        switch (c) {
+          case LyXParagraph::META_INSET: {
+              Inset *inset = par->GetInset(i);
+              if (inset) {
+                 os << "\n\\begin_inset ";
+                 inset->Write(os);
+                 os << "\n\\end_inset \n\n";
+                  column = 0;
+              }
+          }
+          break;
+          case LyXParagraph::META_NEWLINE: 
+              os << "\\newline\n";
+              column = 0;
+              break;
+          case '\\': 
+              os << "\\backslash\n";
+              column = 0;
+              break;
+          default:
+              if (column > 65 && c==' ') {
+                  os << "\n";
+                  column = 0;
+              }
+              // this check is to amend a bug. LyX sometimes
+              // inserts '\0' this could cause problems.
+              if (c != '\0')
+                  os << c;
+              else
+                     lyxerr << "ERROR (InsetText::writeFile):"
+                             " '\\0' char in structure.\n";
+              column++;
+              break;
+        }
+    }
+    // A newline if the last c was not a tag.
+    if (column > 0 &&
+        (c != LyXParagraph::META_INSET &&
+         c != LyXParagraph::META_NEWLINE &&
+         c != '\\')) {
+        os << "\n";
+        column = 0;
+    }
+}
+
+
+void InsetText::Read(LyXLex & lex)
+{
+    string token, tmptok;
+    LyXFont font = LyXFont(LyXFont::ALL_INHERIT);
+    int pos = 0;
+
+    delete par;
+    par = new LyXParagraph;
+    
+    while (lex.IsOK()) {
+        lex.nextToken();
+        token = lex.GetString();
+        if (token.empty())
+            continue;
+        else if (token[0] != '\\') {
+            int n = token.length();
+            for (int i=0; i < n; ++i) {
+                par->InsertChar(pos, token[i]);
+                par->SetFont(pos, font);
+                ++pos;
+            }
+        } else if (token == "\\newline") {
+            par->InsertChar(pos, LyXParagraph::META_NEWLINE);
+            par->SetFont(pos, font);
+            ++pos;
+        } else if (token == "\\family") { 
+            lex.next();
+            font.setLyXFamily(lex.GetString());
+        } else if (token == "\\series") {
+            lex.next();
+            font.setLyXSeries(lex.GetString());
+        } else if (token == "\\shape") {
+            lex.next();
+            font.setLyXShape(lex.GetString());
+        } else if (token == "\\size") {
+            lex.next();
+            font.setLyXSize(lex.GetString());
+        } else if (token == "\\latex") {
+            lex.next();
+            string tok = lex.GetString();
+            // This is dirty, but gone with LyX3. (Asger)
+            if (tok == "no_latex")
+                font.setLatex(LyXFont::OFF);
+            else if (tok == "latex")
+                font.setLatex(LyXFont::ON);
+            else if (tok == "default")
+                font.setLatex(LyXFont::INHERIT);
+            else
+                lex.printError("Unknown LaTeX font flag "
+                               "`$$Token'");
+       } else if (token == "\\direction") {
+               lex.next();
+               string tok = lex.GetString();
+               if (tok == "ltr")
+                       font.setDirection(LyXFont::LTR_DIR);
+               else if (tok == "rtl")
+                       font.setDirection(LyXFont::RTL_DIR);
+               else if (tok == "default")
+                       font.setDirection(LyXFont::INHERIT_DIR);
+               else
+                       lex.printError("Unknown font flag "
+                                      "`$$Token'");
+        } else if (token == "\\emph") {
+            lex.next();
+            font.setEmph(font.setLyXMisc(lex.GetString()));
+        } else if (token == "\\bar") {
+            lex.next();
+            string tok = lex.GetString();
+            // This is dirty, but gone with LyX3. (Asger)
+            if (tok == "under")
+                font.setUnderbar(LyXFont::ON);
+            else if (tok == "no")
+                font.setUnderbar(LyXFont::OFF);
+            else if (tok == "default")
+                font.setUnderbar(LyXFont::INHERIT);
+            else
+                lex.printError("Unknown bar font flag "
+                               "`$$Token'");
+        } else if (token == "\\noun") {
+            lex.next();
+            font.setNoun(font.setLyXMisc(lex.GetString()));
+        } else if (token == "\\color") {
+            lex.next();
+            font.setLyXColor(lex.GetString());
+       } else if (token == "\\begin_inset") {
+           Inset * inset = 0;
+           lex.next();
+           tmptok = lex.GetString();
+           // Test the different insets.
+           if (tmptok == "Quotes") {
+               inset = new InsetQuotes(string());
+               inset->Read(lex);
+           } else if (tmptok == "LaTeXAccent" || tmptok == "\\i") {
+               inset = new InsetLatexAccent;
+               inset->Read(lex);
+           } else if (tmptok == "FormulaMacro") {
+               inset = new InsetFormulaMacro;
+               inset->Read(lex);
+           } else if (tmptok == "Formula") {
+               inset = new InsetFormula;
+               inset->Read(lex);
+           } else if (tmptok == "Figure") {
+               inset = new InsetFig(100,100, buffer);
+               inset->Read(lex);
+#if 0
+           } else if (tmptok == "Tabular") {
+               inset = new InsetTabular(buffer);
+               inset->Read(lex);
+#endif
+           } else if (tmptok == "Text") {
+               inset = new InsetText(buffer);
+               inset->Read(lex);
+           } else if (tmptok == "ERT") {
+               inset = new InsetERT(buffer);
+               inset->Read(lex);
+           } else if (tmptok == "Info") {
+               inset = new InsetInfo;
+               inset->Read(lex);
+           } else if (tmptok == "Include") {
+               inset = new InsetInclude(string(), buffer);
+               inset->Read(lex);
+           } else if (tmptok == "LatexCommand") {
+               InsetCommand inscmd;
+               inscmd.Read(lex);
+               if (inscmd.getCmdName()=="cite") {
+                   inset = new InsetCitation(inscmd.getContents(),
+                                             inscmd.getOptions());
+               } else if (inscmd.getCmdName()=="bibitem") {
+                   lex.printError("Wrong place for bibitem");
+                   inset = inscmd.Clone();
+               } else if (inscmd.getCmdName()=="BibTeX") {
+                   inset = new InsetBibtex(inscmd.getContents(),
+                                           inscmd.getOptions(), buffer);
+               } else if (inscmd.getCmdName()=="index") {
+                   inset = new InsetIndex(inscmd.getContents());
+               } else if (inscmd.getCmdName()=="include") {
+                   inset = new InsetInclude(inscmd.getContents(), buffer);
+               } else if (inscmd.getCmdName()=="label") {
+                   inset = new InsetLabel(inscmd.getCommand());
+               } else if (inscmd.getCmdName() == "ref" ||
+                          inscmd.getCmdName() == "pageref") {
+                   inset = new InsetRef(inscmd, buffer);
+               } else
+                   // The following three are only for compatibility
+                   if (inscmd.getCmdName()=="-") {
+                       inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
+                   } else if (inscmd.getCmdName()=="@.") {
+                       inset = new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
+                   } else if (inscmd.getCmdName()=="ldots") {
+                       inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
+                   } else
+                       inset = inscmd.Clone();
+           }
+           if (inset) {
+               par->InsertChar(pos, LyXParagraph::META_INSET);
+               par->InsertInset(pos, inset);
+               par->SetFont(pos, font);
+               ++pos;
+           } else {
+               lex.printError("Unknown inset `$$Token'. "
+                              "Inserting as text.");
+           }
+#ifndef NO_COMPABILITY
+        } else if (token == "\\hfill") {
+            // now obsolete, but we have a bak compability
+//            Inset * inset = new InsetSpecialChar(LyXParagraph::META_HFILL);
+//            par->InsertChar(pos, LyXParagraph::META_INSET);
+//            par->InsertInset(pos, inset);
+            par->InsertChar(pos, LyXParagraph::META_HFILL);
+            par->SetFont(pos, font);
+            ++pos;
+        } else if (token == "\\protected_separator") {
+            // now obsolete, but we have a back compability
+            par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
+            //Inset * inset = new InsetSpecialChar(LyXParagraph::META_PROTECTED_SEPARATOR);
+//            par->InsertChar(pos, LyXParagraph::META_INSET);
+//            par->InsertInset(pos, inset);
+            par->SetFont(pos, font);
+            ++pos;
+#endif
+        } else if (token == "\\bibitem") {  // ale970302
+            if (!par->bibkey)
+                par->bibkey = new InsetBibKey;
+            par->bibkey->Read(lex);                 
+        }else if (token == "\\backslash") {
+            par->InsertChar(pos, '\\');
+            par->SetFont(pos, font);
+            ++pos;
+        } else if (token == "\\end_inset") {
+            break;
+        } else {
+            lex.printError("Unknown tabular token `$$Token'. Not handled!");
+           break;
+        }
+    }
+    if (token != "\\end_inset") {
+        lex.printError("Missing \\end_inset at this point. "
+                       "Read: `$$Token'");
+    }
+    init_inset = true;
+}
+
+
+int InsetText::ascent(Painter &, LyXFont const & font) const
+{
+    if (maxAscent)
+       return maxAscent;
+    return font.maxAscent();
+}
+
+
+int InsetText::descent(Painter &, LyXFont const & font) const
+{
+    if (maxDescent)
+       return maxDescent;
+    return font.maxDescent();
+}
+
+
+int InsetText::width(Painter &, LyXFont const &) const
+{
+    return insetWidth;
+}
+
+
+int InsetText::getMaxWidth(UpdatableInset * inset) const
+{
+    if (!the_locking_inset) {
+           lyxerr << "Text: No locking inset in this inset.\n";
+       return 0;
+    }
+
+    if (the_locking_inset==inset) 
+       return maxWidth;
+
+    return the_locking_inset->getMaxWidth(inset);
+}
+
+
+void InsetText::draw(Painter & pain,const LyXFont & f,int baseline,float & x) const
+{
+    unsigned int
+        r;
+    bool
+       do_reset_pos;
+
+    UpdatableInset::draw(pain, f, baseline, x);
+    do_reset_pos = (x != top_x) || (baseline != top_baseline);
+    top_x = int(x);
+    top_baseline = baseline;
+    computeBaselines(baseline);
+    for(r=0; r<rows.size()-1; ++r) {
+        drawRowSelection(pain, rows[r].pos, rows[r+1].pos, r, 
+                         rows[r].baseline, x);
+        drawRowText(pain, rows[r].pos, rows[r+1].pos, rows[r].baseline, x);
+    }
+    x += insetWidth;
+    if (!the_locking_inset && do_reset_pos) {
+//        HideInsetCursor(bv);
+//        resetPos(bv);
+//        ShowInsetCursor(bv);
+    }
+}
+
+
+void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos,
+                                 int row, int baseline, float x) const
+{
+    if (!hasSelection())
+       return;
+    int
+       p,
+       ssel_x, esel_x,
+       s_start, s_end;
+    LyXFont
+       font;
+    char
+       ch;
+
+    if (selection_start > selection_end) {
+       s_start = selection_end;
+       s_end = selection_start;
+    } else {
+       s_start = selection_start;
+       s_end = selection_end;
+    }
+    if ((s_start > endpos) || (s_end < startpos))
+       return;
+    ssel_x = esel_x = int(x);
+    for(p=startpos; p < endpos; ++p) {
+       if (p == s_start)
+           ssel_x = int(x);
+       if ((p >= s_start) && (p <= s_end))
+           esel_x = int(x);
+       ch = par->GetChar(p);
+       font = GetFont(par,p);
+       if (IsFloatChar(ch)) {
+           // skip for now
+       } else if (ch == LyXParagraph::META_INSET) {
+           Inset const * tmpinset = par->GetInset(p);
+           x += tmpinset->width(pain, font);
+       } else {
+           x += pain.width(ch,font);
+       }
+    }
+    if (p == s_start)
+       ssel_x = int(x);
+    if ((p >= s_start) && (p <= s_end))
+       esel_x = int(x);
+    if (ssel_x < esel_x) {
+       pain.fillRectangle(int(ssel_x), baseline-rows[row].asc,
+                          int(esel_x - ssel_x),
+                          rows[row].asc + rows[row].desc,
+                          LColor::selection);
+    }
+}
+
+
+void InsetText::drawRowText(Painter & pain, int startpos, int endpos,
+                           int baseline, float x) const
+{
+    Assert(endpos <= par->Last());
+    int
+       p;
+    char
+       ch;
+    LyXFont
+       font;
+    for(p=startpos; p < endpos; ++p) {
+       ch = par->GetChar(p);
+       font = GetFont(par,p);
+       if (IsFloatChar(ch)) {
+           // skip for now
+       } else if (ch == LyXParagraph::META_INSET) {
+           Inset * tmpinset = par->GetInset(p);
+           if (tmpinset) 
+               tmpinset->draw(pain, font, baseline, x);
+       } else {
+           pain.text(int(x), baseline, ch, font);
+           x += pain.width(ch,font);
+       }
+    }
+}
+
+
+const char * InsetText::EditMessage() const
+{
+    return _("Opened Text Inset");
+}
+
+
+void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
+{
+    UpdatableInset::Edit(bv, x, y, button);
+
+    bv->lockInset(this);
+    the_locking_inset = 0;
+    inset_pos = inset_x = inset_y = 0;
+    no_selection = true;
+    setPos(bv, x,y);
+    selection_start = selection_end = actpos;
+    current_font = real_current_font = GetFont(par, actpos);
+}
+
+
+void InsetText::InsetUnlock(BufferView *bv)
+{
+    if (the_locking_inset)
+       the_locking_inset->InsetUnlock(bv);
+    HideInsetCursor(bv);
+    if (hasSelection()) {
+       selection_start = selection_end = actpos;
+       bv->updateInset(this, false);
+    }
+    the_locking_inset = 0;
+    no_selection = false;
+}
+
+
+bool InsetText::UnlockInsetInInset(BufferView * bv, Inset * inset, bool lr)
+{
+    if (!the_locking_inset)
+        return false;
+    if (the_locking_inset == inset) {
+        the_locking_inset->InsetUnlock(bv);
+        the_locking_inset = 0;
+        if (lr)
+            moveRight(bv, false);
+        return true;
+    }
+    return the_locking_inset->UnlockInsetInInset(bv, inset,lr);
+}
+
+bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
+{
+    if (!the_locking_inset)
+        return false;
+    if (the_locking_inset != inset)
+        return the_locking_inset->UpdateInsetInInset(bv, inset);
+    float x = inset_x;
+    inset->draw(bv->getPainter(), real_current_font, inset_y, x);
+    bv->updateInset(this, true);
+    return true;
+}
+
+
+void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
+{
+    if (the_locking_inset) {
+        the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
+        return;
+    }
+    no_selection = false;
+}
+
+
+void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
+{
+    if (hasSelection()) {
+       selection_start = selection_end = actpos;
+       bv->updateInset(this, false);
+    }
+    no_selection = false;
+    if (the_locking_inset) {
+       setPos(bv, x,y,false);
+       UpdatableInset
+           *inset=0;
+       if (par->GetChar(actpos)==LyXParagraph::META_INSET)
+           inset=(UpdatableInset*)par->GetInset(actpos);
+       if (the_locking_inset == inset) {
+           the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
+           return;
+       } else if (inset) {
+           // otherwise unlock the_locking_inset and lock the new inset
+           inset_x = cx-top_x;
+           inset_y = cy;
+           inset_pos = actpos;
+           the_locking_inset->InsetUnlock(bv);
+           the_locking_inset = inset;
+           the_locking_inset->Edit(bv, x - inset_x, y - inset_y, button);
+           return;
+       }
+       // otherwise only unlock the_locking_inset
+       the_locking_inset->InsetUnlock(bv);
+    }
+    HideInsetCursor(bv);
+    the_locking_inset = 0;
+    setPos(bv, x, y);
+    selection_start = selection_end = actpos;
+    if (!the_locking_inset)
+       ShowInsetCursor(bv);
+}
+
+
+void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int button)
+{
+    if (the_locking_inset) {
+        the_locking_inset->InsetMotionNotify(bv, x-inset_x, y-inset_y,button);
+        return;
+    }
+    if (!no_selection) {
+       int
+           old = selection_end;
+       setPos(bv, x, y, false);
+       selection_end = actpos;
+       if (old != selection_end)
+           bv->updateInset(this, false);
+    }
+    no_selection = false;
+}
+
+
+void InsetText::InsetKeyPress(XKeyEvent * xke)
+{
+    if (the_locking_inset) {
+        the_locking_inset->InsetKeyPress(xke);
+        return;
+    }
+}
+
+
+UpdatableInset::RESULT InsetText::LocalDispatch(BufferView * bv,
+                                               int action, string arg)
+{
+    no_selection = false;
+    if (UpdatableInset::LocalDispatch(bv, action, arg)) {
+       resetPos(bv);
+       return DISPATCHED;
+    }
+
+    UpdatableInset::RESULT
+        result=DISPATCHED;
+
+    if ((action < 0) && arg.empty())
+        return FINISHED;
+
+    if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
+        (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
+        old_x = -1;
+    if (the_locking_inset) {
+        result = the_locking_inset->LocalDispatch(bv, action, arg);
+       if (result == DISPATCHED) {
+           the_locking_inset->ToggleInsetCursor(bv);
+           bv->updateInset(this, false);
+           the_locking_inset->ToggleInsetCursor(bv);
+            return result;
+        } else if (result == FINISHED) {
+           if ((action == LFUN_RIGHT) || (action == -1)) {
+               actpos = inset_pos + 1;
+               resetPos(bv);
+           }
+           the_locking_inset = 0;
+           return DISPATCHED;
+       }
+    }
+    HideInsetCursor(bv);
+    switch (action) {
+        // Normal chars
+      case -1:
+          par->InsertChar(actpos,arg[0]);
+         par->SetFont(actpos,real_current_font);
+         computeTextRows(bv);
+         bv->updateInset(this, true);
+          ++actpos;
+         selection_start = selection_end = actpos;
+          resetPos(bv);
+          break;
+        // --- Cursor Movements ---------------------------------------------
+      case LFUN_RIGHTSEL:
+          moveRight(bv, false);
+         selection_end = actpos;
+         bv->updateInset(this, false);
+         break;
+      case LFUN_RIGHT:
+          result= DISPATCH_RESULT(moveRight(bv));
+         if (hasSelection()) {
+             selection_start = selection_end = actpos;
+             bv->updateInset(this, false);
+         } else {
+             selection_start = selection_end = actpos;
+         }
+          break;
+      case LFUN_LEFTSEL:
+          moveLeft(bv, false);
+         selection_end = actpos;
+         bv->updateInset(this, false);
+         break;
+      case LFUN_LEFT:
+          result= DISPATCH_RESULT(moveLeft(bv));
+         if (hasSelection()) {
+             selection_start = selection_end = actpos;
+             bv->updateInset(this, false);
+         } else {
+             selection_start = selection_end = actpos;
+         }
+          break;
+      case LFUN_DOWNSEL:
+          moveDown(bv, false);
+         selection_end = actpos;
+         bv->updateInset(this, false);
+         break;
+      case LFUN_DOWN:
+          result= DISPATCH_RESULT(moveDown(bv));
+         if (hasSelection()) {
+             selection_start = selection_end = actpos;
+             bv->updateInset(this, false);
+         } else {
+             selection_start = selection_end = actpos;
+         }
+          break;
+      case LFUN_UPSEL:
+          moveUp(bv, false);
+         selection_end = actpos;
+         bv->updateInset(this, false);
+         break;
+      case LFUN_UP:
+          result= DISPATCH_RESULT(moveUp(bv));
+         if (hasSelection()) {
+             selection_start = selection_end = actpos;
+             bv->updateInset(this, false);
+         } else {
+             selection_start = selection_end = actpos;
+         }
+          break;
+      case LFUN_BACKSPACE:
+          if (!actpos || par->IsNewline(actpos-1)) {
+             if (hasSelection()) {
+                 selection_start = selection_end = actpos;
+                 bv->updateInset(this, false);
+             }
+              break;
+         }
+          moveLeft(bv);
+      case LFUN_DELETE:
+          if (Delete()) { // we need update
+             selection_start = selection_end = actpos;
+             computeTextRows(bv);
+             bv->updateInset(this, true);
+          } else if (hasSelection()) {
+             selection_start = selection_end = actpos;
+             bv->updateInset(this, false);
+         }
+          break;
+      case LFUN_HOME:
+          for(;actpos > rows[actrow].pos;--actpos)
+              cx -= SingleWidth(bv, par, actpos);
+         cx -= SingleWidth(bv, par, actpos);
+         if (hasSelection()) {
+             selection_start = selection_end = actpos;
+             bv->updateInset(this, false);
+         } else {
+             selection_start = selection_end = actpos;
+         }
+          break;
+      case LFUN_END:
+          for(;actpos < rows[actrow+1].pos;++actpos)
+              cx += SingleWidth(bv, par, actpos);
+         if (hasSelection()) {
+             selection_start = selection_end = actpos;
+             bv->updateInset(this, false);
+         } else {
+             selection_start = selection_end = actpos;
+         }
+          break;
+      case LFUN_MATH_MODE:   // Open or create a math inset
+          InsertInset(bv, new InsetFormula);
+         if (hasSelection()) {
+             selection_start = selection_end = actpos;
+             bv->updateInset(this, false);
+         } else {
+             selection_start = selection_end = actpos;
+         }
+          return DISPATCHED;
+          break;
+      default:
+          result = UNDISPATCHED;
+          break;
+    }
+    if (result != FINISHED) {
+       if (!the_locking_inset)
+           ShowInsetCursor(bv);
+    } else
+        bv->unlockInset(this);
+    return result;
+}
+
+
+int InsetText::Latex(ostream &os, signed char fragile) const
+{
+    string
+        fstr;
+    int
+        i;
+
+    i = Latex(fstr, fragile);
+    os << fstr.c_str();
+    return i;
+}
+
+
+int InsetText::Latex(string & file, signed char /* fragile */) const
+{
+    TexRow
+        texrow;
+
+    return par->SimpleTeXOnePar(file, texrow);
+}
+
+
+void InsetText::Validate(LaTeXFeatures & features) const
+{
+    par->validate(features);
+}
+
+
+// Returns the width of a character at a certain spot
+int InsetText::SingleWidth(BufferView *bv, LyXParagraph * par, int pos)
+{
+    LyXFont
+        font = GetFont(par, pos);
+    char
+        c = par->GetChar(pos);
+
+    // The most common case is handled first (Asger)
+    if (IsPrintable(c)) {
+        return font.width(c);
+    } else if (c == LyXParagraph::META_INSET) {
+        Inset const * tmpinset=par->GetInset(pos);
+        if (tmpinset)
+            return tmpinset->width(bv->getPainter(), font);
+        else
+            return 0;
+    } else if (IsSeparatorChar(c))
+        c = ' ';
+    else if (IsNewlineChar(c))
+        c = 'n';
+    return font.width(c);
+}
+
+
+// Returns the width of a character at a certain spot
+void InsetText::SingleHeight(BufferView * bv, LyXParagraph * par,int pos,
+                            int & asc, int & desc)
+{
+    LyXFont
+        font = GetFont(par, pos);
+    char
+        c = par->GetChar(pos);
+
+    asc = desc = 0;
+    // The most common case is handled first (Asger)
+    if (c == LyXParagraph::META_INSET) {
+        Inset const * tmpinset=par->GetInset(pos);
+        if (tmpinset) {
+           asc = tmpinset->ascent(bv->getPainter(),font);
+           desc = tmpinset->descent(bv->getPainter(),font);
+        }
+    } else {
+        asc = font.maxAscent();
+        desc = font.maxDescent();
+    }
+    return;
+}
+
+
+// Gets the fully instantiated font at a given position in a paragraph
+// Basically the same routine as LyXParagraph::getFont() in paragraph.C.
+// The difference is that this one is used for displaying, and thus we
+// are allowed to make cosmetic improvements. For instance make footnotes
+// smaller. (Asger)
+// If position is -1, we get the layout font of the paragraph.
+// If position is -2, we get the font of the manual label of the paragraph.
+LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
+{
+    char par_depth = par->GetDepth();
+
+    LyXLayout layout =
+           textclasslist.Style(buffer->params.textclass, par->GetLayout());
+
+    // We specialize the 95% common case:
+    if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
+        if (pos >= 0) {
+            // 95% goes here
+            if (layout.labeltype == LABEL_MANUAL
+                && pos < BeginningOfMainBody(par)) {
+               // 1% goes here
+                return par->GetFontSettings(pos).realize(layout.reslabelfont);
+            } else
+                return par->GetFontSettings(pos).realize(layout.resfont);
+        } else {
+            // 5% goes here.
+            // process layoutfont for pos == -1 and labelfont for pos < -1
+            if (pos == -1)
+                return layout.resfont;
+            else
+                return layout.reslabelfont;
+        }
+    }
+    // The uncommon case need not be optimized as much
+
+    LyXFont layoutfont, tmpfont;
+
+    if (pos >= 0){
+        // 95% goes here
+        if (pos < BeginningOfMainBody(par)) {
+            // 1% goes here
+            layoutfont = layout.labelfont;
+        } else {
+            // 99% goes here
+            layoutfont = layout.font;
+        }
+        tmpfont = par->GetFontSettings(pos);
+        tmpfont.realize(layoutfont);
+    } else{
+        // 5% goes here.
+        // process layoutfont for pos == -1 and labelfont for pos < -1
+        if (pos == -1)
+            tmpfont = layout.font;
+        else
+            tmpfont = layout.labelfont;
+    }
+    
+    // Resolve against environment font information
+    //if (par->GetDepth()){ // already in while condition
+    while (par && par_depth && !tmpfont.resolved()) {
+        par = par->DepthHook(par_depth - 1);
+        if (par) {
+            tmpfont.realize(textclasslist.Style(buffer->params.textclass,
+                                                par->GetLayout()).font);
+            par_depth = par->GetDepth();
+        }
+    }
+    tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
+                    defaultfont()));
+    return tmpfont;
+}
+
+
+int InsetText::BeginningOfMainBody(LyXParagraph * par) const
+{
+    if (textclasslist.Style(buffer->params.textclass,
+                       par->GetLayout()).labeltype != LABEL_MANUAL)
+        return 0;
+    else
+        return par->BeginningOfMainBody();
+}
+
+
+void InsetText::GetCursorPos(int & x, int & y)
+{
+    x = cx;
+    y = cy;
+}
+
+
+int InsetText::InsetInInsetY()
+{
+    if (!the_locking_inset)
+       return 0;
+
+    int
+       y = inset_y;
+    return (y + the_locking_inset->InsetInInsetY());
+}
+
+
+void InsetText::ToggleInsetCursor(BufferView * bv)
+{
+    if (the_locking_inset) {
+        the_locking_inset->ToggleInsetCursor(bv);
+        return;
+    }
+    int
+        asc,desc;
+    LyXFont
+        font = GetFont(par, actpos);
+
+    asc = font.maxAscent();
+    desc = font.maxDescent();
+  
+    if (cursor_visible)
+        bv->hideLockedInsetCursor();
+    else
+        bv->showLockedInsetCursor(cx, cy, asc, desc);
+    cursor_visible = !cursor_visible;
+}
+
+
+void InsetText::ShowInsetCursor(BufferView * bv)
+{
+    if (!cursor_visible) {
+       int
+           asc,desc;
+       LyXFont
+           font = GetFont(par, actpos);
+       
+       asc = font.maxAscent();
+       desc = font.maxDescent();
+       bv->fitLockedInsetCursor(cx, cy, asc, desc);
+       bv->showLockedInsetCursor(cx, cy, asc, desc);
+       cursor_visible = true;
+    }
+}
+
+
+void InsetText::HideInsetCursor(BufferView * bv)
+{
+    if (cursor_visible)
+        ToggleInsetCursor(bv);
+}
+
+
+void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
+{
+    int
+       ox = x,
+       oy = y;
+    // search right X-pos x==0 -> top_x
+    actpos = actrow = 0;
+    cy = top_baseline;
+    y += cy;
+    for(unsigned int i=1;
+       ((cy+rows[i-1].desc) < y) && (i < rows.size()-1); ++i) {
+       cy = rows[i].baseline;
+       actpos = rows[i].pos;
+       actrow = i;
+    }
+    cy -= top_baseline;
+    cx = top_x;
+    x += top_x;
+    int
+       sw, swh;
+
+    sw = swh = SingleWidth(bv, par,actpos);
+    if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
+       swh /= 2;
+    while ((actpos < (rows[actrow+1].pos-1)) && ((cx+swh) < x)) {
+       cx += sw;
+       ++actpos;
+       sw = swh = SingleWidth(bv, par,actpos);
+       if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
+           swh /= 2;
+    }
+    if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
+        the_locking_inset=(UpdatableInset*)par->GetInset(actpos);
+       inset_x = cx-top_x;
+       inset_y = cy;
+       inset_pos = actpos;
+        the_locking_inset->Edit(bv, ox - inset_x, oy - inset_y, 0);
+    }
+}
+
+
+bool InsetText::moveRight(BufferView * bv, bool activate_inset)
+{
+    if (actpos >= par->Last())
+       return false;
+    if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
+       the_locking_inset=(UpdatableInset*)par->GetInset(actpos);
+       inset_x = cx-top_x;
+       inset_y = cy;
+       inset_pos = actpos;
+       the_locking_inset->Edit(bv, 0, 0, 0);
+    } else {
+       ++actpos;
+       resetPos(bv);
+    }
+    return true;
+}
+
+
+bool InsetText::moveLeft(BufferView * bv, bool activate_inset)
+{
+    if (actpos <= 0)
+       return false;
+    --actpos;
+    if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
+       the_locking_inset=(UpdatableInset*)par->GetInset(actpos);
+       resetPos(bv);
+       inset_x = cx-top_x;
+       inset_y = cy;
+       inset_pos = actpos;
+       the_locking_inset->Edit(bv, the_locking_inset->
+                               width(bv->getPainter(),GetFont(par,actpos)),
+                               0, 0);
+    } else {
+       resetPos(bv);
+    }
+    return true;
+}
+
+
+bool InsetText::moveUp(BufferView * bv, bool activate_inset)
+{
+    if (!actrow)
+       return false;
+    cy = rows[actrow-1].baseline - top_baseline;
+    setPos(bv, cx-top_x, cy, activate_inset);
+    return true;
+}
+
+
+bool InsetText::moveDown(BufferView * bv, bool activate_inset)
+{
+    if (actrow >= int(rows.size()-2))
+       return false;
+    cy = rows[actrow+1].baseline - top_baseline;
+    setPos(bv, cx-top_x, cy, activate_inset);
+    return true;
+}
+
+
+void InsetText::resetPos(BufferView * bv)
+{
+    int
+       i,
+        old_pos = actpos;
+
+    cy = top_baseline;
+    actrow = 0;
+    for(i=0; rows[i].pos <= actpos; ++i) {
+       cy = rows[i].baseline;
+       actrow = i;
+    }
+    cy -= top_baseline;
+    setPos(bv, 0, cy, false);
+    cx = top_x;
+    while(actpos < old_pos) {
+       cx += SingleWidth(bv, par,actpos);
+       ++actpos;
+    }
+}
+
+
+bool InsetText::Delete()
+{
+    /* some insets are undeletable here */
+    if (par->GetChar(actpos)==LyXParagraph::META_INSET) {
+        /* force complete redo when erasing display insets */ 
+        /* this is a cruel mathod but save..... Matthias */ 
+        if (par->GetInset(actpos)->Deletable() &&
+            par->GetInset(actpos)->display()) {
+            par->Erase(actpos);
+            return true;
+        }
+        return false;
+    }
+    par->Erase(actpos);
+    return true;
+}
+
+
+bool InsetText::InsertInset(BufferView * bv, Inset * inset)
+{
+    par->InsertChar(actpos, LyXParagraph::META_INSET);
+    par->InsertInset(actpos, inset);
+    computeTextRows(bv);
+    bv->updateInset(this, true);
+    the_locking_inset = (UpdatableInset*)inset;
+    inset_x = cx-top_x;
+    inset_y = cy;
+    inset_pos = actpos;
+    inset->Edit(bv, 0, 0, 0);
+    return true;
+}
+
+
+UpdatableInset * InsetText::GetLockingInset()
+{
+    return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
+}
+
+
+void  InsetText::SetFont(BufferView * bv, LyXFont const & font,bool toggleall)
+{
+    // if there is no selection just set the current_font
+    if (!hasSelection()) {
+       // Determine basis font
+       LyXFont layoutfont;
+       if (actpos < BeginningOfMainBody(par))
+           layoutfont = GetFont(par, -2);
+       else
+           layoutfont = GetFont(par, -1);
+       
+       // Update current font
+       real_current_font.update(font, toggleall);
+       
+       // Reduce to implicit settings
+       current_font = real_current_font;
+       current_font.reduce(layoutfont);
+       // And resolve it completely
+       real_current_font.realize(layoutfont);
+       return;
+    }
+    int
+       s_start, s_end;
+
+    if (selection_start > selection_end) {
+       s_start = selection_end;
+       s_end = selection_start;
+    } else {
+       s_start = selection_start;
+       s_end = selection_end;
+    }
+    LyXFont
+       newfont;
+    while(s_start < s_end) {
+       newfont = GetFont(par,s_start);
+       newfont.update(font, toggleall);
+       SetCharFont(s_start, newfont);
+       ++s_start;
+    }
+    computeTextRows(bv);
+    bv->updateInset(this, true);
+}
+
+
+void InsetText::SetCharFont(int pos, LyXFont font)
+{
+    /* let the insets convert their font */ 
+    if (par->GetChar(pos) == LyXParagraph::META_INSET) {
+       if (par->GetInset(pos))
+           font = par->GetInset(pos)->ConvertFont(font);
+    }
+    LyXLayout layout =
+           textclasslist.Style(buffer->params.textclass,par->GetLayout());
+
+    // Get concrete layout font to reduce against
+    LyXFont layoutfont;
+
+    if (pos < BeginningOfMainBody(par))
+       layoutfont = layout.labelfont;
+    else
+       layoutfont = layout.font;
+
+
+    layoutfont.realize((textclasslist.TextClass(buffer->params.textclass).
+                      defaultfont()));
+
+    // Now, reduce font against full layout font
+    font.reduce(layoutfont);
+
+    par->SetFont(pos, font);
+}
+
+
+void InsetText::computeTextRows(BufferView * bv)
+{
+    int
+       p,
+       nwp = 0,
+       asc = 0,
+       desc = 0,
+       oasc = 0,
+       odesc = 0,
+       owidth = 0,
+       width,
+       wordAscent,
+       wordDescent;
+    row_struct
+       row;
+
+    if (rows.size())
+       rows.erase(rows.begin(),rows.end());
+    width = wordAscent = wordDescent = 0;
+    insetWidth = maxAscent = maxDescent = 0;
+    row.asc      = 0;
+    row.desc     = 0;
+    row.pos      = 0;
+    row.baseline = 0;
+    rows.push_back(row);
+    if (maxWidth < 0) {
+       for(p=0; p < par->Last(); ++p) {
+           insetWidth += SingleWidth(bv, par, p);
+           SingleHeight(bv, par, p, asc, desc);
+           if (asc > maxAscent)
+               maxAscent = asc;
+           if (desc > maxDescent)
+               maxDescent = desc;
+       }
+       rows[0].asc = maxAscent;
+       rows[0].desc = maxDescent;
+       // alocate a dummy row for the endpos
+       row.pos = par->Last();
+       rows.push_back(row);
+       return;
+    }
+    bool
+       is_first_word_in_row = true;
+
+    int
+       cw,
+       lastWordWidth=0;
+
+    for(p = 0; p < par->Last(); ++p) {
+       cw = SingleWidth(bv, par, p);
+       width += cw;
+       lastWordWidth += cw;
+       SingleHeight(bv, par, p, asc, desc);
+       if (asc > wordAscent)
+           wordAscent = asc;
+       if (desc > wordDescent)
+           wordDescent = desc;
+       Inset const * inset = 0;
+       if (((p + 1) < par->Last()) &&
+           (par->GetChar(p+1)==LyXParagraph::META_INSET))
+           inset = par->GetInset(p+1);
+       if (inset && inset->display()) {
+           if (!is_first_word_in_row && (width >= maxWidth)) {
+               // we have to split also the row above
+               rows[rows.size()-1].asc = oasc;
+               rows[rows.size()-1].desc = odesc;
+               row.pos = nwp;
+               rows.push_back(row);
+               oasc = wordAscent;
+               odesc = wordDescent;
+               if (insetWidth < owidth)
+                   insetWidth = owidth;
+               width = lastWordWidth;
+               lastWordWidth = 0;
+           } else {
+               if (oasc < wordAscent)
+                   oasc = wordAscent;
+               if (odesc < wordDescent)
+                   odesc = wordDescent;
+           }
+           rows[rows.size() - 1].asc = oasc;
+           rows[rows.size() - 1].desc = odesc;
+           row.pos = ++p;
+           rows.push_back(row);
+           SingleHeight(bv, par, p, asc, desc);
+           rows[rows.size() - 1].asc = asc;
+           rows[rows.size() - 1].desc = desc;
+           row.pos = nwp = p + 1;
+           rows.push_back(row);
+           oasc = odesc = width = lastWordWidth = 0;
+           is_first_word_in_row = true;
+           wordAscent = wordDescent = 0;
+           continue;
+       } else if (par->IsSeparator(p)) {
+           if (width >= maxWidth) {
+               if (is_first_word_in_row) {
+                   rows[rows.size()-1].asc = wordAscent;
+                   rows[rows.size()-1].desc = wordDescent;
+                   row.pos = p+1;
+                   rows.push_back(row);
+                   oasc = odesc = width = 0;
+               } else {
+                   rows[rows.size()-1].asc = oasc;
+                   rows[rows.size()-1].desc = odesc;
+                   row.pos = nwp;
+                   rows.push_back(row);
+                   oasc = wordAscent;
+                   odesc = wordDescent;
+                   if (insetWidth < owidth)
+                       insetWidth = owidth;
+                   width = lastWordWidth;
+               }
+               wordAscent = wordDescent = lastWordWidth = 0;
+               nwp = p+1;
+               continue;
+           }
+           owidth = width;
+           if (oasc < wordAscent)
+               oasc = wordAscent;
+           if (odesc < wordDescent)
+               odesc = wordDescent;
+           wordAscent = wordDescent = lastWordWidth = 0;
+           nwp = p+1;
+           is_first_word_in_row = false;
+       }
+    }
+    // if we have some data in the paragraph we have ascent/descent
+    if (p) {
+       if (width >= maxWidth) {
+           // assign upper row
+           rows[rows.size()-1].asc = oasc;
+           rows[rows.size()-1].desc = odesc;
+           // assign and allocate lower row
+           row.pos = nwp;
+           rows.push_back(row);
+           rows[rows.size()-1].asc = wordAscent;
+           rows[rows.size()-1].desc = wordDescent;
+           if (insetWidth < owidth)
+               insetWidth = owidth;
+           width -= owidth;
+           if (insetWidth < width)
+               insetWidth = width;
+       } else {
+           // assign last row data
+           if (oasc < wordAscent)
+               oasc = wordAscent;
+           if (odesc < wordDescent)
+               odesc = wordDescent;
+           rows[rows.size()-1].asc = oasc;
+           rows[rows.size()-1].desc = odesc;
+       }
+    }
+    // alocate a dummy row for the endpos
+    row.pos = par->Last();
+    rows.push_back(row);
+    // calculate maxAscent/Descent
+    maxAscent = rows[0].asc;
+    maxDescent = rows[0].desc;
+    for (unsigned int i=1; i<rows.size()-1; ++i) {
+       maxDescent += rows[i].asc + rows[i].desc + interline_space;
+    }
+    if (the_locking_inset) {
+       computeBaselines(top_baseline);
+       actpos = inset_pos;
+       resetPos(bv);
+       inset_x = cx-top_x;
+       inset_y = cy;
+    }
+}
+
+void InsetText::computeBaselines(int baseline) const
+{
+    rows[0].baseline = baseline;
+    for (unsigned int i=1; i<rows.size()-1; i++) {
+       rows[i].baseline = rows[i-1].baseline + rows[i-1].desc + 
+           rows[i].asc + interline_space;
+    }
+}
+
+void InsetText::init(BufferView * bv)
+{
+//    if (init_inset)
+    {
+       computeTextRows(bv);
+       init_inset = false;
+    }
+}
diff --git a/src/insets/insettext.h b/src/insets/insettext.h
new file mode 100644 (file)
index 0000000..b7adc79
--- /dev/null
@@ -0,0 +1,242 @@
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ * 
+ *           LyX, The Document Processor
+ *
+ *           Copyright (C) 1998 The LyX Team.
+ *
+ *======================================================
+ */
+// The pristine updatable inset: Text
+
+
+#ifndef INSETTEXT_H
+#define INSETTEXT_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "lyxinset.h"
+#include "lyxparagraph.h"
+#include "LString.h"
+#include "buffer.h"
+
+class Painter;
+class BufferView;
+
+/** A text inset is like a TeX box
+  
+  To write full text (including styles and other insets) in a given
+  space. 
+*/
+class InsetText : public UpdatableInset {
+public:
+       ///
+       enum { TEXT_TO_INSET_OFFSET = 1 };
+    ///
+    InsetText(Buffer *);
+    ///
+    InsetText(InsetText const &, Buffer *);
+    ///
+    ~InsetText();
+    ///
+    InsetText * Clone() const;
+    ///
+    void Read(LyXLex &);
+    ///
+    void Write(ostream &) const;
+    ///
+    int ascent(Painter &, LyXFont const &) const;
+    ///
+    int descent(Painter &, LyXFont const &) const;
+    ///
+    int width(Painter &, LyXFont const & f) const;
+    ///
+    int getMaxWidth(UpdatableInset *) const;
+    ///
+    void draw(Painter & pain, const LyXFont &, int , float &) const;
+    ///
+    const char * EditMessage() const;
+    ///
+    void Edit(BufferView *, int, int, unsigned int);
+    ///
+    void InsetUnlock(BufferView *);
+    ///
+    bool UnlockInsetInInset(BufferView *, Inset *, bool lr=false);
+    ///
+    //void UpdateLocal(bool flag=true);
+    ///
+    bool UpdateInsetInInset(BufferView *, Inset *);
+    ///
+    void InsetButtonRelease(BufferView *, int, int, int);
+    ///
+    void InsetButtonPress(BufferView *, int, int, int);
+    ///
+    void InsetMotionNotify(BufferView *, int, int, int);
+    ///
+    void InsetKeyPress(XKeyEvent *);
+    ///
+    UpdatableInset::RESULT LocalDispatch(BufferView *, int, string);
+    ///
+    int Latex(ostream &, signed char) const;
+    ///
+    int Latex(string &, signed char) const;
+    ///
+    int Linuxdoc(class string &) const { return true; }
+    ///
+    int DocBook(class string &) const { return true; }
+    ///
+    void Validate(LaTeXFeatures & features) const;
+    ///
+    Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
+    ///
+    void GetCursorPos(int & x, int & y);
+    ///
+    int InsetInInsetY();
+    ///
+    void ToggleInsetCursor(BufferView *);
+    ///
+    bool InsertInset(BufferView *, Inset *);
+    ///
+    UpdatableInset * GetLockingInset();
+    ///
+    void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
+    ///
+    void init(BufferView *);
+
+    LyXParagraph * par;
+
+protected:
+    ///
+    void WriteParagraphData(ostream &) const;
+    ///
+    void resetPos(BufferView *);
+    ///
+    void drawSelection(Painter & pain, int pos, int baseline, float x);
+    ///
+    void SingleHeight(BufferView *, LyXParagraph * par,int pos,
+                     int & asc, int & desc);
+    ///
+    int SingleWidth(BufferView * bv, LyXParagraph * par, int pos);
+    ///
+    LyXFont GetFont(LyXParagraph * par, int pos) const;
+    ///
+    Buffer * buffer;
+    ///
+    LyXFont current_font;
+       ///
+        LyXFont real_current_font;
+       ///
+       int maxWidth;
+       ///
+        int maxAscent;
+       ///
+       int maxDescent;
+       ///
+       int insetWidth;
+
+private:
+    ///
+    void drawRowSelection(Painter &, int startpos, int endpos, int row,
+                         int baseline, float x) const;
+    ///
+    void drawRowText(Painter &, int startpos, int endpos, int baseline,
+                     float x) const;
+    ///
+    void computeTextRows(BufferView *);
+    ///
+    void computeBaselines(int) const;
+    ///
+    int BeginningOfMainBody(LyXParagraph * par) const;
+    ///
+    void ShowInsetCursor(BufferView *);
+    ///
+    void HideInsetCursor(BufferView *);
+    ///
+    void setPos(BufferView *, int x, int y, bool activate_inset=true);
+    ///
+    bool moveRight(BufferView *, bool activate_inset = true);
+    bool moveLeft(BufferView *, bool activate_inset = true);
+    bool moveUp(BufferView *, bool activate_inset = true);
+    bool moveDown(BufferView *, bool activate_inset = true);
+    bool Delete();
+    ///
+    bool hasSelection() const {return (selection_start != selection_end);}
+    ///
+    void SetCharFont(int pos, LyXFont font);
+    ///
+    string getText(int);
+       
+    /* Private structures and variables */
+    ///
+    int inset_pos;
+    ///
+    int inset_x;
+    ///
+    int inset_y;
+    ///
+    int interline_space;
+    ///
+    int selection_start;
+    ///
+    int selection_end;
+    ///
+    int old_x;
+    ///
+    int cx;
+    ///
+    int cy;
+    ///
+    int actpos;
+    ///
+    int actrow;
+    ///
+    bool no_selection;
+    ///
+    bool init_inset;
+    ///
+    UpdatableInset * the_locking_inset;
+    ///
+    struct row_struct {
+       ///
+       int asc;
+       ///
+       int desc;
+       ///
+       int pos;
+       ///
+       int baseline;
+    };
+    ///
+    typedef vector<row_struct> RowList;
+    ///
+    mutable RowList rows;
+    InsetText & operator = (InsetText const & it) {
+       par = it.par;
+       buffer = it.buffer; // suspect
+       current_font = it.current_font;
+       real_current_font = it.real_current_font;
+       maxWidth = it.maxWidth;
+       maxAscent = it.maxAscent;
+       maxDescent = it.maxDescent;
+       insetWidth = it.insetWidth;
+       inset_pos = it.inset_pos;
+       inset_x = it.inset_x;
+       inset_y = it.inset_y;
+       interline_space = it.interline_space;
+       selection_start = it.selection_start;
+       selection_end = it.selection_end;
+       old_x = it.old_x;
+       cx = it.cx;
+       cy = it.cy;
+       actpos = it.actpos;
+       actrow = it.actrow;
+       no_selection = it.no_selection;
+       the_locking_inset = it.the_locking_inset; // suspect
+       rows = it.rows;
+       return * this;
+    }
+};
+#endif
index 9aca608ac78c201509451311df3ba4524383dbaa..a4f89da74c1d7a18d6ae321a20c8d7ab85e56f1f 100644 (file)
@@ -10,8 +10,9 @@
 #include "commandtags.h"
 #include "lyxfunc.h"
 #include "LyXView.h"
+#include "BufferView.h"
 
-void InsetTOC::Edit(BufferView * bv, int, int)
+void InsetTOC::Edit(BufferView * bv, int, int, unsigned int)
 {
        bv->owner()->getLyXFunc()->Dispatch(LFUN_TOCVIEW);
 }
index f894d997f51129187d6632a32f40c7f1f8b68e6e..dbe4d446684a7a330a95dece06e689c23b457f23 100644 (file)
@@ -19,7 +19,7 @@
 #include "insetcommand.h"
 #include "gettext.h"
 
-// Created by Lgb 970527
+class Buffer;
 
 /** Used to insert table of contents
  */
@@ -34,7 +34,7 @@ public:
        ///
        string getScreenLabel() const { return _("Table of Contents"); }
        /// On edit, we open the TOC pop-up
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView * bv, int, int, unsigned int);
         ///
        unsigned char Editable() const {
                return 1;
index 9367c6f0c64d39c46098ab4a76ec300d3fc3c6b4..af469908377cd70c9deaff0e6f2ce20d089569c6 100644 (file)
@@ -109,7 +109,7 @@ extern "C" void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data)
 }
 
 
-void InsetUrl::Edit(BufferView * bv, int, int)
+void InsetUrl::Edit(BufferView * bv, int, int, unsigned int)
 {
        static int ow = -1, oh;
 
index a16c00663476531e73dd864074e9e4ea5950c84f..c60de849fdec6c72fd01da338c5126dfe0af2cf7 100644 (file)
@@ -52,13 +52,13 @@ public:
        ///
        void Validate(LaTeXFeatures &) const;
        ///
-       void Edit(BufferView *, int, int);
+       void Edit(BufferView *, int, int, unsigned int);
        ///
        unsigned char Editable() const {
                return 1;
        }
        ///
-       char const * EditMessage() const {return _("Opened Url");}
+       const char * EditMessage() const {return _("Opened Url");}
         ///
        bool display() const { return false; }
        ///
index ccf22b4fa7b4c1351e166ce0092f54b20db00484..b34fa39dfbda5e7715a5ccad033b279257fed011 100644 (file)
@@ -76,7 +76,9 @@ public:
                ///
                PARENT_CODE,
                ///
-               BIBTEX_CODE
+               BIBTEX_CODE,
+               ///
+               TEXT_CODE
        };
 
        ///
@@ -93,9 +95,9 @@ public:
        ///
        virtual LyXFont ConvertFont(LyXFont font);
        /// what appears in the minibuffer when opening
-       virtual char const * EditMessage() const {return _("Opened inset");}
+       virtual const char * EditMessage() const {return _("Opened inset");}
        ///
-       virtual void Edit(BufferView *, int, int);
+       virtual void Edit(BufferView *, int x, int y, unsigned int button);
        ///
        virtual unsigned char Editable() const;
        ///
@@ -142,6 +144,8 @@ public:
        virtual int GetNumberOfLabels() const {
                return 0;
        }
+       ///
+       virtual void init(BufferView *) {}
 
 };
 
@@ -174,6 +178,28 @@ public:
   */
 class UpdatableInset: public Inset {
 public:
+       /** Dispatch result codes
+           Now that nested updatable insets are allowed, the local dispatch
+           becomes a bit complex, just two possible results (boolean)
+           are not enough. 
+        
+           DISPATCHED   = the inset catched the action
+           FINISHED     = the inset must be unlocked as a result
+                          of the action
+           UNDISPATCHED = the action was not catched, it should be
+                          dispatched by lower level insets
+       */ 
+       enum RESULT {
+           UNDISPATCHED=0,
+           DISPATCHED,
+           FINISHED
+       };
+    
+       /// To convert old binary dispatch results
+       RESULT DISPATCH_RESULT(bool b) {
+               return (b) ? DISPATCHED: FINISHED;
+       }
+
        ///
        //virtual ~UpdatableInset() {}
        ///
@@ -188,20 +214,48 @@ public:
        ///
        virtual void InsetButtonRelease(BufferView *,
                                        int x, int y, int button);
-       
        ///
        virtual void InsetKeyPress(XKeyEvent * ev);
        ///
        virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
        ///
        virtual void InsetUnlock(BufferView *);
-   
+       ///
+       virtual void Edit(BufferView *, int x, int y, unsigned int button);
+       ///
+       virtual void draw(Painter &, LyXFont const &,
+                         int baseline, float & x) const;
+       ///
+       virtual void SetFont(LyXFont const &, bool toggleall = false);
+       ///
+       virtual bool InsertInset(Inset *) { return false; }
+       ///
+       virtual UpdatableInset * GetLockingInset() { return this; }
+       ///
+       virtual int InsetInInsetY() { return 0; }
+       ///
+       virtual bool UpdateInsetInInset(BufferView *, Inset *) {return false;}
+       ///
+       virtual bool UnlockInsetInInset(BufferView *,Inset *,bool /*lr*/=false)
+               {return false;}
        ///  An updatable inset could handle lyx editing commands
-       virtual bool LocalDispatch(BufferView *, int, char const *) { return false; };
-       //
-       bool isCursorVisible() const { return cursor_visible; }
+       virtual RESULT LocalDispatch(BufferView *, int, string);
+       ///
+       virtual bool isCursorVisible() const { return cursor_visible; }
+       ///
+       virtual int getMaxWidth(UpdatableInset *) const { return -1; }
+
 protected:
        ///
+       // virtual void UpdateLocal(bool flag=true);
+       ///
+       mutable int top_x;
+       mutable int top_baseline;
        mutable bool cursor_visible;
+
+private:
+       ///
+       int mx_scx;
+       mutable int scx;
 };
 #endif
index be514099666c8f901199bd56ae3aeb50d5639d32..2477c0d0d59a80e0b435cd2d8d5f2eb40e725b50 100644 (file)
@@ -2134,7 +2134,10 @@ void ToggleAndShow(BufferView * bv, LyXFont const & font)
        if (bv->available()) { 
                bv->hideCursor();
                bv->update(-2);
-               bv->text->ToggleFree(font, toggleall);
+               if (bv->the_locking_inset)
+                       bv->the_locking_inset->SetFont(font, toggleall);
+               else
+                       bv->text->ToggleFree(font, toggleall);
                bv->update(1);
        }
 }
@@ -3143,7 +3146,7 @@ extern "C" void FigureApplyCB(FL_OBJECT *, long)
                InsetFig * new_inset = new InsetFig(100, 20, buffer);
                current_view->insertInset(new_inset);
                current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
-               new_inset->Edit(current_view, 0, 0);
+               new_inset->Edit(current_view, 0, 0, 0);
                return;
        }
        
@@ -3192,7 +3195,7 @@ extern "C" void FigureApplyCB(FL_OBJECT *, long)
       
        Inset * new_inset = new InsetFig(100, 100, buffer);
        current_view->insertInset(new_inset);
-       new_inset->Edit(current_view, 0, 0);
+       new_inset->Edit(current_view, 0, 0, 0);
        current_view->update(0);
        current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
        current_view->text->UnFreezeUndo();
index 3500d05d4929f9594f7d9373ef58aef6df75e986..2f84e8359376d1c68a576ccfebb906b13cd457cd 100644 (file)
@@ -41,6 +41,8 @@
 #include "insets/insetindex.h"
 #include "insets/insetinclude.h"
 #include "insets/insetbib.h"
+#include "insets/insettext.h"
+#include "insets/insetert.h"
 #include "mathed/formulamacro.h"
 #include "toolbar.h"
 #include "spellchecker.h" // RVDK_PATCH_5
@@ -524,44 +526,55 @@ string LyXFunc::Dispatch(int ac,
                                inset->GetCursorPos(slx, sly);
                                owner->view()->unlockInset(inset);
                                owner->view()->menuUndo();
-                               inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
-                               if (inset) 
-                                       inset->Edit(owner->view(), slx, sly);
+                               inset = static_cast<UpdatableInset*>(
+                                       owner->view()->text->cursor.par->
+                                       GetInset(owner->view()->text->
+                                                cursor.pos));
+                               if (inset)
+                                       inset->Edit(owner->view(),slx,sly,0);
                                return string();
-                       } else 
-                               if (action == LFUN_REDO) {
-                                       int slx, sly;
-                                       UpdatableInset * inset = owner->view()->the_locking_inset;
-                                       inset->GetCursorPos(slx, sly);
-                                       owner->view()->unlockInset(inset);
-                                       owner->view()->menuRedo();
-                                       inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
-                                       if (inset)
-                                               inset->Edit(owner->view(),
-                                                           slx, sly);
+                       } else if (action == LFUN_REDO) {
+                               int slx, sly;
+                               UpdatableInset * inset = owner->view()->
+                                       the_locking_inset;
+                               inset->GetCursorPos(slx, sly);
+                               owner->view()->unlockInset(inset);
+                               owner->view()->menuRedo();
+                               inset = static_cast<UpdatableInset*>(
+                                       owner->view()->text->cursor.par->
+                                       GetInset(owner->view()->text->
+                                                cursor.pos));
+                               if (inset)
+                                       inset->Edit(owner->view(),slx,sly,0); 
+                               return string();
+                       } else if (owner->view()->the_locking_inset->
+                                  LocalDispatch(owner->view(),action,
+                                                argument) ==
+                                  UpdatableInset::DISPATCHED)
+                               return string();
+                       else {
+                               setMessage(N_("Text mode"));
+                               LyXDirection direction = owner->view()->text->
+                                       cursor.par->getParDirection();
+                               if ((action == -1) ||
+                                   ((action == LFUN_RIGHT) &&
+                                    (direction == LYX_DIR_LEFT_TO_RIGHT))) {
+                                       owner->view()->text->CursorRight();
+                                       moveCursorUpdate(false);
+                                       owner->getMiniBuffer()->
+                                               Set(CurrentState());
+                               }
+                               if ((action == LFUN_LEFT) &&
+                                   (direction == LYX_DIR_RIGHT_TO_LEFT)) {
+                                       owner->view()->text->CursorRight();
+                                       moveCursorUpdate(false);
+                                       owner->getMiniBuffer()->
+                                               Set(CurrentState());
+                               }
+                               if ((action == LFUN_LEFT) ||
+                                   (action == LFUN_RIGHT))
                                        return string();
-                               } else
-                                       if (owner->view()->the_locking_inset->LocalDispatch(owner->view(), action, argument.c_str()))
-                                               return string();
-                                       else {
-                                               setMessage(N_("Text mode"));
-                                               LyXDirection direction = owner->view()->text->cursor.par->getParDirection();
-                                               if ( action == -1 ||
-                                                    (action == LFUN_RIGHT
-                                                     && direction == LYX_DIR_LEFT_TO_RIGHT)) {
-                                                       owner->view()->text->CursorRight();
-                                                       moveCursorUpdate(false);
-                                                       owner->getMiniBuffer()->Set(CurrentState());
-                                               }
-                                               if ( action == LFUN_LEFT 
-                                                    && direction == LYX_DIR_RIGHT_TO_LEFT) {
-                                                       owner->view()->text->CursorRight();
-                                                       moveCursorUpdate(false);
-                                                       owner->getMiniBuffer()->Set(CurrentState());
-                                               }
-                                               if (action == LFUN_LEFT || action == LFUN_RIGHT)
-                                                       return string();
-                                       }
+                       }
                }
        }
 
@@ -1288,7 +1301,7 @@ string LyXFunc::Dispatch(int ac,
                    && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
                        Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
                        setMessage(tmpinset->EditMessage());
-                       tmpinset->Edit(owner->view(), 0, 0);
+                       tmpinset->Edit(owner->view(), 0, 0, 0);
                        break;
                }
                if (direction == LYX_DIR_LEFT_TO_RIGHT)
@@ -1319,7 +1332,8 @@ string LyXFunc::Dispatch(int ac,
                        tmpinset->Edit(owner->view(),
                                       tmpinset->width(owner->view()->painter(),
                                                       txt->GetFont(txt->cursor.par,
-                                                                   txt->cursor.pos)), 0);
+                                                                   txt->cursor.pos)),
+                                      0, 0);
                        break;
                }
                if  (direction == LYX_DIR_RIGHT_TO_LEFT)
@@ -1876,7 +1890,21 @@ string LyXFunc::Dispatch(int ac,
                else
                        new_inset = new InsetUrl("url", "", "");
                owner->view()->insertInset(new_inset);
-               new_inset->Edit(owner->view(), 0, 0);
+               new_inset->Edit(owner->view(), 0, 0, 0);
+       }
+       break;
+       case LFUN_INSET_TEXT:
+       {
+               InsetText * new_inset = new InsetText(owner->buffer());
+               owner->view()->insertInset(new_inset);
+               new_inset->Edit(owner->view(), 0, 0, 0);
+       }
+       break;
+       case LFUN_INSET_ERT:
+       {
+               InsetERT * new_inset = new InsetERT(owner->buffer());
+               owner->view()->insertInset(new_inset);
+               new_inset->Edit(owner->view(), 0, 0, 0);
        }
        break;
 
@@ -2169,7 +2197,7 @@ string LyXFunc::Dispatch(int ac,
                        owner->view()->insertInset(new_inset);
                } else {
                        owner->view()->insertInset(new_inset);
-                       new_inset->Edit(owner->view(), 0, 0);
+                       new_inset->Edit(owner->view(), 0, 0, 0);
                }
        }
        break;
@@ -2190,7 +2218,7 @@ string LyXFunc::Dispatch(int ac,
                
                owner->view()->insertInset(new_inset);
                if (lsarg.empty()) {
-                       new_inset->Edit(owner->view(), 0, 0);
+                       new_inset->Edit(owner->view(), 0, 0, 0);
                }
        }
        break;
@@ -2256,7 +2284,7 @@ string LyXFunc::Dispatch(int ac,
 
                        //don't edit it if the call was to INSERT_LAST
                        if(action != LFUN_INDEX_INSERT_LAST) {
-                               new_inset->Edit(owner->view(), 0, 0);
+                               new_inset->Edit(owner->view(), 0, 0, 0);
                        } else {
                                //it looks blank on the screen unless
                                //we do  something.  put it here.
@@ -2294,7 +2322,7 @@ string LyXFunc::Dispatch(int ac,
                Inset * new_inset = new InsetInclude(argument,
                                                     owner->buffer());
                owner->view()->insertInset(new_inset, "Standard", true);
-               new_inset->Edit(owner->view(), 0, 0);
+               new_inset->Edit(owner->view(), 0, 0, 0);
        }
        break;
 
index 5dcdc812b89e771a78c0d83b2fafdd137d155a47..1c319bddc8126fb5232678da4a9ead813afb34c6 100644 (file)
@@ -154,6 +154,8 @@ public:
        LyXParagraph * TeXOnePar(string & file, TexRow & texrow,
                                string & foot, TexRow & foot_texrow,
                                int & foot_count);
+       ///
+       bool SimpleTeXOnePar(string & file, TexRow & texrow);
 
        ///
        LyXParagraph * TeXEnvironment(string & file, TexRow & texrow,
@@ -522,8 +524,6 @@ private:
                                   int & foot_count,
                                   LyXDirection par_direction);
        ///
-       bool SimpleTeXOnePar(string & file, TexRow & texrow);
-       ///
        bool SimpleTeXOneTablePar(string & file, TexRow & texrow);
        ///
        bool TeXContTableRows(string & file, size_type i,
index 75a32c395ef31914a014991b1654615096610ba4..37fd30db028383cf37724632c75bfe50b04110f0 100644 (file)
@@ -344,11 +344,11 @@ public:
                          LyXAlignment align, 
                          string labelwidthstring,
                          bool noindent);
-        void SetParagraphExtraOpt(int type,
-                                  char const * width,
-                                  char const * widthp,
-                                  int alignment, bool hfill,
-                                  bool start_minipage);
+       void SetParagraphExtraOpt(int type,
+                                 char const * width,
+                                 char const * widthp,
+                                 int alignment, bool hfill,
+                                 bool start_minipage);
 
        /* these things are for search and replace */
 
@@ -468,12 +468,12 @@ public:
        void CursorLeftIntern() const;
        ///
        void CursorRightIntern() const;
-        ///
-        void RemoveTableRow(LyXCursor * cursor) const;
-        ///
-        bool IsEmptyTableCell() const;
-        ///
-        void toggleAppendix();
+       ///
+       void RemoveTableRow(LyXCursor * cursor) const;
+       ///
+       bool IsEmptyTableCell() const;
+       ///
+       void toggleAppendix();
        ///
        unsigned short paperWidth() const { return paperwidth; }
 private:
index da0aa2e6529abb717015bc5d78265298a280f7e3..0700701c6a7b45cf04ff591050b78f08decfaada 100644 (file)
@@ -452,15 +452,15 @@ void InsetFormula::draw(Painter & pain, LyXFont const &,
 }
 
 
-void InsetFormula::Edit(BufferView * bv, int x, int y)
+void InsetFormula::Edit(BufferView * bv, int x, int y, unsigned int)
 {
-   mathcursor = new MathedCursor(par);
-   bv->lockInset(this);
-   par->Metrics();
-   bv->updateInset(this, false);
-   x += par->xo; 
-   y += par->yo; 
-   mathcursor->SetPos(x, y);
+    mathcursor = new MathedCursor(par);
+    bv->lockInset(this);
+    par->Metrics();
+    bv->updateInset(this, false);
+    x += par->xo; 
+    y += par->yo; 
+    mathcursor->SetPos(x, y);
     sel_x = sel_y = 0;
     sel_flag = false;
 }
@@ -712,16 +712,17 @@ bool InsetFormula::SetNumber(bool numbf)
 }
 
 
-bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
+UpdatableInset::RESULT InsetFormula::LocalDispatch(BufferView * bv,
+                                                  int action, string arg)
 {
 //   extern char *dispatch_result;
     MathedTextCodes varcode = LM_TC_MIN;       
-   bool was_macro = mathcursor->InMacroMode();
-   bool sel = false;
-   bool space_on = false;
-   bool was_selection = mathcursor->Selection();
-   bool result = true;
-   static MathSpaceInset * sp= 0;
+    bool was_macro = mathcursor->InMacroMode();
+    bool sel = false;
+    bool space_on = false;
+    bool was_selection = mathcursor->Selection();
+    RESULT result = DISPATCHED;
+    static MathSpaceInset * sp= 0;
 
    HideInsetCursor(bv);
 
@@ -734,23 +735,23 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
     case LFUN_RIGHTSEL: sel = true;
     case LFUN_RIGHT:
       {
-        result = mathcursor->Right(sel);
+        result = DISPATCH_RESULT(mathcursor->Right(sel));
         break;
       }
     case LFUN_LEFTSEL: sel = true;     
     case LFUN_LEFT:
       {
-        result = mathcursor->Left(sel);
+        result = DISPATCH_RESULT(mathcursor->Left(sel));
         break;
       }
     case LFUN_UPSEL: sel = true;  
     case LFUN_UP:
-      result = mathcursor->Up(sel);
+      result = DISPATCH_RESULT(mathcursor->Up(sel));
       break;
        
     case LFUN_DOWNSEL: sel = true;  
     case LFUN_DOWN:
-      result = mathcursor->Down(sel);
+      result = DISPATCH_RESULT(mathcursor->Down(sel));
       break;
     case LFUN_HOME:
       mathcursor->Home();
@@ -802,7 +803,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
     case LFUN_SETXY:
       {
         int x, y, x1, y1;
-         sscanf(arg, "%d %d", &x, &y);
+         sscanf(arg.c_str(), "%d %d", &x, &y);
         par->GetXY(x1, y1);
         mathcursor->SetPos(x1+x, y1+y);
       }
@@ -918,8 +919,8 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
     }
  
     case LFUN_MATH_SIZE:
-       if (arg) {
-          latexkeys * l = in_word_set (arg, strlen(arg));
+       if (!arg.empty()) {
+          latexkeys * l = in_word_set (arg.c_str(), strlen(arg.c_str()));
           int sz = (l) ? l->id: -1;
           mathcursor->SetSize(sz);
           UpdateLocal(bv);
@@ -929,7 +930,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
     case LFUN_INSERT_MATH:
     {
        bv->lockedInsetStoreUndo(Undo::INSERT);
-       InsertSymbol(bv, arg);
+       InsertSymbol(bv, arg.c_str());
        break;
     }
     
@@ -939,7 +940,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
        int k, m, n;
        char s[80], arg2[80];
        // This is just so that too long args won't ooze out of s.
-       strncpy(arg2, arg, 80); arg2[79]= '\0';
+       strncpy(arg2, arg.c_str(), 80); arg2[79]= '\0';
        k = sscanf(arg2, "%d %d %s", &m, &n, s);
        s[79] = '\0';
        
@@ -967,8 +968,9 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
        latexkeys * l;
        string vdelim("(){}[]./|");
        
-       if (!arg) break;
-       strncpy(arg2, arg, 40); arg2[39]= '\0';
+       if (arg.empty())
+              break;
+       strncpy(arg2, arg.c_str(), 40); arg2[39]= '\0';
        int n = sscanf(arg2, "%s %s", lf, rg);
        lf[39] = '\0'; rg[39] = '\0';
 
@@ -1070,7 +1072,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
        break;
        
     default:
-      if ((action == -1  || action == LFUN_SELFINSERT) && arg)  {
+      if ((action == -1  || action == LFUN_SELFINSERT) && !arg.empty())  {
         unsigned char c = arg[0];
         bv->lockedInsetStoreUndo(Undo::INSERT);
         
@@ -1158,7 +1160,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
                 space_on = true;
              } else {
                  if (!mathcursor->Pop() && mathcursor->IsEnd()) 
-                   result = false;
+                   result = FINISHED;
              }
           } else
           if (c == '\'') {
@@ -1173,7 +1175,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
         UpdateLocal(bv);
       } else {
        // lyxerr << "Closed by action " << action << endl;
-       result =  false;
+       result =  FINISHED;
       }
    }
    if (was_macro != mathcursor->InMacroMode()
@@ -1184,7 +1186,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
    if (mathcursor->Selection() || was_selection)
        ToggleInsetSelection(bv);
     
-   if (result)
+   if (result == DISPATCHED)
       ShowInsetCursor(bv);
    else
       bv->unlockInset(this);
index 5a10386682946dce39781aa89796a925f107d4e2..06a5052751d343c7849b0e7bb49f0f12483ed3d3 100644 (file)
@@ -70,9 +70,9 @@ public:
        }
 
        /// what appears in the minibuffer when opening
-       char const * EditMessage() const {return _("Math editor mode");}
+       const char * EditMessage() const {return _("Math editor mode");}
        ///
-       void Edit(BufferView *, int x, int y);
+       void Edit(BufferView *, int x, int y, unsigned int button);
        ///
        bool display() const { return (disp_flag) ? true: false; }
        ///
@@ -99,7 +99,7 @@ public:
        void InsetUnlock(BufferView *);
    
        ///  To allow transparent use of math editing functions
-       virtual bool LocalDispatch(BufferView *, int, char const *);
+       virtual RESULT LocalDispatch(BufferView *, int, string);
     
        ///
        void InsertSymbol(BufferView *, char const *);
index b735a210546699c890c60be1c0c49c536e10a432..d887fea0cbbb8e08aca601becb523f8dd9c51162 100644 (file)
@@ -146,7 +146,7 @@ int InsetFormulaMacro::width(Painter & pain, LyXFont const & f) const
 
 
 void InsetFormulaMacro::draw(Painter & pain, LyXFont const & f,
-                            int baseline, float & x) const
+                            int baseline, float & x)
 {
        LyXFont font(f);
        tmacro->update();
@@ -173,11 +173,11 @@ void InsetFormulaMacro::draw(Painter & pain, LyXFont const & f,
 }
 
 
-void InsetFormulaMacro::Edit(BufferView * bv, int x, int y)
+void InsetFormulaMacro::Edit(BufferView * bv, int x, int y,unsigned int button)
 {
     opened = true;
     par = static_cast<MathParInset*>(tmacro->Clone());
-    InsetFormula::Edit(bv, x, y);
+    InsetFormula::Edit(bv, x, y, button);
 }
 
               
@@ -193,21 +193,21 @@ void InsetFormulaMacro::InsetUnlock(BufferView * bv)
 }
 
 
-bool InsetFormulaMacro::LocalDispatch(BufferView * bv,
-                                     int action, char const * arg)
+UpdatableInset::RESULT InsetFormulaMacro::LocalDispatch(BufferView * bv,
+                                                       int action, string arg)
 {
     if (action == LFUN_MATH_MACROARG) {
-       int i = atoi(arg) - 1;
+       int i = atoi(arg.c_str()) - 1;
        if (i >= 0 && i < tmacro->getNoArgs()) {
            mathcursor->Insert(tmacro->getMacroPar(i), LM_TC_INSET);
            InsetFormula::UpdateLocal(bv);
        }
        
-       return true;
+       return DISPATCHED;
     }
     tmacro->setEditMode(true);
     tmacro->Metrics();
-    bool result = InsetFormula::LocalDispatch(bv, action, arg);
+    RESULT result = InsetFormula::LocalDispatch(bv, action, arg);
     tmacro->setEditMode(false);
     
     return result;
index 511bcc68f7f6c48df0d97d0e02fd29b73e9f6db0..988c7481e121c962d439453057165793b88ce744 100644 (file)
@@ -42,7 +42,7 @@ public:
        ///
        int width(Painter &, LyXFont const &) const;
        ///
-       void draw(Painter &, LyXFont const &, int baseline, float & x) const;
+       void draw(Painter &, LyXFont const &, int baseline, float & x);
        ///
        void Read(LyXLex & lex);
         ///
@@ -59,16 +59,18 @@ public:
        Inset * Clone() const;
 
        /// what appears in the minibuffer when opening
-       char const * EditMessage() const {return _("Math macro editor mode");}
+       const char * EditMessage() const {return _("Math macro editor mode");}
        ///
-       void Edit(BufferView *, int x, int y);
+       void Edit(BufferView *, int x, int y, unsigned int button);
        ///
        void InsetUnlock(BufferView *);
        ///
-       bool LocalDispatch(BufferView *, int, char const *);
+       RESULT LocalDispatch(BufferView *, int, string);
+
 protected:
        ///
        //void UpdateLocal();
+
 private:
        ///
         bool opened;
index f1f28bac03667d1d8b9ff5c60f307c58fca9d7eb..3a308f49523073091b82d1358388ea2e70e0f0c0 100644 (file)
@@ -287,9 +287,9 @@ class MathedInset  {
 
     /// In a near future maybe we use a better fonts renderer than X
     void drawStr(Painter &, short, int, int, int, byte *, int);
-       ///
+    ///
     friend class MathedCursor;
-       ///
+    ///
     friend void mathed_init_fonts();
 };
 
index 85b08375433dfa14f853c5054ef02692a990be2e..f1afe0b833db6eb47f18206dd12b9b076441a05f 100644 (file)
@@ -371,7 +371,7 @@ void math_insert_symbol(char const * s)
         current_view->beforeChange();
         current_view->insertInset(new_inset);
 //      Update(1);//BUG
-        new_inset->Edit(current_view, 0, 0);
+        new_inset->Edit(current_view, 0, 0, 0);
         new_inset->InsertSymbol(current_view, s);
       } else
        if (current_view->the_locking_inset->LyxCode() == Inset::MATH_CODE)
index d21cc00f46bd8ef36fac9451df53a8e2b8e530d0..717b05c68156b5d7c2440cd0e7326d2d6459a44d 100644 (file)
@@ -370,9 +370,11 @@ void LyXText::draw(Row const * row,
                return;
        } else if (c == LyXParagraph::META_INSET) {
                Inset * tmpinset = row->par->GetInset(pos);
-               if (tmpinset) 
+               if (tmpinset) {
+                       tmpinset->init(owner_);
                        tmpinset->draw(owner_->painter(), font,
                                       offset + row->baseline, x);
+               }
                ++vpos;
                return;
        }
index d951b56c63a4b32992e8ed585d1764b7516125a2..d151ef37dec59e69ed7ddddf3f31a3ba8d4cf6a4 100644 (file)
@@ -348,7 +348,7 @@ void LyXText::ToggleFootnote()
 void LyXText::OpenStuff()
 {
        if (cursor.pos == 0 && cursor.par->bibkey){
-               cursor.par->bibkey->Edit(owner_, 0, 0);
+               cursor.par->bibkey->Edit(owner_, 0, 0, 0);
        }
        else if (cursor.pos < cursor.par->Last() 
                 && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
@@ -357,7 +357,7 @@ void LyXText::OpenStuff()
                        ->Set(cursor.par->GetInset(cursor.pos)->EditMessage());
                if (cursor.par->GetInset(cursor.pos)->Editable() != 2)
                        SetCursorParUndo();
-               cursor.par->GetInset(cursor.pos)->Edit(owner_, 0, 0);
+               cursor.par->GetInset(cursor.pos)->Edit(owner_, 0, 0, 0);
        } else {
                ToggleFootnote();
        }