Here's a rough and unready start on insetcode. Try it with "code-insert"

Issues :

o extra newline between pars. I suspect we need some handling in
  TeXOnePar but that sounds hacky

o we can trivially allow insets such as insetref OK I think

o footnote is more difficult due to the "%\n" string. Is that just there
  for niceness ? Note that LyX-Code has the same problem

o math is a lot more difficult. "^" and "$" are not processed specially

o tables don't work

o lyx2lyx stuff needed

o can't delete blank lines properly

o wherefor listings ...

Comments ? Suggestions ?

regards
john


Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.373
diff -u -p -r1.373 BufferView_pimpl.C
--- BufferView_pimpl.C  27 May 2003 17:28:57 -0000      1.373
+++ BufferView_pimpl.C  6 Jun 2003 04:21:37 -0000
@@ -674,6 +674,7 @@ void BufferView::Pimpl::switchKeyMap()
        if (!lyxrc.rtl_support)
                return;
 
+#warning InsetCode ?
        LyXText * text = bv_->getLyXText();
        if (text->real_current_font.isRightToLeft()
            && !(bv_->theLockingInset()
Index: LaTeXFeatures.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LaTeXFeatures.C,v
retrieving revision 1.82
diff -u -p -r1.82 LaTeXFeatures.C
--- LaTeXFeatures.C     23 May 2003 11:18:42 -0000      1.82
+++ LaTeXFeatures.C     6 Jun 2003 04:21:38 -0000
@@ -177,7 +177,8 @@ char const * simplefeatures[] = {
        "prettyref",
        "float",
        "wasy",
-       "dvipost"
+       "dvipost",
+       "alltt"
 };
 
 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
Index: LyXAction.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LyXAction.C,v
retrieving revision 1.170
diff -u -p -r1.170 LyXAction.C
--- LyXAction.C 2 Jun 2003 14:19:29 -0000       1.170
+++ LyXAction.C 6 Jun 2003 04:21:39 -0000
@@ -325,6 +325,7 @@ void LyXAction::init()
                { LFUN_INSET_SETTINGS, "inset-settings", ReadOnly },
                { LFUN_PARAGRAPH_APPLY, "paragraph-params-apply", Noop },
                { LFUN_PARAGRAPH_UPDATE, "", Noop },
+               { LFUN_INSET_CODE, "code-insert", Noop },
                { LFUN_NOACTION, "", Noop }
        };
 
Index: buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.478
diff -u -p -r1.478 buffer.C
--- buffer.C    5 Jun 2003 22:49:30 -0000       1.478
+++ buffer.C    6 Jun 2003 04:21:42 -0000
@@ -414,7 +414,7 @@ void Buffer::insertStringAsLines(Paragra
        for(string::const_iterator cit = str.begin();
            cit != str.end(); ++cit) {
                if (*cit == '\n') {
-                       if (autobreakrows && (!par->empty() || layout->keepempty)) {
+                       if (autobreakrows && (!par->empty() || par->allowEmpty())) {
                                breakParagraph(params, paragraphs, par, pos,
                                               layout->isEnvironment());
                                ++par;
@@ -425,12 +425,10 @@ void Buffer::insertStringAsLines(Paragra
                        }
                        // do not insert consecutive spaces if !free_spacing
                } else if ((*cit == ' ' || *cit == '\t') &&
-                          space_inserted && !layout->free_spacing &&
-                                  !par->isFreeSpacing())
-               {
+                          space_inserted && !par->isFreeSpacing()) {
                        continue;
                } else if (*cit == '\t') {
-                       if (!layout->free_spacing && !par->isFreeSpacing()) {
+                       if (!par->isFreeSpacing()) {
                                // tabs are like spaces here
                                par->insertChar(pos, ' ', font);
                                ++pos;
@@ -1522,7 +1520,7 @@ void Buffer::simpleLinuxDocOnePar(ostrea
                        bool ws;
                        string str;
                        boost::tie(ws, str) = sgml::escapeChar(c);
-                       if (ws && !style->free_spacing && !par->isFreeSpacing()) {
+                       if (ws && !par->isFreeSpacing()) {
                                // in freespacing mode, spaces are
                                // non-breaking characters
                                if (desc_on) {// if char is ' ' then...
@@ -1907,9 +1905,9 @@ void Buffer::simpleDocBookOnePar(ostream
 
                        if (style->pass_thru) {
                                os << c;
-                       } else if (style->free_spacing || par->isFreeSpacing() || c != 
' ') {
+                       } else if (par->isFreeSpacing() || c != ' ') {
                                        os << str;
-                       } else if (desc_on ==1) {
+                       } else if (desc_on == 1) {
                                ++char_line_count;
                                os << "\n</term><listitem><para>";
                                desc_on = 2;
Index: factory.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/factory.C,v
retrieving revision 1.33
diff -u -p -r1.33 factory.C
--- factory.C   4 Jun 2003 09:16:28 -0000       1.33
+++ factory.C   6 Jun 2003 04:21:43 -0000
@@ -25,6 +25,7 @@
 #include "insets/insetcite.h"
 #include "insets/insetenv.h"
 #include "insets/insetert.h"
+#include "insets/insetcode.h"
 #include "insets/insetexternal.h"
 #include "insets/insetfloat.h"
 #include "insets/insetfloatlist.h"
@@ -74,6 +75,9 @@ Inset * createInset(FuncRequest const & 
        case LFUN_INSET_ERT:
                return new InsetERT(params);
 
+       case LFUN_INSET_CODE:
+               return new InsetCode(params);
+
        case LFUN_INSET_FOOTNOTE:
                return new InsetFoot(params);
 
@@ -188,10 +192,17 @@ Inset * createInset(FuncRequest const & 
                        inset->setLoadingBuffer(bv->buffer(), false);
                        return inset;
 
+               } else if (name == "code") {
+                       InsetCode * inset = new InsetCode(params);
+                       InsetCode::FreeStatus s;
+                       InsetFreeMailer::string2params(cmd.argument, s);
+                       inset->status(bv, s);
+                       return inset;
+
                } else if (name == "ert") {
                        InsetERT * inset = new InsetERT(params);
-                       InsetERT::ERTStatus s;
-                       InsetERTMailer::string2params(cmd.argument, s);
+                       InsetERT::FreeStatus s;
+                       InsetFreeMailer::string2params(cmd.argument, s);
                        inset->status(bv, s);
                        return inset;
 
@@ -356,6 +367,8 @@ Inset * readInset(LyXLex & lex, Buffer c
                        inset = new InsetEnvironment(buf.params, lex.getString());
                } else if (tmptok == "ERT") {
                        inset = new InsetERT(buf.params);
+               } else if (tmptok == "Code") {
+                       inset = new InsetCode(buf.params);
                } else if (tmptok == "InsetSpace") {
                        inset = new InsetSpace;
                } else if (tmptok == "Tabular") {
Index: lfuns.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lfuns.h,v
retrieving revision 1.12
diff -u -p -r1.12 lfuns.h
--- lfuns.h     2 Jun 2003 14:19:29 -0000       1.12
+++ lfuns.h     6 Jun 2003 04:21:43 -0000
@@ -335,6 +335,7 @@ enum kb_action {
        // 255
        LFUN_PARAGRAPH_APPLY,
        LFUN_PARAGRAPH_UPDATE,
+       LFUN_INSET_CODE,
 
        LFUN_LASTACTION                  // end of the table
 };
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.449
diff -u -p -r1.449 lyxfunc.C
--- lyxfunc.C   4 Jun 2003 07:14:01 -0000       1.449
+++ lyxfunc.C   6 Jun 2003 04:21:45 -0000
@@ -353,7 +353,9 @@ FuncStatus LyXFunc::getStatus(FuncReques
                break;
 
        case LFUN_LAYOUT_CHARACTER:
-               disable = tli && tli->lyxCode() == Inset::ERT_CODE;
+               disable = tli &&
+                       (tli->lyxCode() == Inset::ERT_CODE ||
+                       tli->lyxCode() == Inset::CODE_CODE);
                break;
 
        case LFUN_LAYOUT_TABULAR:
@@ -509,7 +511,10 @@ FuncStatus LyXFunc::getStatus(FuncReques
                                disable = ev.argument != "tabular";
                                break;
                        case Inset::ERT_CODE:
-                               disable = ev.argument != "ert";
+                               disable = ev.argument != "free";
+                               break;
+                       case Inset::CODE_CODE:
+                               disable = ev.argument != "free";
                                break;
                        case Inset::FLOAT_CODE:
                                disable = ev.argument != "float";
@@ -564,6 +569,8 @@ FuncStatus LyXFunc::getStatus(FuncReques
                        code = Inset::CITE_CODE;
                else if (ev.argument == "ert")
                        code = Inset::ERT_CODE;
+               else if (ev.argument == "code")
+                       code = Inset::CODE_CODE;
                else if (ev.argument == "external")
                        code = Inset::EXTERNAL_CODE;
                else if (ev.argument == "float")
@@ -590,6 +597,9 @@ FuncStatus LyXFunc::getStatus(FuncReques
 
        case LFUN_INSET_ERT:
                code = Inset::ERT_CODE;
+               break;
+       case LFUN_INSET_CODE:
+               code = Inset::CODE_CODE;
                break;
        case LFUN_INSET_FOOTNOTE:
                code = Inset::FOOT_CODE;
Index: paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.282
diff -u -p -r1.282 paragraph.C
--- paragraph.C 4 Jun 2003 16:14:36 -0000       1.282
+++ paragraph.C 6 Jun 2003 04:21:46 -0000
@@ -623,7 +623,7 @@ void Paragraph::makeSameLayout(Paragraph
 
 int Paragraph::stripLeadingSpaces()
 {
-       if (layout()->free_spacing || isFreeSpacing())
+       if (isFreeSpacing())
                return 0;
 
        int i = 0;
@@ -1152,6 +1152,7 @@ Paragraph::getParLanguage(BufferParams c
 
 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
 {
+#warning InsetCode ?
        return lyxrc.rtl_support
                && getParLanguage(bparams)->RightToLeft()
                && !(inInset() && inInset()->owner() &&
@@ -1409,11 +1410,37 @@ ParagraphParameters const & Paragraph::p
 
 bool Paragraph::isFreeSpacing() const
 {
+       if (layout()->free_spacing)
+               return true;
+
        // for now we just need this, later should we need this in some
        // other way we can always add a function to Inset::() too.
-       if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
-               return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);
-       return false;
+       if (!pimpl_->inset_owner)
+               return false;
+       if (!pimpl_->inset_owner->owner())
+               return false;
+
+       Inset * i = pimpl_->inset_owner->owner();
+
+       return i->lyxCode() == Inset::ERT_CODE || i->lyxCode() == Inset::CODE_CODE;
+}
+
+
+bool Paragraph::allowEmpty() const
+{
+       if (layout()->keepempty)
+               return true;
+
+       // for now we just need this, later should we need this in some
+       // other way we can always add a function to Inset::() too.
+       if (!pimpl_->inset_owner)
+               return false;
+       if (!pimpl_->inset_owner->owner())
+               return false;
+
+       Inset * i = pimpl_->inset_owner->owner();
+
+       return i->lyxCode() == Inset::ERT_CODE || i->lyxCode() == Inset::CODE_CODE;
 }
 
 
Index: paragraph.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v
retrieving revision 1.87
diff -u -p -r1.87 paragraph.h
--- paragraph.h 4 Jun 2003 07:14:03 -0000       1.87
+++ paragraph.h 6 Jun 2003 04:21:47 -0000
@@ -283,8 +283,11 @@ public:
        ///
        int stripLeadingSpaces();
 
-       ///
+       /// return true if we allow multiple spaces
        bool isFreeSpacing() const;
+
+       /// return true if we allow this par to stay empty
+       bool allowEmpty() const;
 
        ///
        ParagraphParameters & params();
Index: paragraph_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.C,v
retrieving revision 1.44
diff -u -p -r1.44 paragraph_funcs.C
--- paragraph_funcs.C   29 May 2003 01:13:16 -0000      1.44
+++ paragraph_funcs.C   6 Jun 2003 04:21:49 -0000
@@ -71,7 +71,7 @@ void breakParagraph(BufferParams const &
                tmp->setLabelWidthString(par->params().labelWidthString());
        }
 
-       bool const isempty = (par->layout()->keepempty && par->empty());
+       bool const isempty = (par->allowEmpty() && par->empty());
 
        if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
                tmp->layout(par->layout());
@@ -937,10 +937,10 @@ int readParToken(Buffer & buf, Paragraph
                lex.next();
                font.setLyXColor(lex.getString());
        } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
-               LyXLayout_ptr const & layout = par.layout();
 
                // Insets don't make sense in a free-spacing context! ---Kayvan
-               if (layout->free_spacing || par.isFreeSpacing()) {
+#warning this will break insetcode using alltt probably
+               if (par.isFreeSpacing()) {
                        if (token == "\\InsetSpace")
                                par.insertChar(par.size(), ' ', font, change);
                        else if (lex.isOK()) {
Index: paragraph_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_pimpl.C,v
retrieving revision 1.71
diff -u -p -r1.71 paragraph_pimpl.C
--- paragraph_pimpl.C   29 May 2003 01:13:17 -0000      1.71
+++ paragraph_pimpl.C   6 Jun 2003 04:21:50 -0000
@@ -429,8 +429,7 @@ void Paragraph::Pimpl::simpleTeXBlanks(o
            && getChar(i - 1) != ' '
            && (i < size() - 1)
            // same in FreeSpacing mode
-           && !style.free_spacing
-               && !owner_->isFreeSpacing()
+           && !owner_->isFreeSpacing()
            // In typewriter mode, we want to avoid
            // ! . ? : at the end of a line
            && !(font.family() == LyXFont::TYPEWRITER_FAMILY
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.365
diff -u -p -r1.365 text.C
--- text.C      28 May 2003 16:36:53 -0000      1.365
+++ text.C      6 Jun 2003 04:21:54 -0000
@@ -368,6 +368,7 @@ void LyXText::computeBidiTables(Buffer c
 
        ParagraphList::iterator row_par = row->par();
 
+#warning InsetCode ?
        Inset * inset = row_par->inInset();
        if (inset && inset->owner() &&
            inset->owner()->lyxCode() == Inset::ERT_CODE) {
@@ -1461,10 +1462,9 @@ void LyXText::breakParagraph(ParagraphLi
        LyXLayout_ptr const & layout = cursor.par()->layout();
 
        // this is only allowed, if the current paragraph is not empty or caption
-       // and if it has not the keepempty flag aktive
-       if (cursor.par()->empty()
-          && layout->labeltype != LABEL_SENSITIVE
-          && !layout->keepempty)
+       // and if it has not the keepempty flag active
+       if (cursor.par()->empty() && !cursor.par()->allowEmpty()
+          && layout->labeltype != LABEL_SENSITIVE)
                return;
 
        setUndo(bv(), Undo::FINISH, cursor.par());
@@ -1487,7 +1487,7 @@ void LyXText::breakParagraph(ParagraphLi
        // breakParagraph call should return a bool if it inserts the
        // paragraph before or behind and we should react on that one
        // but we can fix this in 1.3.0 (Jug 20020509)
-       bool const isempty = (layout->keepempty && cursor.par()->empty());
+       bool const isempty = (cursor.par()->allowEmpty() && cursor.par()->empty());
        ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), 
cursor.pos(),
                       keep_layout);
 
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.368
diff -u -p -r1.368 text2.C
--- text2.C     5 Jun 2003 11:34:54 -0000       1.368
+++ text2.C     6 Jun 2003 04:21:56 -0000
@@ -2224,7 +2224,7 @@ bool LyXText::deleteEmptyParagraphMechan
                return false;
 
        // Do not delete empty paragraphs with keepempty set.
-       if (old_cursor.par()->layout()->keepempty)
+       if (old_cursor.par()->allowEmpty())
                return false;
 
        // only do our magic if we changed paragraph
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.79
diff -u -p -r1.79 text3.C
--- text3.C     2 Jun 2003 14:19:29 -0000       1.79
+++ text3.C     6 Jun 2003 04:21:58 -0000
@@ -1577,6 +1577,7 @@ Inset::RESULT LyXText::dispatch(FuncRequ
 #endif
        case LFUN_INSERT_NOTE:
        case LFUN_INSERT_BIBITEM:
+       case LFUN_INSET_CODE:
        case LFUN_INSET_ERT:
        case LFUN_INSET_FLOAT:
        case LFUN_INSET_FOOTNOTE:
Index: frontends/Dialogs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/Dialogs.C,v
retrieving revision 1.23
diff -u -p -r1.23 Dialogs.C
--- frontends/Dialogs.C 12 Mar 2003 22:17:48 -0000      1.23
+++ frontends/Dialogs.C 6 Jun 2003 04:21:58 -0000
@@ -74,8 +74,8 @@ Dialogs::Dialogs(LyXView & lyxview)
 
 Dialog * Dialogs::find(string const & name)
 {
-       if (!isValidName(name))
-               return 0;
+       if (!isValidName(name))
+               return 0;
 
        std::map<string, DialogPtr>::iterator it =
                dialogs_.find(name);
Index: frontends/controllers/ControlERT.C
===================================================================
RCS file: frontends/controllers/ControlERT.C
diff -N frontends/controllers/ControlERT.C
--- frontends/controllers/ControlERT.C  14 Mar 2003 00:20:42 -0000      1.17
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,40 +0,0 @@
-/**
- * \file ControlERT.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jürgen Vigna
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS
- */
-
-#include <config.h>
-
-#include "ControlERT.h"
-#include "funcrequest.h"
-
-
-ControlERT::ControlERT(Dialog & parent)
-       : Dialog::Controller(parent), status_(InsetERT::Collapsed)
-{}
-
-
-bool ControlERT::initialiseParams(string const & data)
-{
-       InsetERTMailer::string2params(data, status_);
-       return true;
-}
-
-
-void ControlERT::clearParams()
-{
-       status_ = InsetERT::Collapsed;
-}
-
-
-void ControlERT::dispatchParams()
-{
-       string const lfun = InsetERTMailer::params2string(status_);
-       kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
-}
Index: frontends/controllers/ControlERT.h
===================================================================
RCS file: frontends/controllers/ControlERT.h
diff -N frontends/controllers/ControlERT.h
--- frontends/controllers/ControlERT.h  14 Mar 2003 00:20:42 -0000      1.9
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,42 +0,0 @@
-// -*- C++ -*-
-/**
- * \file ControlERT.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jürgen Vigna
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS
- */
-
-#ifndef CONTROLERT_H
-#define CONTROLERT_H
-
-
-#include "Dialog.h"
-#include "insets/insetert.h" // InsetERT::ERTStatus
-
-
-class ControlERT : public Dialog::Controller {
-public:
-       ///
-       ControlERT(Dialog &);
-       ///
-       InsetERT::ERTStatus status() const { return status_; }
-       ///
-       void setStatus(InsetERT::ERTStatus status) { status_ = status; }
-       ///
-       virtual bool initialiseParams(string const & data);
-       /// clean-up on hide.
-       virtual void clearParams();
-       /// clean-up on hide.
-       virtual void dispatchParams();
-       ///
-       virtual bool isBufferDependent() const { return true; }
-private:
-       ///
-       InsetERT::ERTStatus status_;
-};
-
-#endif
Index: frontends/controllers/ControlFree.C
===================================================================
RCS file: frontends/controllers/ControlFree.C
diff -N frontends/controllers/ControlFree.C
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ frontends/controllers/ControlFree.C 6 Jun 2003 04:21:58 -0000
@@ -0,0 +1,40 @@
+/**
+ * \file ControlFree.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Vigna
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <config.h>
+
+#include "ControlFree.h"
+#include "funcrequest.h"
+
+
+ControlFree::ControlFree(Dialog & parent)
+       : Dialog::Controller(parent), status_(InsetFree::Collapsed)
+{}
+
+
+bool ControlFree::initialiseParams(string const & data)
+{
+       InsetFreeMailer::string2params(data, status_);
+       return true;
+}
+
+
+void ControlFree::clearParams()
+{
+       status_ = InsetFree::Collapsed;
+}
+
+
+void ControlFree::dispatchParams()
+{
+       string const lfun = InsetFreeMailer::params2string(status_);
+       kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
+}
Index: frontends/controllers/ControlFree.h
===================================================================
RCS file: frontends/controllers/ControlFree.h
diff -N frontends/controllers/ControlFree.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ frontends/controllers/ControlFree.h 6 Jun 2003 04:21:58 -0000
@@ -0,0 +1,42 @@
+// -*- C++ -*-
+/**
+ * \file ControlFree.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Vigna
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef CONTROLFREE_H
+#define CONTROLFREE_H
+
+
+#include "Dialog.h"
+#include "insets/insetfree.h" // InsetFree::FreeStatus
+
+
+class ControlFree : public Dialog::Controller {
+public:
+       ///
+       ControlFree(Dialog &);
+       ///
+       InsetFree::FreeStatus status() const { return status_; }
+       ///
+       void setStatus(InsetFree::FreeStatus status) { status_ = status; }
+       ///
+       virtual bool initialiseParams(string const & data);
+       /// clean-up on hide.
+       virtual void clearParams();
+       /// clean-up on hide.
+       virtual void dispatchParams();
+       ///
+       virtual bool isBufferDependent() const { return true; }
+private:
+       ///
+       InsetFree::FreeStatus status_;
+};
+
+#endif
Index: frontends/controllers/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/Makefile.am,v
retrieving revision 1.55
diff -u -p -r1.55 Makefile.am
--- frontends/controllers/Makefile.am   13 May 2003 21:15:47 -0000      1.55
+++ frontends/controllers/Makefile.am   6 Jun 2003 04:21:59 -0000
@@ -52,8 +52,8 @@ libcontrollers_la_SOURCES= \
        ControlError.h \
        ControlErrorList.C \
        ControlErrorList.h \
-       ControlERT.C \
-       ControlERT.h \
+       ControlFree.C \
+       ControlFree.h \
        ControlExternal.C \
        ControlExternal.h \
        ControlFloat.C \
Index: frontends/qt2/Dialogs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/Dialogs.C,v
retrieving revision 1.85
diff -u -p -r1.85 Dialogs.C
--- frontends/qt2/Dialogs.C     4 Jun 2003 09:16:29 -0000       1.85
+++ frontends/qt2/Dialogs.C     6 Jun 2003 04:21:59 -0000
@@ -20,9 +20,9 @@
 #include "ControlCitation.h"
 #include "ControlError.h"
 #include "ControlErrorList.h"
-#include "ControlERT.h"
 #include "ControlExternal.h"
 #include "ControlFloat.h"
+#include "ControlFree.h"
 #include "ControlGraphics.h"
 #include "ControlInclude.h"
 #include "ControlLog.h"
@@ -44,9 +44,9 @@
 #include "QCitation.h"
 #include "QError.h"
 #include "QErrorList.h"
-#include "QERT.h"
 #include "QExternal.h"
 #include "QFloat.h"
+#include "QFree.h"
 // Here would be an appropriate point to lecture on the evils
 // of the Qt headers, those most fucked up of disgusting ratholes.
 // But I won't.
@@ -79,7 +79,7 @@
 namespace {
 
 char const * const dialognames[] = { "about", "bibitem", "bibtex", "changes",
-"character", "citation", "error", "errorlist", "ert", "external", "file",
+"character", "citation", "error", "errorlist", "external", "file", "free",
 "float", "graphics", "include", "index", "label", "log", "minipage",
 "paragraph", "ref", "tabular", "tabularcreate",
 
@@ -152,9 +152,9 @@ Dialog * Dialogs::build(string const & n
                dialog->setController(new ControlErrorList(*dialog));
                dialog->setView(new QErrorList(*dialog));
                dialog->bc().bp(new OkCancelPolicy);
-       } else if (name == "ert") {
-               dialog->setController(new ControlERT(*dialog));
-               dialog->setView(new QERT(*dialog));
+       } else if (name == "free") {
+               dialog->setController(new ControlFree(*dialog));
+               dialog->setView(new QFree(*dialog));
                dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
        } else if (name == "external") {
                dialog->setController(new ControlExternal(*dialog));
Index: frontends/qt2/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/Makefile.am,v
retrieving revision 1.80
diff -u -p -r1.80 Makefile.am
--- frontends/qt2/Makefile.am   24 May 2003 15:19:05 -0000      1.80
+++ frontends/qt2/Makefile.am   6 Jun 2003 04:21:59 -0000
@@ -36,9 +36,9 @@ libqt2_la_SOURCES = \
        QDocument.C QDocument.h \
        QError.C QError.h \
        QErrorList.C QErrorList.h \
-       QERT.C QERT.h \
        QExternal.C QExternal.h \
        QFloat.C QFloat.h \
+       QFree.C QFree.h \
        QGraphics.C QGraphics.h \
        QInclude.C QInclude.h \
        QIndex.C QIndex.h \
Index: frontends/qt2/Makefile.dialogs
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/Makefile.dialogs,v
retrieving revision 1.41
diff -u -p -r1.41 Makefile.dialogs
--- frontends/qt2/Makefile.dialogs      13 May 2003 21:15:48 -0000      1.41
+++ frontends/qt2/Makefile.dialogs      6 Jun 2003 04:21:59 -0000
@@ -24,9 +24,9 @@ UIFILES = \
        QDocumentDialogBase.ui \
        QErrorDialogBase.ui \
        QErrorListDialogBase.ui \
-       QERTDialogBase.ui \
        QExternalDialogBase.ui \
        QFloatDialogBase.ui \
+       QFreeDialogBase.ui \
        QGraphicsDialogBase.ui \
        QIncludeDialogBase.ui \
        QIndexDialogBase.ui \
@@ -89,9 +89,9 @@ MOCFILES = \
        QDocumentDialog.C QDocumentDialog.h \
        QErrorDialog.C QErrorDialog.h \
        QErrorListDialog.C QErrorListDialog.h \
-       QERTDialog.C QERTDialog.h \
        QExternalDialog.C QExternalDialog.h \
        QFloatDialog.C QFloatDialog.h \
+       QFreeDialog.C QFreeDialog.h \
        QGraphicsDialog.C QGraphicsDialog.h \
        qgridview.C qgridview.h \
        QIncludeDialog.C QIncludeDialog.h \
Index: frontends/qt2/QERT.C
===================================================================
RCS file: frontends/qt2/QERT.C
diff -N frontends/qt2/QERT.C
--- frontends/qt2/QERT.C        22 May 2003 15:42:50 -0000      1.15
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,64 +0,0 @@
-/**
- * \file QERT.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS
- */
-
-#include <config.h>
-
-
-#include "ControlERT.h"
-#include "qt_helpers.h"
-
-#include <qradiobutton.h>
-#include <qpushbutton.h>
-
-#include "QERTDialog.h"
-#include "QERT.h"
-#include "Qt2BC.h"
-
-typedef QController<ControlERT, QView<QERTDialog> > base_class;
-
-
-QERT::QERT(Dialog & parent)
-       : base_class(parent, _("LyX: TeX Code Settings"))
-{
-}
-
-
-void QERT::build_dialog()
-{
-       dialog_.reset(new QERTDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-}
-
-
-void QERT::apply()
-{
-       if (dialog_->openRB->isChecked())
-               controller().setStatus(InsetERT::Open);
-       else if (dialog_->inlineRB->isChecked())
-               controller().setStatus(InsetERT::Inlined);
-       else
-               controller().setStatus(InsetERT::Collapsed);
-}
-
-
-void QERT::update_contents()
-{
-       QRadioButton * rb = 0;
-
-       switch (controller().status()) {
-               case InsetERT::Open: rb = dialog_->openRB; break;
-               case InsetERT::Inlined: rb = dialog_->inlineRB; break;
-               case InsetERT::Collapsed: rb = dialog_->collapsedRB; break;
-       }
-
-       rb->setChecked(true);
-}
Index: frontends/qt2/QERT.h
===================================================================
RCS file: frontends/qt2/QERT.h
diff -N frontends/qt2/QERT.h
--- frontends/qt2/QERT.h        25 Feb 2003 14:51:34 -0000      1.8
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,38 +0,0 @@
-// -*- C++ -*-
-/**
- * \file QERT.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS
- */
-
-#ifndef QERT_H
-#define QERT_H
-
-
-#include "QDialogView.h"
-
-
-class ControlERT;
-class QERTDialog;
-
-
-class QERT : public QController<ControlERT, QView<QERTDialog> >
-{
-public:
-       friend class QERTDialog;
-
-       QERT(Dialog &);
-private:
-       /// Apply changes
-       virtual void apply();
-       /// update
-       virtual void update_contents();
-       /// build the dialog
-       virtual void build_dialog();
-};
-
-#endif // QERT_H
Index: frontends/qt2/QERTDialog.C
===================================================================
RCS file: frontends/qt2/QERTDialog.C
diff -N frontends/qt2/QERTDialog.C
--- frontends/qt2/QERTDialog.C  13 Feb 2003 16:52:52 -0000      1.6
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,41 +0,0 @@
-/**
- * \file QERTDialog.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS
- */
-
-#include <config.h>
-
-
-#include "QERT.h"
-#include "QERTDialog.h"
-
-#include <qpushbutton.h>
-
-
-QERTDialog::QERTDialog(QERT * form)
-       : QERTDialogBase(0, 0, false, 0),
-       form_(form)
-{
-       connect(okPB, SIGNAL(clicked()),
-               form, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()),
-               form, SLOT(slotClose()));
-}
-
-
-void QERTDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QERTDialog::change_adaptor()
-{
-       form_->changed();
-}
Index: frontends/qt2/QERTDialog.h
===================================================================
RCS file: frontends/qt2/QERTDialog.h
diff -N frontends/qt2/QERTDialog.h
--- frontends/qt2/QERTDialog.h  13 Feb 2003 16:52:52 -0000      1.6
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,32 +0,0 @@
-// -*- C++ -*-
-/**
- * \file QERTDialog.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS
- */
-
-#ifndef QERTDIALOG_H
-#define QERTDIALOG_H
-
-#include "ui/QERTDialogBase.h"
-
-
-class QERT;
-
-class QERTDialog : public QERTDialogBase {
-       Q_OBJECT
-public:
-       QERTDialog(QERT * form);
-protected slots:
-       virtual void change_adaptor();
-protected:
-       virtual void closeEvent(QCloseEvent * e);
-private:
-       QERT * form_;
-};
-
-#endif // QERTDIALOG_H
Index: frontends/qt2/QFree.C
===================================================================
RCS file: frontends/qt2/QFree.C
diff -N frontends/qt2/QFree.C
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ frontends/qt2/QFree.C       6 Jun 2003 04:21:59 -0000
@@ -0,0 +1,64 @@
+/**
+ * \file QFree.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <config.h>
+
+
+#include "ControlFree.h"
+#include "qt_helpers.h"
+
+#include <qradiobutton.h>
+#include <qpushbutton.h>
+
+#include "QFreeDialog.h"
+#include "QFree.h"
+#include "Qt2BC.h"
+
+typedef QController<ControlFree, QView<QFreeDialog> > base_class;
+
+
+QFree::QFree(Dialog & parent)
+       : base_class(parent, _("LyX: Code Settings"))
+{
+}
+
+
+void QFree::build_dialog()
+{
+       dialog_.reset(new QFreeDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setCancel(dialog_->closePB);
+}
+
+
+void QFree::apply()
+{
+       if (dialog_->openRB->isChecked())
+               controller().setStatus(InsetFree::Open);
+       else if (dialog_->inlineRB->isChecked())
+               controller().setStatus(InsetFree::Inlined);
+       else
+               controller().setStatus(InsetFree::Collapsed);
+}
+
+
+void QFree::update_contents()
+{
+       QRadioButton * rb = 0;
+
+       switch (controller().status()) {
+               case InsetFree::Open: rb = dialog_->openRB; break;
+               case InsetFree::Inlined: rb = dialog_->inlineRB; break;
+               case InsetFree::Collapsed: rb = dialog_->collapsedRB; break;
+       }
+
+       rb->setChecked(true);
+}
Index: frontends/qt2/QFree.h
===================================================================
RCS file: frontends/qt2/QFree.h
diff -N frontends/qt2/QFree.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ frontends/qt2/QFree.h       6 Jun 2003 04:21:59 -0000
@@ -0,0 +1,38 @@
+// -*- C++ -*-
+/**
+ * \file QFree.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef QFREE_H
+#define QFREE_H
+
+
+#include "QDialogView.h"
+
+
+class ControlFree;
+class QFreeDialog;
+
+
+class QFree : public QController<ControlFree, QView<QFreeDialog> >
+{
+public:
+       friend class QFreeDialog;
+
+       QFree(Dialog &);
+private:
+       /// Apply changes
+       virtual void apply();
+       /// update
+       virtual void update_contents();
+       /// build the dialog
+       virtual void build_dialog();
+};
+
+#endif // QFREE_H
Index: frontends/qt2/QFreeDialog.C
===================================================================
RCS file: frontends/qt2/QFreeDialog.C
diff -N frontends/qt2/QFreeDialog.C
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ frontends/qt2/QFreeDialog.C 6 Jun 2003 04:21:59 -0000
@@ -0,0 +1,41 @@
+/**
+ * \file QFreeDialog.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <config.h>
+
+
+#include "QFree.h"
+#include "QFreeDialog.h"
+
+#include <qpushbutton.h>
+
+
+QFreeDialog::QFreeDialog(QFree * form)
+       : QFreeDialogBase(0, 0, false, 0),
+       form_(form)
+{
+       connect(okPB, SIGNAL(clicked()),
+               form, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()),
+               form, SLOT(slotClose()));
+}
+
+
+void QFreeDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QFreeDialog::change_adaptor()
+{
+       form_->changed();
+}
Index: frontends/qt2/QFreeDialog.h
===================================================================
RCS file: frontends/qt2/QFreeDialog.h
diff -N frontends/qt2/QFreeDialog.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ frontends/qt2/QFreeDialog.h 6 Jun 2003 04:21:59 -0000
@@ -0,0 +1,32 @@
+// -*- C++ -*-
+/**
+ * \file QFreeDialog.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef QFREEDIALOG_H
+#define QFREEDIALOG_H
+
+#include "ui/QFreeDialogBase.h"
+
+
+class QFree;
+
+class QFreeDialog : public QFreeDialogBase {
+       Q_OBJECT
+public:
+       QFreeDialog(QFree * form);
+protected slots:
+       virtual void change_adaptor();
+protected:
+       virtual void closeEvent(QCloseEvent * e);
+private:
+       QFree * form_;
+};
+
+#endif // QFREEDIALOG_H
Index: frontends/qt2/ui/QERTDialogBase.ui
===================================================================
RCS file: frontends/qt2/ui/QERTDialogBase.ui
diff -N frontends/qt2/ui/QERTDialogBase.ui
--- frontends/qt2/ui/QERTDialogBase.ui  23 Jan 2003 16:23:40 -0000      1.2
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,194 +0,0 @@
-<!DOCTYPE UI><UI>
-<class>QERTDialogBase</class>
-<include location="global">config.h</include>
-<include location="local">qt_helpers.h</include>
-<widget>
-    <class>QDialog</class>
-    <property stdset="1">
-        <name>name</name>
-        <cstring>QERTDialogBase</cstring>
-    </property>
-    <property stdset="1">
-        <name>geometry</name>
-        <rect>
-            <x>0</x>
-            <y>0</y>
-            <width>197</width>
-            <height>158</height>
-        </rect>
-    </property>
-    <property stdset="1">
-        <name>caption</name>
-        <string>ERT inset display</string>
-    </property>
-    <property stdset="1">
-        <name>sizeGripEnabled</name>
-        <bool>true</bool>
-    </property>
-    <vbox>
-        <property stdset="1">
-            <name>margin</name>
-            <number>11</number>
-        </property>
-        <property stdset="1">
-            <name>spacing</name>
-            <number>6</number>
-        </property>
-        <widget>
-            <class>QButtonGroup</class>
-            <property stdset="1">
-                <name>name</name>
-                <cstring>ertBG</cstring>
-            </property>
-            <property stdset="1">
-                <name>title</name>
-                <string>Display</string>
-            </property>
-            <vbox>
-                <property stdset="1">
-                    <name>margin</name>
-                    <number>11</number>
-                </property>
-                <property stdset="1">
-                    <name>spacing</name>
-                    <number>6</number>
-                </property>
-                <widget>
-                    <class>QRadioButton</class>
-                    <property stdset="1">
-                        <name>name</name>
-                        <cstring>inlineRB</cstring>
-                    </property>
-                    <property stdset="1">
-                        <name>text</name>
-                        <string>&amp;Inline</string>
-                    </property>
-                    <property>
-                        <name>toolTip</name>
-                        <string>Show ERT inline</string>
-                    </property>
-                </widget>
-                <widget>
-                    <class>QRadioButton</class>
-                    <property stdset="1">
-                        <name>name</name>
-                        <cstring>collapsedRB</cstring>
-                    </property>
-                    <property stdset="1">
-                        <name>text</name>
-                        <string>&amp;Collapsed</string>
-                    </property>
-                    <property>
-                        <name>toolTip</name>
-                        <string>Show ERT button only</string>
-                    </property>
-                </widget>
-                <widget>
-                    <class>QRadioButton</class>
-                    <property stdset="1">
-                        <name>name</name>
-                        <cstring>openRB</cstring>
-                    </property>
-                    <property stdset="1">
-                        <name>text</name>
-                        <string>&amp;Open</string>
-                    </property>
-                    <property>
-                        <name>toolTip</name>
-                        <string>Show ERT contents</string>
-                    </property>
-                </widget>
-            </vbox>
-        </widget>
-        <widget>
-            <class>QLayoutWidget</class>
-            <property stdset="1">
-                <name>name</name>
-                <cstring>Layout2</cstring>
-            </property>
-            <hbox>
-                <property stdset="1">
-                    <name>margin</name>
-                    <number>0</number>
-                </property>
-                <property stdset="1">
-                    <name>spacing</name>
-                    <number>6</number>
-                </property>
-                <spacer>
-                    <property>
-                        <name>name</name>
-                        <cstring>Spacer3</cstring>
-                    </property>
-                    <property stdset="1">
-                        <name>orientation</name>
-                        <enum>Horizontal</enum>
-                    </property>
-                    <property stdset="1">
-                        <name>sizeType</name>
-                        <enum>Expanding</enum>
-                    </property>
-                    <property>
-                        <name>sizeHint</name>
-                        <size>
-                            <width>20</width>
-                            <height>20</height>
-                        </size>
-                    </property>
-                </spacer>
-                <widget>
-                    <class>QPushButton</class>
-                    <property stdset="1">
-                        <name>name</name>
-                        <cstring>okPB</cstring>
-                    </property>
-                    <property stdset="1">
-                        <name>text</name>
-                        <string>OK</string>
-                    </property>
-                    <property stdset="1">
-                        <name>default</name>
-                        <bool>false</bool>
-                    </property>
-                </widget>
-                <widget>
-                    <class>QPushButton</class>
-                    <property stdset="1">
-                        <name>name</name>
-                        <cstring>closePB</cstring>
-                    </property>
-                    <property stdset="1">
-                        <name>text</name>
-                        <string>&amp;Close</string>
-                    </property>
-                    <property stdset="1">
-                        <name>default</name>
-                        <bool>true</bool>
-                    </property>
-                </widget>
-            </hbox>
-        </widget>
-    </vbox>
-</widget>
-<connections>
-    <connection>
-        <sender>inlineRB</sender>
-        <signal>toggled(bool)</signal>
-        <receiver>QERTDialogBase</receiver>
-        <slot>change_adaptor()</slot>
-    </connection>
-    <connection>
-        <sender>collapsedRB</sender>
-        <signal>toggled(bool)</signal>
-        <receiver>QERTDialogBase</receiver>
-        <slot>change_adaptor()</slot>
-    </connection>
-    <connection>
-        <sender>openRB</sender>
-        <signal>toggled(bool)</signal>
-        <receiver>QERTDialogBase</receiver>
-        <slot>change_adaptor()</slot>
-    </connection>
-    <slot access="public">change_adaptor()</slot>
-</connections>
-</UI>
Index: frontends/qt2/ui/QFreeDialogBase.ui
===================================================================
RCS file: frontends/qt2/ui/QFreeDialogBase.ui
diff -N frontends/qt2/ui/QFreeDialogBase.ui
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ frontends/qt2/ui/QFreeDialogBase.ui 6 Jun 2003 04:22:01 -0000
@@ -0,0 +1,194 @@
+<!DOCTYPE UI><UI>
+<class>QFreeDialogBase</class>
+<include location="global">config.h</include>
+<include location="local">qt_helpers.h</include>
+<widget>
+    <class>QDialog</class>
+    <property stdset="1">
+        <name>name</name>
+        <cstring>QFreeDialogBase</cstring>
+    </property>
+    <property stdset="1">
+        <name>geometry</name>
+        <rect>
+            <x>0</x>
+            <y>0</y>
+            <width>197</width>
+            <height>158</height>
+        </rect>
+    </property>
+    <property stdset="1">
+        <name>caption</name>
+        <string>Code display</string>
+    </property>
+    <property stdset="1">
+        <name>sizeGripEnabled</name>
+        <bool>true</bool>
+    </property>
+    <vbox>
+        <property stdset="1">
+            <name>margin</name>
+            <number>11</number>
+        </property>
+        <property stdset="1">
+            <name>spacing</name>
+            <number>6</number>
+        </property>
+        <widget>
+            <class>QButtonGroup</class>
+            <property stdset="1">
+                <name>name</name>
+                <cstring>ertBG</cstring>
+            </property>
+            <property stdset="1">
+                <name>title</name>
+                <string>Display</string>
+            </property>
+            <vbox>
+                <property stdset="1">
+                    <name>margin</name>
+                    <number>11</number>
+                </property>
+                <property stdset="1">
+                    <name>spacing</name>
+                    <number>6</number>
+                </property>
+                <widget>
+                    <class>QRadioButton</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>inlineRB</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>text</name>
+                        <string>&amp;Inline</string>
+                    </property>
+                    <property>
+                        <name>toolTip</name>
+                        <string>Show code inline</string>
+                    </property>
+                </widget>
+                <widget>
+                    <class>QRadioButton</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>collapsedRB</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>text</name>
+                        <string>&amp;Collapsed</string>
+                    </property>
+                    <property>
+                        <name>toolTip</name>
+                        <string>Show code button only</string>
+                    </property>
+                </widget>
+                <widget>
+                    <class>QRadioButton</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>openRB</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>text</name>
+                        <string>&amp;Open</string>
+                    </property>
+                    <property>
+                        <name>toolTip</name>
+                        <string>Show code contents</string>
+                    </property>
+                </widget>
+            </vbox>
+        </widget>
+        <widget>
+            <class>QLayoutWidget</class>
+            <property stdset="1">
+                <name>name</name>
+                <cstring>Layout2</cstring>
+            </property>
+            <hbox>
+                <property stdset="1">
+                    <name>margin</name>
+                    <number>0</number>
+                </property>
+                <property stdset="1">
+                    <name>spacing</name>
+                    <number>6</number>
+                </property>
+                <spacer>
+                    <property>
+                        <name>name</name>
+                        <cstring>Spacer3</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>orientation</name>
+                        <enum>Horizontal</enum>
+                    </property>
+                    <property stdset="1">
+                        <name>sizeType</name>
+                        <enum>Expanding</enum>
+                    </property>
+                    <property>
+                        <name>sizeHint</name>
+                        <size>
+                            <width>20</width>
+                            <height>20</height>
+                        </size>
+                    </property>
+                </spacer>
+                <widget>
+                    <class>QPushButton</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>okPB</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>text</name>
+                        <string>OK</string>
+                    </property>
+                    <property stdset="1">
+                        <name>default</name>
+                        <bool>false</bool>
+                    </property>
+                </widget>
+                <widget>
+                    <class>QPushButton</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>closePB</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>text</name>
+                        <string>&amp;Close</string>
+                    </property>
+                    <property stdset="1">
+                        <name>default</name>
+                        <bool>true</bool>
+                    </property>
+                </widget>
+            </hbox>
+        </widget>
+    </vbox>
+</widget>
+<connections>
+    <connection>
+        <sender>inlineRB</sender>
+        <signal>toggled(bool)</signal>
+        <receiver>QFreeDialogBase</receiver>
+        <slot>change_adaptor()</slot>
+    </connection>
+    <connection>
+        <sender>collapsedRB</sender>
+        <signal>toggled(bool)</signal>
+        <receiver>QFreeDialogBase</receiver>
+        <slot>change_adaptor()</slot>
+    </connection>
+    <connection>
+        <sender>openRB</sender>
+        <signal>toggled(bool)</signal>
+        <receiver>QFreeDialogBase</receiver>
+        <slot>change_adaptor()</slot>
+    </connection>
+    <slot access="public">change_adaptor()</slot>
+</connections>
+</UI>
Index: frontends/xforms/Dialogs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/Dialogs.C,v
retrieving revision 1.106
diff -u -p -r1.106 Dialogs.C
--- frontends/xforms/Dialogs.C  4 Jun 2003 09:16:29 -0000       1.106
+++ frontends/xforms/Dialogs.C  6 Jun 2003 04:22:02 -0000
@@ -23,9 +23,9 @@
 #include "ControlCommand.h"
 #include "ControlError.h"
 #include "ControlErrorList.h"
-#include "ControlERT.h"
 #include "ControlExternal.h"
 #include "ControlFloat.h"
+#include "ControlFree.h"
 #include "ControlGraphics.h"
 #include "ControlInclude.h"
 #include "ControlLog.h"
@@ -47,9 +47,9 @@
 #include "FormCitation.h"
 #include "FormError.h"
 #include "FormErrorList.h"
-#include "FormERT.h"
 #include "FormExternal.h"
 #include "FormFloat.h"
+#include "FormFree.h"
 #include "FormGraphics.h"
 #include "FormInclude.h"
 #include "FormLog.h"
@@ -76,7 +76,7 @@
 
 namespace {
 
-char const * const dialognames[] = { "about", "bibitem", "bibtex", "changes", 
"character", "citation", "error", "errorlist" , "ert", "external", "file", "float", 
"graphics", "include", "index", "label", "log", "minipage", "paragraph", "ref", 
"tabular", "tabularcreate",
+char const * const dialognames[] = { "about", "bibitem", "bibtex", "changes", 
"character", "citation", "error", "errorlist" , "external", "file", "float", "free", 
"graphics", "include", "index", "label", "log", "minipage", "paragraph", "ref", 
"tabular", "tabularcreate",
 
 #ifdef HAVE_LIBAIKSAURUS
 "thesaurus",
@@ -147,9 +147,9 @@ Dialog * Dialogs::build(string const & n
                dialog->setController(new ControlErrorList(*dialog));
                dialog->setView(new FormErrorList(*dialog));
                dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "ert") {
-               dialog->setController(new ControlERT(*dialog));
-               dialog->setView(new FormERT(*dialog));
+       } else if (name == "free") {
+               dialog->setController(new ControlFree(*dialog));
+               dialog->setView(new FormFree(*dialog));
                dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
        } else if (name == "external") {
                dialog->setController(new ControlExternal(*dialog));
Index: frontends/xforms/FormERT.C
===================================================================
RCS file: frontends/xforms/FormERT.C
diff -N frontends/xforms/FormERT.C
--- frontends/xforms/FormERT.C  14 May 2003 09:17:20 -0000      1.16
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,69 +0,0 @@
-/**
- * \file FormERT.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jürgen Vigna
- *
- * Full author contact details are available in file CREDITS
- */
-
-#include <config.h>
-
-
-#include "xformsBC.h"
-#include "ControlERT.h"
-#include "FormERT.h"
-#include "forms/form_ert.h"
-#include "support/lstrings.h"
-#include "helper_funcs.h"
-#include "debug.h"
-#include "lyx_forms.h"
-
-typedef  FormController<ControlERT, FormView<FD_ert> > base_class;
-
-FormERT::FormERT(Dialog & parent)
-       : base_class(parent, _("TeX Settings"))
-{}
-
-
-void FormERT::build()
-{
-       dialog_.reset(build_ert(this));
-
-       // Manage the ok, apply and cancel/close buttons
-       bcview().setOK(dialog_->button_ok);
-       bcview().setApply(dialog_->button_apply);
-       bcview().setCancel(dialog_->button_close);
-
-       bcview().addReadOnly(dialog_->radio_open);
-       bcview().addReadOnly(dialog_->radio_collapsed);
-       bcview().addReadOnly(dialog_->radio_inlined);
-}
-
-
-void FormERT::apply()
-{
-       if (fl_get_button(dialog_->radio_open))
-               controller().setStatus(InsetERT::Open);
-       else if (fl_get_button(dialog_->radio_collapsed))
-               controller().setStatus(InsetERT::Collapsed);
-       else
-               controller().setStatus(InsetERT::Inlined);
-}
-
-
-void FormERT::update()
-{
-       switch (controller().status()) {
-       case InsetERT::Open:
-               fl_set_button(dialog_->radio_open, 1);
-               break;
-       case InsetERT::Collapsed:
-               fl_set_button(dialog_->radio_collapsed, 1);
-               break;
-       case InsetERT::Inlined:
-               fl_set_button(dialog_->radio_inlined, 1);
-               break;
-       }
-}
Index: frontends/xforms/FormERT.h
===================================================================
RCS file: frontends/xforms/FormERT.h
diff -N frontends/xforms/FormERT.h
--- frontends/xforms/FormERT.h  27 Feb 2003 15:57:11 -0000      1.11
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,38 +0,0 @@
-// -*- C++ -*-
-/**
- * \file FormERT.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jürgen Vigna
- *
- * Full author contact details are available in file CREDITS
- */
-
-#ifndef FORMERT_H
-#define FORMERT_H
-
-
-#include "FormDialogView.h"
-
-
-class ControlERT;
-struct FD_ert;
-
-/** This class provides an XForms implementation of the ERT
-    Dialog.
- */
-class FormERT : public FormController<ControlERT, FormView<FD_ert> > {
-public:
-       ///
-       FormERT(Dialog &);
-private:
-       /// Set the Params variable for the Controller.
-       virtual void apply();
-       /// Build the dialog.
-       virtual void build();
-       /// Update dialog before/whilst showing it.
-       virtual void update();
-};
-
-#endif // FORMERT_H
Index: frontends/xforms/FormFree.C
===================================================================
RCS file: frontends/xforms/FormFree.C
diff -N frontends/xforms/FormFree.C
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ frontends/xforms/FormFree.C 6 Jun 2003 04:22:02 -0000
@@ -0,0 +1,70 @@
+/**
+ * \file FormFree.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Vigna
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <config.h>
+
+
+#include "xformsBC.h"
+#include "ControlFree.h"
+#include "FormFree.h"
+#include "forms/form_free.h"
+#include "support/lstrings.h"
+#include "helper_funcs.h"
+#include "debug.h"
+#include "lyx_forms.h"
+
+typedef  FormController<ControlFree, FormView<FD_free> > base_class;
+
+#warning FIXME: better title needed
+FormFree::FormFree(Dialog & parent)
+       : base_class(parent, _("Code Settings"))
+{}
+
+
+void FormFree::build()
+{
+       dialog_.reset(build_free(this));
+
+       // Manage the ok, apply and cancel/close buttons
+       bcview().setOK(dialog_->button_ok);
+       bcview().setApply(dialog_->button_apply);
+       bcview().setCancel(dialog_->button_close);
+
+       bcview().addReadOnly(dialog_->radio_open);
+       bcview().addReadOnly(dialog_->radio_collapsed);
+       bcview().addReadOnly(dialog_->radio_inlined);
+}
+
+
+void FormFree::apply()
+{
+       if (fl_get_button(dialog_->radio_open))
+               controller().setStatus(InsetFree::Open);
+       else if (fl_get_button(dialog_->radio_collapsed))
+               controller().setStatus(InsetFree::Collapsed);
+       else
+               controller().setStatus(InsetFree::Inlined);
+}
+
+
+void FormFree::update()
+{
+       switch (controller().status()) {
+       case InsetFree::Open:
+               fl_set_button(dialog_->radio_open, 1);
+               break;
+       case InsetFree::Collapsed:
+               fl_set_button(dialog_->radio_collapsed, 1);
+               break;
+       case InsetFree::Inlined:
+               fl_set_button(dialog_->radio_inlined, 1);
+               break;
+       }
+}
Index: frontends/xforms/FormFree.h
===================================================================
RCS file: frontends/xforms/FormFree.h
diff -N frontends/xforms/FormFree.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ frontends/xforms/FormFree.h 6 Jun 2003 04:22:02 -0000
@@ -0,0 +1,38 @@
+// -*- C++ -*-
+/**
+ * \file FormFree.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Vigna
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef FORMFREE_H
+#define FORMFREE_H
+
+
+#include "FormDialogView.h"
+
+
+class ControlFree;
+struct FD_free;
+
+/** This class provides an XForms implementation of the
+    Dialog for free spacing insets
+ */
+class FormFree : public FormController<ControlFree, FormView<FD_free> > {
+public:
+       ///
+       FormFree(Dialog &);
+private:
+       /// Set the Params variable for the Controller.
+       virtual void apply();
+       /// Build the dialog.
+       virtual void build();
+       /// Update dialog before/whilst showing it.
+       virtual void update();
+};
+
+#endif // FORMFREE_H
Index: frontends/xforms/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/Makefile.am,v
retrieving revision 1.98
diff -u -p -r1.98 Makefile.am
--- frontends/xforms/Makefile.am        14 May 2003 09:17:21 -0000      1.98
+++ frontends/xforms/Makefile.am        6 Jun 2003 04:22:02 -0000
@@ -83,14 +83,14 @@ libxforms_la_SOURCES = \
        FormError.h \
        FormErrorList.C \
        FormErrorList.h \
-       FormERT.C \
-       FormERT.h \
        FormExternal.C \
        FormExternal.h \
        FormFloat.C \
        FormFloat.h \
        FormForks.C \
        FormForks.h \
+       FormFree.C \
+       FormFree.h \
        FormGraphics.C \
        FormGraphics.h \
        FormInclude.C \
Index: frontends/xforms/forms/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/forms/Makefile.am,v
retrieving revision 1.20
diff -u -p -r1.20 Makefile.am
--- frontends/xforms/forms/Makefile.am  19 May 2003 19:12:30 -0000      1.20
+++ frontends/xforms/forms/Makefile.am  6 Jun 2003 04:22:02 -0000
@@ -19,11 +19,11 @@ SRCS =  form_aboutlyx.fd \
        form_document.fd \
        form_error.fd \
        form_errorlist.fd \
-       form_ert.fd \
        form_external.fd \
        form_filedialog.fd \
        form_float.fd \
        form_forks.fd \
+       form_free.fd \
        form_graphics.fd \
        form_include.fd \
        form_maths_delim.fd \
Index: insets/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/Makefile.am,v
retrieving revision 1.62
diff -u -p -r1.62 Makefile.am
--- insets/Makefile.am  3 Jun 2003 17:49:09 -0000       1.62
+++ insets/Makefile.am  6 Jun 2003 04:22:03 -0000
@@ -33,6 +33,8 @@ libinsets_la_SOURCES = \
        insetcaption.h \
        insetcite.C \
        insetcite.h \
+       insetcode.C \
+       insetcode.h \
        insetcollapsable.C \
        insetcollapsable.h \
        insetcommand.C \
@@ -55,6 +57,8 @@ libinsets_la_SOURCES = \
        insetfoot.h \
        insetfootlike.C \
        insetfootlike.h \
+       insetfree.C \
+       insetfree.h \
        insetgraphicsParams.h \
        insetgraphicsParams.C \
        insetgraphics.C \
Index: insets/inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v
retrieving revision 1.100
diff -u -p -r1.100 inset.h
--- insets/inset.h      4 Jun 2003 07:14:04 -0000       1.100
+++ insets/inset.h      6 Jun 2003 04:22:03 -0000
@@ -129,7 +129,9 @@ public:
                ///
                HFILL_CODE,
                ///
-               NEWLINE_CODE
+               NEWLINE_CODE,
+               ///
+               CODE_CODE
        };
 
        ///
Index: insets/insetcode.C
===================================================================
RCS file: insets/insetcode.C
diff -N insets/insetcode.C
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ insets/insetcode.C  6 Jun 2003 04:22:03 -0000
@@ -0,0 +1,125 @@
+/**
+ * \file insetcode.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Vigna
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS
+ */
+#include <config.h>
+
+#include "insetcode.h"
+#include "insettext.h"
+
+#include "buffer.h"
+#include "BufferView.h"
+#include "debug.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "language.h"
+#include "lyxfont.h"
+#include "lyxlex.h"
+#include "lyxrow.h"
+#include "lyxtext.h"
+#include "WordLangTuple.h"
+
+#include "frontends/Alert.h"
+#include "frontends/Dialogs.h"
+#include "frontends/LyXView.h"
+
+#include "support/LOstream.h"
+#include "support/LAssert.h"
+#include "support/tostr.h"
+
+
+using std::ostream;
+using std::min;
+using std::endl;
+
+using lyx::pos_type;
+
+
+void InsetCode::init()
+{
+       setInsetName("Code");
+       setButtonLabel();
+       labelfont = LyXFont(LyXFont::ALL_SANE);
+       labelfont.decSize();
+       labelfont.decSize();
+       labelfont.setColor(LColor::latex);
+}
+
+
+InsetCode::InsetCode(BufferParams const & bp, bool collapsed)
+       : InsetFree(bp, collapsed)
+{
+       init();
+}
+
+
+InsetCode::InsetCode(InsetCode const & in)
+       : InsetFree(in)
+{
+       init();
+}
+
+
+Inset * InsetCode::clone() const
+{
+       return new InsetCode(*this);
+}
+
+
+InsetCode::InsetCode(BufferParams const & bp,
+                  Language const * l, string const & contents, bool collapsed)
+       : InsetFree(bp, l, contents, collapsed)
+{
+       init();
+}
+
+
+InsetCode::~InsetCode()
+{
+}
+
+
+string const InsetCode::editMessage() const
+{
+       return _("Opened code");
+}
+
+
+bool InsetCode::insertInset(BufferView *, Inset *)
+{
+       // FIXME: we can allow more than nothing ...
+       return false;
+}
+
+
+void InsetCode::validate(LaTeXFeatures & f) const
+{
+       f.require("alltt");
+}
+
+
+int InsetCode::latex(Buffer const * b, ostream & os,
+                   LatexRunParams const & rp) const
+{
+       os << "\\begin{alltt}";
+
+       int const lines = InsetFree::latex(b, os, rp);
+       
+       os << "\\end{alltt}";
+
+       return lines;
+}
+
+
+void InsetCode::getDrawFont(LyXFont & font) const
+{
+       LyXFont f(LyXFont::ALL_INHERIT, latex_language);
+       font = f;
+       font.setFamily(LyXFont::TYPEWRITER_FAMILY);
+}
Index: insets/insetcode.h
===================================================================
RCS file: insets/insetcode.h
diff -N insets/insetcode.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ insets/insetcode.h  6 Jun 2003 04:22:03 -0000
@@ -0,0 +1,59 @@
+// -*- C++ -*-
+/**
+ * \file insetcode.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef INSETCODE_H
+#define INSETCODE_H
+
+#include "insetfree.h"
+
+/**
+ * A collapsable text inset for snippets of program code and similar.
+ */
+
+class InsetCode : public InsetFree {
+public:
+       ///
+       InsetCode(BufferParams const &, bool collapsed = false);
+       ///
+       InsetCode(InsetCode const &);
+       ///
+       Inset * clone() const;
+       ///
+       InsetCode(BufferParams const &,
+                Language const *, string const & contents, bool collapsed);
+       ///
+       ~InsetCode();
+       ///
+       Inset::Code lyxCode() const { return Inset::CODE_CODE; }
+       ///
+       string const editMessage() const;
+       ///
+       bool insertInset(BufferView *, Inset *);
+       /// FIXME: we can allow more than this but we have problems with the comment 
'%'
+       bool insetAllowed(Inset::Code code) const { return code == 
Inset::NEWLINE_CODE; }
+
+       /// latex output
+       int latex(Buffer const *, std::ostream &, LatexRunParams const &) const;
+       /// what latex features are needed
+       void validate(LaTeXFeatures &) const;
+       /// visual font
+       void getDrawFont(LyXFont &) const;
+
+       bool forceDefaultParagraphs(Inset const *) const {
+               return true;
+       }
+
+private:
+       void init();
+
+};
+
+#endif // INSETCODE_H
Index: insets/insetert.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.C,v
retrieving revision 1.129
diff -u -p -r1.129 insetert.C
--- insets/insetert.C   3 Jun 2003 15:10:08 -0000       1.129
+++ insets/insetert.C   6 Jun 2003 04:22:03 -0000
@@ -43,28 +43,24 @@ using lyx::pos_type;
 
 void InsetERT::init()
 {
+       setInsetName("ERT");
        setButtonLabel();
        labelfont = LyXFont(LyXFont::ALL_SANE);
        labelfont.decSize();
        labelfont.decSize();
        labelfont.setColor(LColor::latex);
-       setInsetName("ERT");
 }
 
 
 InsetERT::InsetERT(BufferParams const & bp, bool collapsed)
-       : InsetCollapsable(bp, collapsed)
+       : InsetFree(bp, collapsed)
 {
-       if (collapsed)
-               status_ = Collapsed;
-       else
-               status_ = Open;
        init();
 }
 
 
 InsetERT::InsetERT(InsetERT const & in)
-       : InsetCollapsable(in), status_(in.status_)
+       : InsetFree(in)
 {
        init();
 }
@@ -78,161 +74,20 @@ Inset * InsetERT::clone() const
 
 InsetERT::InsetERT(BufferParams const & bp,
                   Language const * l, string const & contents, bool collapsed)
-       : InsetCollapsable(bp, collapsed)
+       : InsetFree(bp, l, contents, collapsed)
 {
-       if (collapsed)
-               status_ = Collapsed;
-       else
-               status_ = Open;
-
-       LyXFont font(LyXFont::ALL_INHERIT, l);
-#ifdef SET_HARD_FONT
-       font.setFamily(LyXFont::TYPEWRITER_FAMILY);
-       font.setColor(LColor::latex);
-#endif
-
-       string::const_iterator cit = contents.begin();
-       string::const_iterator end = contents.end();
-       pos_type pos = 0;
-       for (; cit != end; ++cit) {
-               inset.paragraphs.begin()->insertChar(pos++, *cit, font);
-       }
-       // the init has to be after the initialization of the paragraph
-       // because of the label settings (draw_label for ert insets).
        init();
 }
 
 
 InsetERT::~InsetERT()
 {
-       InsetERTMailer mailer(*this);
-       mailer.hideDialog();
-}
-
-
-void InsetERT::read(Buffer const * buf, LyXLex & lex)
-{
-       bool token_found = false;
-       if (lex.isOK()) {
-               lex.next();
-               string const token = lex.getString();
-               if (token == "status") {
-                       lex.next();
-                       string const tmp_token = lex.getString();
-
-                       if (tmp_token == "Inlined") {
-                               status(0, Inlined);
-                       } else if (tmp_token == "Collapsed") {
-                               status(0, Collapsed);
-                       } else {
-                               // leave this as default!
-                               status(0, Open);
-                       }
-
-                       token_found = true;
-               } else {
-                       lyxerr << "InsetERT::Read: Missing 'status'-tag!"
-                                  << endl;
-                       // take countermeasures
-                       lex.pushToken(token);
-               }
-       }
-#if 0
-#warning this should be really short lived only for compatibility to
-#warning files written 07/08/2001 so this has to go before 1.2.0! (Jug)
-       if (lex.isOK()) {
-               lex.next();
-               string const token = lex.getString();
-               if (token == "collapsed") {
-                       lex.next();
-                       collapsed_ = lex.getBool();
-               } else {
-                       // Take countermeasures
-                       lex.pushToken(token);
-               }
-       }
-#endif
-       inset.read(buf, lex);
-
-#ifdef SET_HARD_FONT
-       LyXFont font(LyXFont::ALL_INHERIT, latex_language);
-       font.setFamily(LyXFont::TYPEWRITER_FAMILY);
-       font.setColor(LColor::latex);
-
-       ParagraphList::iterator pit = inset.paragraphs.begin();
-       ParagraphList::iterator pend = inset.paragraphs.end();
-       for (; pit != pend; ++pit) {
-               pos_type siz = pit->size();
-               for (pos_type i = 0; i < siz; ++i) {
-                       pit->setFont(i, font);
-               }
-       }
-#endif
-
-       if (!token_found) {
-               if (collapsed_) {
-                       status(0, Collapsed);
-               } else {
-                       status(0, Open);
-               }
-       }
-       setButtonLabel();
-}
-
-
-void InsetERT::write(Buffer const * buf, ostream & os) const
-{
-       string st;
-
-       switch (status_) {
-       case Open:
-               st = "Open";
-               break;
-       case Collapsed:
-               st = "Collapsed";
-               break;
-       case Inlined:
-               st = "Inlined";
-               break;
-       }
-
-       os << getInsetName() << "\n"
-          << "status "<< st << "\n";
-
-       //inset.writeParagraphData(buf, os);
-       string const layout(buf->params.getLyXTextClass().defaultLayoutName());
-       ParagraphList::iterator par = inset.paragraphs.begin();
-       ParagraphList::iterator end = inset.paragraphs.end();
-       for (; par != end; ++par) {
-               os << "\n\\layout " << layout << "\n";
-               pos_type siz = par->size();
-               for (pos_type i = 0; i < siz; ++i) {
-                       Paragraph::value_type c = par->getChar(i);
-                       switch (c) {
-                       case Paragraph::META_INSET:
-                               if (par->getInset(i)->lyxCode() != 
Inset::NEWLINE_CODE) {
-                                       lyxerr << "Element is not allowed in insertERT"
-                                              << endl;
-                               } else {
-                                       par->getInset(i)->write(buf, os);
-                               }
-                               break;
-
-                       case '\\':
-                               os << "\n\\backslash \n";
-                               break;
-                       default:
-                               os << c;
-                               break;
-                       }
-               }
-       }
 }
 
 
 string const InsetERT::editMessage() const
 {
-       return _("Opened ERT Inset");
+       return _("Opened TeX Code");
 }
 
 
@@ -242,87 +97,6 @@ bool InsetERT::insertInset(BufferView *,
 }
 
 
-void InsetERT::setFont(BufferView *, LyXFont const &, bool, bool selectall)
-{
-#ifdef WITH_WARNINGS
-#warning FIXME. More UI stupidity...
-#endif
-       // if selectall is activated then the fontchange was an outside general
-       // fontchange and this messages is not needed
-       if (!selectall)
-               Alert::error(_("Cannot change font"),
-                          _("You cannot change font settings inside TeX code."));
-}
-
-
-void InsetERT::updateStatus(BufferView * bv, bool swap) const
-{
-       if (status_ != Inlined) {
-               if (collapsed_) {
-                       status(bv, swap ? Open : Collapsed);
-               } else {
-                       status(bv, swap ? Collapsed : Open);
-               }
-       }
-}
-
-
-Inset::EDITABLE InsetERT::editable() const
-{
-       if (status_ == Collapsed)
-               return IS_EDITABLE;
-       return HIGHLY_EDITABLE;
-}
-
-
-void InsetERT::lfunMousePress(FuncRequest const & cmd)
-{
-       if (status_ == Inlined)
-               inset.localDispatch(cmd);
-       else
-               InsetCollapsable::localDispatch(cmd);
-}
-
-
-bool InsetERT::lfunMouseRelease(FuncRequest const & cmd)
-{
-       BufferView * bv = cmd.view();
-
-       if (cmd.button() == mouse_button::button3) {
-               showInsetDialog(bv);
-               return true;
-       }
-
-       if (status_ != Inlined && (cmd.x >= 0) && (cmd.x < button_length) &&
-           (cmd.y >= button_top_y) && (cmd.y <= button_bottom_y)) {
-               updateStatus(bv, true);
-       } else {
-               LyXFont font(LyXFont::ALL_SANE);
-               FuncRequest cmd1 = cmd;
-               cmd1.y = ascent(bv, font) + cmd.y - inset.ascent(bv, font);
-
-               // inlined is special - the text appears above
-               // button_bottom_y
-               if (status_ == Inlined)
-                       inset.localDispatch(cmd1);
-               else if (!collapsed_ && (cmd.y > button_bottom_y)) {
-                       cmd1.y -= height_collapsed();
-                       inset.localDispatch(cmd1);
-               }
-       }
-       return false;
-}
-
-
-void InsetERT::lfunMouseMotion(FuncRequest const & cmd)
-{
-       if (status_ == Inlined)
-               inset.localDispatch(cmd);
-       else
-               InsetCollapsable::localDispatch(cmd);
-}
-
-
 int InsetERT::latex(Buffer const *, ostream & os,
                    LatexRunParams const &) const
 {
@@ -346,7 +120,7 @@ int InsetERT::latex(Buffer const *, ostr
                }
                ++par;
                if (par != end) {
-                       os << "\n\n";
+                       os << "\n";
                        lines += 2;
                }
        }
@@ -415,299 +189,10 @@ int InsetERT::docbook(Buffer const *, os
 }
 
 
-Inset::RESULT InsetERT::localDispatch(FuncRequest const & cmd)
-{
-       Inset::RESULT result = UNDISPATCHED;
-       BufferView * bv = cmd.view();
-
-       if (inset.paragraphs.begin()->empty()) {
-               set_latex_font(bv);
-       }
-
-       switch (cmd.action) {
-
-       case LFUN_INSET_EDIT:
-               if (cmd.button() == mouse_button::button3)
-                       break;
-               if (status_ == Inlined) {
-                       if (!bv->lockInset(this))
-                               break;
-                       result = inset.localDispatch(cmd);
-               } else {
-                       result = InsetCollapsable::localDispatch(cmd);
-               }
-               set_latex_font(bv);
-               updateStatus(bv);
-               break;
-
-       case LFUN_INSET_MODIFY: {
-               InsetERT::ERTStatus status_;
-               InsetERTMailer::string2params(cmd.argument, status_);
-
-               status(bv, status_);
-
-               /* FIXME: I refuse to believe we have to live
-                * with ugliness like this ! Note that this
-                * rebreak *is* needed. Consider a change from
-                * Open (needfullrow) to Inlined (only the space
-                * taken by the text).
-                */
-               LyXText * t = inset.getLyXText(cmd.view());
-               t->need_break_row = t->rows().begin();
-               t->fullRebreak();
-               t->setCursorIntern(t->cursor.par(), t->cursor.pos());
-               inset.update(cmd.view(), true);
-               bv->updateInset(this);
-               result = DISPATCHED;
-       }
-       break;
-
-       case LFUN_MOUSE_PRESS:
-               lfunMousePress(cmd);
-               result = DISPATCHED;
-               break;
-
-       case LFUN_MOUSE_MOTION:
-               lfunMouseMotion(cmd);
-               result = DISPATCHED;
-               break;
-
-       case LFUN_MOUSE_RELEASE:
-               lfunMouseRelease(cmd);
-               result = DISPATCHED;
-               break;
-
-       case LFUN_LAYOUT:
-               bv->owner()->setLayout(inset.paragraphs.begin()->layout()->name());
-               result = DISPATCHED_NOUPDATE;
-               break;
-
-       default:
-               result = InsetCollapsable::localDispatch(cmd);
-       }
-
-       switch (cmd.action) {
-       case LFUN_BREAKPARAGRAPH:
-       case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
-       case LFUN_BACKSPACE:
-       case LFUN_BACKSPACE_SKIP:
-       case LFUN_DELETE:
-       case LFUN_DELETE_SKIP:
-       case LFUN_DELETE_LINE_FORWARD:
-       case LFUN_CUT:
-               set_latex_font(bv);
-               break;
-
-       default:
-               break;
-       }
-       return result;
-}
-
-
-string const InsetERT::get_new_label() const
-{
-       string la;
-       pos_type const max_length = 15;
-       pos_type const p_siz = inset.paragraphs.begin()->size();
-       pos_type const n = min(max_length, p_siz);
-       pos_type i = 0;
-       pos_type j = 0;
-       for(; i < n && j < p_siz; ++j) {
-               if (inset.paragraphs.begin()->isInset(j))
-                       continue;
-               la += inset.paragraphs.begin()->getChar(j);
-               ++i;
-       }
-       if (boost::next(inset.paragraphs.begin()) != inset.paragraphs.end() ||
-           (i > 0 && j < p_siz)) {
-               la += "...";
-       }
-       if (la.empty()) {
-               la = _("ERT");
-       }
-       return la;
-}
-
-
-void InsetERT::setButtonLabel() const
-{
-       if (status_ == Collapsed) {
-               setLabel(get_new_label());
-       } else {
-               setLabel(_("ERT"));
-       }
-}
-
-
-bool InsetERT::checkInsertChar(LyXFont & /* font */)
-{
-#ifdef SET_HARD_FONT
-       LyXFont f(LyXFont::ALL_INHERIT, latex_language);
-       font = f;
-       font.setFamily(LyXFont::TYPEWRITER_FAMILY);
-       font.setColor(LColor::latex);
-#endif
-       return true;
-}
-
-
-void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
-{
-       if (inlined())
-               inset.metrics(mi, dim);
-       else
-               InsetCollapsable::metrics(mi, dim);
-}
-
-
-void InsetERT::draw(PainterInfo & pi, int x, int y) const
-{
-       InsetCollapsable::draw(pi, x, y, inlined());
-}
-
-
-void InsetERT::set_latex_font(BufferView * /* bv */)
-{
-#ifdef SET_HARD_FONT
-       LyXFont font(LyXFont::ALL_INHERIT, latex_language);
-
-       font.setFamily(LyXFont::TYPEWRITER_FAMILY);
-       font.setColor(LColor::latex);
-
-       inset.getLyXText(bv)->setFont(bv, font, false);
-#endif
-}
-
-
-// attention this function can be called with bv == 0
-void InsetERT::status(BufferView * bv, ERTStatus const st) const
-{
-       if (st != status_) {
-               status_ = st;
-               switch (st) {
-               case Inlined:
-                       if (bv)
-                               inset.setUpdateStatus(bv, InsetText::INIT);
-                       break;
-               case Open:
-                       collapsed_ = false;
-                       setButtonLabel();
-                       break;
-               case Collapsed:
-                       collapsed_ = true;
-                       setButtonLabel();
-                       if (bv)
-                               bv->unlockInset(const_cast<InsetERT *>(this));
-                       break;
-               }
-               if (bv) {
-                       bv->updateInset(const_cast<InsetERT *>(this));
-                       bv->buffer()->markDirty();
-               }
-       }
-}
-
-
-bool InsetERT::showInsetDialog(BufferView * bv) const
-{
-       InsetERTMailer mailer(const_cast<InsetERT &>(*this));
-       mailer.showDialog(bv);
-       return true;
-}
-
-
-void InsetERT::open(BufferView * bv)
-{
-       if (!collapsed_)
-               return;
-       status(bv, Open);
-}
-
-
-void InsetERT::close(BufferView * bv) const
-{
-       if (status_ == Collapsed || status_ == Inlined)
-               return;
-
-       status(bv, Collapsed);
-}
-
-
-WordLangTuple const
-InsetERT::selectNextWordToSpellcheck(BufferView * bv, float &) const
-{
-       bv->unlockInset(const_cast<InsetERT *>(this));
-       return WordLangTuple();
-}
-
-
 void InsetERT::getDrawFont(LyXFont & font) const
 {
        LyXFont f(LyXFont::ALL_INHERIT, latex_language);
        font = f;
        font.setFamily(LyXFont::TYPEWRITER_FAMILY);
        font.setColor(LColor::latex);
-}
-
-
-int InsetERT::getMaxWidth(BufferView * bv, UpdatableInset const * in) const
-{
-       int w = InsetCollapsable::getMaxWidth(bv, in);
-       if (status_ != Inlined || w < 0)
-               return w;
-       LyXText * text = inset.getLyXText(bv);
-       int rw = text->rows().begin()->width();
-       if (!rw)
-               rw = w;
-       rw += 40;
-       if (text->rows().size() == 1 && rw < w)
-               return -1;
-       return w;
-}
-
-
-void InsetERT::update(BufferView * bv, bool reinit)
-{
-       if (inset.need_update & InsetText::INIT ||
-           inset.need_update & InsetText::FULL) {
-               setButtonLabel();
-       }
-
-       InsetCollapsable::update(bv, reinit);
-}
-
-
-string const InsetERTMailer::name_("ert");
-
-InsetERTMailer::InsetERTMailer(InsetERT & inset)
-       : inset_(inset)
-{}
-
-
-string const InsetERTMailer::inset2string() const
-{
-       return params2string(inset_.status());
-}
-
-
-void InsetERTMailer::string2params(string const & in,
-                                  InsetERT::ERTStatus & status)
-{
-       status = InsetERT::Collapsed;
-
-       string name;
-       string body = split(in, name, ' ');
-
-       if (body.empty())
-               return;
-
-       status = static_cast<InsetERT::ERTStatus>(strToInt(body));
-}
-
-
-string const
-InsetERTMailer::params2string(InsetERT::ERTStatus status)
-{
-       return name_ + ' ' + tostr(status);
 }
Index: insets/insetert.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.h,v
retrieving revision 1.75
diff -u -p -r1.75 insetert.h
--- insets/insetert.h   3 Jun 2003 15:10:08 -0000       1.75
+++ insets/insetert.h   6 Jun 2003 04:22:03 -0000
@@ -13,8 +13,7 @@
 #ifndef INSETERT_H
 #define INSETERT_H
 
-
-#include "insetcollapsable.h"
+#include "insetfree.h"
 
 /** A collapsable text inset for LaTeX insertions.
 
@@ -25,17 +24,9 @@
   versions of this inset.
 */
 
-class Language;
-
-class InsetERT : public InsetCollapsable {
+class InsetERT : public InsetFree {
 public:
        ///
-       enum ERTStatus {
-               Open,
-               Collapsed,
-               Inlined
-       };
-       ///
        InsetERT(BufferParams const &, bool collapsed = false);
        ///
        InsetERT(InsetERT const &);
@@ -49,21 +40,12 @@ public:
        ///
        Inset::Code lyxCode() const { return Inset::ERT_CODE; }
        ///
-       void read(Buffer const * buf, LyXLex & lex);
-       ///
-       void write(Buffer const * buf, std::ostream & os) const;
-       ///
        string const editMessage() const;
        ///
        bool insertInset(BufferView *, Inset *);
        ///
        bool insetAllowed(Inset::Code code) const { return code == 
Inset::NEWLINE_CODE; }
        ///
-       void setFont(BufferView *, LyXFont const &,
-                            bool toggleall = false, bool selectall = false);
-       ///
-       EDITABLE editable() const;
-       ///
        int latex(Buffer const *, std::ostream &,
                  LatexRunParams const &) const;
        ///
@@ -76,95 +58,15 @@ public:
        ///
        void validate(LaTeXFeatures &) const {}
        ///
-       RESULT localDispatch(FuncRequest const &);
-       ///
-       bool checkInsertChar(LyXFont &);
-       ///
-       // this are needed here because of the label/inlined functionallity
-       ///
-       bool needFullRow() const { return status_ == Open; }
-       ///
-       bool isOpen() const { return status_ == Open || status_ == Inlined; }
-       ///
-       bool inlined() const { return status_ == Inlined; }
-       ///
-       ERTStatus status() const { return status_; }
-       ///
-       void open(BufferView *);
-       ///
-       void close(BufferView *) const;
-       ///
-       bool allowSpellcheck() const { return false; }
-
-       WordLangTuple const
-       selectNextWordToSpellcheck(BufferView *, float &) const;
-       ///
-       void metrics(MetricsInfo &, Dimension &) const;
-       ///
-       void draw(PainterInfo & pi, int x, int y) const;
-       /// set the status of the inset
-       void status(BufferView *, ERTStatus const st) const;
-       ///
-       bool showInsetDialog(BufferView *) const;
-       ///
        void getDrawFont(LyXFont &) const;
        ///
        bool forceDefaultParagraphs(Inset const *) const {
                return true;
        }
-       ///
-       int getMaxWidth(BufferView *, UpdatableInset const *) const;
-       ///
-       void update(BufferView *, bool =false);
 
 private:
-       ///
-       void lfunMousePress(FuncRequest const &);
-       ///
-       // the bool return is used to see if we opened a dialog so that we can
-       // check this from an outer inset and open the dialog of the outer inset
-       // if that one has one!
-       ///
-       bool lfunMouseRelease(FuncRequest const &);
-       ///
-       void lfunMouseMotion(FuncRequest const &);
-       ///
        void init();
-       ///
-       string const get_new_label() const;
-       ///
-       void setButtonLabel() const;
-       ///
-       void set_latex_font(BufferView *);
-       /// update status on button
-       void updateStatus(BufferView *, bool = false) const;
-
-       ///
-       mutable ERTStatus status_;
-};
-
 
-#include "mailinset.h"
-
-class InsetERTMailer : public MailInset {
-public:
-       ///
-       InsetERTMailer(InsetERT & inset);
-       ///
-       virtual InsetBase & inset() const { return inset_; }
-       ///
-       virtual string const & name() const { return name_; }
-       ///
-       virtual string const inset2string() const;
-       ///
-       static void string2params(string const &, InsetERT::ERTStatus &);
-       ///
-       static string const params2string(InsetERT::ERTStatus);
-private:
-       ///
-       static string const name_;
-       ///
-       InsetERT & inset_;
 };
 
 #endif
Index: insets/insetfree.C
===================================================================
RCS file: insets/insetfree.C
diff -N insets/insetfree.C
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ insets/insetfree.C  6 Jun 2003 04:22:04 -0000
@@ -0,0 +1,497 @@
+/**
+ * \file insetfree.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Vigna
+ * \author Lars Gullik Bjønnes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+#include <config.h>
+
+#include "insetfree.h"
+#include "insettext.h"
+
+#include "buffer.h"
+#include "BufferView.h"
+#include "debug.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "language.h"
+#include "lyxfont.h"
+#include "lyxlex.h"
+#include "lyxrow.h"
+#include "lyxtext.h"
+#include "WordLangTuple.h"
+
+#include "frontends/Alert.h"
+#include "frontends/Dialogs.h"
+#include "frontends/LyXView.h"
+
+#include "support/LOstream.h"
+#include "support/LAssert.h"
+#include "support/tostr.h"
+
+
+using std::ostream;
+using std::min;
+using std::endl;
+
+using lyx::pos_type;
+
+
+InsetFree::InsetFree(BufferParams const & bp, bool collapsed)
+       : InsetCollapsable(bp, collapsed)
+{
+       if (collapsed)
+               status_ = Collapsed;
+       else
+               status_ = Open;
+}
+
+
+InsetFree::InsetFree(InsetFree const & in)
+       : InsetCollapsable(in), status_(in.status_)
+{
+}
+
+
+InsetFree::InsetFree(BufferParams const & bp,
+                  Language const * l, string const & contents, bool collapsed)
+       : InsetCollapsable(bp, collapsed)
+{
+       if (collapsed)
+               status_ = Collapsed;
+       else
+               status_ = Open;
+
+       LyXFont font(LyXFont::ALL_INHERIT, l);
+
+       string::const_iterator cit = contents.begin();
+       string::const_iterator end = contents.end();
+       pos_type pos = 0;
+       for (; cit != end; ++cit) {
+               inset.paragraphs.begin()->insertChar(pos++, *cit, font);
+       }
+       // the init has to be after the initialization of the paragraph
+       // because of the label settings (draw_label for free insets).
+}
+
+
+InsetFree::~InsetFree()
+{
+       InsetFreeMailer mailer(*this);
+       mailer.hideDialog();
+}
+
+
+void InsetFree::read(Buffer const * buf, LyXLex & lex)
+{
+       bool token_found = false;
+       if (lex.isOK()) {
+               lex.next();
+               string const token = lex.getString();
+               if (token == "status") {
+                       lex.next();
+                       string const tmp_token = lex.getString();
+
+                       if (tmp_token == "Inlined") {
+                               status(0, Inlined);
+                       } else if (tmp_token == "Collapsed") {
+                               status(0, Collapsed);
+                       } else {
+                               // leave this as default!
+                               status(0, Open);
+                       }
+
+                       token_found = true;
+               } else {
+                       lyxerr << "InsetFree::Read: Missing 'status'-tag!"
+                                  << endl;
+                       // take countermeasures
+                       lex.pushToken(token);
+               }
+       }
+       inset.read(buf, lex);
+
+       if (!token_found) {
+               if (collapsed_) {
+                       status(0, Collapsed);
+               } else {
+                       status(0, Open);
+               }
+       }
+       setButtonLabel();
+}
+
+
+void InsetFree::write(Buffer const * buf, ostream & os) const
+{
+       string st;
+
+       switch (status_) {
+       case Open:
+               st = "Open";
+               break;
+       case Collapsed:
+               st = "Collapsed";
+               break;
+       case Inlined:
+               st = "Inlined";
+               break;
+       }
+
+       os << getInsetName() << "\n"
+          << "status "<< st << "\n";
+
+       string const layout(buf->params.getLyXTextClass().defaultLayoutName());
+       ParagraphList::iterator par = inset.paragraphs.begin();
+       ParagraphList::iterator end = inset.paragraphs.end();
+       for (; par != end; ++par) {
+               os << "\n\\layout " << layout << "\n";
+               pos_type siz = par->size();
+               for (pos_type i = 0; i < siz; ++i) {
+                       Paragraph::value_type c = par->getChar(i);
+                       switch (c) {
+                       case Paragraph::META_INSET:
+                               par->getInset(i)->write(buf, os);
+                               break;
+
+                       case '\\':
+                               os << "\n\\backslash \n";
+                               break;
+                       default:
+                               os << c;
+                               break;
+                       }
+               }
+       }
+}
+
+
+void InsetFree::setFont(BufferView *, LyXFont const &, bool, bool selectall)
+{
+#ifdef WITH_WARNINGS
+#warning FIXME. More UI stupidity...
+#endif
+       // if selectall is activated then the fontchange was an outside general
+       // fontchange and this messages is not needed
+       if (!selectall)
+               Alert::error(_("Cannot change font"),
+                          _("You cannot change font settings inside code."));
+}
+
+
+void InsetFree::updateStatus(BufferView * bv, bool swap) const
+{
+       if (status_ != Inlined) {
+               if (collapsed_) {
+                       status(bv, swap ? Open : Collapsed);
+               } else {
+                       status(bv, swap ? Collapsed : Open);
+               }
+       }
+}
+
+
+Inset::EDITABLE InsetFree::editable() const
+{
+       if (status_ == Collapsed)
+               return IS_EDITABLE;
+       return HIGHLY_EDITABLE;
+}
+
+
+void InsetFree::lfunMousePress(FuncRequest const & cmd)
+{
+       if (status_ == Inlined)
+               inset.localDispatch(cmd);
+       else
+               InsetCollapsable::localDispatch(cmd);
+}
+
+
+bool InsetFree::lfunMouseRelease(FuncRequest const & cmd)
+{
+       BufferView * bv = cmd.view();
+
+       if (cmd.button() == mouse_button::button3) {
+               showInsetDialog(bv);
+               return true;
+       }
+
+       if (status_ != Inlined && (cmd.x >= 0) && (cmd.x < button_length) &&
+           (cmd.y >= button_top_y) && (cmd.y <= button_bottom_y)) {
+               updateStatus(bv, true);
+       } else {
+               LyXFont font(LyXFont::ALL_SANE);
+               FuncRequest cmd1 = cmd;
+               cmd1.y = ascent(bv, font) + cmd.y - inset.ascent(bv, font);
+
+               // inlined is special - the text appears above
+               // button_bottom_y
+               if (status_ == Inlined)
+                       inset.localDispatch(cmd1);
+               else if (!collapsed_ && (cmd.y > button_bottom_y)) {
+                       cmd1.y -= height_collapsed();
+                       inset.localDispatch(cmd1);
+               }
+       }
+       return false;
+}
+
+
+void InsetFree::lfunMouseMotion(FuncRequest const & cmd)
+{
+       if (status_ == Inlined)
+               inset.localDispatch(cmd);
+       else
+               InsetCollapsable::localDispatch(cmd);
+}
+
+
+Inset::RESULT InsetFree::localDispatch(FuncRequest const & cmd)
+{
+       Inset::RESULT result = UNDISPATCHED;
+       BufferView * bv = cmd.view();
+
+       switch (cmd.action) {
+
+       case LFUN_INSET_EDIT:
+               if (cmd.button() == mouse_button::button3)
+                       break;
+               if (status_ == Inlined) {
+                       if (!bv->lockInset(this))
+                               break;
+                       result = inset.localDispatch(cmd);
+               } else {
+                       result = InsetCollapsable::localDispatch(cmd);
+               }
+               updateStatus(bv);
+               break;
+
+       case LFUN_INSET_MODIFY: {
+               FreeStatus status_;
+               InsetFreeMailer::string2params(cmd.argument, status_);
+
+               status(bv, status_);
+
+               /* FIXME: I refuse to believe we have to live
+                * with ugliness like this ! Note that this
+                * rebreak *is* needed. Consider a change from
+                * Open (needfullrow) to Inlined (only the space
+                * taken by the text).
+                */
+               LyXText * t = inset.getLyXText(cmd.view());
+               t->need_break_row = t->rows().begin();
+               t->fullRebreak();
+               t->setCursorIntern(t->cursor.par(), t->cursor.pos());
+               inset.update(cmd.view(), true);
+               bv->updateInset(this);
+               result = DISPATCHED;
+       }
+       break;
+
+       case LFUN_MOUSE_PRESS:
+               lfunMousePress(cmd);
+               result = DISPATCHED;
+               break;
+
+       case LFUN_MOUSE_MOTION:
+               lfunMouseMotion(cmd);
+               result = DISPATCHED;
+               break;
+
+       case LFUN_MOUSE_RELEASE:
+               lfunMouseRelease(cmd);
+               result = DISPATCHED;
+               break;
+
+       case LFUN_LAYOUT:
+               bv->owner()->setLayout(inset.paragraphs.begin()->layout()->name());
+               result = DISPATCHED_NOUPDATE;
+               break;
+
+       default:
+               result = InsetCollapsable::localDispatch(cmd);
+       }
+
+       return result;
+}
+
+
+string const InsetFree::get_new_label() const
+{
+       string la;
+       pos_type const max_length = 15;
+       pos_type const p_siz = inset.paragraphs.begin()->size();
+       pos_type const n = min(max_length, p_siz);
+       pos_type i = 0;
+       pos_type j = 0;
+       for(; i < n && j < p_siz; ++j) {
+               if (inset.paragraphs.begin()->isInset(j))
+                       continue;
+               la += inset.paragraphs.begin()->getChar(j);
+               ++i;
+       }
+       if (boost::next(inset.paragraphs.begin()) != inset.paragraphs.end() ||
+           (i > 0 && j < p_siz)) {
+               la += "...";
+       }
+
+       if (la.empty())
+               la = _(getInsetName());
+
+       return la;
+}
+
+
+void InsetFree::setButtonLabel() const
+{
+       if (status_ == Collapsed) {
+               setLabel(get_new_label());
+       } else {
+               setLabel(_(getInsetName()));
+       }
+}
+
+
+void InsetFree::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       if (inlined())
+               inset.metrics(mi, dim);
+       else
+               InsetCollapsable::metrics(mi, dim);
+}
+
+
+void InsetFree::draw(PainterInfo & pi, int x, int y) const
+{
+       InsetCollapsable::draw(pi, x, y, inlined());
+}
+
+
+// attention this function can be called with bv == 0
+void InsetFree::status(BufferView * bv, FreeStatus const st) const
+{
+       if (st != status_) {
+               status_ = st;
+               switch (st) {
+               case Inlined:
+                       if (bv)
+                               inset.setUpdateStatus(bv, InsetText::INIT);
+                       break;
+               case Open:
+                       collapsed_ = false;
+                       setButtonLabel();
+                       break;
+               case Collapsed:
+                       collapsed_ = true;
+                       setButtonLabel();
+                       if (bv)
+                               bv->unlockInset(const_cast<InsetFree *>(this));
+                       break;
+               }
+               if (bv) {
+                       bv->updateInset(const_cast<InsetFree *>(this));
+                       bv->buffer()->markDirty();
+               }
+       }
+}
+
+
+void InsetFree::open(BufferView * bv)
+{
+       if (!collapsed_)
+               return;
+       status(bv, Open);
+}
+
+
+void InsetFree::close(BufferView * bv) const
+{
+       if (status_ == Collapsed || status_ == Inlined)
+               return;
+
+       status(bv, Collapsed);
+}
+
+
+WordLangTuple const
+InsetFree::selectNextWordToSpellcheck(BufferView * bv, float &) const
+{
+       bv->unlockInset(const_cast<InsetFree *>(this));
+       return WordLangTuple();
+}
+
+
+int InsetFree::getMaxWidth(BufferView * bv, UpdatableInset const * in) const
+{
+       int w = InsetCollapsable::getMaxWidth(bv, in);
+       if (status_ != Inlined || w < 0)
+               return w;
+       LyXText * text = inset.getLyXText(bv);
+       int rw = text->rows().begin()->width();
+       if (!rw)
+               rw = w;
+       rw += 40;
+       if (text->rows().size() == 1 && rw < w)
+               return -1;
+       return w;
+}
+
+
+void InsetFree::update(BufferView * bv, bool reinit)
+{
+       if (inset.need_update & InsetText::INIT ||
+           inset.need_update & InsetText::FULL) {
+               setButtonLabel();
+       }
+
+       InsetCollapsable::update(bv, reinit);
+}
+
+
+bool InsetFree::showInsetDialog(BufferView * bv) const
+{
+       InsetFreeMailer mailer(const_cast<InsetFree &>(*this));
+       mailer.showDialog(bv);
+       return true;
+}
+
+
+string const InsetFreeMailer::name_("free");
+
+InsetFreeMailer::InsetFreeMailer(InsetFree & inset)
+       : inset_(inset)
+{}
+
+
+string const InsetFreeMailer::inset2string() const
+{
+       return params2string(inset_.status());
+}
+
+
+void InsetFreeMailer::string2params(string const & in,
+                                  InsetFree::FreeStatus & status)
+{
+       status = InsetFree::Collapsed;
+
+       string name;
+       string body = split(in, name, ' ');
+
+       if (body.empty())
+               return;
+
+       status = static_cast<InsetFree::FreeStatus>(strToInt(body));
+}
+
+
+string const
+InsetFreeMailer::params2string(InsetFree::FreeStatus status)
+{
+       return name_ + ' ' + tostr(status);
+}
Index: insets/insetfree.h
===================================================================
RCS file: insets/insetfree.h
diff -N insets/insetfree.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ insets/insetfree.h  6 Jun 2003 04:22:04 -0000
@@ -0,0 +1,134 @@
+// -*- C++ -*-
+/**
+ * \file insetfree.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Vigna
+ * \author Lars Gullik Bjønnes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef INSETFREE_H
+#define INSETFREE_H
+
+#include "insetcollapsable.h"
+
+class Language;
+
+/** 
+ * A collapsable text inset for free-spaced code such as ERT.
+ *
+ * Note that collapsed_ encompasses both the inline and collapsed button
+ * versions of this inset.
+ */
+class InsetFree : public InsetCollapsable {
+public:
+       ///
+       enum FreeStatus {
+               Open,
+               Collapsed,
+               Inlined
+       };
+       ///
+       InsetFree(BufferParams const &, bool collapsed = false);
+       ///
+       InsetFree(InsetFree const &);
+       ///
+       InsetFree(BufferParams const &,
+                Language const *, string const & contents, bool collapsed);
+       ///
+       ~InsetFree();
+       ///
+       void read(Buffer const * buf, LyXLex & lex);
+       ///
+       void write(Buffer const * buf, std::ostream & os) const;
+       ///
+       void setFont(BufferView *, LyXFont const &,
+                            bool toggleall = false, bool selectall = false);
+       ///
+       EDITABLE editable() const;
+       ///
+       RESULT localDispatch(FuncRequest const &);
+       ///
+       // this are needed here because of the label/inlined functionallity
+       ///
+       bool needFullRow() const { return status_ == Open; }
+       ///
+       bool isOpen() const { return status_ == Open || status_ == Inlined; }
+       ///
+       bool inlined() const { return status_ == Inlined; }
+       ///
+       FreeStatus status() const { return status_; }
+       ///
+       void open(BufferView *);
+       ///
+       void close(BufferView *) const;
+       ///
+       bool allowSpellcheck() const { return false; }
+
+       WordLangTuple const
+       selectNextWordToSpellcheck(BufferView *, float &) const;
+       ///
+       void metrics(MetricsInfo &, Dimension &) const;
+       ///
+       void draw(PainterInfo & pi, int x, int y) const;
+       /// set the status of the inset
+       void status(BufferView *, FreeStatus const st) const;
+       ///
+       int getMaxWidth(BufferView *, UpdatableInset const *) const;
+       ///
+       void update(BufferView *, bool =false);
+
+       bool showInsetDialog(BufferView * bv) const;
+
+protected:
+       /// reset the label
+       virtual void setButtonLabel() const;
+
+private:
+       ///
+       void lfunMousePress(FuncRequest const &);
+       ///
+       // the bool return is used to see if we opened a dialog so that we can
+       // check this from an outer inset and open the dialog of the outer inset
+       // if that one has one!
+       ///
+       bool lfunMouseRelease(FuncRequest const &);
+       ///
+       void lfunMouseMotion(FuncRequest const &);
+       /// content-showing label
+       string const get_new_label() const;
+       /// update status on button
+       void updateStatus(BufferView *, bool = false) const;
+
+       ///
+       mutable FreeStatus status_;
+};
+
+#include "mailinset.h"
+
+class InsetFreeMailer : public MailInset {
+public:
+       ///
+       InsetFreeMailer(InsetFree & inset);
+       ///
+       virtual InsetBase & inset() const { return inset_; }
+       ///
+       virtual string const & name() const { return name_; }
+       ///
+       virtual string const inset2string() const;
+       ///
+       static void string2params(string const &, InsetFree::FreeStatus &);
+       ///
+       static string const params2string(InsetFree::FreeStatus);
+private:
+       ///
+       static string const name_;
+       ///
+       InsetFree & inset_;
+};
+
+#endif

Reply via email to