From: Jürgen Vigna Date: Fri, 25 Feb 2000 12:06:15 +0000 (+0000) Subject: All changes I made to have text-insets working. Look at the Changelog X-Git-Tag: 1.6.10~22368 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d6fa7c567c47f1af95f026174a83bf75dde08f84;p=features.git All changes I made to have text-insets working. Look at the Changelog for more details. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@571 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index f83550dca5..290bdde8e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2000-02-24 Juergen Vigna + + * 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 * src/lyx_cb.C src/UpdateInset.[Ch]: move the updateinsetlist into diff --git a/po/POTFILES.in b/po/POTFILES.in index 7f6a48b17b..ea2a66716e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -29,6 +29,7 @@ src/insets/form_url.C src/insets/insetbib.C src/insets/inseterror.C src/insets/inseterror.h +src/insets/insetert.C src/insets/insetinclude.C src/insets/insetindex.C src/insets/insetinfo.C @@ -38,6 +39,7 @@ src/insets/insetlof.h src/insets/insetlot.h src/insets/insetparent.h src/insets/insetref.C +src/insets/insettext.C src/insets/insettoc.h src/insets/inseturl.C src/insets/inseturl.h diff --git a/src/BufferView.C b/src/BufferView.C index 94d7e5532d..b4624ee8a7 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -736,7 +736,7 @@ void BufferView::workAreaButtonPress(int xpos, int ypos, unsigned int button) selection_possible = false; owner_->updateLayoutChoice(); owner_->getMiniBuffer()->Set(inset_hit->EditMessage()); - inset_hit->Edit(this, xpos, ypos); + inset_hit->Edit(this, xpos, ypos, button); return; } @@ -870,7 +870,7 @@ void BufferView::workAreaButtonRelease(int x, int y, unsigned int button) } owner_->getMiniBuffer()->Set(inset_hit->EditMessage()); - inset_hit->Edit(this, x, y); + inset_hit->Edit(this, x, y, button); return; } @@ -946,7 +946,7 @@ void BufferView::workAreaButtonRelease(int x, int y, unsigned int button) textclasslist .TextClass(buffer_-> params.textclass).defaultfont())) { - text->cursor.par->bibkey->Edit(this, 0, 0); + text->cursor.par->bibkey->Edit(this, 0, 0, 0); } return; @@ -1025,7 +1025,6 @@ Inset * BufferView::checkInsetHit(int & x, int & y) return 0; } - void BufferView::workAreaExpose() { // this is a hack to ensure that we only call this through @@ -1427,7 +1426,7 @@ void BufferView::insetSleep() void BufferView::insetWakeup() { if (the_locking_inset && inset_slept) { - the_locking_inset->Edit(this, slx, sly); + the_locking_inset->Edit(this, slx, sly, 0); inset_slept = false; } } @@ -1462,6 +1461,18 @@ bool BufferView::active() const } +Painter & BufferView::getPainter() const +{ + return workarea->getPainter(); +} + + +unsigned short BufferView::paperWidth() const +{ + return text->paperWidth(); +} + + bool BufferView::belowMouse() const { return workarea->belowMouse(); diff --git a/src/BufferView.h b/src/BufferView.h index 0f43d9fa14..b07ef0935d 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -41,6 +41,8 @@ public: /// Painter & painter(); /// + Painter & getPainter() const; + /// void buffer(Buffer * b); /// void resize(int, int, int, int); @@ -83,8 +85,12 @@ public: */ LyXText * text; /// + unsigned short paperWidth() const; + /// UpdatableInset * the_locking_inset; /// + void updateInset(Inset * inset, bool mark_dirty); + /// bool inset_slept; /// int slx; @@ -264,8 +270,6 @@ private: /// UpdateInset updatelist; public: - /// - void updateInset(Inset *, bool); /// void pushIntoUpdateList(Inset * i) { updatelist.push(i); diff --git a/src/BufferView2.C b/src/BufferView2.C index ea2aa084fa..edd0a38e24 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -237,7 +237,7 @@ void BufferView::open_new_inset(UpdatableInset * new_inset) insertInset(new_inset); text->CursorLeft(); update(1); - new_inset->Edit(this, 0, 0); + new_inset->Edit(this, 0, 0, 0); } /* This is also a buffer property (ale) */ @@ -360,7 +360,7 @@ void BufferView::insertNote() { InsetInfo * new_inset = new InsetInfo(); insertInset(new_inset); - new_inset->Edit(this, 0, 0); + new_inset->Edit(this, 0, 0, 0); } @@ -684,6 +684,7 @@ void BufferView::replaceWord(string const & replacestring) // End of spellchecker stuff + /* these functions return 1 if an error occured, otherwise 0 */ int BufferView::lockInset(UpdatableInset * inset) @@ -756,16 +757,31 @@ void BufferView::updateInset(Inset * inset, bool mark_dirty) return; // first check for locking insets - if (the_locking_inset == inset) { - if (text->UpdateInset(inset)){ - update(); - if (mark_dirty){ - if (buffer()->isLyxClean()) - owner()->getMiniBuffer()->setTimer(4); - buffer()->markDirty(); + if (the_locking_inset) { + if (the_locking_inset == inset) { + if (text->UpdateInset(inset)){ + update(); + if (mark_dirty){ + if (buffer()->isLyxClean()) + owner()->getMiniBuffer()-> + setTimer(4); + buffer()->markDirty(); + } + updateScrollbar(); + return; + } + } else if (the_locking_inset->UpdateInsetInInset(this,inset)) { + if (text->UpdateInset(the_locking_inset)) { + update(); + if (mark_dirty){ + if (buffer()->isLyxClean()) + owner()->getMiniBuffer()-> + setTimer(4); + buffer()->markDirty(); + } + updateScrollbar(); + return; } - updateScrollbar(); - return; } } diff --git a/src/LyXAction.C b/src/LyXAction.C index 52a41787c1..7f0ba2f873 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -177,6 +177,8 @@ void LyXAction::init() { LFUN_GOTOERROR, "error-next", N_("Go to next error"), Noop }, { LFUN_REMOVEERRORS, "error-remove-all", N_("Remove all error boxes"), ReadOnly }, + { LFUN_INSET_ERT, "ert-inset-insert", + N_("Insert a new ERT Inset"), Noop }, { LFUN_FIGURE, "figure-insert", N_("Insert Figure"), Noop }, { LFUN_FILE_INSERT, "file-insert", "", Noop }, { LFUN_FILE_INSERT_ASCII, "file-insert-ascii", "", Noop }, @@ -330,6 +332,8 @@ void LyXAction::init() { LFUN_TABINSERT, "tab-insert", "", Noop }, { LFUN_TABLE, "table-insert", N_("Insert Table"), Noop }, { LFUN_TEX, "tex-mode", N_("Toggle TeX style"), Noop }, + { LFUN_INSET_TEXT, "text-inset-insert", + N_("Insert a new Text Inset"), Noop }, { LFUN_TOC_INSERT, "toc-insert", N_("Insert table of contents"), Noop }, { LFUN_TOCVIEW, "toc-view", diff --git a/src/buffer.C b/src/buffer.C index 131a716971..6c4495db6b 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -73,6 +73,8 @@ using std::setw; #include "insets/insetparent.h" #include "insets/insetspecialchar.h" #include "insets/figinset.h" +#include "insets/insettext.h" +#include "insets/insetert.h" #include "support/filetools.h" #include "support/path.h" #include "LaTeX.h" @@ -745,6 +747,20 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) par->InsertInset(pos, inset); par->SetFont(pos, font); ++pos; + } else if (tmptok == "ERT") { + inset = new InsetERT(this); + inset->Read(lex); + par->InsertChar(pos, LyXParagraph::META_INSET); + par->InsertInset(pos, inset); + par->SetFont(pos, font); + ++pos; + } else if (tmptok == "Text") { + inset = new InsetText(this); + inset->Read(lex); + par->InsertChar(pos, LyXParagraph::META_INSET); + par->InsertInset(pos, inset); + par->SetFont(pos, font); + ++pos; } else if (tmptok == "LatexCommand") { InsetCommand inscmd; inscmd.Read(lex); diff --git a/src/commandtags.h b/src/commandtags.h index bafd6ffde3..b0c2f7ffee 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -240,6 +240,8 @@ enum kb_action { LFUN_SAVEPREFERENCES, // Lgb 991127 LFUN_DATE_INSERT, // jdblair 20000131 LFUN_RTL, // Dekel 20000203 + LFUN_INSET_TEXT, // Jug 20000214 + LFUN_INSET_ERT, // Jug 20000218 LFUN_LASTACTION /* this marks the end of the table */ }; diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index cb0e3b132f..e7fc7eaa16 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -17,6 +17,8 @@ libinsets_la_SOURCES = \ insetcommand.h \ inseterror.C \ inseterror.h \ + insetert.C \ + insetert.h \ insetinclude.C \ insetinclude.h \ insetindex.C \ @@ -41,6 +43,8 @@ libinsets_la_SOURCES = \ insetref.h \ insetspecialchar.C \ insetspecialchar.h \ + insettext.C \ + insettext.h \ insettoc.C \ insettoc.h \ inseturl.C \ diff --git a/src/insets/figinset.C b/src/insets/figinset.C index 0210ef4511..854caea8c6 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -1036,8 +1036,7 @@ int InsetFig::width(Painter &, LyXFont const &) const } -void InsetFig::draw(Painter & pain, LyXFont const & f, - int baseline, float & x) const +void InsetFig::draw(Painter & pain, LyXFont const & f, int baseline, float & x) const { LyXFont font(f); @@ -1241,7 +1240,7 @@ bool InsetFig::Deletable() const } -void InsetFig::Edit(BufferView * bv, int, int) +void InsetFig::Edit(BufferView * bv, int, int, unsigned int) { lyxerr.debug() << "Editing InsetFig." << endl; Regenerate(); diff --git a/src/insets/figinset.h b/src/insets/figinset.h index 10e0c19205..1ee86e042a 100644 --- a/src/insets/figinset.h +++ b/src/insets/figinset.h @@ -49,9 +49,9 @@ public: void Validate(LaTeXFeatures & features) const; /// what appears in the minibuffer when opening - char const * EditMessage() const { return _("Opened figure"); } + const char * EditMessage() const { return _("Opened figure"); } /// - void Edit(BufferView *, int, int); + void Edit(BufferView *, int, int, unsigned int); /// unsigned char Editable() const; /// diff --git a/src/insets/inset.C b/src/insets/inset.C index e924c636ff..628f853aae 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -16,6 +16,7 @@ #include "lyxinset.h" #include "debug.h" +#include "BufferView.h" #include "support/lstrings.h" /* Insets default methods */ @@ -49,7 +50,7 @@ bool Inset::AutoDelete() const } -void Inset::Edit(BufferView *, int, int) +void Inset::Edit(BufferView *, int, int, unsigned int) { } @@ -105,3 +106,48 @@ unsigned char UpdatableInset::Editable() const void UpdatableInset::ToggleInsetCursor(BufferView *) { } + +void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int) +{ + LyXFont + font; +// bview = bv; + scx = 0; + + mx_scx=abs((width(bv->getPainter(), font) - bv->paperWidth())/2); +} + + +void UpdatableInset::draw(Painter &, LyXFont const &, + int baseline, float & x) const +{ + if (scx) x += float(scx); + top_x = int(x); + top_baseline = baseline; +} + + +void UpdatableInset::SetFont(LyXFont const &, bool ) +{ +} + +/// An updatable inset could handle lyx editing commands +#ifdef SCROLL_INSET +UpdatableInset::RESULT UpdatableInset::LocalDispatch(BufferView *, + int action, string arg) +#else +UpdatableInset::RESULT UpdatableInset::LocalDispatch(BufferView *, int, string) +#endif +{ +#ifdef SCROLL_INSET + if (action==LFUN_SCROLL_INSET) + { + float xx; + sscanf(arg.c_str(), "%f", &xx); + scroll(xx); + + return DISPATCHED; + } +#endif + return UNDISPATCHED; +} diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 4898652810..dd34a47a22 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -156,7 +156,7 @@ InsetCitation::~InsetCitation() } -void InsetCitation::Edit(BufferView * bv, int, int) +void InsetCitation::Edit(BufferView * bv, int, int, unsigned int) { if(bv->buffer()->isReadonly()) WarnReadonly(bv->buffer()->fileName()); @@ -265,7 +265,7 @@ string InsetBibKey::getScreenLabel() const upwards? (Joacim 1998-03-04) */ -void InsetBibKey::Edit(BufferView * bv, int, int) +void InsetBibKey::Edit(BufferView * bv, int, int, unsigned int) { if(bv->buffer()->isReadonly()) WarnReadonly(bv->buffer()->fileName()); @@ -419,7 +419,7 @@ string InsetBibtex::getKeys(char delim) // BibTeX should have its own dialog. This is provisional. -void InsetBibtex::Edit(BufferView *, int, int) +void InsetBibtex::Edit(BufferView *, int, int, unsigned int) { if (!bibitem_form) { bibitem_form = create_form_bibitem_form(); diff --git a/src/insets/insetbib.h b/src/insets/insetbib.h index e907229599..b8a0d1760e 100644 --- a/src/insets/insetbib.h +++ b/src/insets/insetbib.h @@ -18,8 +18,7 @@ #include "insetcommand.h" -// Created by Alejandro 970222 - +class Buffer; /** Used to insert citations */ @@ -38,7 +37,7 @@ public: /// string getScreenLabel()const; /// - void Edit(BufferView *, int, int); + void Edit(BufferView *, int x, int y, unsigned int button); /// unsigned char Editable() const { return 1; @@ -77,7 +76,7 @@ public: /// virtual string getScreenLabel() const; /// - void Edit(BufferView *, int, int); + void Edit(BufferView *, int x, int y, unsigned int button); /// unsigned char Editable() const { return 1; @@ -126,7 +125,7 @@ public: /// string getScreenLabel() const; /// - void Edit(BufferView *, int, int); + void Edit(BufferView *, int x, int y, unsigned int button); /// int Latex(ostream &, signed char) const; /// diff --git a/src/insets/inseterror.C b/src/insets/inseterror.C index a3d2928b58..d41ad691db 100644 --- a/src/insets/inseterror.C +++ b/src/insets/inseterror.C @@ -155,7 +155,7 @@ extern "C" void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data) } -void InsetError::Edit(BufferView *, int, int) +void InsetError::Edit(BufferView *, int, int, unsigned int) { static int ow = 400, oh = 240; diff --git a/src/insets/inseterror.h b/src/insets/inseterror.h index f3b14341e0..4fe2556586 100644 --- a/src/insets/inseterror.h +++ b/src/insets/inseterror.h @@ -41,8 +41,7 @@ public: /// int width(Painter &, LyXFont const & font) const; /// - void draw(Painter &, LyXFont const & font, - int baseline, float & x) const; + void draw(Painter &, LyXFont const & font, int baseline, float & x) const; /// void Write(ostream &) const; /// @@ -58,9 +57,9 @@ public: /// bool AutoDelete() const; /// what appears in the minibuffer when opening - char const * EditMessage() const {return _("Opened error");} + const char * EditMessage() const {return _("Opened error");} /// - void Edit(BufferView *, int, int); + void Edit(BufferView *, int x, int y, unsigned int button); /// unsigned char Editable() const; /// diff --git a/src/insets/insetert.C b/src/insets/insetert.C new file mode 100644 index 0000000000..83a9a81e83 --- /dev/null +++ b/src/insets/insetert.C @@ -0,0 +1,191 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright (C) 1998 The LyX Team. + * + *======================================================*/ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "insetert.h" +#include "gettext.h" +#include "lyxfont.h" +#include "Painter.h" +#include "lyx_gui_misc.h" + + +InsetERT::InsetERT(Buffer * bf): InsetText(bf) +{ + closed = true; + nomotion = false; +} + + +InsetERT * InsetERT::Clone() const +{ + InsetERT * result = new InsetERT(buffer); + return result; +} + + +void InsetERT::Write(ostream & os) const +{ + os << "ERT\n"; + WriteParagraphData(os); +} + + +int InsetERT::ascent_closed(Painter & pain, LyXFont const & f) const +{ + int width, ascent, descent; + LyXFont font(LyXFont::ALL_SANE); + font.setSize(f.size()); + font.decSize(); + font.decSize(); + pain.buttonText(0, 0, _("ERT"), font, false, width, ascent, descent); + return ascent; +} + + +int InsetERT::descent_closed(Painter & pain, LyXFont const & f) const +{ + int width, ascent, descent; + LyXFont font(LyXFont::ALL_SANE); + font.setSize(f.size()); + font.decSize(); + font.decSize(); + pain.buttonText(0, 0, _("ERT"), font, false, width, ascent, descent); + return descent; +} + + +int InsetERT::width_closed(Painter & pain, LyXFont const & f) const +{ + int width, ascent, descent; + LyXFont font(LyXFont::ALL_SANE); + font.setSize(f.size()); + font.decSize(); + font.decSize(); + pain.buttonText(TEXT_TO_INSET_OFFSET, 0, _("ERT"), font, false, + width, ascent, descent); + return width + (2*TEXT_TO_INSET_OFFSET); +} + + +int InsetERT::ascent(Painter & pain, LyXFont const & font) const +{ + if (closed) + return ascent_closed(pain, font); + else + return InsetText::ascent(pain, font); +} + + +int InsetERT::descent(Painter & pain, LyXFont const & font) const +{ + + if (closed) + return descent_closed(pain, font); + else + return InsetText::descent(pain, font); +} + + +int InsetERT::width(Painter & pain, LyXFont const & font) const +{ + if (closed) + return width_closed(pain, font); + else + return InsetText::width(pain, font); +} + + +void InsetERT::draw_closed(Painter & pain, LyXFont const & f, + int baseline, float & x) const +{ + LyXFont font(LyXFont::ALL_SANE); + font.setSize(f.size()); + font.decSize(); + font.decSize(); + font.setColor(LColor::ert); + int width; + pain.buttonText(int(x)+TEXT_TO_INSET_OFFSET, baseline, _("ERT"), font, + true, width); + x += width + (2*TEXT_TO_INSET_OFFSET); +} + + +void InsetERT::draw(Painter & pain, LyXFont const & f, int baseline, float & x) const +{ + if (closed) { + top_x = int(x); + top_baseline = baseline; + draw_closed(pain, f, baseline, x); + } else { + InsetText::draw(pain, f, baseline, x); + } +// resetPos(bv); +} + + +void InsetERT::InsetButtonRelease(BufferView * bv, int x, int y, int button) +{ + nomotion = false; + InsetText::InsetButtonRelease(bv, x, y, button); +} + + +void InsetERT::InsetButtonPress(BufferView * bv, int x, int y, int button) +{ + nomotion = false; + InsetText::InsetButtonPress(bv, x, y, button); +} + + +void InsetERT::InsetMotionNotify(BufferView * bv, int x, int y, int button) +{ + if (nomotion) + return; + InsetText::InsetMotionNotify(bv, x, y, button); +} + + +void InsetERT::Edit(BufferView * bv, int x, int y, unsigned int button) +{ + closed = false; + nomotion = true; + LyXFont font(LyXFont::ALL_SANE); + font.setLatex (LyXFont::ON); + InsetText::Edit(bv, (x > (width_closed(bv->getPainter(),font)-5) ? + width(bv->getPainter(), font) : 0), y, button); + real_current_font = current_font = font; + bv->updateInset(this, false); +} + + +void InsetERT::InsetUnlock(BufferView * bv) +{ + closed = true; + InsetText::InsetUnlock(bv); + bv->updateInset(this, false); +} + + +bool InsetERT::InsertInset(Inset *) +{ + return false; +} + + +void InsetERT::SetFont(LyXFont const &, bool) +{ + WriteAlert(_("Impossible Operation!"), + _("Not permitted to change font-types inside ERT-insets!"), + _("Sorry.")); +} diff --git a/src/insets/insetert.h b/src/insets/insetert.h new file mode 100644 index 0000000000..76bf317929 --- /dev/null +++ b/src/insets/insetert.h @@ -0,0 +1,86 @@ +// -*- C++ -*- +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright (C) 1998 The LyX Team. + * + *====================================================== + */ +// The pristine updatable inset: Text + + +#ifndef INSETERT_H +#define INSETERT_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "insettext.h" + +class Painter; + +/** A colapsable text inset + + To write full ert (including styles and other insets) in a given + space. +*/ +class InsetERT : public InsetText { +public: + /// + InsetERT(Buffer *); + /// + // InsetERT(InsetERT const &, Buffer *); + /// + ~InsetERT() {} + /// + InsetERT * Clone() const; + /// + // void Read(LyXLex &); + /// + void Write(ostream &) const; + /// + int ascent(Painter &, LyXFont const &) const; + /// + int descent(Painter &, LyXFont const &) const; + /// + int width(Painter &, LyXFont const & f) const; + /// + void draw(Painter & pain, const LyXFont &, int , float &) const; + /// + //LString EditMessage() const; + /// + void InsetButtonRelease(BufferView *, int, int, int); + /// + void InsetButtonPress(BufferView *, int, int, int); + /// + void InsetMotionNotify(BufferView *, int, int, int); + /// + void Edit(BufferView *, int, int, unsigned int); + /// + void InsetUnlock(BufferView *); + /// + bool InsertInset(Inset *); + /// + void SetFont(LyXFont const &, bool toggleall); + +protected: + /// + int ascent_closed(Painter &, LyXFont const &) const; + /// + int descent_closed(Painter &, LyXFont const &) const; + /// + int width_closed(Painter &, LyXFont const & f) const; + /// + void draw_closed(Painter & pain, const LyXFont &, int , float &) const; + +private: + /// + bool + closed, + nomotion; +}; + +#endif diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 4a447b29d6..b9fdd55e03 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -226,7 +226,7 @@ Inset * InsetInclude::Clone() const } -void InsetInclude::Edit(BufferView * bv, int, int) +void InsetInclude::Edit(BufferView * bv, int, int, unsigned int) { if(bv->buffer()->isReadonly()) WarnReadonly(bv->buffer()->fileName()); diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 6b0fb58438..0cd817b2f2 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -47,7 +47,7 @@ public: /// This returns the list of bibkeys on the child buffer string getKeys(char delim) const; /// - void Edit(BufferView *, int, int); + void Edit(BufferView *, int x, int y, unsigned int button); /// unsigned char Editable() const { diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index dd187d63eb..03e844d5d5 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -85,7 +85,7 @@ InsetIndex::~InsetIndex() } -void InsetIndex::Edit(BufferView * bv, int, int) +void InsetIndex::Edit(BufferView * bv, int, int, unsigned int) { if(bv->buffer()->isReadonly()) WarnReadonly(bv->buffer()->fileName()); diff --git a/src/insets/insetindex.h b/src/insets/insetindex.h index 152dd6597d..b4905bf0b0 100644 --- a/src/insets/insetindex.h +++ b/src/insets/insetindex.h @@ -37,7 +37,7 @@ public: /// Inset * Clone() const { return new InsetIndex(contents);} /// - void Edit(BufferView *, int, int); + void Edit(BufferView *, int, int, unsigned int); /// unsigned char Editable() const { @@ -59,7 +59,7 @@ public: /// Updates needed features for this inset. void Validate(LaTeXFeatures & features) const; /// - void Edit(BufferView *, int, int) {} + void Edit(BufferView *, int, int, unsigned int) {} /// unsigned char Editable() const{ return 1; diff --git a/src/insets/insetinfo.C b/src/insets/insetinfo.C index 2e0978f356..848285ee59 100644 --- a/src/insets/insetinfo.C +++ b/src/insets/insetinfo.C @@ -180,7 +180,7 @@ extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data) } -void InsetInfo::Edit(BufferView * bv, int, int) +void InsetInfo::Edit(BufferView *bv, int, int, unsigned int) { static int ow = -1, oh; diff --git a/src/insets/insetinfo.h b/src/insets/insetinfo.h index 422b531f76..20ffaf207c 100644 --- a/src/insets/insetinfo.h +++ b/src/insets/insetinfo.h @@ -57,9 +57,9 @@ public: /// int DocBook(string & file) const; /// what appears in the minibuffer when opening - char const * EditMessage() const {return _("Opened note");} + const char * EditMessage() const {return _("Opened note");} /// - void Edit(BufferView *, int, int); + void Edit(BufferView *, int, int, unsigned int); /// unsigned char Editable() const; /// diff --git a/src/insets/insetloa.h b/src/insets/insetloa.h index 27757f4a00..49ca447356 100644 --- a/src/insets/insetloa.h +++ b/src/insets/insetloa.h @@ -19,7 +19,7 @@ #include "insetcommand.h" #include "gettext.h" -// Created by Bernhard 970807 +class Buffer; /** Used to insert table of algorithms */ diff --git a/src/insets/insetparent.C b/src/insets/insetparent.C index cca6c089bd..0fd046ddab 100644 --- a/src/insets/insetparent.C +++ b/src/insets/insetparent.C @@ -35,10 +35,10 @@ InsetParent::InsetParent(string const & fn, Buffer * owner) } -void InsetParent::Edit(BufferView * bv, int, int) +void InsetParent::Edit(BufferView * bv, int, int, unsigned int) { - bv->owner()->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, - getContents().c_str()); + bv->owner()->getLyXFunc()-> + Dispatch(LFUN_CHILDOPEN, getContents().c_str()); } diff --git a/src/insets/insetparent.h b/src/insets/insetparent.h index 1e7ab37207..2e863c1dea 100644 --- a/src/insets/insetparent.h +++ b/src/insets/insetparent.h @@ -17,7 +17,8 @@ #include "insetcommand.h" #include "gettext.h" -// Created by asierra 970813 + +class Buffer; /** Reference to the parent document. @@ -41,7 +42,7 @@ public: return string(_("Parent:")) + getContents(); } /// - void Edit(BufferView *, int, int); + void Edit(BufferView *, int, int, unsigned int); /// unsigned char Editable() const { return 1; diff --git a/src/insets/insetref.C b/src/insets/insetref.C index b4a7c2408c..79dd932872 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -43,10 +43,10 @@ InsetRef::InsetRef(InsetCommand const & inscmd, Buffer * bf) } -void InsetRef::Edit(BufferView * bv, int, int) +void InsetRef::Edit(BufferView * bv, int, int, unsigned int) { - bv->owner()->getLyXFunc() - ->Dispatch(LFUN_REFGOTO, getContents().c_str()); + bv->owner()->getLyXFunc()-> + Dispatch(LFUN_REFGOTO, getContents().c_str()); } diff --git a/src/insets/insetref.h b/src/insets/insetref.h index fe4e71487c..3644753e23 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -45,7 +45,7 @@ public: /// Inset::Code LyxCode() const { return Inset::REF_CODE; } /// - void Edit(BufferView *, int, int); + void Edit(BufferView *, int, int, unsigned int); /// unsigned char Editable() const { return 1; diff --git a/src/insets/insettext.C b/src/insets/insettext.C new file mode 100644 index 0000000000..c0da234c2c --- /dev/null +++ b/src/insets/insettext.C @@ -0,0 +1,1466 @@ +// -*- C++ -*- +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright (C) 1998 The LyX Team. + * + * ====================================================== + */ + +#include + +#include +using std::ifstream; + +#include + +#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 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 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 diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index 9aca608ac7..a4f89da74c 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -10,8 +10,9 @@ #include "commandtags.h" #include "lyxfunc.h" #include "LyXView.h" +#include "BufferView.h" -void InsetTOC::Edit(BufferView * bv, int, int) +void InsetTOC::Edit(BufferView * bv, int, int, unsigned int) { bv->owner()->getLyXFunc()->Dispatch(LFUN_TOCVIEW); } diff --git a/src/insets/insettoc.h b/src/insets/insettoc.h index f894d997f5..dbe4d44668 100644 --- a/src/insets/insettoc.h +++ b/src/insets/insettoc.h @@ -19,7 +19,7 @@ #include "insetcommand.h" #include "gettext.h" -// Created by Lgb 970527 +class Buffer; /** Used to insert table of contents */ @@ -34,7 +34,7 @@ public: /// string getScreenLabel() const { return _("Table of Contents"); } /// On edit, we open the TOC pop-up - void Edit(BufferView *, int, int); + void Edit(BufferView * bv, int, int, unsigned int); /// unsigned char Editable() const { return 1; diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index 9367c6f0c6..af46990837 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -109,7 +109,7 @@ extern "C" void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data) } -void InsetUrl::Edit(BufferView * bv, int, int) +void InsetUrl::Edit(BufferView * bv, int, int, unsigned int) { static int ow = -1, oh; diff --git a/src/insets/inseturl.h b/src/insets/inseturl.h index a16c006634..c60de849fd 100644 --- a/src/insets/inseturl.h +++ b/src/insets/inseturl.h @@ -52,13 +52,13 @@ public: /// void Validate(LaTeXFeatures &) const; /// - void Edit(BufferView *, int, int); + void Edit(BufferView *, int, int, unsigned int); /// unsigned char Editable() const { return 1; } /// - char const * EditMessage() const {return _("Opened Url");} + const char * EditMessage() const {return _("Opened Url");} /// bool display() const { return false; } /// diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index ccf22b4fa7..b34fa39dfb 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -76,7 +76,9 @@ public: /// PARENT_CODE, /// - BIBTEX_CODE + BIBTEX_CODE, + /// + TEXT_CODE }; /// @@ -93,9 +95,9 @@ public: /// virtual LyXFont ConvertFont(LyXFont font); /// what appears in the minibuffer when opening - virtual char const * EditMessage() const {return _("Opened inset");} + virtual const char * EditMessage() const {return _("Opened inset");} /// - virtual void Edit(BufferView *, int, int); + virtual void Edit(BufferView *, int x, int y, unsigned int button); /// virtual unsigned char Editable() const; /// @@ -142,6 +144,8 @@ public: virtual int GetNumberOfLabels() const { return 0; } + /// + virtual void init(BufferView *) {} }; @@ -174,6 +178,28 @@ public: */ class UpdatableInset: public Inset { public: + /** Dispatch result codes + Now that nested updatable insets are allowed, the local dispatch + becomes a bit complex, just two possible results (boolean) + are not enough. + + DISPATCHED = the inset catched the action + FINISHED = the inset must be unlocked as a result + of the action + UNDISPATCHED = the action was not catched, it should be + dispatched by lower level insets + */ + enum RESULT { + UNDISPATCHED=0, + DISPATCHED, + FINISHED + }; + + /// To convert old binary dispatch results + RESULT DISPATCH_RESULT(bool b) { + return (b) ? DISPATCHED: FINISHED; + } + /// //virtual ~UpdatableInset() {} /// @@ -188,20 +214,48 @@ public: /// virtual void InsetButtonRelease(BufferView *, int x, int y, int button); - /// virtual void InsetKeyPress(XKeyEvent * ev); /// virtual void InsetMotionNotify(BufferView *, int x, int y, int state); /// virtual void InsetUnlock(BufferView *); - + /// + virtual void Edit(BufferView *, int x, int y, unsigned int button); + /// + virtual void draw(Painter &, LyXFont const &, + int baseline, float & x) const; + /// + virtual void SetFont(LyXFont const &, bool toggleall = false); + /// + virtual bool InsertInset(Inset *) { return false; } + /// + virtual UpdatableInset * GetLockingInset() { return this; } + /// + virtual int InsetInInsetY() { return 0; } + /// + virtual bool UpdateInsetInInset(BufferView *, Inset *) {return false;} + /// + virtual bool UnlockInsetInInset(BufferView *,Inset *,bool /*lr*/=false) + {return false;} /// An updatable inset could handle lyx editing commands - virtual bool LocalDispatch(BufferView *, int, char const *) { return false; }; - // - bool isCursorVisible() const { return cursor_visible; } + virtual RESULT LocalDispatch(BufferView *, int, string); + /// + virtual bool isCursorVisible() const { return cursor_visible; } + /// + virtual int getMaxWidth(UpdatableInset *) const { return -1; } + protected: /// + // virtual void UpdateLocal(bool flag=true); + /// + mutable int top_x; + mutable int top_baseline; mutable bool cursor_visible; + +private: + /// + int mx_scx; + mutable int scx; }; #endif diff --git a/src/lyx_cb.C b/src/lyx_cb.C index be51409966..2477c0d0d5 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -2134,7 +2134,10 @@ void ToggleAndShow(BufferView * bv, LyXFont const & font) if (bv->available()) { bv->hideCursor(); bv->update(-2); - bv->text->ToggleFree(font, toggleall); + if (bv->the_locking_inset) + bv->the_locking_inset->SetFont(font, toggleall); + else + bv->text->ToggleFree(font, toggleall); bv->update(1); } } @@ -3143,7 +3146,7 @@ extern "C" void FigureApplyCB(FL_OBJECT *, long) InsetFig * new_inset = new InsetFig(100, 20, buffer); current_view->insertInset(new_inset); current_view->owner()->getMiniBuffer()->Set(_("Figure inserted")); - new_inset->Edit(current_view, 0, 0); + new_inset->Edit(current_view, 0, 0, 0); return; } @@ -3192,7 +3195,7 @@ extern "C" void FigureApplyCB(FL_OBJECT *, long) Inset * new_inset = new InsetFig(100, 100, buffer); current_view->insertInset(new_inset); - new_inset->Edit(current_view, 0, 0); + new_inset->Edit(current_view, 0, 0, 0); current_view->update(0); current_view->owner()->getMiniBuffer()->Set(_("Figure inserted")); current_view->text->UnFreezeUndo(); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 3500d05d49..2f84e83593 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -41,6 +41,8 @@ #include "insets/insetindex.h" #include "insets/insetinclude.h" #include "insets/insetbib.h" +#include "insets/insettext.h" +#include "insets/insetert.h" #include "mathed/formulamacro.h" #include "toolbar.h" #include "spellchecker.h" // RVDK_PATCH_5 @@ -524,44 +526,55 @@ string LyXFunc::Dispatch(int ac, inset->GetCursorPos(slx, sly); owner->view()->unlockInset(inset); owner->view()->menuUndo(); - inset = static_cast(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos)); - if (inset) - inset->Edit(owner->view(), slx, sly); + inset = static_cast( + 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(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( + owner->view()->text->cursor.par-> + GetInset(owner->view()->text-> + cursor.pos)); + if (inset) + inset->Edit(owner->view(),slx,sly,0); + return string(); + } else if (owner->view()->the_locking_inset-> + LocalDispatch(owner->view(),action, + argument) == + UpdatableInset::DISPATCHED) + return string(); + else { + setMessage(N_("Text mode")); + LyXDirection direction = owner->view()->text-> + cursor.par->getParDirection(); + if ((action == -1) || + ((action == LFUN_RIGHT) && + (direction == LYX_DIR_LEFT_TO_RIGHT))) { + owner->view()->text->CursorRight(); + moveCursorUpdate(false); + owner->getMiniBuffer()-> + Set(CurrentState()); + } + if ((action == LFUN_LEFT) && + (direction == LYX_DIR_RIGHT_TO_LEFT)) { + owner->view()->text->CursorRight(); + moveCursorUpdate(false); + owner->getMiniBuffer()-> + Set(CurrentState()); + } + if ((action == LFUN_LEFT) || + (action == LFUN_RIGHT)) return string(); - } else - if (owner->view()->the_locking_inset->LocalDispatch(owner->view(), action, argument.c_str())) - return string(); - else { - setMessage(N_("Text mode")); - LyXDirection direction = owner->view()->text->cursor.par->getParDirection(); - if ( action == -1 || - (action == LFUN_RIGHT - && direction == LYX_DIR_LEFT_TO_RIGHT)) { - owner->view()->text->CursorRight(); - moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState()); - } - if ( action == LFUN_LEFT - && direction == LYX_DIR_RIGHT_TO_LEFT) { - owner->view()->text->CursorRight(); - moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState()); - } - if (action == LFUN_LEFT || action == LFUN_RIGHT) - return string(); - } + } } } @@ -1288,7 +1301,7 @@ string LyXFunc::Dispatch(int ac, && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){ Inset * tmpinset = tmptext->cursor.par->GetInset(tmptext->cursor.pos); setMessage(tmpinset->EditMessage()); - tmpinset->Edit(owner->view(), 0, 0); + tmpinset->Edit(owner->view(), 0, 0, 0); break; } if (direction == LYX_DIR_LEFT_TO_RIGHT) @@ -1319,7 +1332,8 @@ string LyXFunc::Dispatch(int ac, tmpinset->Edit(owner->view(), tmpinset->width(owner->view()->painter(), txt->GetFont(txt->cursor.par, - txt->cursor.pos)), 0); + txt->cursor.pos)), + 0, 0); break; } if (direction == LYX_DIR_RIGHT_TO_LEFT) @@ -1876,7 +1890,21 @@ string LyXFunc::Dispatch(int ac, else new_inset = new InsetUrl("url", "", ""); owner->view()->insertInset(new_inset); - new_inset->Edit(owner->view(), 0, 0); + new_inset->Edit(owner->view(), 0, 0, 0); + } + break; + case LFUN_INSET_TEXT: + { + InsetText * new_inset = new InsetText(owner->buffer()); + owner->view()->insertInset(new_inset); + new_inset->Edit(owner->view(), 0, 0, 0); + } + break; + case LFUN_INSET_ERT: + { + InsetERT * new_inset = new InsetERT(owner->buffer()); + owner->view()->insertInset(new_inset); + new_inset->Edit(owner->view(), 0, 0, 0); } break; @@ -2169,7 +2197,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->insertInset(new_inset); } else { owner->view()->insertInset(new_inset); - new_inset->Edit(owner->view(), 0, 0); + new_inset->Edit(owner->view(), 0, 0, 0); } } break; @@ -2190,7 +2218,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->insertInset(new_inset); if (lsarg.empty()) { - new_inset->Edit(owner->view(), 0, 0); + new_inset->Edit(owner->view(), 0, 0, 0); } } break; @@ -2256,7 +2284,7 @@ string LyXFunc::Dispatch(int ac, //don't edit it if the call was to INSERT_LAST if(action != LFUN_INDEX_INSERT_LAST) { - new_inset->Edit(owner->view(), 0, 0); + new_inset->Edit(owner->view(), 0, 0, 0); } else { //it looks blank on the screen unless //we do something. put it here. @@ -2294,7 +2322,7 @@ string LyXFunc::Dispatch(int ac, Inset * new_inset = new InsetInclude(argument, owner->buffer()); owner->view()->insertInset(new_inset, "Standard", true); - new_inset->Edit(owner->view(), 0, 0); + new_inset->Edit(owner->view(), 0, 0, 0); } break; diff --git a/src/lyxparagraph.h b/src/lyxparagraph.h index 5dcdc812b8..1c319bddc8 100644 --- a/src/lyxparagraph.h +++ b/src/lyxparagraph.h @@ -154,6 +154,8 @@ public: LyXParagraph * TeXOnePar(string & file, TexRow & texrow, string & foot, TexRow & foot_texrow, int & foot_count); + /// + bool SimpleTeXOnePar(string & file, TexRow & texrow); /// LyXParagraph * TeXEnvironment(string & file, TexRow & texrow, @@ -522,8 +524,6 @@ private: int & foot_count, LyXDirection par_direction); /// - bool SimpleTeXOnePar(string & file, TexRow & texrow); - /// bool SimpleTeXOneTablePar(string & file, TexRow & texrow); /// bool TeXContTableRows(string & file, size_type i, diff --git a/src/lyxtext.h b/src/lyxtext.h index 75a32c395e..37fd30db02 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -344,11 +344,11 @@ public: LyXAlignment align, string labelwidthstring, bool noindent); - void SetParagraphExtraOpt(int type, - char const * width, - char const * widthp, - int alignment, bool hfill, - bool start_minipage); + void SetParagraphExtraOpt(int type, + char const * width, + char const * widthp, + int alignment, bool hfill, + bool start_minipage); /* these things are for search and replace */ @@ -468,12 +468,12 @@ public: void CursorLeftIntern() const; /// void CursorRightIntern() const; - /// - void RemoveTableRow(LyXCursor * cursor) const; - /// - bool IsEmptyTableCell() const; - /// - void toggleAppendix(); + /// + void RemoveTableRow(LyXCursor * cursor) const; + /// + bool IsEmptyTableCell() const; + /// + void toggleAppendix(); /// unsigned short paperWidth() const { return paperwidth; } private: diff --git a/src/mathed/formula.C b/src/mathed/formula.C index da0aa2e652..0700701c6a 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -452,15 +452,15 @@ void InsetFormula::draw(Painter & pain, LyXFont const &, } -void InsetFormula::Edit(BufferView * bv, int x, int y) +void InsetFormula::Edit(BufferView * bv, int x, int y, unsigned int) { - mathcursor = new MathedCursor(par); - bv->lockInset(this); - par->Metrics(); - bv->updateInset(this, false); - x += par->xo; - y += par->yo; - mathcursor->SetPos(x, y); + mathcursor = new MathedCursor(par); + bv->lockInset(this); + par->Metrics(); + bv->updateInset(this, false); + x += par->xo; + y += par->yo; + mathcursor->SetPos(x, y); sel_x = sel_y = 0; sel_flag = false; } @@ -712,16 +712,17 @@ bool InsetFormula::SetNumber(bool numbf) } -bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg) +UpdatableInset::RESULT InsetFormula::LocalDispatch(BufferView * bv, + int action, string arg) { // extern char *dispatch_result; MathedTextCodes varcode = LM_TC_MIN; - bool was_macro = mathcursor->InMacroMode(); - bool sel = false; - bool space_on = false; - bool was_selection = mathcursor->Selection(); - bool result = true; - static MathSpaceInset * sp= 0; + bool was_macro = mathcursor->InMacroMode(); + bool sel = false; + bool space_on = false; + bool was_selection = mathcursor->Selection(); + RESULT result = DISPATCHED; + static MathSpaceInset * sp= 0; HideInsetCursor(bv); @@ -734,23 +735,23 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg) case LFUN_RIGHTSEL: sel = true; case LFUN_RIGHT: { - result = mathcursor->Right(sel); + result = DISPATCH_RESULT(mathcursor->Right(sel)); break; } case LFUN_LEFTSEL: sel = true; case LFUN_LEFT: { - result = mathcursor->Left(sel); + result = DISPATCH_RESULT(mathcursor->Left(sel)); break; } case LFUN_UPSEL: sel = true; case LFUN_UP: - result = mathcursor->Up(sel); + result = DISPATCH_RESULT(mathcursor->Up(sel)); break; case LFUN_DOWNSEL: sel = true; case LFUN_DOWN: - result = mathcursor->Down(sel); + result = DISPATCH_RESULT(mathcursor->Down(sel)); break; case LFUN_HOME: mathcursor->Home(); @@ -802,7 +803,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg) case LFUN_SETXY: { int x, y, x1, y1; - sscanf(arg, "%d %d", &x, &y); + sscanf(arg.c_str(), "%d %d", &x, &y); par->GetXY(x1, y1); mathcursor->SetPos(x1+x, y1+y); } @@ -918,8 +919,8 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg) } case LFUN_MATH_SIZE: - if (arg) { - latexkeys * l = in_word_set (arg, strlen(arg)); + if (!arg.empty()) { + latexkeys * l = in_word_set (arg.c_str(), strlen(arg.c_str())); int sz = (l) ? l->id: -1; mathcursor->SetSize(sz); UpdateLocal(bv); @@ -929,7 +930,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg) case LFUN_INSERT_MATH: { bv->lockedInsetStoreUndo(Undo::INSERT); - InsertSymbol(bv, arg); + InsertSymbol(bv, arg.c_str()); break; } @@ -939,7 +940,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg) int k, m, n; char s[80], arg2[80]; // This is just so that too long args won't ooze out of s. - strncpy(arg2, arg, 80); arg2[79]= '\0'; + strncpy(arg2, arg.c_str(), 80); arg2[79]= '\0'; k = sscanf(arg2, "%d %d %s", &m, &n, s); s[79] = '\0'; @@ -967,8 +968,9 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg) latexkeys * l; string vdelim("(){}[]./|"); - if (!arg) break; - strncpy(arg2, arg, 40); arg2[39]= '\0'; + if (arg.empty()) + break; + strncpy(arg2, arg.c_str(), 40); arg2[39]= '\0'; int n = sscanf(arg2, "%s %s", lf, rg); lf[39] = '\0'; rg[39] = '\0'; @@ -1070,7 +1072,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg) break; default: - if ((action == -1 || action == LFUN_SELFINSERT) && arg) { + if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) { unsigned char c = arg[0]; bv->lockedInsetStoreUndo(Undo::INSERT); @@ -1158,7 +1160,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg) space_on = true; } else { if (!mathcursor->Pop() && mathcursor->IsEnd()) - result = false; + result = FINISHED; } } else if (c == '\'') { @@ -1173,7 +1175,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg) UpdateLocal(bv); } else { // lyxerr << "Closed by action " << action << endl; - result = false; + result = FINISHED; } } if (was_macro != mathcursor->InMacroMode() @@ -1184,7 +1186,7 @@ bool InsetFormula::LocalDispatch(BufferView * bv, int action, char const * arg) if (mathcursor->Selection() || was_selection) ToggleInsetSelection(bv); - if (result) + if (result == DISPATCHED) ShowInsetCursor(bv); else bv->unlockInset(this); diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 5a10386682..06a5052751 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -70,9 +70,9 @@ public: } /// what appears in the minibuffer when opening - char const * EditMessage() const {return _("Math editor mode");} + const char * EditMessage() const {return _("Math editor mode");} /// - void Edit(BufferView *, int x, int y); + void Edit(BufferView *, int x, int y, unsigned int button); /// bool display() const { return (disp_flag) ? true: false; } /// @@ -99,7 +99,7 @@ public: void InsetUnlock(BufferView *); /// To allow transparent use of math editing functions - virtual bool LocalDispatch(BufferView *, int, char const *); + virtual RESULT LocalDispatch(BufferView *, int, string); /// void InsertSymbol(BufferView *, char const *); diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index b735a21054..d887fea0cb 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -146,7 +146,7 @@ int InsetFormulaMacro::width(Painter & pain, LyXFont const & f) const void InsetFormulaMacro::draw(Painter & pain, LyXFont const & f, - int baseline, float & x) const + int baseline, float & x) { LyXFont font(f); tmacro->update(); @@ -173,11 +173,11 @@ void InsetFormulaMacro::draw(Painter & pain, LyXFont const & f, } -void InsetFormulaMacro::Edit(BufferView * bv, int x, int y) +void InsetFormulaMacro::Edit(BufferView * bv, int x, int y,unsigned int button) { opened = true; par = static_cast(tmacro->Clone()); - InsetFormula::Edit(bv, x, y); + InsetFormula::Edit(bv, x, y, button); } @@ -193,21 +193,21 @@ void InsetFormulaMacro::InsetUnlock(BufferView * bv) } -bool InsetFormulaMacro::LocalDispatch(BufferView * bv, - int action, char const * arg) +UpdatableInset::RESULT InsetFormulaMacro::LocalDispatch(BufferView * bv, + int action, string arg) { if (action == LFUN_MATH_MACROARG) { - int i = atoi(arg) - 1; + int i = atoi(arg.c_str()) - 1; if (i >= 0 && i < tmacro->getNoArgs()) { mathcursor->Insert(tmacro->getMacroPar(i), LM_TC_INSET); InsetFormula::UpdateLocal(bv); } - return true; + return DISPATCHED; } tmacro->setEditMode(true); tmacro->Metrics(); - bool result = InsetFormula::LocalDispatch(bv, action, arg); + RESULT result = InsetFormula::LocalDispatch(bv, action, arg); tmacro->setEditMode(false); return result; diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index 511bcc68f7..988c7481e1 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -42,7 +42,7 @@ public: /// int width(Painter &, LyXFont const &) const; /// - void draw(Painter &, LyXFont const &, int baseline, float & x) const; + void draw(Painter &, LyXFont const &, int baseline, float & x); /// void Read(LyXLex & lex); /// @@ -59,16 +59,18 @@ public: Inset * Clone() const; /// what appears in the minibuffer when opening - char const * EditMessage() const {return _("Math macro editor mode");} + const char * EditMessage() const {return _("Math macro editor mode");} /// - void Edit(BufferView *, int x, int y); + void Edit(BufferView *, int x, int y, unsigned int button); /// void InsetUnlock(BufferView *); /// - bool LocalDispatch(BufferView *, int, char const *); + RESULT LocalDispatch(BufferView *, int, string); + protected: /// //void UpdateLocal(); + private: /// bool opened; diff --git a/src/mathed/math_defs.h b/src/mathed/math_defs.h index f1f28bac03..3a308f4952 100644 --- a/src/mathed/math_defs.h +++ b/src/mathed/math_defs.h @@ -287,9 +287,9 @@ class MathedInset { /// In a near future maybe we use a better fonts renderer than X void drawStr(Painter &, short, int, int, int, byte *, int); - /// + /// friend class MathedCursor; - /// + /// friend void mathed_init_fonts(); }; diff --git a/src/mathed/math_symbols.C b/src/mathed/math_symbols.C index 85b0837543..f1afe0b833 100644 --- a/src/mathed/math_symbols.C +++ b/src/mathed/math_symbols.C @@ -371,7 +371,7 @@ void math_insert_symbol(char const * s) current_view->beforeChange(); current_view->insertInset(new_inset); // Update(1);//BUG - new_inset->Edit(current_view, 0, 0); + new_inset->Edit(current_view, 0, 0, 0); new_inset->InsertSymbol(current_view, s); } else if (current_view->the_locking_inset->LyxCode() == Inset::MATH_CODE) diff --git a/src/text.C b/src/text.C index d21cc00f46..717b05c681 100644 --- a/src/text.C +++ b/src/text.C @@ -370,9 +370,11 @@ void LyXText::draw(Row const * row, return; } else if (c == LyXParagraph::META_INSET) { Inset * tmpinset = row->par->GetInset(pos); - if (tmpinset) + if (tmpinset) { + tmpinset->init(owner_); tmpinset->draw(owner_->painter(), font, offset + row->baseline, x); + } ++vpos; return; } diff --git a/src/text2.C b/src/text2.C index d951b56c63..d151ef37de 100644 --- a/src/text2.C +++ b/src/text2.C @@ -348,7 +348,7 @@ void LyXText::ToggleFootnote() void LyXText::OpenStuff() { if (cursor.pos == 0 && cursor.par->bibkey){ - cursor.par->bibkey->Edit(owner_, 0, 0); + cursor.par->bibkey->Edit(owner_, 0, 0, 0); } else if (cursor.pos < cursor.par->Last() && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET @@ -357,7 +357,7 @@ void LyXText::OpenStuff() ->Set(cursor.par->GetInset(cursor.pos)->EditMessage()); if (cursor.par->GetInset(cursor.pos)->Editable() != 2) SetCursorParUndo(); - cursor.par->GetInset(cursor.pos)->Edit(owner_, 0, 0); + cursor.par->GetInset(cursor.pos)->Edit(owner_, 0, 0, 0); } else { ToggleFootnote(); }