+2000-02-24 Juergen Vigna <jug@sad.it>
+
+ * src/buffer.C:
+ * src/commandtags.h:
+ * src/LyXAction.C:
+ * src/lyxfunc.C: added code for LFUN_INSET_ERT and LFUN_INSET_TEXT
+
+ * src/BufferView.h
+ * src/BufferView.C
+ * src/BufferView2.C: added/updated code for various inset-functions
+
+ * src/insets/insetert.[Ch]: added implementation of InsetERT
+
+ * src/insets/insettext.[Ch]: added implementation of InsetText
+
+ * src/insets/inset.C (Edit): added "unsigned int button" parameter
+ (draw): added preliminary code for inset scrolling not finshed yet
+
+ * src/insets/inset.C (LocalDispatch): changed arg parameter to string
+ as it is in lyxfunc.C now
+
+ * src/insets/lyxinset.h: Added functions for text-insets
+
2000-02-22 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/lyx_cb.C src/UpdateInset.[Ch]: move the updateinsetlist into
src/insets/insetbib.C
src/insets/inseterror.C
src/insets/inseterror.h
+src/insets/insetert.C
src/insets/insetinclude.C
src/insets/insetindex.C
src/insets/insetinfo.C
src/insets/insetlot.h
src/insets/insetparent.h
src/insets/insetref.C
+src/insets/insettext.C
src/insets/insettoc.h
src/insets/inseturl.C
src/insets/inseturl.h
selection_possible = false;
owner_->updateLayoutChoice();
owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
- inset_hit->Edit(this, xpos, ypos);
+ inset_hit->Edit(this, xpos, ypos, button);
return;
}
}
owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
- inset_hit->Edit(this, x, y);
+ inset_hit->Edit(this, x, y, button);
return;
}
textclasslist
.TextClass(buffer_->
params.textclass).defaultfont())) {
- text->cursor.par->bibkey->Edit(this, 0, 0);
+ text->cursor.par->bibkey->Edit(this, 0, 0, 0);
}
return;
return 0;
}
-
void BufferView::workAreaExpose()
{
// this is a hack to ensure that we only call this through
void BufferView::insetWakeup()
{
if (the_locking_inset && inset_slept) {
- the_locking_inset->Edit(this, slx, sly);
+ the_locking_inset->Edit(this, slx, sly, 0);
inset_slept = false;
}
}
}
+Painter & BufferView::getPainter() const
+{
+ return workarea->getPainter();
+}
+
+
+unsigned short BufferView::paperWidth() const
+{
+ return text->paperWidth();
+}
+
+
bool BufferView::belowMouse() const
{
return workarea->belowMouse();
///
Painter & painter();
///
+ Painter & getPainter() const;
+ ///
void buffer(Buffer * b);
///
void resize(int, int, int, int);
*/
LyXText * text;
///
+ unsigned short paperWidth() const;
+ ///
UpdatableInset * the_locking_inset;
///
+ void updateInset(Inset * inset, bool mark_dirty);
+ ///
bool inset_slept;
///
int slx;
///
UpdateInset updatelist;
public:
- ///
- void updateInset(Inset *, bool);
///
void pushIntoUpdateList(Inset * i) {
updatelist.push(i);
insertInset(new_inset);
text->CursorLeft();
update(1);
- new_inset->Edit(this, 0, 0);
+ new_inset->Edit(this, 0, 0, 0);
}
/* This is also a buffer property (ale) */
{
InsetInfo * new_inset = new InsetInfo();
insertInset(new_inset);
- new_inset->Edit(this, 0, 0);
+ new_inset->Edit(this, 0, 0, 0);
}
// End of spellchecker stuff
+
/* these functions return 1 if an error occured,
otherwise 0 */
int BufferView::lockInset(UpdatableInset * inset)
return;
// first check for locking insets
- if (the_locking_inset == inset) {
- if (text->UpdateInset(inset)){
- update();
- if (mark_dirty){
- if (buffer()->isLyxClean())
- owner()->getMiniBuffer()->setTimer(4);
- buffer()->markDirty();
+ if (the_locking_inset) {
+ if (the_locking_inset == inset) {
+ if (text->UpdateInset(inset)){
+ update();
+ if (mark_dirty){
+ if (buffer()->isLyxClean())
+ owner()->getMiniBuffer()->
+ setTimer(4);
+ buffer()->markDirty();
+ }
+ updateScrollbar();
+ return;
+ }
+ } else if (the_locking_inset->UpdateInsetInInset(this,inset)) {
+ if (text->UpdateInset(the_locking_inset)) {
+ update();
+ if (mark_dirty){
+ if (buffer()->isLyxClean())
+ owner()->getMiniBuffer()->
+ setTimer(4);
+ buffer()->markDirty();
+ }
+ updateScrollbar();
+ return;
}
- updateScrollbar();
- return;
}
}
{ LFUN_GOTOERROR, "error-next", N_("Go to next error"), Noop },
{ LFUN_REMOVEERRORS, "error-remove-all",
N_("Remove all error boxes"), ReadOnly },
+ { LFUN_INSET_ERT, "ert-inset-insert",
+ N_("Insert a new ERT Inset"), Noop },
{ LFUN_FIGURE, "figure-insert", N_("Insert Figure"), Noop },
{ LFUN_FILE_INSERT, "file-insert", "", Noop },
{ LFUN_FILE_INSERT_ASCII, "file-insert-ascii", "", Noop },
{ LFUN_TABINSERT, "tab-insert", "", Noop },
{ LFUN_TABLE, "table-insert", N_("Insert Table"), Noop },
{ LFUN_TEX, "tex-mode", N_("Toggle TeX style"), Noop },
+ { LFUN_INSET_TEXT, "text-inset-insert",
+ N_("Insert a new Text Inset"), Noop },
{ LFUN_TOC_INSERT, "toc-insert",
N_("Insert table of contents"), Noop },
{ LFUN_TOCVIEW, "toc-view",
#include "insets/insetparent.h"
#include "insets/insetspecialchar.h"
#include "insets/figinset.h"
+#include "insets/insettext.h"
+#include "insets/insetert.h"
#include "support/filetools.h"
#include "support/path.h"
#include "LaTeX.h"
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
+ } else if (tmptok == "ERT") {
+ inset = new InsetERT(this);
+ inset->Read(lex);
+ par->InsertChar(pos, LyXParagraph::META_INSET);
+ par->InsertInset(pos, inset);
+ par->SetFont(pos, font);
+ ++pos;
+ } else if (tmptok == "Text") {
+ inset = new InsetText(this);
+ inset->Read(lex);
+ par->InsertChar(pos, LyXParagraph::META_INSET);
+ par->InsertInset(pos, inset);
+ par->SetFont(pos, font);
+ ++pos;
} else if (tmptok == "LatexCommand") {
InsetCommand inscmd;
inscmd.Read(lex);
LFUN_SAVEPREFERENCES, // Lgb 991127
LFUN_DATE_INSERT, // jdblair 20000131
LFUN_RTL, // Dekel 20000203
+ LFUN_INSET_TEXT, // Jug 20000214
+ LFUN_INSET_ERT, // Jug 20000218
LFUN_LASTACTION /* this marks the end of the table */
};
insetcommand.h \
inseterror.C \
inseterror.h \
+ insetert.C \
+ insetert.h \
insetinclude.C \
insetinclude.h \
insetindex.C \
insetref.h \
insetspecialchar.C \
insetspecialchar.h \
+ insettext.C \
+ insettext.h \
insettoc.C \
insettoc.h \
inseturl.C \
}
-void InsetFig::draw(Painter & pain, LyXFont const & f,
- int baseline, float & x) const
+void InsetFig::draw(Painter & pain, LyXFont const & f, int baseline, float & x) const
{
LyXFont font(f);
}
-void InsetFig::Edit(BufferView * bv, int, int)
+void InsetFig::Edit(BufferView * bv, int, int, unsigned int)
{
lyxerr.debug() << "Editing InsetFig." << endl;
Regenerate();
void Validate(LaTeXFeatures & features) const;
/// what appears in the minibuffer when opening
- char const * EditMessage() const { return _("Opened figure"); }
+ const char * EditMessage() const { return _("Opened figure"); }
///
- void Edit(BufferView *, int, int);
+ void Edit(BufferView *, int, int, unsigned int);
///
unsigned char Editable() const;
///
#include "lyxinset.h"
#include "debug.h"
+#include "BufferView.h"
#include "support/lstrings.h"
/* Insets default methods */
}
-void Inset::Edit(BufferView *, int, int)
+void Inset::Edit(BufferView *, int, int, unsigned int)
{
}
void UpdatableInset::ToggleInsetCursor(BufferView *)
{
}
+
+void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int)
+{
+ LyXFont
+ font;
+// bview = bv;
+ scx = 0;
+
+ mx_scx=abs((width(bv->getPainter(), font) - bv->paperWidth())/2);
+}
+
+
+void UpdatableInset::draw(Painter &, LyXFont const &,
+ int baseline, float & x) const
+{
+ if (scx) x += float(scx);
+ top_x = int(x);
+ top_baseline = baseline;
+}
+
+
+void UpdatableInset::SetFont(LyXFont const &, bool )
+{
+}
+
+/// An updatable inset could handle lyx editing commands
+#ifdef SCROLL_INSET
+UpdatableInset::RESULT UpdatableInset::LocalDispatch(BufferView *,
+ int action, string arg)
+#else
+UpdatableInset::RESULT UpdatableInset::LocalDispatch(BufferView *, int, string)
+#endif
+{
+#ifdef SCROLL_INSET
+ if (action==LFUN_SCROLL_INSET)
+ {
+ float xx;
+ sscanf(arg.c_str(), "%f", &xx);
+ scroll(xx);
+
+ return DISPATCHED;
+ }
+#endif
+ return UNDISPATCHED;
+}
}
-void InsetCitation::Edit(BufferView * bv, int, int)
+void InsetCitation::Edit(BufferView * bv, int, int, unsigned int)
{
if(bv->buffer()->isReadonly())
WarnReadonly(bv->buffer()->fileName());
upwards?
(Joacim 1998-03-04)
*/
-void InsetBibKey::Edit(BufferView * bv, int, int)
+void InsetBibKey::Edit(BufferView * bv, int, int, unsigned int)
{
if(bv->buffer()->isReadonly())
WarnReadonly(bv->buffer()->fileName());
// BibTeX should have its own dialog. This is provisional.
-void InsetBibtex::Edit(BufferView *, int, int)
+void InsetBibtex::Edit(BufferView *, int, int, unsigned int)
{
if (!bibitem_form) {
bibitem_form = create_form_bibitem_form();
#include "insetcommand.h"
-// Created by Alejandro 970222
-
+class Buffer;
/** Used to insert citations
*/
///
string getScreenLabel()const;
///
- void Edit(BufferView *, int, int);
+ void Edit(BufferView *, int x, int y, unsigned int button);
///
unsigned char Editable() const {
return 1;
///
virtual string getScreenLabel() const;
///
- void Edit(BufferView *, int, int);
+ void Edit(BufferView *, int x, int y, unsigned int button);
///
unsigned char Editable() const {
return 1;
///
string getScreenLabel() const;
///
- void Edit(BufferView *, int, int);
+ void Edit(BufferView *, int x, int y, unsigned int button);
///
int Latex(ostream &, signed char) const;
///
}
-void InsetError::Edit(BufferView *, int, int)
+void InsetError::Edit(BufferView *, int, int, unsigned int)
{
static int ow = 400, oh = 240;
///
int width(Painter &, LyXFont const & font) const;
///
- void draw(Painter &, LyXFont const & font,
- int baseline, float & x) const;
+ void draw(Painter &, LyXFont const & font, int baseline, float & x) const;
///
void Write(ostream &) const;
///
///
bool AutoDelete() const;
/// what appears in the minibuffer when opening
- char const * EditMessage() const {return _("Opened error");}
+ const char * EditMessage() const {return _("Opened error");}
///
- void Edit(BufferView *, int, int);
+ void Edit(BufferView *, int x, int y, unsigned int button);
///
unsigned char Editable() const;
///
--- /dev/null
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright (C) 1998 The LyX Team.
+ *
+ *======================================================*/
+
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "insetert.h"
+#include "gettext.h"
+#include "lyxfont.h"
+#include "Painter.h"
+#include "lyx_gui_misc.h"
+
+
+InsetERT::InsetERT(Buffer * bf): InsetText(bf)
+{
+ closed = true;
+ nomotion = false;
+}
+
+
+InsetERT * InsetERT::Clone() const
+{
+ InsetERT * result = new InsetERT(buffer);
+ return result;
+}
+
+
+void InsetERT::Write(ostream & os) const
+{
+ os << "ERT\n";
+ WriteParagraphData(os);
+}
+
+
+int InsetERT::ascent_closed(Painter & pain, LyXFont const & f) const
+{
+ int width, ascent, descent;
+ LyXFont font(LyXFont::ALL_SANE);
+ font.setSize(f.size());
+ font.decSize();
+ font.decSize();
+ pain.buttonText(0, 0, _("ERT"), font, false, width, ascent, descent);
+ return ascent;
+}
+
+
+int InsetERT::descent_closed(Painter & pain, LyXFont const & f) const
+{
+ int width, ascent, descent;
+ LyXFont font(LyXFont::ALL_SANE);
+ font.setSize(f.size());
+ font.decSize();
+ font.decSize();
+ pain.buttonText(0, 0, _("ERT"), font, false, width, ascent, descent);
+ return descent;
+}
+
+
+int InsetERT::width_closed(Painter & pain, LyXFont const & f) const
+{
+ int width, ascent, descent;
+ LyXFont font(LyXFont::ALL_SANE);
+ font.setSize(f.size());
+ font.decSize();
+ font.decSize();
+ pain.buttonText(TEXT_TO_INSET_OFFSET, 0, _("ERT"), font, false,
+ width, ascent, descent);
+ return width + (2*TEXT_TO_INSET_OFFSET);
+}
+
+
+int InsetERT::ascent(Painter & pain, LyXFont const & font) const
+{
+ if (closed)
+ return ascent_closed(pain, font);
+ else
+ return InsetText::ascent(pain, font);
+}
+
+
+int InsetERT::descent(Painter & pain, LyXFont const & font) const
+{
+
+ if (closed)
+ return descent_closed(pain, font);
+ else
+ return InsetText::descent(pain, font);
+}
+
+
+int InsetERT::width(Painter & pain, LyXFont const & font) const
+{
+ if (closed)
+ return width_closed(pain, font);
+ else
+ return InsetText::width(pain, font);
+}
+
+
+void InsetERT::draw_closed(Painter & pain, LyXFont const & f,
+ int baseline, float & x) const
+{
+ LyXFont font(LyXFont::ALL_SANE);
+ font.setSize(f.size());
+ font.decSize();
+ font.decSize();
+ font.setColor(LColor::ert);
+ int width;
+ pain.buttonText(int(x)+TEXT_TO_INSET_OFFSET, baseline, _("ERT"), font,
+ true, width);
+ x += width + (2*TEXT_TO_INSET_OFFSET);
+}
+
+
+void InsetERT::draw(Painter & pain, LyXFont const & f, int baseline, float & x) const
+{
+ if (closed) {
+ top_x = int(x);
+ top_baseline = baseline;
+ draw_closed(pain, f, baseline, x);
+ } else {
+ InsetText::draw(pain, f, baseline, x);
+ }
+// resetPos(bv);
+}
+
+
+void InsetERT::InsetButtonRelease(BufferView * bv, int x, int y, int button)
+{
+ nomotion = false;
+ InsetText::InsetButtonRelease(bv, x, y, button);
+}
+
+
+void InsetERT::InsetButtonPress(BufferView * bv, int x, int y, int button)
+{
+ nomotion = false;
+ InsetText::InsetButtonPress(bv, x, y, button);
+}
+
+
+void InsetERT::InsetMotionNotify(BufferView * bv, int x, int y, int button)
+{
+ if (nomotion)
+ return;
+ InsetText::InsetMotionNotify(bv, x, y, button);
+}
+
+
+void InsetERT::Edit(BufferView * bv, int x, int y, unsigned int button)
+{
+ closed = false;
+ nomotion = true;
+ LyXFont font(LyXFont::ALL_SANE);
+ font.setLatex (LyXFont::ON);
+ InsetText::Edit(bv, (x > (width_closed(bv->getPainter(),font)-5) ?
+ width(bv->getPainter(), font) : 0), y, button);
+ real_current_font = current_font = font;
+ bv->updateInset(this, false);
+}
+
+
+void InsetERT::InsetUnlock(BufferView * bv)
+{
+ closed = true;
+ InsetText::InsetUnlock(bv);
+ bv->updateInset(this, false);
+}
+
+
+bool InsetERT::InsertInset(Inset *)
+{
+ return false;
+}
+
+
+void InsetERT::SetFont(LyXFont const &, bool)
+{
+ WriteAlert(_("Impossible Operation!"),
+ _("Not permitted to change font-types inside ERT-insets!"),
+ _("Sorry."));
+}
--- /dev/null
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright (C) 1998 The LyX Team.
+ *
+ *======================================================
+ */
+// The pristine updatable inset: Text
+
+
+#ifndef INSETERT_H
+#define INSETERT_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "insettext.h"
+
+class Painter;
+
+/** A colapsable text inset
+
+ To write full ert (including styles and other insets) in a given
+ space.
+*/
+class InsetERT : public InsetText {
+public:
+ ///
+ InsetERT(Buffer *);
+ ///
+ // InsetERT(InsetERT const &, Buffer *);
+ ///
+ ~InsetERT() {}
+ ///
+ InsetERT * Clone() const;
+ ///
+ // void Read(LyXLex &);
+ ///
+ void Write(ostream &) const;
+ ///
+ int ascent(Painter &, LyXFont const &) const;
+ ///
+ int descent(Painter &, LyXFont const &) const;
+ ///
+ int width(Painter &, LyXFont const & f) const;
+ ///
+ void draw(Painter & pain, const LyXFont &, int , float &) const;
+ ///
+ //LString EditMessage() const;
+ ///
+ void InsetButtonRelease(BufferView *, int, int, int);
+ ///
+ void InsetButtonPress(BufferView *, int, int, int);
+ ///
+ void InsetMotionNotify(BufferView *, int, int, int);
+ ///
+ void Edit(BufferView *, int, int, unsigned int);
+ ///
+ void InsetUnlock(BufferView *);
+ ///
+ bool InsertInset(Inset *);
+ ///
+ void SetFont(LyXFont const &, bool toggleall);
+
+protected:
+ ///
+ int ascent_closed(Painter &, LyXFont const &) const;
+ ///
+ int descent_closed(Painter &, LyXFont const &) const;
+ ///
+ int width_closed(Painter &, LyXFont const & f) const;
+ ///
+ void draw_closed(Painter & pain, const LyXFont &, int , float &) const;
+
+private:
+ ///
+ bool
+ closed,
+ nomotion;
+};
+
+#endif
}
-void InsetInclude::Edit(BufferView * bv, int, int)
+void InsetInclude::Edit(BufferView * bv, int, int, unsigned int)
{
if(bv->buffer()->isReadonly())
WarnReadonly(bv->buffer()->fileName());
/// This returns the list of bibkeys on the child buffer
string getKeys(char delim) const;
///
- void Edit(BufferView *, int, int);
+ void Edit(BufferView *, int x, int y, unsigned int button);
///
unsigned char Editable() const
{
}
-void InsetIndex::Edit(BufferView * bv, int, int)
+void InsetIndex::Edit(BufferView * bv, int, int, unsigned int)
{
if(bv->buffer()->isReadonly())
WarnReadonly(bv->buffer()->fileName());
///
Inset * Clone() const { return new InsetIndex(contents);}
///
- void Edit(BufferView *, int, int);
+ void Edit(BufferView *, int, int, unsigned int);
///
unsigned char Editable() const
{
/// Updates needed features for this inset.
void Validate(LaTeXFeatures & features) const;
///
- void Edit(BufferView *, int, int) {}
+ void Edit(BufferView *, int, int, unsigned int) {}
///
unsigned char Editable() const{
return 1;
}
-void InsetInfo::Edit(BufferView * bv, int, int)
+void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
{
static int ow = -1, oh;
///
int DocBook(string & file) const;
/// what appears in the minibuffer when opening
- char const * EditMessage() const {return _("Opened note");}
+ const char * EditMessage() const {return _("Opened note");}
///
- void Edit(BufferView *, int, int);
+ void Edit(BufferView *, int, int, unsigned int);
///
unsigned char Editable() const;
///
#include "insetcommand.h"
#include "gettext.h"
-// Created by Bernhard 970807
+class Buffer;
/** Used to insert table of algorithms
*/
}
-void InsetParent::Edit(BufferView * bv, int, int)
+void InsetParent::Edit(BufferView * bv, int, int, unsigned int)
{
- bv->owner()->getLyXFunc()->Dispatch(LFUN_CHILDOPEN,
- getContents().c_str());
+ bv->owner()->getLyXFunc()->
+ Dispatch(LFUN_CHILDOPEN, getContents().c_str());
}
#include "insetcommand.h"
#include "gettext.h"
-// Created by asierra 970813
+
+class Buffer;
/** Reference to the parent document.
return string(_("Parent:")) + getContents();
}
///
- void Edit(BufferView *, int, int);
+ void Edit(BufferView *, int, int, unsigned int);
///
unsigned char Editable() const {
return 1;
}
-void InsetRef::Edit(BufferView * bv, int, int)
+void InsetRef::Edit(BufferView * bv, int, int, unsigned int)
{
- bv->owner()->getLyXFunc()
- ->Dispatch(LFUN_REFGOTO, getContents().c_str());
+ bv->owner()->getLyXFunc()->
+ Dispatch(LFUN_REFGOTO, getContents().c_str());
}
///
Inset::Code LyxCode() const { return Inset::REF_CODE; }
///
- void Edit(BufferView *, int, int);
+ void Edit(BufferView *, int, int, unsigned int);
///
unsigned char Editable() const {
return 1;
--- /dev/null
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright (C) 1998 The LyX Team.
+ *
+ * ======================================================
+ */
+
+#include <config.h>
+
+#include <fstream>
+using std::ifstream;
+
+#include <cstdlib>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "insettext.h"
+#include "lyxlex.h"
+#include "debug.h"
+#include "lyxfont.h"
+#include "lyxlex.h"
+#include "commandtags.h"
+#include "buffer.h"
+#include "LyXView.h"
+#include "BufferView.h"
+#include "support/textutils.h"
+#include "layout.h"
+#include "insetlatexaccent.h"
+#include "insetquotes.h"
+#include "mathed/formulamacro.h"
+#include "figinset.h"
+#include "insetinfo.h"
+#include "insetinclude.h"
+#include "insetbib.h"
+#include "insetcommand.h"
+#include "insetindex.h"
+#include "insetlabel.h"
+#include "insetref.h"
+//#include "insettabular.h"
+#include "insetert.h"
+#include "insetspecialchar.h"
+#include "LaTeXFeatures.h"
+#include "Painter.h"
+#include "lyx_gui_misc.h"
+#include "support/LAssert.h"
+
+extern unsigned char getCurrentTextClass(Buffer *);
+
+InsetText::InsetText(Buffer * buf)
+{
+ par = new LyXParagraph();
+ the_locking_inset = 0;
+ buffer = buf;
+ cursor_visible = false;
+ maxWidth = old_x = -1;
+ actpos = selection_start = selection_end = 0;
+ interline_space = 1;
+ no_selection = false;
+ init_inset = true;
+}
+
+
+InsetText::InsetText(InsetText const & ins, Buffer * buf)
+{
+ par = new LyXParagraph(ins.par);
+ the_locking_inset = 0;
+ buffer = buf;
+ cursor_visible = false;
+ maxWidth = old_x = -1;
+ actpos = selection_start = selection_end = 0;
+ interline_space = 1;
+ no_selection = false;
+ init_inset = true;
+}
+
+
+InsetText::~InsetText()
+{
+ delete par;
+}
+
+
+InsetText * InsetText::Clone() const
+{
+ InsetText * t = new InsetText(*this, buffer);
+ return t;
+}
+
+
+void InsetText::Write(ostream & os) const
+{
+ os << "Text\n";
+ WriteParagraphData(os);
+}
+
+
+void InsetText::WriteParagraphData(ostream &os) const
+{
+ LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
+ LyXFont font2;
+ int column = 0;
+ char c = 0;
+
+ for (int i = 0; i < par->Last(); ++i) {
+ // Write font changes
+ font2 = par->GetFontSettings(i);
+ if (font2 != font1) {
+ font2.lyxWriteChanges(font1, os);
+ column = 0;
+ font1 = font2;
+ }
+ c = par->GetChar(i);
+ // A newline before tags
+ if (column > 0 &&
+ (c == LyXParagraph::META_INSET ||
+ c == LyXParagraph::META_NEWLINE ||
+ c == '\\')) {
+ os << "\n";
+ column = 0;
+ }
+
+ switch (c) {
+ case LyXParagraph::META_INSET: {
+ Inset *inset = par->GetInset(i);
+ if (inset) {
+ os << "\n\\begin_inset ";
+ inset->Write(os);
+ os << "\n\\end_inset \n\n";
+ column = 0;
+ }
+ }
+ break;
+ case LyXParagraph::META_NEWLINE:
+ os << "\\newline\n";
+ column = 0;
+ break;
+ case '\\':
+ os << "\\backslash\n";
+ column = 0;
+ break;
+ default:
+ if (column > 65 && c==' ') {
+ os << "\n";
+ column = 0;
+ }
+ // this check is to amend a bug. LyX sometimes
+ // inserts '\0' this could cause problems.
+ if (c != '\0')
+ os << c;
+ else
+ lyxerr << "ERROR (InsetText::writeFile):"
+ " '\\0' char in structure.\n";
+ column++;
+ break;
+ }
+ }
+ // A newline if the last c was not a tag.
+ if (column > 0 &&
+ (c != LyXParagraph::META_INSET &&
+ c != LyXParagraph::META_NEWLINE &&
+ c != '\\')) {
+ os << "\n";
+ column = 0;
+ }
+}
+
+
+void InsetText::Read(LyXLex & lex)
+{
+ string token, tmptok;
+ LyXFont font = LyXFont(LyXFont::ALL_INHERIT);
+ int pos = 0;
+
+ delete par;
+ par = new LyXParagraph;
+
+ while (lex.IsOK()) {
+ lex.nextToken();
+ token = lex.GetString();
+ if (token.empty())
+ continue;
+ else if (token[0] != '\\') {
+ int n = token.length();
+ for (int i=0; i < n; ++i) {
+ par->InsertChar(pos, token[i]);
+ par->SetFont(pos, font);
+ ++pos;
+ }
+ } else if (token == "\\newline") {
+ par->InsertChar(pos, LyXParagraph::META_NEWLINE);
+ par->SetFont(pos, font);
+ ++pos;
+ } else if (token == "\\family") {
+ lex.next();
+ font.setLyXFamily(lex.GetString());
+ } else if (token == "\\series") {
+ lex.next();
+ font.setLyXSeries(lex.GetString());
+ } else if (token == "\\shape") {
+ lex.next();
+ font.setLyXShape(lex.GetString());
+ } else if (token == "\\size") {
+ lex.next();
+ font.setLyXSize(lex.GetString());
+ } else if (token == "\\latex") {
+ lex.next();
+ string tok = lex.GetString();
+ // This is dirty, but gone with LyX3. (Asger)
+ if (tok == "no_latex")
+ font.setLatex(LyXFont::OFF);
+ else if (tok == "latex")
+ font.setLatex(LyXFont::ON);
+ else if (tok == "default")
+ font.setLatex(LyXFont::INHERIT);
+ else
+ lex.printError("Unknown LaTeX font flag "
+ "`$$Token'");
+ } else if (token == "\\direction") {
+ lex.next();
+ string tok = lex.GetString();
+ if (tok == "ltr")
+ font.setDirection(LyXFont::LTR_DIR);
+ else if (tok == "rtl")
+ font.setDirection(LyXFont::RTL_DIR);
+ else if (tok == "default")
+ font.setDirection(LyXFont::INHERIT_DIR);
+ else
+ lex.printError("Unknown font flag "
+ "`$$Token'");
+ } else if (token == "\\emph") {
+ lex.next();
+ font.setEmph(font.setLyXMisc(lex.GetString()));
+ } else if (token == "\\bar") {
+ lex.next();
+ string tok = lex.GetString();
+ // This is dirty, but gone with LyX3. (Asger)
+ if (tok == "under")
+ font.setUnderbar(LyXFont::ON);
+ else if (tok == "no")
+ font.setUnderbar(LyXFont::OFF);
+ else if (tok == "default")
+ font.setUnderbar(LyXFont::INHERIT);
+ else
+ lex.printError("Unknown bar font flag "
+ "`$$Token'");
+ } else if (token == "\\noun") {
+ lex.next();
+ font.setNoun(font.setLyXMisc(lex.GetString()));
+ } else if (token == "\\color") {
+ lex.next();
+ font.setLyXColor(lex.GetString());
+ } else if (token == "\\begin_inset") {
+ Inset * inset = 0;
+ lex.next();
+ tmptok = lex.GetString();
+ // Test the different insets.
+ if (tmptok == "Quotes") {
+ inset = new InsetQuotes(string());
+ inset->Read(lex);
+ } else if (tmptok == "LaTeXAccent" || tmptok == "\\i") {
+ inset = new InsetLatexAccent;
+ inset->Read(lex);
+ } else if (tmptok == "FormulaMacro") {
+ inset = new InsetFormulaMacro;
+ inset->Read(lex);
+ } else if (tmptok == "Formula") {
+ inset = new InsetFormula;
+ inset->Read(lex);
+ } else if (tmptok == "Figure") {
+ inset = new InsetFig(100,100, buffer);
+ inset->Read(lex);
+#if 0
+ } else if (tmptok == "Tabular") {
+ inset = new InsetTabular(buffer);
+ inset->Read(lex);
+#endif
+ } else if (tmptok == "Text") {
+ inset = new InsetText(buffer);
+ inset->Read(lex);
+ } else if (tmptok == "ERT") {
+ inset = new InsetERT(buffer);
+ inset->Read(lex);
+ } else if (tmptok == "Info") {
+ inset = new InsetInfo;
+ inset->Read(lex);
+ } else if (tmptok == "Include") {
+ inset = new InsetInclude(string(), buffer);
+ inset->Read(lex);
+ } else if (tmptok == "LatexCommand") {
+ InsetCommand inscmd;
+ inscmd.Read(lex);
+ if (inscmd.getCmdName()=="cite") {
+ inset = new InsetCitation(inscmd.getContents(),
+ inscmd.getOptions());
+ } else if (inscmd.getCmdName()=="bibitem") {
+ lex.printError("Wrong place for bibitem");
+ inset = inscmd.Clone();
+ } else if (inscmd.getCmdName()=="BibTeX") {
+ inset = new InsetBibtex(inscmd.getContents(),
+ inscmd.getOptions(), buffer);
+ } else if (inscmd.getCmdName()=="index") {
+ inset = new InsetIndex(inscmd.getContents());
+ } else if (inscmd.getCmdName()=="include") {
+ inset = new InsetInclude(inscmd.getContents(), buffer);
+ } else if (inscmd.getCmdName()=="label") {
+ inset = new InsetLabel(inscmd.getCommand());
+ } else if (inscmd.getCmdName() == "ref" ||
+ inscmd.getCmdName() == "pageref") {
+ inset = new InsetRef(inscmd, buffer);
+ } else
+ // The following three are only for compatibility
+ if (inscmd.getCmdName()=="-") {
+ inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
+ } else if (inscmd.getCmdName()=="@.") {
+ inset = new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
+ } else if (inscmd.getCmdName()=="ldots") {
+ inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
+ } else
+ inset = inscmd.Clone();
+ }
+ if (inset) {
+ par->InsertChar(pos, LyXParagraph::META_INSET);
+ par->InsertInset(pos, inset);
+ par->SetFont(pos, font);
+ ++pos;
+ } else {
+ lex.printError("Unknown inset `$$Token'. "
+ "Inserting as text.");
+ }
+#ifndef NO_COMPABILITY
+ } else if (token == "\\hfill") {
+ // now obsolete, but we have a bak compability
+// Inset * inset = new InsetSpecialChar(LyXParagraph::META_HFILL);
+// par->InsertChar(pos, LyXParagraph::META_INSET);
+// par->InsertInset(pos, inset);
+ par->InsertChar(pos, LyXParagraph::META_HFILL);
+ par->SetFont(pos, font);
+ ++pos;
+ } else if (token == "\\protected_separator") {
+ // now obsolete, but we have a back compability
+ par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
+ //Inset * inset = new InsetSpecialChar(LyXParagraph::META_PROTECTED_SEPARATOR);
+// par->InsertChar(pos, LyXParagraph::META_INSET);
+// par->InsertInset(pos, inset);
+ par->SetFont(pos, font);
+ ++pos;
+#endif
+ } else if (token == "\\bibitem") { // ale970302
+ if (!par->bibkey)
+ par->bibkey = new InsetBibKey;
+ par->bibkey->Read(lex);
+ }else if (token == "\\backslash") {
+ par->InsertChar(pos, '\\');
+ par->SetFont(pos, font);
+ ++pos;
+ } else if (token == "\\end_inset") {
+ break;
+ } else {
+ lex.printError("Unknown tabular token `$$Token'. Not handled!");
+ break;
+ }
+ }
+ if (token != "\\end_inset") {
+ lex.printError("Missing \\end_inset at this point. "
+ "Read: `$$Token'");
+ }
+ init_inset = true;
+}
+
+
+int InsetText::ascent(Painter &, LyXFont const & font) const
+{
+ if (maxAscent)
+ return maxAscent;
+ return font.maxAscent();
+}
+
+
+int InsetText::descent(Painter &, LyXFont const & font) const
+{
+ if (maxDescent)
+ return maxDescent;
+ return font.maxDescent();
+}
+
+
+int InsetText::width(Painter &, LyXFont const &) const
+{
+ return insetWidth;
+}
+
+
+int InsetText::getMaxWidth(UpdatableInset * inset) const
+{
+ if (!the_locking_inset) {
+ lyxerr << "Text: No locking inset in this inset.\n";
+ return 0;
+ }
+
+ if (the_locking_inset==inset)
+ return maxWidth;
+
+ return the_locking_inset->getMaxWidth(inset);
+}
+
+
+void InsetText::draw(Painter & pain,const LyXFont & f,int baseline,float & x) const
+{
+ unsigned int
+ r;
+ bool
+ do_reset_pos;
+
+ UpdatableInset::draw(pain, f, baseline, x);
+ do_reset_pos = (x != top_x) || (baseline != top_baseline);
+ top_x = int(x);
+ top_baseline = baseline;
+ computeBaselines(baseline);
+ for(r=0; r<rows.size()-1; ++r) {
+ drawRowSelection(pain, rows[r].pos, rows[r+1].pos, r,
+ rows[r].baseline, x);
+ drawRowText(pain, rows[r].pos, rows[r+1].pos, rows[r].baseline, x);
+ }
+ x += insetWidth;
+ if (!the_locking_inset && do_reset_pos) {
+// HideInsetCursor(bv);
+// resetPos(bv);
+// ShowInsetCursor(bv);
+ }
+}
+
+
+void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos,
+ int row, int baseline, float x) const
+{
+ if (!hasSelection())
+ return;
+ int
+ p,
+ ssel_x, esel_x,
+ s_start, s_end;
+ LyXFont
+ font;
+ char
+ ch;
+
+ if (selection_start > selection_end) {
+ s_start = selection_end;
+ s_end = selection_start;
+ } else {
+ s_start = selection_start;
+ s_end = selection_end;
+ }
+ if ((s_start > endpos) || (s_end < startpos))
+ return;
+ ssel_x = esel_x = int(x);
+ for(p=startpos; p < endpos; ++p) {
+ if (p == s_start)
+ ssel_x = int(x);
+ if ((p >= s_start) && (p <= s_end))
+ esel_x = int(x);
+ ch = par->GetChar(p);
+ font = GetFont(par,p);
+ if (IsFloatChar(ch)) {
+ // skip for now
+ } else if (ch == LyXParagraph::META_INSET) {
+ Inset const * tmpinset = par->GetInset(p);
+ x += tmpinset->width(pain, font);
+ } else {
+ x += pain.width(ch,font);
+ }
+ }
+ if (p == s_start)
+ ssel_x = int(x);
+ if ((p >= s_start) && (p <= s_end))
+ esel_x = int(x);
+ if (ssel_x < esel_x) {
+ pain.fillRectangle(int(ssel_x), baseline-rows[row].asc,
+ int(esel_x - ssel_x),
+ rows[row].asc + rows[row].desc,
+ LColor::selection);
+ }
+}
+
+
+void InsetText::drawRowText(Painter & pain, int startpos, int endpos,
+ int baseline, float x) const
+{
+ Assert(endpos <= par->Last());
+ int
+ p;
+ char
+ ch;
+ LyXFont
+ font;
+ for(p=startpos; p < endpos; ++p) {
+ ch = par->GetChar(p);
+ font = GetFont(par,p);
+ if (IsFloatChar(ch)) {
+ // skip for now
+ } else if (ch == LyXParagraph::META_INSET) {
+ Inset * tmpinset = par->GetInset(p);
+ if (tmpinset)
+ tmpinset->draw(pain, font, baseline, x);
+ } else {
+ pain.text(int(x), baseline, ch, font);
+ x += pain.width(ch,font);
+ }
+ }
+}
+
+
+const char * InsetText::EditMessage() const
+{
+ return _("Opened Text Inset");
+}
+
+
+void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
+{
+ UpdatableInset::Edit(bv, x, y, button);
+
+ bv->lockInset(this);
+ the_locking_inset = 0;
+ inset_pos = inset_x = inset_y = 0;
+ no_selection = true;
+ setPos(bv, x,y);
+ selection_start = selection_end = actpos;
+ current_font = real_current_font = GetFont(par, actpos);
+}
+
+
+void InsetText::InsetUnlock(BufferView *bv)
+{
+ if (the_locking_inset)
+ the_locking_inset->InsetUnlock(bv);
+ HideInsetCursor(bv);
+ if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ bv->updateInset(this, false);
+ }
+ the_locking_inset = 0;
+ no_selection = false;
+}
+
+
+bool InsetText::UnlockInsetInInset(BufferView * bv, Inset * inset, bool lr)
+{
+ if (!the_locking_inset)
+ return false;
+ if (the_locking_inset == inset) {
+ the_locking_inset->InsetUnlock(bv);
+ the_locking_inset = 0;
+ if (lr)
+ moveRight(bv, false);
+ return true;
+ }
+ return the_locking_inset->UnlockInsetInInset(bv, inset,lr);
+}
+
+bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
+{
+ if (!the_locking_inset)
+ return false;
+ if (the_locking_inset != inset)
+ return the_locking_inset->UpdateInsetInInset(bv, inset);
+ float x = inset_x;
+ inset->draw(bv->getPainter(), real_current_font, inset_y, x);
+ bv->updateInset(this, true);
+ return true;
+}
+
+
+void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
+{
+ if (the_locking_inset) {
+ the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
+ return;
+ }
+ no_selection = false;
+}
+
+
+void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
+{
+ if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ bv->updateInset(this, false);
+ }
+ no_selection = false;
+ if (the_locking_inset) {
+ setPos(bv, x,y,false);
+ UpdatableInset
+ *inset=0;
+ if (par->GetChar(actpos)==LyXParagraph::META_INSET)
+ inset=(UpdatableInset*)par->GetInset(actpos);
+ if (the_locking_inset == inset) {
+ the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
+ return;
+ } else if (inset) {
+ // otherwise unlock the_locking_inset and lock the new inset
+ inset_x = cx-top_x;
+ inset_y = cy;
+ inset_pos = actpos;
+ the_locking_inset->InsetUnlock(bv);
+ the_locking_inset = inset;
+ the_locking_inset->Edit(bv, x - inset_x, y - inset_y, button);
+ return;
+ }
+ // otherwise only unlock the_locking_inset
+ the_locking_inset->InsetUnlock(bv);
+ }
+ HideInsetCursor(bv);
+ the_locking_inset = 0;
+ setPos(bv, x, y);
+ selection_start = selection_end = actpos;
+ if (!the_locking_inset)
+ ShowInsetCursor(bv);
+}
+
+
+void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int button)
+{
+ if (the_locking_inset) {
+ the_locking_inset->InsetMotionNotify(bv, x-inset_x, y-inset_y,button);
+ return;
+ }
+ if (!no_selection) {
+ int
+ old = selection_end;
+ setPos(bv, x, y, false);
+ selection_end = actpos;
+ if (old != selection_end)
+ bv->updateInset(this, false);
+ }
+ no_selection = false;
+}
+
+
+void InsetText::InsetKeyPress(XKeyEvent * xke)
+{
+ if (the_locking_inset) {
+ the_locking_inset->InsetKeyPress(xke);
+ return;
+ }
+}
+
+
+UpdatableInset::RESULT InsetText::LocalDispatch(BufferView * bv,
+ int action, string arg)
+{
+ no_selection = false;
+ if (UpdatableInset::LocalDispatch(bv, action, arg)) {
+ resetPos(bv);
+ return DISPATCHED;
+ }
+
+ UpdatableInset::RESULT
+ result=DISPATCHED;
+
+ if ((action < 0) && arg.empty())
+ return FINISHED;
+
+ if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
+ (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
+ old_x = -1;
+ if (the_locking_inset) {
+ result = the_locking_inset->LocalDispatch(bv, action, arg);
+ if (result == DISPATCHED) {
+ the_locking_inset->ToggleInsetCursor(bv);
+ bv->updateInset(this, false);
+ the_locking_inset->ToggleInsetCursor(bv);
+ return result;
+ } else if (result == FINISHED) {
+ if ((action == LFUN_RIGHT) || (action == -1)) {
+ actpos = inset_pos + 1;
+ resetPos(bv);
+ }
+ the_locking_inset = 0;
+ return DISPATCHED;
+ }
+ }
+ HideInsetCursor(bv);
+ switch (action) {
+ // Normal chars
+ case -1:
+ par->InsertChar(actpos,arg[0]);
+ par->SetFont(actpos,real_current_font);
+ computeTextRows(bv);
+ bv->updateInset(this, true);
+ ++actpos;
+ selection_start = selection_end = actpos;
+ resetPos(bv);
+ break;
+ // --- Cursor Movements ---------------------------------------------
+ case LFUN_RIGHTSEL:
+ moveRight(bv, false);
+ selection_end = actpos;
+ bv->updateInset(this, false);
+ break;
+ case LFUN_RIGHT:
+ result= DISPATCH_RESULT(moveRight(bv));
+ if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ bv->updateInset(this, false);
+ } else {
+ selection_start = selection_end = actpos;
+ }
+ break;
+ case LFUN_LEFTSEL:
+ moveLeft(bv, false);
+ selection_end = actpos;
+ bv->updateInset(this, false);
+ break;
+ case LFUN_LEFT:
+ result= DISPATCH_RESULT(moveLeft(bv));
+ if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ bv->updateInset(this, false);
+ } else {
+ selection_start = selection_end = actpos;
+ }
+ break;
+ case LFUN_DOWNSEL:
+ moveDown(bv, false);
+ selection_end = actpos;
+ bv->updateInset(this, false);
+ break;
+ case LFUN_DOWN:
+ result= DISPATCH_RESULT(moveDown(bv));
+ if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ bv->updateInset(this, false);
+ } else {
+ selection_start = selection_end = actpos;
+ }
+ break;
+ case LFUN_UPSEL:
+ moveUp(bv, false);
+ selection_end = actpos;
+ bv->updateInset(this, false);
+ break;
+ case LFUN_UP:
+ result= DISPATCH_RESULT(moveUp(bv));
+ if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ bv->updateInset(this, false);
+ } else {
+ selection_start = selection_end = actpos;
+ }
+ break;
+ case LFUN_BACKSPACE:
+ if (!actpos || par->IsNewline(actpos-1)) {
+ if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ bv->updateInset(this, false);
+ }
+ break;
+ }
+ moveLeft(bv);
+ case LFUN_DELETE:
+ if (Delete()) { // we need update
+ selection_start = selection_end = actpos;
+ computeTextRows(bv);
+ bv->updateInset(this, true);
+ } else if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ bv->updateInset(this, false);
+ }
+ break;
+ case LFUN_HOME:
+ for(;actpos > rows[actrow].pos;--actpos)
+ cx -= SingleWidth(bv, par, actpos);
+ cx -= SingleWidth(bv, par, actpos);
+ if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ bv->updateInset(this, false);
+ } else {
+ selection_start = selection_end = actpos;
+ }
+ break;
+ case LFUN_END:
+ for(;actpos < rows[actrow+1].pos;++actpos)
+ cx += SingleWidth(bv, par, actpos);
+ if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ bv->updateInset(this, false);
+ } else {
+ selection_start = selection_end = actpos;
+ }
+ break;
+ case LFUN_MATH_MODE: // Open or create a math inset
+ InsertInset(bv, new InsetFormula);
+ if (hasSelection()) {
+ selection_start = selection_end = actpos;
+ bv->updateInset(this, false);
+ } else {
+ selection_start = selection_end = actpos;
+ }
+ return DISPATCHED;
+ break;
+ default:
+ result = UNDISPATCHED;
+ break;
+ }
+ if (result != FINISHED) {
+ if (!the_locking_inset)
+ ShowInsetCursor(bv);
+ } else
+ bv->unlockInset(this);
+ return result;
+}
+
+
+int InsetText::Latex(ostream &os, signed char fragile) const
+{
+ string
+ fstr;
+ int
+ i;
+
+ i = Latex(fstr, fragile);
+ os << fstr.c_str();
+ return i;
+}
+
+
+int InsetText::Latex(string & file, signed char /* fragile */) const
+{
+ TexRow
+ texrow;
+
+ return par->SimpleTeXOnePar(file, texrow);
+}
+
+
+void InsetText::Validate(LaTeXFeatures & features) const
+{
+ par->validate(features);
+}
+
+
+// Returns the width of a character at a certain spot
+int InsetText::SingleWidth(BufferView *bv, LyXParagraph * par, int pos)
+{
+ LyXFont
+ font = GetFont(par, pos);
+ char
+ c = par->GetChar(pos);
+
+ // The most common case is handled first (Asger)
+ if (IsPrintable(c)) {
+ return font.width(c);
+ } else if (c == LyXParagraph::META_INSET) {
+ Inset const * tmpinset=par->GetInset(pos);
+ if (tmpinset)
+ return tmpinset->width(bv->getPainter(), font);
+ else
+ return 0;
+ } else if (IsSeparatorChar(c))
+ c = ' ';
+ else if (IsNewlineChar(c))
+ c = 'n';
+ return font.width(c);
+}
+
+
+// Returns the width of a character at a certain spot
+void InsetText::SingleHeight(BufferView * bv, LyXParagraph * par,int pos,
+ int & asc, int & desc)
+{
+ LyXFont
+ font = GetFont(par, pos);
+ char
+ c = par->GetChar(pos);
+
+ asc = desc = 0;
+ // The most common case is handled first (Asger)
+ if (c == LyXParagraph::META_INSET) {
+ Inset const * tmpinset=par->GetInset(pos);
+ if (tmpinset) {
+ asc = tmpinset->ascent(bv->getPainter(),font);
+ desc = tmpinset->descent(bv->getPainter(),font);
+ }
+ } else {
+ asc = font.maxAscent();
+ desc = font.maxDescent();
+ }
+ return;
+}
+
+
+// Gets the fully instantiated font at a given position in a paragraph
+// Basically the same routine as LyXParagraph::getFont() in paragraph.C.
+// The difference is that this one is used for displaying, and thus we
+// are allowed to make cosmetic improvements. For instance make footnotes
+// smaller. (Asger)
+// If position is -1, we get the layout font of the paragraph.
+// If position is -2, we get the font of the manual label of the paragraph.
+LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
+{
+ char par_depth = par->GetDepth();
+
+ LyXLayout layout =
+ textclasslist.Style(buffer->params.textclass, par->GetLayout());
+
+ // We specialize the 95% common case:
+ if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
+ if (pos >= 0) {
+ // 95% goes here
+ if (layout.labeltype == LABEL_MANUAL
+ && pos < BeginningOfMainBody(par)) {
+ // 1% goes here
+ return par->GetFontSettings(pos).realize(layout.reslabelfont);
+ } else
+ return par->GetFontSettings(pos).realize(layout.resfont);
+ } else {
+ // 5% goes here.
+ // process layoutfont for pos == -1 and labelfont for pos < -1
+ if (pos == -1)
+ return layout.resfont;
+ else
+ return layout.reslabelfont;
+ }
+ }
+ // The uncommon case need not be optimized as much
+
+ LyXFont layoutfont, tmpfont;
+
+ if (pos >= 0){
+ // 95% goes here
+ if (pos < BeginningOfMainBody(par)) {
+ // 1% goes here
+ layoutfont = layout.labelfont;
+ } else {
+ // 99% goes here
+ layoutfont = layout.font;
+ }
+ tmpfont = par->GetFontSettings(pos);
+ tmpfont.realize(layoutfont);
+ } else{
+ // 5% goes here.
+ // process layoutfont for pos == -1 and labelfont for pos < -1
+ if (pos == -1)
+ tmpfont = layout.font;
+ else
+ tmpfont = layout.labelfont;
+ }
+
+ // Resolve against environment font information
+ //if (par->GetDepth()){ // already in while condition
+ while (par && par_depth && !tmpfont.resolved()) {
+ par = par->DepthHook(par_depth - 1);
+ if (par) {
+ tmpfont.realize(textclasslist.Style(buffer->params.textclass,
+ par->GetLayout()).font);
+ par_depth = par->GetDepth();
+ }
+ }
+ tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
+ defaultfont()));
+ return tmpfont;
+}
+
+
+int InsetText::BeginningOfMainBody(LyXParagraph * par) const
+{
+ if (textclasslist.Style(buffer->params.textclass,
+ par->GetLayout()).labeltype != LABEL_MANUAL)
+ return 0;
+ else
+ return par->BeginningOfMainBody();
+}
+
+
+void InsetText::GetCursorPos(int & x, int & y)
+{
+ x = cx;
+ y = cy;
+}
+
+
+int InsetText::InsetInInsetY()
+{
+ if (!the_locking_inset)
+ return 0;
+
+ int
+ y = inset_y;
+ return (y + the_locking_inset->InsetInInsetY());
+}
+
+
+void InsetText::ToggleInsetCursor(BufferView * bv)
+{
+ if (the_locking_inset) {
+ the_locking_inset->ToggleInsetCursor(bv);
+ return;
+ }
+ int
+ asc,desc;
+ LyXFont
+ font = GetFont(par, actpos);
+
+ asc = font.maxAscent();
+ desc = font.maxDescent();
+
+ if (cursor_visible)
+ bv->hideLockedInsetCursor();
+ else
+ bv->showLockedInsetCursor(cx, cy, asc, desc);
+ cursor_visible = !cursor_visible;
+}
+
+
+void InsetText::ShowInsetCursor(BufferView * bv)
+{
+ if (!cursor_visible) {
+ int
+ asc,desc;
+ LyXFont
+ font = GetFont(par, actpos);
+
+ asc = font.maxAscent();
+ desc = font.maxDescent();
+ bv->fitLockedInsetCursor(cx, cy, asc, desc);
+ bv->showLockedInsetCursor(cx, cy, asc, desc);
+ cursor_visible = true;
+ }
+}
+
+
+void InsetText::HideInsetCursor(BufferView * bv)
+{
+ if (cursor_visible)
+ ToggleInsetCursor(bv);
+}
+
+
+void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
+{
+ int
+ ox = x,
+ oy = y;
+ // search right X-pos x==0 -> top_x
+ actpos = actrow = 0;
+ cy = top_baseline;
+ y += cy;
+ for(unsigned int i=1;
+ ((cy+rows[i-1].desc) < y) && (i < rows.size()-1); ++i) {
+ cy = rows[i].baseline;
+ actpos = rows[i].pos;
+ actrow = i;
+ }
+ cy -= top_baseline;
+ cx = top_x;
+ x += top_x;
+ int
+ sw, swh;
+
+ sw = swh = SingleWidth(bv, par,actpos);
+ if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
+ swh /= 2;
+ while ((actpos < (rows[actrow+1].pos-1)) && ((cx+swh) < x)) {
+ cx += sw;
+ ++actpos;
+ sw = swh = SingleWidth(bv, par,actpos);
+ if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
+ swh /= 2;
+ }
+ if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
+ the_locking_inset=(UpdatableInset*)par->GetInset(actpos);
+ inset_x = cx-top_x;
+ inset_y = cy;
+ inset_pos = actpos;
+ the_locking_inset->Edit(bv, ox - inset_x, oy - inset_y, 0);
+ }
+}
+
+
+bool InsetText::moveRight(BufferView * bv, bool activate_inset)
+{
+ if (actpos >= par->Last())
+ return false;
+ if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
+ the_locking_inset=(UpdatableInset*)par->GetInset(actpos);
+ inset_x = cx-top_x;
+ inset_y = cy;
+ inset_pos = actpos;
+ the_locking_inset->Edit(bv, 0, 0, 0);
+ } else {
+ ++actpos;
+ resetPos(bv);
+ }
+ return true;
+}
+
+
+bool InsetText::moveLeft(BufferView * bv, bool activate_inset)
+{
+ if (actpos <= 0)
+ return false;
+ --actpos;
+ if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
+ the_locking_inset=(UpdatableInset*)par->GetInset(actpos);
+ resetPos(bv);
+ inset_x = cx-top_x;
+ inset_y = cy;
+ inset_pos = actpos;
+ the_locking_inset->Edit(bv, the_locking_inset->
+ width(bv->getPainter(),GetFont(par,actpos)),
+ 0, 0);
+ } else {
+ resetPos(bv);
+ }
+ return true;
+}
+
+
+bool InsetText::moveUp(BufferView * bv, bool activate_inset)
+{
+ if (!actrow)
+ return false;
+ cy = rows[actrow-1].baseline - top_baseline;
+ setPos(bv, cx-top_x, cy, activate_inset);
+ return true;
+}
+
+
+bool InsetText::moveDown(BufferView * bv, bool activate_inset)
+{
+ if (actrow >= int(rows.size()-2))
+ return false;
+ cy = rows[actrow+1].baseline - top_baseline;
+ setPos(bv, cx-top_x, cy, activate_inset);
+ return true;
+}
+
+
+void InsetText::resetPos(BufferView * bv)
+{
+ int
+ i,
+ old_pos = actpos;
+
+ cy = top_baseline;
+ actrow = 0;
+ for(i=0; rows[i].pos <= actpos; ++i) {
+ cy = rows[i].baseline;
+ actrow = i;
+ }
+ cy -= top_baseline;
+ setPos(bv, 0, cy, false);
+ cx = top_x;
+ while(actpos < old_pos) {
+ cx += SingleWidth(bv, par,actpos);
+ ++actpos;
+ }
+}
+
+
+bool InsetText::Delete()
+{
+ /* some insets are undeletable here */
+ if (par->GetChar(actpos)==LyXParagraph::META_INSET) {
+ /* force complete redo when erasing display insets */
+ /* this is a cruel mathod but save..... Matthias */
+ if (par->GetInset(actpos)->Deletable() &&
+ par->GetInset(actpos)->display()) {
+ par->Erase(actpos);
+ return true;
+ }
+ return false;
+ }
+ par->Erase(actpos);
+ return true;
+}
+
+
+bool InsetText::InsertInset(BufferView * bv, Inset * inset)
+{
+ par->InsertChar(actpos, LyXParagraph::META_INSET);
+ par->InsertInset(actpos, inset);
+ computeTextRows(bv);
+ bv->updateInset(this, true);
+ the_locking_inset = (UpdatableInset*)inset;
+ inset_x = cx-top_x;
+ inset_y = cy;
+ inset_pos = actpos;
+ inset->Edit(bv, 0, 0, 0);
+ return true;
+}
+
+
+UpdatableInset * InsetText::GetLockingInset()
+{
+ return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
+}
+
+
+void InsetText::SetFont(BufferView * bv, LyXFont const & font,bool toggleall)
+{
+ // if there is no selection just set the current_font
+ if (!hasSelection()) {
+ // Determine basis font
+ LyXFont layoutfont;
+ if (actpos < BeginningOfMainBody(par))
+ layoutfont = GetFont(par, -2);
+ else
+ layoutfont = GetFont(par, -1);
+
+ // Update current font
+ real_current_font.update(font, toggleall);
+
+ // Reduce to implicit settings
+ current_font = real_current_font;
+ current_font.reduce(layoutfont);
+ // And resolve it completely
+ real_current_font.realize(layoutfont);
+ return;
+ }
+ int
+ s_start, s_end;
+
+ if (selection_start > selection_end) {
+ s_start = selection_end;
+ s_end = selection_start;
+ } else {
+ s_start = selection_start;
+ s_end = selection_end;
+ }
+ LyXFont
+ newfont;
+ while(s_start < s_end) {
+ newfont = GetFont(par,s_start);
+ newfont.update(font, toggleall);
+ SetCharFont(s_start, newfont);
+ ++s_start;
+ }
+ computeTextRows(bv);
+ bv->updateInset(this, true);
+}
+
+
+void InsetText::SetCharFont(int pos, LyXFont font)
+{
+ /* let the insets convert their font */
+ if (par->GetChar(pos) == LyXParagraph::META_INSET) {
+ if (par->GetInset(pos))
+ font = par->GetInset(pos)->ConvertFont(font);
+ }
+ LyXLayout layout =
+ textclasslist.Style(buffer->params.textclass,par->GetLayout());
+
+ // Get concrete layout font to reduce against
+ LyXFont layoutfont;
+
+ if (pos < BeginningOfMainBody(par))
+ layoutfont = layout.labelfont;
+ else
+ layoutfont = layout.font;
+
+
+ layoutfont.realize((textclasslist.TextClass(buffer->params.textclass).
+ defaultfont()));
+
+ // Now, reduce font against full layout font
+ font.reduce(layoutfont);
+
+ par->SetFont(pos, font);
+}
+
+
+void InsetText::computeTextRows(BufferView * bv)
+{
+ int
+ p,
+ nwp = 0,
+ asc = 0,
+ desc = 0,
+ oasc = 0,
+ odesc = 0,
+ owidth = 0,
+ width,
+ wordAscent,
+ wordDescent;
+ row_struct
+ row;
+
+ if (rows.size())
+ rows.erase(rows.begin(),rows.end());
+ width = wordAscent = wordDescent = 0;
+ insetWidth = maxAscent = maxDescent = 0;
+ row.asc = 0;
+ row.desc = 0;
+ row.pos = 0;
+ row.baseline = 0;
+ rows.push_back(row);
+ if (maxWidth < 0) {
+ for(p=0; p < par->Last(); ++p) {
+ insetWidth += SingleWidth(bv, par, p);
+ SingleHeight(bv, par, p, asc, desc);
+ if (asc > maxAscent)
+ maxAscent = asc;
+ if (desc > maxDescent)
+ maxDescent = desc;
+ }
+ rows[0].asc = maxAscent;
+ rows[0].desc = maxDescent;
+ // alocate a dummy row for the endpos
+ row.pos = par->Last();
+ rows.push_back(row);
+ return;
+ }
+ bool
+ is_first_word_in_row = true;
+
+ int
+ cw,
+ lastWordWidth=0;
+
+ for(p = 0; p < par->Last(); ++p) {
+ cw = SingleWidth(bv, par, p);
+ width += cw;
+ lastWordWidth += cw;
+ SingleHeight(bv, par, p, asc, desc);
+ if (asc > wordAscent)
+ wordAscent = asc;
+ if (desc > wordDescent)
+ wordDescent = desc;
+ Inset const * inset = 0;
+ if (((p + 1) < par->Last()) &&
+ (par->GetChar(p+1)==LyXParagraph::META_INSET))
+ inset = par->GetInset(p+1);
+ if (inset && inset->display()) {
+ if (!is_first_word_in_row && (width >= maxWidth)) {
+ // we have to split also the row above
+ rows[rows.size()-1].asc = oasc;
+ rows[rows.size()-1].desc = odesc;
+ row.pos = nwp;
+ rows.push_back(row);
+ oasc = wordAscent;
+ odesc = wordDescent;
+ if (insetWidth < owidth)
+ insetWidth = owidth;
+ width = lastWordWidth;
+ lastWordWidth = 0;
+ } else {
+ if (oasc < wordAscent)
+ oasc = wordAscent;
+ if (odesc < wordDescent)
+ odesc = wordDescent;
+ }
+ rows[rows.size() - 1].asc = oasc;
+ rows[rows.size() - 1].desc = odesc;
+ row.pos = ++p;
+ rows.push_back(row);
+ SingleHeight(bv, par, p, asc, desc);
+ rows[rows.size() - 1].asc = asc;
+ rows[rows.size() - 1].desc = desc;
+ row.pos = nwp = p + 1;
+ rows.push_back(row);
+ oasc = odesc = width = lastWordWidth = 0;
+ is_first_word_in_row = true;
+ wordAscent = wordDescent = 0;
+ continue;
+ } else if (par->IsSeparator(p)) {
+ if (width >= maxWidth) {
+ if (is_first_word_in_row) {
+ rows[rows.size()-1].asc = wordAscent;
+ rows[rows.size()-1].desc = wordDescent;
+ row.pos = p+1;
+ rows.push_back(row);
+ oasc = odesc = width = 0;
+ } else {
+ rows[rows.size()-1].asc = oasc;
+ rows[rows.size()-1].desc = odesc;
+ row.pos = nwp;
+ rows.push_back(row);
+ oasc = wordAscent;
+ odesc = wordDescent;
+ if (insetWidth < owidth)
+ insetWidth = owidth;
+ width = lastWordWidth;
+ }
+ wordAscent = wordDescent = lastWordWidth = 0;
+ nwp = p+1;
+ continue;
+ }
+ owidth = width;
+ if (oasc < wordAscent)
+ oasc = wordAscent;
+ if (odesc < wordDescent)
+ odesc = wordDescent;
+ wordAscent = wordDescent = lastWordWidth = 0;
+ nwp = p+1;
+ is_first_word_in_row = false;
+ }
+ }
+ // if we have some data in the paragraph we have ascent/descent
+ if (p) {
+ if (width >= maxWidth) {
+ // assign upper row
+ rows[rows.size()-1].asc = oasc;
+ rows[rows.size()-1].desc = odesc;
+ // assign and allocate lower row
+ row.pos = nwp;
+ rows.push_back(row);
+ rows[rows.size()-1].asc = wordAscent;
+ rows[rows.size()-1].desc = wordDescent;
+ if (insetWidth < owidth)
+ insetWidth = owidth;
+ width -= owidth;
+ if (insetWidth < width)
+ insetWidth = width;
+ } else {
+ // assign last row data
+ if (oasc < wordAscent)
+ oasc = wordAscent;
+ if (odesc < wordDescent)
+ odesc = wordDescent;
+ rows[rows.size()-1].asc = oasc;
+ rows[rows.size()-1].desc = odesc;
+ }
+ }
+ // alocate a dummy row for the endpos
+ row.pos = par->Last();
+ rows.push_back(row);
+ // calculate maxAscent/Descent
+ maxAscent = rows[0].asc;
+ maxDescent = rows[0].desc;
+ for (unsigned int i=1; i<rows.size()-1; ++i) {
+ maxDescent += rows[i].asc + rows[i].desc + interline_space;
+ }
+ if (the_locking_inset) {
+ computeBaselines(top_baseline);
+ actpos = inset_pos;
+ resetPos(bv);
+ inset_x = cx-top_x;
+ inset_y = cy;
+ }
+}
+
+void InsetText::computeBaselines(int baseline) const
+{
+ rows[0].baseline = baseline;
+ for (unsigned int i=1; i<rows.size()-1; i++) {
+ rows[i].baseline = rows[i-1].baseline + rows[i-1].desc +
+ rows[i].asc + interline_space;
+ }
+}
+
+void InsetText::init(BufferView * bv)
+{
+// if (init_inset)
+ {
+ computeTextRows(bv);
+ init_inset = false;
+ }
+}
--- /dev/null
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright (C) 1998 The LyX Team.
+ *
+ *======================================================
+ */
+// The pristine updatable inset: Text
+
+
+#ifndef INSETTEXT_H
+#define INSETTEXT_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "lyxinset.h"
+#include "lyxparagraph.h"
+#include "LString.h"
+#include "buffer.h"
+
+class Painter;
+class BufferView;
+
+/** A text inset is like a TeX box
+
+ To write full text (including styles and other insets) in a given
+ space.
+*/
+class InsetText : public UpdatableInset {
+public:
+ ///
+ enum { TEXT_TO_INSET_OFFSET = 1 };
+ ///
+ InsetText(Buffer *);
+ ///
+ InsetText(InsetText const &, Buffer *);
+ ///
+ ~InsetText();
+ ///
+ InsetText * Clone() const;
+ ///
+ void Read(LyXLex &);
+ ///
+ void Write(ostream &) const;
+ ///
+ int ascent(Painter &, LyXFont const &) const;
+ ///
+ int descent(Painter &, LyXFont const &) const;
+ ///
+ int width(Painter &, LyXFont const & f) const;
+ ///
+ int getMaxWidth(UpdatableInset *) const;
+ ///
+ void draw(Painter & pain, const LyXFont &, int , float &) const;
+ ///
+ const char * EditMessage() const;
+ ///
+ void Edit(BufferView *, int, int, unsigned int);
+ ///
+ void InsetUnlock(BufferView *);
+ ///
+ bool UnlockInsetInInset(BufferView *, Inset *, bool lr=false);
+ ///
+ //void UpdateLocal(bool flag=true);
+ ///
+ bool UpdateInsetInInset(BufferView *, Inset *);
+ ///
+ void InsetButtonRelease(BufferView *, int, int, int);
+ ///
+ void InsetButtonPress(BufferView *, int, int, int);
+ ///
+ void InsetMotionNotify(BufferView *, int, int, int);
+ ///
+ void InsetKeyPress(XKeyEvent *);
+ ///
+ UpdatableInset::RESULT LocalDispatch(BufferView *, int, string);
+ ///
+ int Latex(ostream &, signed char) const;
+ ///
+ int Latex(string &, signed char) const;
+ ///
+ int Linuxdoc(class string &) const { return true; }
+ ///
+ int DocBook(class string &) const { return true; }
+ ///
+ void Validate(LaTeXFeatures & features) const;
+ ///
+ Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
+ ///
+ void GetCursorPos(int & x, int & y);
+ ///
+ int InsetInInsetY();
+ ///
+ void ToggleInsetCursor(BufferView *);
+ ///
+ bool InsertInset(BufferView *, Inset *);
+ ///
+ UpdatableInset * GetLockingInset();
+ ///
+ void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
+ ///
+ void init(BufferView *);
+
+ LyXParagraph * par;
+
+protected:
+ ///
+ void WriteParagraphData(ostream &) const;
+ ///
+ void resetPos(BufferView *);
+ ///
+ void drawSelection(Painter & pain, int pos, int baseline, float x);
+ ///
+ void SingleHeight(BufferView *, LyXParagraph * par,int pos,
+ int & asc, int & desc);
+ ///
+ int SingleWidth(BufferView * bv, LyXParagraph * par, int pos);
+ ///
+ LyXFont GetFont(LyXParagraph * par, int pos) const;
+ ///
+ Buffer * buffer;
+ ///
+ LyXFont current_font;
+ ///
+ LyXFont real_current_font;
+ ///
+ int maxWidth;
+ ///
+ int maxAscent;
+ ///
+ int maxDescent;
+ ///
+ int insetWidth;
+
+private:
+ ///
+ void drawRowSelection(Painter &, int startpos, int endpos, int row,
+ int baseline, float x) const;
+ ///
+ void drawRowText(Painter &, int startpos, int endpos, int baseline,
+ float x) const;
+ ///
+ void computeTextRows(BufferView *);
+ ///
+ void computeBaselines(int) const;
+ ///
+ int BeginningOfMainBody(LyXParagraph * par) const;
+ ///
+ void ShowInsetCursor(BufferView *);
+ ///
+ void HideInsetCursor(BufferView *);
+ ///
+ void setPos(BufferView *, int x, int y, bool activate_inset=true);
+ ///
+ bool moveRight(BufferView *, bool activate_inset = true);
+ bool moveLeft(BufferView *, bool activate_inset = true);
+ bool moveUp(BufferView *, bool activate_inset = true);
+ bool moveDown(BufferView *, bool activate_inset = true);
+ bool Delete();
+ ///
+ bool hasSelection() const {return (selection_start != selection_end);}
+ ///
+ void SetCharFont(int pos, LyXFont font);
+ ///
+ string getText(int);
+
+ /* Private structures and variables */
+ ///
+ int inset_pos;
+ ///
+ int inset_x;
+ ///
+ int inset_y;
+ ///
+ int interline_space;
+ ///
+ int selection_start;
+ ///
+ int selection_end;
+ ///
+ int old_x;
+ ///
+ int cx;
+ ///
+ int cy;
+ ///
+ int actpos;
+ ///
+ int actrow;
+ ///
+ bool no_selection;
+ ///
+ bool init_inset;
+ ///
+ UpdatableInset * the_locking_inset;
+ ///
+ struct row_struct {
+ ///
+ int asc;
+ ///
+ int desc;
+ ///
+ int pos;
+ ///
+ int baseline;
+ };
+ ///
+ typedef vector<row_struct> RowList;
+ ///
+ mutable RowList rows;
+ InsetText & operator = (InsetText const & it) {
+ par = it.par;
+ buffer = it.buffer; // suspect
+ current_font = it.current_font;
+ real_current_font = it.real_current_font;
+ maxWidth = it.maxWidth;
+ maxAscent = it.maxAscent;
+ maxDescent = it.maxDescent;
+ insetWidth = it.insetWidth;
+ inset_pos = it.inset_pos;
+ inset_x = it.inset_x;
+ inset_y = it.inset_y;
+ interline_space = it.interline_space;
+ selection_start = it.selection_start;
+ selection_end = it.selection_end;
+ old_x = it.old_x;
+ cx = it.cx;
+ cy = it.cy;
+ actpos = it.actpos;
+ actrow = it.actrow;
+ no_selection = it.no_selection;
+ the_locking_inset = it.the_locking_inset; // suspect
+ rows = it.rows;
+ return * this;
+ }
+};
+#endif
#include "commandtags.h"
#include "lyxfunc.h"
#include "LyXView.h"
+#include "BufferView.h"
-void InsetTOC::Edit(BufferView * bv, int, int)
+void InsetTOC::Edit(BufferView * bv, int, int, unsigned int)
{
bv->owner()->getLyXFunc()->Dispatch(LFUN_TOCVIEW);
}
#include "insetcommand.h"
#include "gettext.h"
-// Created by Lgb 970527
+class Buffer;
/** Used to insert table of contents
*/
///
string getScreenLabel() const { return _("Table of Contents"); }
/// On edit, we open the TOC pop-up
- void Edit(BufferView *, int, int);
+ void Edit(BufferView * bv, int, int, unsigned int);
///
unsigned char Editable() const {
return 1;
}
-void InsetUrl::Edit(BufferView * bv, int, int)
+void InsetUrl::Edit(BufferView * bv, int, int, unsigned int)
{
static int ow = -1, oh;
///
void Validate(LaTeXFeatures &) const;
///
- void Edit(BufferView *, int, int);
+ void Edit(BufferView *, int, int, unsigned int);
///
unsigned char Editable() const {
return 1;
}
///
- char const * EditMessage() const {return _("Opened Url");}
+ const char * EditMessage() const {return _("Opened Url");}
///
bool display() const { return false; }
///
///
PARENT_CODE,
///
- BIBTEX_CODE
+ BIBTEX_CODE,
+ ///
+ TEXT_CODE
};
///
///
virtual LyXFont ConvertFont(LyXFont font);
/// what appears in the minibuffer when opening
- virtual char const * EditMessage() const {return _("Opened inset");}
+ virtual const char * EditMessage() const {return _("Opened inset");}
///
- virtual void Edit(BufferView *, int, int);
+ virtual void Edit(BufferView *, int x, int y, unsigned int button);
///
virtual unsigned char Editable() const;
///
virtual int GetNumberOfLabels() const {
return 0;
}
+ ///
+ virtual void init(BufferView *) {}
};
*/
class UpdatableInset: public Inset {
public:
+ /** Dispatch result codes
+ Now that nested updatable insets are allowed, the local dispatch
+ becomes a bit complex, just two possible results (boolean)
+ are not enough.
+
+ DISPATCHED = the inset catched the action
+ FINISHED = the inset must be unlocked as a result
+ of the action
+ UNDISPATCHED = the action was not catched, it should be
+ dispatched by lower level insets
+ */
+ enum RESULT {
+ UNDISPATCHED=0,
+ DISPATCHED,
+ FINISHED
+ };
+
+ /// To convert old binary dispatch results
+ RESULT DISPATCH_RESULT(bool b) {
+ return (b) ? DISPATCHED: FINISHED;
+ }
+
///
//virtual ~UpdatableInset() {}
///
///
virtual void InsetButtonRelease(BufferView *,
int x, int y, int button);
-
///
virtual void InsetKeyPress(XKeyEvent * ev);
///
virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
///
virtual void InsetUnlock(BufferView *);
-
+ ///
+ virtual void Edit(BufferView *, int x, int y, unsigned int button);
+ ///
+ virtual void draw(Painter &, LyXFont const &,
+ int baseline, float & x) const;
+ ///
+ virtual void SetFont(LyXFont const &, bool toggleall = false);
+ ///
+ virtual bool InsertInset(Inset *) { return false; }
+ ///
+ virtual UpdatableInset * GetLockingInset() { return this; }
+ ///
+ virtual int InsetInInsetY() { return 0; }
+ ///
+ virtual bool UpdateInsetInInset(BufferView *, Inset *) {return false;}
+ ///
+ virtual bool UnlockInsetInInset(BufferView *,Inset *,bool /*lr*/=false)
+ {return false;}
/// An updatable inset could handle lyx editing commands
- virtual bool LocalDispatch(BufferView *, int, char const *) { return false; };
- //
- bool isCursorVisible() const { return cursor_visible; }
+ virtual RESULT LocalDispatch(BufferView *, int, string);
+ ///
+ virtual bool isCursorVisible() const { return cursor_visible; }
+ ///
+ virtual int getMaxWidth(UpdatableInset *) const { return -1; }
+
protected:
///
+ // virtual void UpdateLocal(bool flag=true);
+ ///
+ mutable int top_x;
+ mutable int top_baseline;
mutable bool cursor_visible;
+
+private:
+ ///
+ int mx_scx;
+ mutable int scx;
};
#endif
if (bv->available()) {
bv->hideCursor();
bv->update(-2);
- bv->text->ToggleFree(font, toggleall);
+ if (bv->the_locking_inset)
+ bv->the_locking_inset->SetFont(font, toggleall);
+ else
+ bv->text->ToggleFree(font, toggleall);
bv->update(1);
}
}
InsetFig * new_inset = new InsetFig(100, 20, buffer);
current_view->insertInset(new_inset);
current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
- new_inset->Edit(current_view, 0, 0);
+ new_inset->Edit(current_view, 0, 0, 0);
return;
}
Inset * new_inset = new InsetFig(100, 100, buffer);
current_view->insertInset(new_inset);
- new_inset->Edit(current_view, 0, 0);
+ new_inset->Edit(current_view, 0, 0, 0);
current_view->update(0);
current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
current_view->text->UnFreezeUndo();
#include "insets/insetindex.h"
#include "insets/insetinclude.h"
#include "insets/insetbib.h"
+#include "insets/insettext.h"
+#include "insets/insetert.h"
#include "mathed/formulamacro.h"
#include "toolbar.h"
#include "spellchecker.h" // RVDK_PATCH_5
inset->GetCursorPos(slx, sly);
owner->view()->unlockInset(inset);
owner->view()->menuUndo();
- inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
- if (inset)
- inset->Edit(owner->view(), slx, sly);
+ inset = static_cast<UpdatableInset*>(
+ owner->view()->text->cursor.par->
+ GetInset(owner->view()->text->
+ cursor.pos));
+ if (inset)
+ inset->Edit(owner->view(),slx,sly,0);
return string();
- } else
- if (action == LFUN_REDO) {
- int slx, sly;
- UpdatableInset * inset = owner->view()->the_locking_inset;
- inset->GetCursorPos(slx, sly);
- owner->view()->unlockInset(inset);
- owner->view()->menuRedo();
- inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
- if (inset)
- inset->Edit(owner->view(),
- slx, sly);
+ } else if (action == LFUN_REDO) {
+ int slx, sly;
+ UpdatableInset * inset = owner->view()->
+ the_locking_inset;
+ inset->GetCursorPos(slx, sly);
+ owner->view()->unlockInset(inset);
+ owner->view()->menuRedo();
+ inset = static_cast<UpdatableInset*>(
+ owner->view()->text->cursor.par->
+ GetInset(owner->view()->text->
+ cursor.pos));
+ if (inset)
+ inset->Edit(owner->view(),slx,sly,0);
+ return string();
+ } else if (owner->view()->the_locking_inset->
+ LocalDispatch(owner->view(),action,
+ argument) ==
+ UpdatableInset::DISPATCHED)
+ return string();
+ else {
+ setMessage(N_("Text mode"));
+ LyXDirection direction = owner->view()->text->
+ cursor.par->getParDirection();
+ if ((action == -1) ||
+ ((action == LFUN_RIGHT) &&
+ (direction == LYX_DIR_LEFT_TO_RIGHT))) {
+ owner->view()->text->CursorRight();
+ moveCursorUpdate(false);
+ owner->getMiniBuffer()->
+ Set(CurrentState());
+ }
+ if ((action == LFUN_LEFT) &&
+ (direction == LYX_DIR_RIGHT_TO_LEFT)) {
+ owner->view()->text->CursorRight();
+ moveCursorUpdate(false);
+ owner->getMiniBuffer()->
+ Set(CurrentState());
+ }
+ if ((action == LFUN_LEFT) ||
+ (action == LFUN_RIGHT))
return string();
- } else
- if (owner->view()->the_locking_inset->LocalDispatch(owner->view(), action, argument.c_str()))
- return string();
- else {
- setMessage(N_("Text mode"));
- LyXDirection direction = owner->view()->text->cursor.par->getParDirection();
- if ( action == -1 ||
- (action == LFUN_RIGHT
- && direction == LYX_DIR_LEFT_TO_RIGHT)) {
- owner->view()->text->CursorRight();
- moveCursorUpdate(false);
- owner->getMiniBuffer()->Set(CurrentState());
- }
- if ( action == LFUN_LEFT
- && direction == LYX_DIR_RIGHT_TO_LEFT) {
- owner->view()->text->CursorRight();
- moveCursorUpdate(false);
- owner->getMiniBuffer()->Set(CurrentState());
- }
- if (action == LFUN_LEFT || action == LFUN_RIGHT)
- return string();
- }
+ }
}
}
&& tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos);
setMessage(tmpinset->EditMessage());
- tmpinset->Edit(owner->view(), 0, 0);
+ tmpinset->Edit(owner->view(), 0, 0, 0);
break;
}
if (direction == LYX_DIR_LEFT_TO_RIGHT)
tmpinset->Edit(owner->view(),
tmpinset->width(owner->view()->painter(),
txt->GetFont(txt->cursor.par,
- txt->cursor.pos)), 0);
+ txt->cursor.pos)),
+ 0, 0);
break;
}
if (direction == LYX_DIR_RIGHT_TO_LEFT)
else
new_inset = new InsetUrl("url", "", "");
owner->view()->insertInset(new_inset);
- new_inset->Edit(owner->view(), 0, 0);
+ new_inset->Edit(owner->view(), 0, 0, 0);
+ }
+ break;
+ case LFUN_INSET_TEXT:
+ {
+ InsetText * new_inset = new InsetText(owner->buffer());
+ owner->view()->insertInset(new_inset);
+ new_inset->Edit(owner->view(), 0, 0, 0);
+ }
+ break;
+ case LFUN_INSET_ERT:
+ {
+ InsetERT * new_inset = new InsetERT(owner->buffer());
+ owner->view()->insertInset(new_inset);
+ new_inset->Edit(owner->view(), 0, 0, 0);
}
break;
owner->view()->insertInset(new_inset);
} else {
owner->view()->insertInset(new_inset);
- new_inset->Edit(owner->view(), 0, 0);
+ new_inset->Edit(owner->view(), 0, 0, 0);
}
}
break;
owner->view()->insertInset(new_inset);
if (lsarg.empty()) {
- new_inset->Edit(owner->view(), 0, 0);
+ new_inset->Edit(owner->view(), 0, 0, 0);
}
}
break;
//don't edit it if the call was to INSERT_LAST
if(action != LFUN_INDEX_INSERT_LAST) {
- new_inset->Edit(owner->view(), 0, 0);
+ new_inset->Edit(owner->view(), 0, 0, 0);
} else {
//it looks blank on the screen unless
//we do something. put it here.
Inset * new_inset = new InsetInclude(argument,
owner->buffer());
owner->view()->insertInset(new_inset, "Standard", true);
- new_inset->Edit(owner->view(), 0, 0);
+ new_inset->Edit(owner->view(), 0, 0, 0);
}
break;
LyXParagraph * TeXOnePar(string & file, TexRow & texrow,
string & foot, TexRow & foot_texrow,
int & foot_count);
+ ///
+ bool SimpleTeXOnePar(string & file, TexRow & texrow);
///
LyXParagraph * TeXEnvironment(string & file, TexRow & texrow,
int & foot_count,
LyXDirection par_direction);
///
- bool SimpleTeXOnePar(string & file, TexRow & texrow);
- ///
bool SimpleTeXOneTablePar(string & file, TexRow & texrow);
///
bool TeXContTableRows(string & file, size_type i,
LyXAlignment align,
string labelwidthstring,
bool noindent);
- void SetParagraphExtraOpt(int type,
- char const * width,
- char const * widthp,
- int alignment, bool hfill,
- bool start_minipage);
+ void SetParagraphExtraOpt(int type,
+ char const * width,
+ char const * widthp,
+ int alignment, bool hfill,
+ bool start_minipage);
/* these things are for search and replace */
void CursorLeftIntern() const;
///
void CursorRightIntern() const;
- ///
- void RemoveTableRow(LyXCursor * cursor) const;
- ///
- bool IsEmptyTableCell() const;
- ///
- void toggleAppendix();
+ ///
+ void RemoveTableRow(LyXCursor * cursor) const;
+ ///
+ bool IsEmptyTableCell() const;
+ ///
+ void toggleAppendix();
///
unsigned short paperWidth() const { return paperwidth; }
private:
}
-void InsetFormula::Edit(BufferView * bv, int x, int y)
+void InsetFormula::Edit(BufferView * bv, int x, int y, unsigned int)
{
- mathcursor = new MathedCursor(par);
- bv->lockInset(this);
- par->Metrics();
- bv->updateInset(this, false);
- x += par->xo;
- y += par->yo;
- mathcursor->SetPos(x, y);
+ mathcursor = new MathedCursor(par);
+ bv->lockInset(this);
+ par->Metrics();
+ bv->updateInset(this, false);
+ x += par->xo;
+ y += par->yo;
+ mathcursor->SetPos(x, y);
sel_x = sel_y = 0;
sel_flag = false;
}
}
-bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg)
+UpdatableInset::RESULT InsetFormula::LocalDispatch(BufferView * bv,
+ int action, string arg)
{
// extern char *dispatch_result;
MathedTextCodes varcode = LM_TC_MIN;
- bool was_macro = mathcursor->InMacroMode();
- bool sel = false;
- bool space_on = false;
- bool was_selection = mathcursor->Selection();
- bool result = true;
- static MathSpaceInset * sp= 0;
+ bool was_macro = mathcursor->InMacroMode();
+ bool sel = false;
+ bool space_on = false;
+ bool was_selection = mathcursor->Selection();
+ RESULT result = DISPATCHED;
+ static MathSpaceInset * sp= 0;
HideInsetCursor(bv);
case LFUN_RIGHTSEL: sel = true;
case LFUN_RIGHT:
{
- result = mathcursor->Right(sel);
+ result = DISPATCH_RESULT(mathcursor->Right(sel));
break;
}
case LFUN_LEFTSEL: sel = true;
case LFUN_LEFT:
{
- result = mathcursor->Left(sel);
+ result = DISPATCH_RESULT(mathcursor->Left(sel));
break;
}
case LFUN_UPSEL: sel = true;
case LFUN_UP:
- result = mathcursor->Up(sel);
+ result = DISPATCH_RESULT(mathcursor->Up(sel));
break;
case LFUN_DOWNSEL: sel = true;
case LFUN_DOWN:
- result = mathcursor->Down(sel);
+ result = DISPATCH_RESULT(mathcursor->Down(sel));
break;
case LFUN_HOME:
mathcursor->Home();
case LFUN_SETXY:
{
int x, y, x1, y1;
- sscanf(arg, "%d %d", &x, &y);
+ sscanf(arg.c_str(), "%d %d", &x, &y);
par->GetXY(x1, y1);
mathcursor->SetPos(x1+x, y1+y);
}
}
case LFUN_MATH_SIZE:
- if (arg) {
- latexkeys * l = in_word_set (arg, strlen(arg));
+ if (!arg.empty()) {
+ latexkeys * l = in_word_set (arg.c_str(), strlen(arg.c_str()));
int sz = (l) ? l->id: -1;
mathcursor->SetSize(sz);
UpdateLocal(bv);
case LFUN_INSERT_MATH:
{
bv->lockedInsetStoreUndo(Undo::INSERT);
- InsertSymbol(bv, arg);
+ InsertSymbol(bv, arg.c_str());
break;
}
int k, m, n;
char s[80], arg2[80];
// This is just so that too long args won't ooze out of s.
- strncpy(arg2, arg, 80); arg2[79]= '\0';
+ strncpy(arg2, arg.c_str(), 80); arg2[79]= '\0';
k = sscanf(arg2, "%d %d %s", &m, &n, s);
s[79] = '\0';
latexkeys * l;
string vdelim("(){}[]./|");
- if (!arg) break;
- strncpy(arg2, arg, 40); arg2[39]= '\0';
+ if (arg.empty())
+ break;
+ strncpy(arg2, arg.c_str(), 40); arg2[39]= '\0';
int n = sscanf(arg2, "%s %s", lf, rg);
lf[39] = '\0'; rg[39] = '\0';
break;
default:
- if ((action == -1 || action == LFUN_SELFINSERT) && arg) {
+ if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
unsigned char c = arg[0];
bv->lockedInsetStoreUndo(Undo::INSERT);
space_on = true;
} else {
if (!mathcursor->Pop() && mathcursor->IsEnd())
- result = false;
+ result = FINISHED;
}
} else
if (c == '\'') {
UpdateLocal(bv);
} else {
// lyxerr << "Closed by action " << action << endl;
- result = false;
+ result = FINISHED;
}
}
if (was_macro != mathcursor->InMacroMode()
if (mathcursor->Selection() || was_selection)
ToggleInsetSelection(bv);
- if (result)
+ if (result == DISPATCHED)
ShowInsetCursor(bv);
else
bv->unlockInset(this);
}
/// what appears in the minibuffer when opening
- char const * EditMessage() const {return _("Math editor mode");}
+ const char * EditMessage() const {return _("Math editor mode");}
///
- void Edit(BufferView *, int x, int y);
+ void Edit(BufferView *, int x, int y, unsigned int button);
///
bool display() const { return (disp_flag) ? true: false; }
///
void InsetUnlock(BufferView *);
/// To allow transparent use of math editing functions
- virtual bool LocalDispatch(BufferView *, int, char const *);
+ virtual RESULT LocalDispatch(BufferView *, int, string);
///
void InsertSymbol(BufferView *, char const *);
void InsetFormulaMacro::draw(Painter & pain, LyXFont const & f,
- int baseline, float & x) const
+ int baseline, float & x)
{
LyXFont font(f);
tmacro->update();
}
-void InsetFormulaMacro::Edit(BufferView * bv, int x, int y)
+void InsetFormulaMacro::Edit(BufferView * bv, int x, int y,unsigned int button)
{
opened = true;
par = static_cast<MathParInset*>(tmacro->Clone());
- InsetFormula::Edit(bv, x, y);
+ InsetFormula::Edit(bv, x, y, button);
}
}
-bool InsetFormulaMacro::LocalDispatch(BufferView * bv,
- int action, char const * arg)
+UpdatableInset::RESULT InsetFormulaMacro::LocalDispatch(BufferView * bv,
+ int action, string arg)
{
if (action == LFUN_MATH_MACROARG) {
- int i = atoi(arg) - 1;
+ int i = atoi(arg.c_str()) - 1;
if (i >= 0 && i < tmacro->getNoArgs()) {
mathcursor->Insert(tmacro->getMacroPar(i), LM_TC_INSET);
InsetFormula::UpdateLocal(bv);
}
- return true;
+ return DISPATCHED;
}
tmacro->setEditMode(true);
tmacro->Metrics();
- bool result = InsetFormula::LocalDispatch(bv, action, arg);
+ RESULT result = InsetFormula::LocalDispatch(bv, action, arg);
tmacro->setEditMode(false);
return result;
///
int width(Painter &, LyXFont const &) const;
///
- void draw(Painter &, LyXFont const &, int baseline, float & x) const;
+ void draw(Painter &, LyXFont const &, int baseline, float & x);
///
void Read(LyXLex & lex);
///
Inset * Clone() const;
/// what appears in the minibuffer when opening
- char const * EditMessage() const {return _("Math macro editor mode");}
+ const char * EditMessage() const {return _("Math macro editor mode");}
///
- void Edit(BufferView *, int x, int y);
+ void Edit(BufferView *, int x, int y, unsigned int button);
///
void InsetUnlock(BufferView *);
///
- bool LocalDispatch(BufferView *, int, char const *);
+ RESULT LocalDispatch(BufferView *, int, string);
+
protected:
///
//void UpdateLocal();
+
private:
///
bool opened;
/// In a near future maybe we use a better fonts renderer than X
void drawStr(Painter &, short, int, int, int, byte *, int);
- ///
+ ///
friend class MathedCursor;
- ///
+ ///
friend void mathed_init_fonts();
};
current_view->beforeChange();
current_view->insertInset(new_inset);
// Update(1);//BUG
- new_inset->Edit(current_view, 0, 0);
+ new_inset->Edit(current_view, 0, 0, 0);
new_inset->InsertSymbol(current_view, s);
} else
if (current_view->the_locking_inset->LyxCode() == Inset::MATH_CODE)
return;
} else if (c == LyXParagraph::META_INSET) {
Inset * tmpinset = row->par->GetInset(pos);
- if (tmpinset)
+ if (tmpinset) {
+ tmpinset->init(owner_);
tmpinset->draw(owner_->painter(), font,
offset + row->baseline, x);
+ }
++vpos;
return;
}
void LyXText::OpenStuff()
{
if (cursor.pos == 0 && cursor.par->bibkey){
- cursor.par->bibkey->Edit(owner_, 0, 0);
+ cursor.par->bibkey->Edit(owner_, 0, 0, 0);
}
else if (cursor.pos < cursor.par->Last()
&& cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
->Set(cursor.par->GetInset(cursor.pos)->EditMessage());
if (cursor.par->GetInset(cursor.pos)->Editable() != 2)
SetCursorParUndo();
- cursor.par->GetInset(cursor.pos)->Edit(owner_, 0, 0);
+ cursor.par->GetInset(cursor.pos)->Edit(owner_, 0, 0, 0);
} else {
ToggleFootnote();
}