From: Jürgen Vigna Date: Tue, 4 Jul 2000 11:30:07 +0000 (+0000) Subject: Lots of changes for update of TextInsets, still some problems! X-Git-Tag: 1.6.10~22141 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=eb7220abe64a6e301c51974fb34bb916ac41d64b;p=features.git Lots of changes for update of TextInsets, still some problems! git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@854 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index b62ff1d580..011c794361 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2000-07-04 Juergen Vigna + + * src/text.C (NextBreakPoint): added support for needFullRow() + + * src/insets/lyxinset.h: added needFullRow() + + * src/insets/insetcollapsable.C: redone now this uses a text-inset + and isn't one. + + * src/insets/insettext.C: lots of changes for update! + 2000-07-03 Angus Leeming * src/LaTeXFeatures.h: add a missing std:: qualifier. @@ -36,6 +47,14 @@ * src/lyx_main.C (easyParse): accept linuxdoc and docbook as formats to export with command line argument -x. +2000-06-29 Juergen Vigna + + * src/mathed/formula.C (LocalDispatch): changed only-cursor-movements + to return DISPATCHED_NOUPDATE so that a it does not redraw the inset! + + * src/text.C (GetVisibleRow): added 'bool cleared' parameter as the + region could already been cleared by an inset! + 2000-06-28 Lars Gullik Bjønnes * src/BufferView_pimpl.h: remove member variables lyx_focus and diff --git a/src/BufferView.C b/src/BufferView.C index 1d8592f3c3..e244fb46b3 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -117,6 +117,13 @@ void BufferView::updateScrollbar() } +Inset * BufferView::checkInsetHit(LyXText * text, int & x, int & y, + unsigned int button) +{ + return pimpl_->checkInsetHit(text, x, y, button); +} + + void BufferView::redoCurrentBuffer() { pimpl_->redoCurrentBuffer(); diff --git a/src/BufferView.h b/src/BufferView.h index 2795f8c0cd..b5783957aa 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -66,6 +66,8 @@ public: /// void updateScrollbar(); /// + Inset * checkInsetHit(LyXText *, int & x, int & y, unsigned int button); + /// void redoCurrentBuffer(); /// int resizeCurrentBuffer(); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index a9cc18b099..df4a1244ad 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -529,7 +529,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos, if (buffer_ == 0 || !screen_) return; - Inset * inset_hit = checkInsetHit(xpos, ypos, button); + Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button); // ok ok, this is a hack. if (button == 4 || button == 5) { @@ -725,7 +725,7 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y, // If we hit an inset, we have the inset coordinates in these // and inset_hit points to the inset. If we do not hit an // inset, inset_hit is 0, and inset_x == x, inset_y == y. - Inset * inset_hit = checkInsetHit(x, y, button); + Inset * inset_hit = checkInsetHit(bv_->text, x, y, button); if (bv_->the_locking_inset) { // We are in inset locking mode. @@ -877,19 +877,19 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y, * If hit, the coordinates are changed relative to the inset. * Otherwise coordinates are not changed, and false is returned. */ -Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y, +Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y, unsigned int /* button */) { if (!screen_) return 0; - unsigned int y_tmp = y + bv_->text->first; + unsigned int y_tmp = y + text->first; LyXCursor cursor; - bv_->text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp); + text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp); #if 0 // Are you planning to use this Jürgen? (Lgb) - bool move_cursor = ((cursor.par != bv_->text->cursor.par) || - (cursor.pos != bv_->text->cursor.pos())); + bool move_cursor = ((cursor.par != text->cursor.par) || + (cursor.pos != text->cursor.pos())); #endif if (cursor.pos() < cursor.par()->Last() && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET @@ -898,7 +898,7 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y, // Check whether the inset really was hit Inset * tmpinset = cursor.par()->GetInset(cursor.pos()); - LyXFont font = bv_->text->GetFont(bv_->buffer(), + LyXFont font = text->GetFont(bv_->buffer(), cursor.par(), cursor.pos()); bool is_rtl = font.isVisibleRightToLeft(); int start_x, end_x; @@ -917,10 +917,10 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y, #if 0 if (move_cursor && (tmpinset != bv_->the_locking_inset)) #endif - bv_->text->SetCursor(bv_, cursor.par(),cursor.pos(),true); + text->SetCursor(bv_, cursor.par(),cursor.pos(),true); x = x - start_x; // The origin of an inset is on the baseline - y = y_tmp - (bv_->text->cursor.y()); + y = y_tmp - (text->cursor.y()); return tmpinset; } } @@ -930,7 +930,7 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y, (cursor.par()->GetInset(cursor.pos() - 1)) && (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) { Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1); - LyXFont font = bv_->text->GetFont(bv_->buffer(), cursor.par(), + LyXFont font = text->GetFont(bv_->buffer(), cursor.par(), cursor.pos()-1); bool is_rtl = font.isVisibleRightToLeft(); int start_x, end_x; @@ -948,10 +948,10 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y, #if 0 if (move_cursor && (tmpinset != bv_->the_locking_inset)) #endif - bv_->text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true); + text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true); x = x - start_x; // The origin of an inset is on the baseline - y = y_tmp - (bv_->text->cursor.y()); + y = y_tmp - (text->cursor.y()); return tmpinset; } } diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 7f9aae0b96..6ee7a9c4bf 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -50,7 +50,7 @@ struct BufferView::Pimpl : public SigC::Object { /// void scrollCB(double value); /// - Inset * checkInsetHit(int & x, int & y, unsigned int button); + Inset * checkInsetHit(LyXText *, int & x, int & y, unsigned int button); /// int scrollUp(long time); /// diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 1889b8a169..0daae7037f 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -19,29 +19,37 @@ #include "lyxfont.h" #include "BufferView.h" #include "Painter.h" +#include "insets/insettext.h" #include "support/LOstream.h" #include "support/lstrings.h" +class LyXText; + using std::ostream; InsetCollapsable::InsetCollapsable() - : InsetText() + : UpdatableInset() { + inset = new InsetText; + inset->setOwner(this); collapsed = true; label = "Label"; autocollapse = true; - autoBreakRows = true; - framecolor = LColor::footnoteframe; - widthOffset = 2 * TEXT_TO_INSET_OFFSET + 2; // 1+1 (frame) + inset->SetAutoBreakRows(true); + inset->SetDrawFrame(0, InsetText::ALWAYS); + inset->SetFrameColor(0, LColor::footnoteframe); button_length = button_top_y = button_bottom_y = 0; setInsetName("Collapsable"); + widthCollapsed = oldWidth = 0; + need_update = FULL; } Inset * InsetCollapsable::Clone() const { InsetCollapsable * result = new InsetCollapsable(); - result->init(this); + result->inset->init(inset); + result->inset->setOwner(result); result->collapsed = collapsed; return result; @@ -50,11 +58,12 @@ Inset * InsetCollapsable::Clone() const void InsetCollapsable::Write(Buffer const * buf, ostream & os) const { - os << "collapsed " << tostr(!display()) << "\n"; - WriteParagraphData(buf, os); + os << "collapsed " << tostr(collapsed) << "\n"; + inset->WriteParagraphData(buf, os); } + void InsetCollapsable::Read(Buffer const * buf, LyXLex & lex) { if (lex.IsOK()) { @@ -65,7 +74,7 @@ void InsetCollapsable::Read(Buffer const * buf, LyXLex & lex) collapsed = lex.GetBool(); } } - InsetText::Read(buf, lex); + inset->Read(buf, lex); } @@ -101,7 +110,7 @@ int InsetCollapsable::ascent(Painter & pain, LyXFont const & font) const if (collapsed) return ascent_collapsed(pain, font); else - return InsetText::ascent(pain, font) + TEXT_TO_TOP_OFFSET; + return inset->ascent(pain, font) + TEXT_TO_TOP_OFFSET; } @@ -110,28 +119,26 @@ int InsetCollapsable::descent(Painter & pain, LyXFont const & font) const if (collapsed) return descent_collapsed(pain, font); else - return InsetText::descent(pain, font) + TEXT_TO_BOTTOM_OFFSET; + return inset->descent(pain, font) + TEXT_TO_BOTTOM_OFFSET; } int InsetCollapsable::width(Painter & pain, LyXFont const & font) const { if (collapsed) - return width_collapsed(pain, font); + return widthCollapsed; - return InsetText::width(pain, font) + width_collapsed(pain,font) + - widthOffset; + return inset->width(pain, font) + widthCollapsed; } -void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const & font, +void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const &, int baseline, float & x) const { int width = 0; pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET, - baseline-ascent(pain, font)+ascent_collapsed(pain, font), - label.c_str(), labelfont, true, width); - x += width + (2 * TEXT_TO_INSET_OFFSET); + baseline, label.c_str(), labelfont, true, width); + x += width + TEXT_TO_INSET_OFFSET; } @@ -140,56 +147,56 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, { Painter & pain = bv->painter(); - button_length = width_collapsed(pain, labelfont) + 2; + button_length = widthCollapsed; button_top_y = -ascent_collapsed(pain, f); button_bottom_y = descent_collapsed(pain, f); if (collapsed) { draw_collapsed(pain, f, baseline, x); + x += TEXT_TO_INSET_OFFSET; return; } - if (!cleared && ((need_update==FULL) || (topx!=int(x)) || - (topbaseline!=baseline))) { - int w = width(pain, f); + if (!cleared && ((need_update == FULL) || + (top_x!=int(x)) || (top_baseline!=baseline))) { + int w = owner()? width(pain, f) : pain.paperWidth(); int h = ascent(pain,f) + descent(pain, f); - int tx = display()? 0:topx; + int tx = (display() && !owner())? 0:int(x); int ty = baseline - ascent(pain,f); if (ty < 0) ty = 0; if ((ty + h) > pain.paperHeight()) h = pain.paperHeight(); - if ((topx + w) > pain.paperWidth()) + if ((top_x + w) > pain.paperWidth()) w = pain.paperWidth(); pain.fillRectangle(tx, ty-1, w, h+2); cleared = true; } // not needed if collapsed - topx = int(x); - topbaseline = baseline; - - int w = InsetText::width(pain, f) + (2 * TEXT_TO_INSET_OFFSET); - int h = ascent(pain,f) + descent(pain, f); + top_x = int(x); + top_baseline = baseline; draw_collapsed(pain, f, baseline, x); - x -= TEXT_TO_INSET_OFFSET; - - int save_x = static_cast(x); - x += TEXT_TO_INSET_OFFSET; - InsetText::draw(bv, f, baseline, x, cleared); - pain.rectangle(save_x, baseline - ascent(pain, f), w, h, framecolor); + inset->draw(bv, f, baseline, x, cleared); + need_update = NONE; } void InsetCollapsable::Edit(BufferView * bv, int x, int y, unsigned int button) { + UpdatableInset::Edit(bv, x, y, button); + if (collapsed && autocollapse) { collapsed = false; - UpdateLocal(bv, FULL, false); - InsetText::Edit(bv, 0, 0, button); + if (!bv->lockInset(this)) + return; + bv->updateInset(this, false); + inset->Edit(bv, 0, 0, button); } else if (!collapsed) { - InsetText::Edit(bv, x, y, button); + if (!bv->lockInset(this)) + return; + inset->Edit(bv, x-widthCollapsed, y, button); } } @@ -207,15 +214,15 @@ void InsetCollapsable::InsetUnlock(BufferView * bv) if (autocollapse) { collapsed = true; } - InsetText::InsetUnlock(bv); - UpdateLocal(bv, FULL, false); + inset->InsetUnlock(bv); + bv->updateInset(this, false); } void InsetCollapsable::InsetButtonPress(BufferView * bv,int x,int y,int button) { if (!collapsed && (x >= button_length)) { - InsetText::InsetButtonPress(bv, x, y, button); + inset->InsetButtonPress(bv, x-widthCollapsed, y, button); } } @@ -227,15 +234,15 @@ void InsetCollapsable::InsetButtonRelease(BufferView * bv, (y >= button_top_y) && (y < button_bottom_y)) { if (collapsed) { collapsed = false; - InsetText::InsetButtonRelease(bv, 0, 0, button); - UpdateLocal(bv, FULL, false); + inset->InsetButtonRelease(bv, 0, 0, button); + bv->updateInset(this, false); } else { collapsed = true; - UpdateLocal(bv, FULL, false); bv->unlockInset(this); + bv->updateInset(this, false); } } else if (!collapsed && (x >= button_length) && (y >= button_top_y)) { - InsetText::InsetButtonRelease(bv, x, y, button); + inset->InsetButtonRelease(bv, x-widthCollapsed, y, button); } } @@ -244,37 +251,166 @@ void InsetCollapsable::InsetMotionNotify(BufferView * bv, int x, int y, int state) { if (x >= button_length) { - InsetText::InsetMotionNotify(bv, x, y, state); + inset->InsetMotionNotify(bv, x-widthCollapsed, y, state); } } +void InsetCollapsable::InsetKeyPress(XKeyEvent * xke) +{ + inset->InsetKeyPress(xke); +} + + +int InsetCollapsable::Latex(Buffer const * buf, ostream & os, bool fragile, bool free_spc) const +{ + return inset->Latex(buf, os, fragile, free_spc); +} + + int InsetCollapsable::getMaxWidth(Painter & pain, UpdatableInset const * inset) const { - if ((this == inset) && !owner()) - return pain.paperWidth(); - if (this == inset) - return static_cast(owner())->getMaxWidth(pain,inset); + int w; if (owner()) - return static_cast(owner())->getMaxWidth(pain,inset)- - width_collapsed(pain, labelfont) - widthOffset; + w = static_cast(owner())->getMaxWidth(pain,inset); + else + w = pain.paperWidth(); - return pain.paperWidth()-width_collapsed(pain, labelfont) - widthOffset; + if (w < 0) + return w; + + return w; // - top_x - widthCollapsed; } int InsetCollapsable::getMaxTextWidth(Painter & pain, UpdatableInset const * inset) const { - return getMaxWidth(pain, inset) - - width_collapsed(pain, labelfont) - widthOffset; + return getMaxWidth(pain, inset) - widthCollapsed; } void InsetCollapsable::update(BufferView * bv, LyXFont const & font, bool dodraw) { - drawTextXOffset = width_collapsed(bv->painter(), font); - InsetText::update(bv, font, dodraw); + if (!widthCollapsed) { + widthCollapsed = width_collapsed(bv->painter(), font); + inset->deleteLyXText(bv); + need_update = FULL; + if (owner()) { + owner()->update(bv, font, dodraw); + return; + } + } + if (oldWidth != width(bv->painter(), font)) { + oldWidth = width(bv->painter(), font); + inset->deleteLyXText(bv); + need_update = FULL; + if (owner()) { + owner()->update(bv, font, dodraw); + return; + } + } + inset->update(bv, font, dodraw); +} + +UpdatableInset::RESULT +InsetCollapsable::LocalDispatch(BufferView * bv, int action, string const & arg) +{ + UpdatableInset::RESULT result = inset->LocalDispatch(bv, action, arg); + if (result == FINISHED) + bv->unlockInset(this); + return result; +} + +bool InsetCollapsable::LockInsetInInset(BufferView * bv, UpdatableInset * in) +{ + if (inset == in) + return true; + return inset->LockInsetInInset(bv, in); +} + + +bool InsetCollapsable::UnlockInsetInInset(BufferView * bv, UpdatableInset * in, + bool lr) +{ + if (inset == in) { + bv->unlockInset(this); + return true; + } + return inset->UnlockInsetInInset(bv, in, lr); +} + + +bool InsetCollapsable::UpdateInsetInInset(BufferView * bv, Inset *in) +{ + if (in == inset) + return true; + return inset->UpdateInsetInInset(bv, in); +} + + +int InsetCollapsable::InsetInInsetY() +{ + return inset->InsetInInsetY(); +} + + +void InsetCollapsable::Validate(LaTeXFeatures & features) const +{ + inset->Validate(features); } + + +void InsetCollapsable::GetCursorPos(BufferView * bv, int & x, int & y) const +{ + inset->GetCursorPos(bv, x , y); +} + + +void InsetCollapsable::ToggleInsetCursor(BufferView * bv) +{ + inset->ToggleInsetCursor(bv); +} + + +UpdatableInset * InsetCollapsable::GetLockingInset() +{ + UpdatableInset *in = inset->GetLockingInset(); + if (inset == in) + return this; + return in; +} + + +UpdatableInset * InsetCollapsable::GetFirstLockingInsetOfType(Inset::Code c) +{ + if (c == LyxCode()) + return this; + return inset->GetFirstLockingInsetOfType(c); +} + + +void InsetCollapsable::SetFont(BufferView * bv, LyXFont const & font, bool toggleall) +{ + inset->SetFont(bv, font, toggleall); +} + +bool InsetCollapsable::doClearArea() const +{ + return inset->doClearArea(); +} + + +LyXText * InsetCollapsable::getLyXText(BufferView * bv) const +{ + return inset->getLyXText(bv); +} + + +void InsetCollapsable::deleteLyXText(BufferView * bv) +{ + inset->deleteLyXText(bv); +} + diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 42ec6507fb..687c11317a 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -17,18 +17,25 @@ #pragma interface #endif -#include "insettext.h" +#include "lyxinset.h" #include "lyxfont.h" #include "LColor.h" class Painter; +class InsetText; +class LyXText; /** A colapsable text inset */ -class InsetCollapsable : public InsetText { +class InsetCollapsable : public UpdatableInset { public: + /// + enum UpdateCodes { + NONE = 0, + FULL + }; /// static int const TEXT_TO_TOP_OFFSET = 2; /// @@ -59,9 +66,21 @@ public: /// EDITABLE Editable() const; /// + bool IsTextInset() const { return true; } + /// + bool doClearArea() const; + /// void InsetUnlock(BufferView *); /// - bool display() const { return (!collapsed); } + bool needFullRow() const { return !collapsed; } + /// + bool LockInsetInInset(BufferView *, UpdatableInset *); + /// + bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false); + /// + bool UpdateInsetInInset(BufferView *, Inset *); + /// + int InsetInInsetY(); /// void InsetButtonRelease(BufferView *, int, int, int); /// @@ -69,6 +88,30 @@ public: /// void InsetMotionNotify(BufferView *, int, int, int); /// + void InsetKeyPress(XKeyEvent *); + /// + UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &); + /// + int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const; + /// + int Ascii(Buffer const *, std::ostream &) const { return 0; } + /// + int Linuxdoc(Buffer const *, std::ostream &) const { return 0; } + /// + int DocBook(Buffer const *, std::ostream &) const { return 0; } + /// + void Validate(LaTeXFeatures & features) const; + /// + void GetCursorPos(BufferView *, int & x, int & y) const; + /// + void ToggleInsetCursor(BufferView *); + /// + UpdatableInset * GetLockingInset(); + /// + UpdatableInset * GetFirstLockingInsetOfType(Inset::Code); + /// + void SetFont(BufferView *, LyXFont const &, bool toggleall = false); + /// void setLabel(string const & l) { label = l; } /// void setLabelFont(LyXFont & f) { labelfont = f; } @@ -76,6 +119,9 @@ public: void setAutoCollapse(bool f) { autocollapse = f; } /// int getMaxWidth(Painter & pain, UpdatableInset const *) const; + /// + LyXText * getLyXText(BufferView *) const; + void deleteLyXText(BufferView *); protected: /// @@ -95,24 +141,27 @@ protected: LColor::color framecolor; /// LyXFont labelfont; + /// + InsetText * inset; + // Instead of making these ints protected we could have a + // protected method "clickInButton" (Lgb) + /// + mutable int + button_length, button_top_y, button_bottom_y; private: /// string label; /// bool autocollapse; -protected: - // Instead of making these ints protected we could have a - // protected method "clickInButton" (Lgb) /// - mutable int - button_length, button_top_y, button_bottom_y; -private: + int widthCollapsed; /// - int widthOffset; + int oldWidth; /// mutable int topx; mutable int topbaseline; + mutable UpdateCodes need_update; }; #endif diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 67af3e3d13..32bb4476f1 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -18,6 +18,7 @@ #include "lyxfont.h" #include "Painter.h" #include "buffer.h" +#include "insets/insettext.h" #include "support/LOstream.h" #include "lyx_gui_misc.h" @@ -46,8 +47,8 @@ void InsetERT::Write(Buffer const * buf, ostream & os) const Inset * InsetERT::Clone() const { - InsetERT * result = new InsetERT(); - result->init(this); + InsetERT * result = new InsetERT; + result->inset->init(inset); result->collapsed = collapsed; return result; diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index 8d8c8c6a2f..cc893bc70d 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -19,6 +19,7 @@ #include "BufferView.h" #include "Painter.h" #include "lyxtext.h" +#include "insets/insettext.h" #include "support/LOstream.h" #include "FloatList.h" #include "LaTeXFeatures.h" @@ -130,7 +131,7 @@ void InsetFloat::Validate(LaTeXFeatures & features) const Inset * InsetFloat::Clone() const { InsetFloat * result = new InsetFloat; - result->init(this); + result->inset->init(inset); result->collapsed = collapsed; return result; @@ -152,32 +153,32 @@ int InsetFloat::Latex(Buffer const * buf, os << "[" << floatPlacement << "]"; os << "%\n"; - int i = InsetText::Latex(buf, os, fragile, fp); + int i = inset->Latex(buf, os, fragile, fp); os << "\\end{" << floatType << "}%\n"; return i + 2; } -bool InsetFloat::InsertInset(BufferView * bv, Inset * inset) +bool InsetFloat::InsertInset(BufferView * bv, Inset * in) { - if (!InsertInsetAllowed(inset)) + if (!InsertInsetAllowed(in)) return false; - return InsetText::InsertInset(bv, inset); + return inset->InsertInset(bv, in); } -bool InsetFloat::InsertInsetAllowed(Inset * inset) const +bool InsetFloat::InsertInsetAllowed(Inset * in) const { - if ((inset->LyxCode() == Inset::FOOT_CODE) || - (inset->LyxCode() == Inset::MARGIN_CODE)) { + if ((in->LyxCode() == Inset::FOOT_CODE) || + (in->LyxCode() == Inset::MARGIN_CODE)) { return false; } return true; } - +#if 0 LyXFont InsetFloat::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const { @@ -185,7 +186,7 @@ LyXFont InsetFloat::GetDrawFont(BufferView * bv, fn.decSize().decSize(); return fn; } - +#endif void InsetFloat::InsetButtonRelease(BufferView * bv, int x, int y, int button) { diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index b76d4e0241..997c99f73a 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -49,7 +49,7 @@ public: /// bool InsertInsetAllowed(Inset * inset) const; /// - LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; +// LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; /// void InsetButtonRelease(BufferView * bv, int x, int y, int button); private: diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index 818db8b97a..e9f56e6785 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -20,6 +20,7 @@ #include "BufferView.h" #include "Painter.h" #include "lyxtext.h" +#include "insets/insettext.h" #include "support/LOstream.h" using std::ostream; @@ -48,7 +49,7 @@ void InsetFoot::Write(Buffer const * buf, ostream & os) const Inset * InsetFoot::Clone() const { InsetFoot * result = new InsetFoot; - result->init(this); + result->inset->init(inset); result->collapsed = collapsed; return result; @@ -66,32 +67,32 @@ int InsetFoot::Latex(Buffer const * buf, { os << "\\footnote{%\n"; - int i = InsetText::Latex(buf, os, fragile, fp); + int i = inset->Latex(buf, os, fragile, fp); os << "}%\n"; return i + 2; } -bool InsetFoot::InsertInset(BufferView * bv, Inset * inset) +bool InsetFoot::InsertInset(BufferView * bv, Inset * in) { - if (!InsertInsetAllowed(inset)) + if (!InsertInsetAllowed(in)) return false; - return InsetText::InsertInset(bv, inset); + return inset->InsertInset(bv, in); } -bool InsetFoot::InsertInsetAllowed(Inset * inset) const +bool InsetFoot::InsertInsetAllowed(Inset * in) const { - if ((inset->LyxCode() == Inset::FOOT_CODE) || - (inset->LyxCode() == Inset::MARGIN_CODE)) { + if ((in->LyxCode() == Inset::FOOT_CODE) || + (in->LyxCode() == Inset::MARGIN_CODE)) { return false; } return true; } - +#if 0 LyXFont InsetFoot::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const { @@ -99,3 +100,4 @@ LyXFont InsetFoot::GetDrawFont(BufferView * bv, fn.decSize().decSize(); return fn; } +#endif diff --git a/src/insets/insetfoot.h b/src/insets/insetfoot.h index 0f417281d1..115ce8ff20 100644 --- a/src/insets/insetfoot.h +++ b/src/insets/insetfoot.h @@ -47,7 +47,7 @@ public: /// bool InsertInsetAllowed(Inset * inset) const; /// - LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; +// LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; }; #endif diff --git a/src/insets/insetlist.C b/src/insets/insetlist.C index 640b3cb5f1..2b67d19468 100644 --- a/src/insets/insetlist.C +++ b/src/insets/insetlist.C @@ -19,6 +19,7 @@ #include "BufferView.h" #include "Painter.h" #include "lyxtext.h" +#include "insets/insettext.h" #include "support/LOstream.h" using std::ostream; @@ -59,7 +60,7 @@ void InsetList::Write(Buffer const * buf, ostream & os) const Inset * InsetList::Clone() const { InsetList * result = new InsetList; - result->init(this); + result->inset->init(inset); result->collapsed = collapsed; return result; @@ -77,35 +78,36 @@ int InsetList::Latex(Buffer const * buf, { os << "\\footnote{%\n"; - int i = InsetText::Latex(buf, os, fragile, fp); + int i = inset->Latex(buf, os, fragile, fp); os << "}%\n"; return i + 2; } -bool InsetList::InsertInset(BufferView * bv, Inset * inset) +bool InsetList::InsertInset(BufferView * bv, Inset * in) { - if (!InsertInsetAllowed(inset)) + if (!InsertInsetAllowed(in)) return false; - return InsetText::InsertInset(bv, inset); + return inset->InsertInset(bv, in); } -bool InsetList::InsertInsetAllowed(Inset * inset) const +bool InsetList::InsertInsetAllowed(Inset * in) const { - if ((inset->LyxCode() == Inset::FOOT_CODE) || - (inset->LyxCode() == Inset::MARGIN_CODE)) { + if ((in->LyxCode() == Inset::FOOT_CODE) || + (in->LyxCode() == Inset::MARGIN_CODE)) { return false; } return true; } - +#if 0 LyXFont InsetList::GetDrawFont(BufferView * bv,LyXParagraph * p, int pos) const { LyXFont fn = getLyXText(bv)->GetFont(bv->buffer(), p, pos); fn.decSize().decSize(); return fn; } +#endif diff --git a/src/insets/insetlist.h b/src/insets/insetlist.h index a8e1a27c0f..342a7f8b28 100644 --- a/src/insets/insetlist.h +++ b/src/insets/insetlist.h @@ -45,7 +45,7 @@ public: /// bool InsertInsetAllowed(Inset * inset) const; /// - LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; +// LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; }; #endif diff --git a/src/insets/insetmarginal.C b/src/insets/insetmarginal.C index 546a36c124..ce0fe40f81 100644 --- a/src/insets/insetmarginal.C +++ b/src/insets/insetmarginal.C @@ -20,6 +20,7 @@ #include "BufferView.h" #include "Painter.h" #include "lyxtext.h" +#include "insets/insettext.h" #include "support/LOstream.h" using std::ostream; @@ -49,7 +50,7 @@ void InsetMarginal::Write(Buffer const * buf, ostream & os) const Inset * InsetMarginal::Clone() const { InsetMarginal * result = new InsetMarginal; - result->init(this); + result->inset->init(inset); result->collapsed = collapsed; return result; @@ -67,32 +68,32 @@ int InsetMarginal::Latex(Buffer const * buf, { os << "\\marginpar{%\n"; - int i = InsetText::Latex(buf, os, fragile, fp); + int i = inset->Latex(buf, os, fragile, fp); os << "}%\n"; return i + 2; } -bool InsetMarginal::InsertInset(BufferView * bv, Inset * inset) +bool InsetMarginal::InsertInset(BufferView * bv, Inset * in) { - if (!InsertInsetAllowed(inset)) + if (!InsertInsetAllowed(in)) return false; - return InsetText::InsertInset(bv, inset); + return inset->InsertInset(bv, in); } -bool InsetMarginal::InsertInsetAllowed(Inset * inset) const +bool InsetMarginal::InsertInsetAllowed(Inset * in) const { - if ((inset->LyxCode() == Inset::FOOT_CODE) || - (inset->LyxCode() == Inset::MARGIN_CODE)) { + if ((in->LyxCode() == Inset::FOOT_CODE) || + (in->LyxCode() == Inset::MARGIN_CODE)) { return false; } return true; } - +#if 0 LyXFont InsetMarginal::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const { @@ -100,3 +101,4 @@ LyXFont InsetMarginal::GetDrawFont(BufferView * bv, fn.decSize().decSize(); return fn; } +#endif diff --git a/src/insets/insetmarginal.h b/src/insets/insetmarginal.h index f8d650b970..6a47bfeb7b 100644 --- a/src/insets/insetmarginal.h +++ b/src/insets/insetmarginal.h @@ -45,7 +45,7 @@ public: /// bool InsertInsetAllowed(Inset * inset) const; /// - LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; +// LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; }; #endif diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 606648bcb9..2e90212764 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -19,6 +19,7 @@ #include "BufferView.h" #include "Painter.h" #include "lyxtext.h" +#include "insets/insettext.h" #include "support/LOstream.h" using std::ostream; @@ -77,7 +78,7 @@ void InsetMinipage::Write(Buffer const * buf, ostream & os) const Inset * InsetMinipage::Clone() const { InsetMinipage * result = new InsetMinipage; - result->init(this); + result->inset->init(inset); result->collapsed = collapsed; return result; @@ -95,32 +96,32 @@ int InsetMinipage::Latex(Buffer const * buf, { os << "\\begin{minipage}{\\columnwidth}%\n"; - int i = InsetText::Latex(buf, os, fragile, fp); + int i = inset->Latex(buf, os, fragile, fp); os << "\\end{minipage}%\n"; return i + 2; } -bool InsetMinipage::InsertInset(BufferView * bv, Inset * inset) +bool InsetMinipage::InsertInset(BufferView * bv, Inset * in) { - if (!InsertInsetAllowed(inset)) + if (!InsertInsetAllowed(in)) return false; - return InsetText::InsertInset(bv, inset); + return inset->InsertInset(bv, in); } -bool InsetMinipage::InsertInsetAllowed(Inset * inset) const +bool InsetMinipage::InsertInsetAllowed(Inset * in) const { - if ((inset->LyxCode() == Inset::FLOAT_CODE) || - (inset->LyxCode() == Inset::MARGIN_CODE)) { + if ((in->LyxCode() == Inset::FLOAT_CODE) || + (in->LyxCode() == Inset::MARGIN_CODE)) { return false; } return true; } - +#if 0 LyXFont InsetMinipage::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const { @@ -128,3 +129,4 @@ LyXFont InsetMinipage::GetDrawFont(BufferView * bv, fn.decSize().decSize(); return fn; } +#endif diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index 2c4cc02468..daba5e9486 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -45,7 +45,7 @@ public: /// bool InsertInsetAllowed(Inset * inset) const; /// - LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; +// LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; }; #endif diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 735df9e4c1..10347afe2e 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -56,10 +56,6 @@ using std::max; extern unsigned char getCurrentTextClass(Buffer *); -// Jürgen, we don't like macros, even small ones like this. (Lgb) -//#define TEXT(a) getLyXText(a) -// I created a inline function in insettext.h instead. (Lgb) - InsetText::InsetText() { par = new LyXParagraph(); @@ -93,12 +89,13 @@ void InsetText::init(InsetText const * ins) no_selection = false; need_update = INIT; drawTextXOffset = drawTextYOffset = 0; - autoBreakRows = drawLockedFrame = false; + autoBreakRows = false; + drawFrame = NEVER; xpos = 0.0; if (ins) { SetParagraphData(ins->par); autoBreakRows = ins->autoBreakRows; - drawLockedFrame = ins->drawLockedFrame; + drawFrame = ins->drawFrame; } par->SetInsetOwner(this); frame_color = LColor::insetframe; @@ -210,7 +207,21 @@ int InsetText::width(Painter &, LyXFont const &) const int InsetText::textWidth(Painter & pain) const { - return getMaxTextWidth(pain, this) - drawTextXOffset; + int w = getMaxWidth(pain, this); + if (w < 0) { +// printf("WW1: %d\n",w); + return w; + } +#if 0 + if (owner()) { + w = w - top_x + owner()->x(); + printf("WW2: %d\n",w); + return w; // - top_x + owner()->x(); + } +#endif + w -= (2 * TEXT_TO_INSET_OFFSET); +// printf("WW2: %d\n",w); + return w; // - top_x - (2 * TEXT_TO_INSET_OFFSET); } @@ -248,7 +259,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, last_width = width(pain, f); last_height = ascent(pain, f) + descent(pain, f); - if (the_locking_inset && (cpos(bv) == inset_pos)) { + if (the_locking_inset && (cpar(bv) == inset_par) && (cpos(bv) == inset_pos)) { inset_x = cx(bv) - top_x + drawTextXOffset; inset_y = cy(bv) + drawTextYOffset; } @@ -263,7 +274,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, y += baseline - row->ascent_of_text() + 1; if (cleared || !locked || (need_update == FULL)) { while (row != 0) { - TEXT(bv)->GetVisibleRow(bv, y, x, row, y); + TEXT(bv)->GetVisibleRow(bv, y, x, row, y, cleared); y += row->height(); row = row->next(); } @@ -276,12 +287,12 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, } TEXT(bv)->refresh_y = 0; TEXT(bv)->status = LyXText::UNCHANGED; - if (drawLockedFrame && locked) { - pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f), - ascent(pain,f) + descent(pain, f), frame_color); + if ((drawFrame == ALWAYS) || ((drawFrame == LOCKED) && locked)) { + pain.rectangle(top_x, baseline - insetAscent, insetWidth, + insetAscent + insetDescent, frame_color); } else { - pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f), - ascent(pain,f) + descent(pain, f), + pain.rectangle(top_x, baseline - insetAscent, insetWidth, + insetAscent + insetDescent, LColor::background); } x += width(pain, f) - TEXT_TO_INSET_OFFSET; @@ -297,19 +308,66 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool dodraw) deleteLyXText(bv); need_update = FULL; } + int oldw = insetWidth; +#if 1 + insetWidth = max(textWidth(bv->painter()), + static_cast(TEXT(bv)->width) + drawTextXOffset) + + (2 * TEXT_TO_INSET_OFFSET); +#else + insetWidth = textWidth(bv->painter()); + if (insetWidth < 0) + insetWidth = static_cast(TEXT(bv)->width); +#endif + if (oldw != insetWidth) { + printf("TW(%p): %d-%d-%d-%d\n",this,insetWidth, oldw, + textWidth(bv->painter()),static_cast(TEXT(bv)->width)); + deleteLyXText(bv); +#if 0 + if (owner()) { + owner()->update(bv, font, dodraw); + return; + } +#else +#if 1 + update(bv, font, dodraw); +#else + UpdateLocal(bv, INIT, false); +#endif +#endif + return; + } if (dodraw && (need_update != CURSOR)) need_update = FULL; TEXT(bv)->FullRebreak(bv); + if ((need_update==CURSOR_PAR) && (TEXT(bv)->status==LyXText::UNCHANGED) && + the_locking_inset) + { + TEXT(bv)->UpdateInset(bv, the_locking_inset); + } + long int y_temp = 0; Row * row = TEXT(bv)->GetRowNearY(y_temp); insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET; insetDescent = TEXT(bv)->height - row->ascent_of_text() + TEXT_TO_INSET_OFFSET; - insetWidth = max(textWidth(bv->painter()), - static_cast(TEXT(bv)->width)) + - (2 * TEXT_TO_INSET_OFFSET); +} + + +void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty) +{ + TEXT(bv)->FullRebreak(bv); + if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH) + need_update = FULL; + else if (!the_locking_inset || (what != CURSOR)) + need_update = what; + if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED)) + bv->updateInset(this, mark_dirty); + if (old_par != cpar(bv)) { + bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1); + old_par = cpar(bv); + } } @@ -331,10 +389,9 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button) locked = true; the_locking_inset = 0; inset_pos = inset_x = inset_y = 0; - TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset, - y+TEXT(bv)->first-drawTextYOffset+ - insetAscent); - checkAndActivateInset(bv, x, y, button); + inset_par = 0; + if (!checkAndActivateInset(bv, x, y, button)) + TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset, y); TEXT(bv)->sel_cursor = TEXT(bv)->cursor; bv->text->FinishUndo(); UpdateLocal(bv, FULL, false); @@ -364,15 +421,15 @@ bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset) if (inset == cpar(bv)->GetInset(cpos(bv))) { lyxerr[Debug::INSETS] << "OK" << endl; the_locking_inset = inset; -// resetPos(bv->painter()); inset_x = cx(bv) - top_x + drawTextXOffset; inset_y = cy(bv) + drawTextYOffset; inset_pos = cpos(bv); + inset_par = cpar(bv); + TEXT(bv)->UpdateInset(bv, the_locking_inset); return true; } else if (the_locking_inset && (the_locking_inset == inset)) { - if (cpos(bv) == inset_pos) { + if (cpar(bv) == inset_par && cpos(bv) == inset_pos) { lyxerr[Debug::INSETS] << "OK" << endl; -// resetPos(bv->painter()); inset_x = cx(bv) - top_x + drawTextXOffset; inset_y = cy(bv) + drawTextYOffset; } else { @@ -398,7 +455,7 @@ bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset, the_locking_inset = 0; if (lr) moveRight(bv, false); - UpdateLocal(bv, FULL, false); + UpdateLocal(bv, CURSOR_PAR, false); return true; } return the_locking_inset->UnlockInsetInInset(bv, inset, lr); @@ -409,11 +466,15 @@ bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset) { if (!the_locking_inset) return false; - if (the_locking_inset != inset) + if (the_locking_inset != inset) { + TEXT(bv)->UpdateInset(bv, the_locking_inset); + need_update = CURSOR_PAR; return the_locking_inset->UpdateInsetInInset(bv, inset); + } // UpdateLocal(bv, FULL, false); - TEXT(bv)->UpdateInset(bv, inset); - if (cpos(bv) == inset_pos) { + if (TEXT(bv)->UpdateInset(bv, inset)) + UpdateLocal(bv, CURSOR_PAR, false); + if (cpar(bv) == inset_par && cpos(bv) == inset_pos) { inset_x = cx(bv) - top_x + drawTextXOffset; inset_y = cy(bv) + drawTextYOffset; } @@ -428,13 +489,13 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) UpdateLocal(bv, FULL, false); } no_selection = false; - TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset, - y+TEXT(bv)->first-drawTextYOffset+ - insetAscent); + + int tmp_x = x - drawTextXOffset; +// int tmp_y = y + TEXT(bv)->first + insetAscent; + int tmp_y = y + insetAscent; + Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y, button); + if (the_locking_inset) { - UpdatableInset * inset = 0; - if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) - inset = static_cast(cpar(bv)->GetInset(cpos(bv))); if (the_locking_inset == inset) { the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button); return; @@ -445,7 +506,8 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) inset_y = cy(bv) + drawTextYOffset; inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button); inset->Edit(bv, x - inset_x, y - inset_y, button); - UpdateLocal(bv, FULL, false); + if (the_locking_inset) + UpdateLocal(bv, CURSOR_PAR, false); return; } // otherwise only unlock the_locking_inset @@ -453,19 +515,22 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) the_locking_inset = 0; } if (bv->the_locking_inset) { - if ((cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) && - cpar(bv)->GetInset(cpos(bv)) && - (cpar(bv)->GetInset(cpos(bv))->Editable() == Inset::HIGHLY_EDITABLE)) { - UpdatableInset * inset = - static_cast(cpar(bv)->GetInset(cpos(bv))); + if (inset && inset->Editable() == Inset::HIGHLY_EDITABLE) { + UpdatableInset * uinset = static_cast(inset); inset_x = cx(bv) - top_x + drawTextXOffset; inset_y = cy(bv) + drawTextYOffset; - inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button); - inset->Edit(bv, x - inset_x, y - inset_y, 0); - UpdateLocal(bv, FULL, false); + inset_pos = cpos(bv); + inset_par = cpar(bv); + uinset->InsetButtonPress(bv, x - inset_x, y - inset_y, button); + uinset->Edit(bv, x - inset_x, y - inset_y, 0); + if (the_locking_inset) + UpdateLocal(bv, CURSOR_PAR, false); + return; } } -// selection_start_cursor = selection_end_cursor = cursor; + if (!inset) + TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset, + y+TEXT(bv)->first+insetAscent); } @@ -903,11 +968,9 @@ InsetText::moveRight(BufferView * bv, bool activate_inset) { if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last())) return FINISHED; - if (activate_inset && checkAndActivateInset(bv)) { + if (activate_inset && checkAndActivateInset(bv, false)) return DISPATCHED; - } TEXT(bv)->CursorRight(bv); -// real_current_font = current_font = GetFont(bv->buffer(), cpar(bv), cpos(bv)); return DISPATCHED_NOUPDATE; } @@ -918,9 +981,8 @@ InsetText::moveLeft(BufferView * bv, bool activate_inset) if (!cpar(bv)->previous && (cpos(bv) <= 0)) return FINISHED; TEXT(bv)->CursorLeft(bv); - if (activate_inset) - if (checkAndActivateInset(bv, -1, -1)) - return DISPATCHED; + if (activate_inset && checkAndActivateInset(bv, true)) + return DISPATCHED; return DISPATCHED_NOUPDATE; } @@ -989,32 +1051,43 @@ void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall) } -void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty) +bool InsetText::checkAndActivateInset(BufferView * bv, bool behind) { - if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH) - need_update = FULL; - else - need_update = what; - if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED)) - bv->updateInset(this, mark_dirty); - if (old_par != cpar(bv)) { - bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1); - old_par = cpar(bv); + if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) { + int x, y; + Inset * inset = + static_cast(cpar(bv)->GetInset(cpos(bv))); + LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv)); + if (behind) { + x = inset->width(bv->painter(), font); + y = inset->descent(bv->painter(), font); + } else { + x = y = 0; + } + inset_x = cx(bv) - top_x + drawTextXOffset; + inset_y = cy(bv) + drawTextYOffset; + inset->Edit(bv, x-inset_x, y-inset_y, 0); + if (!the_locking_inset) + return false; + UpdateLocal(bv, CURSOR_PAR, false); + return true; } + return false; } bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y, int button) { - if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) { - UpdatableInset * inset = - static_cast(cpar(bv)->GetInset(cpos(bv))); - LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv)); + int tmp_x = x - drawTextXOffset; + int tmp_y = y + insetAscent; + Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y, button); + + if (inset) { if (x < 0) - x = inset->width(bv->painter(), font); + x = insetWidth; if (y < 0) - y = inset->descent(bv->painter(), font); + y = insetDescent; inset_x = cx(bv) - top_x + drawTextXOffset; inset_y = cy(bv) + drawTextYOffset; inset->Edit(bv, x - inset_x, y - inset_y, button); @@ -1070,25 +1143,31 @@ void InsetText::SetAutoBreakRows(bool flag) } -void InsetText::SetDrawLockedFrame(bool flag) +void InsetText::SetDrawFrame(BufferView * bv, DrawFrame how) { - if (flag != drawLockedFrame) - drawLockedFrame = flag; + if (how != drawFrame) { + drawFrame = how; + if (bv) + UpdateLocal(bv, FRAME, false); + } } -void InsetText::SetFrameColor(LColor::color col) +void InsetText::SetFrameColor(BufferView * bv, LColor::color col) { - if (frame_color != col) + if (frame_color != col) { frame_color = col; + if (bv) + UpdateLocal(bv, FRAME, false); + } } - +#if 0 LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const { return TEXT(bv)->GetFont(bv->buffer(), p, pos); } - +#endif int InsetText::cx(BufferView * bv) const { @@ -1129,6 +1208,9 @@ LyXText * InsetText::getLyXText(BufferView * bv) const LyXText * lt = new LyXText(const_cast(this)); lt->init(bv); cache[bv] = lt; + if (the_locking_inset) { + lt->SetCursor(bv, inset_par, inset_pos); + } return lt; } @@ -1136,4 +1218,9 @@ LyXText * InsetText::getLyXText(BufferView * bv) const void InsetText::deleteLyXText(BufferView * bv) { cache.erase(bv); + /// then remove all LyXText in text-insets + LyXParagraph * p = par; + for(;p;p = p->next) { + p->deleteInsetsLyXText(bv); + } } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index b6738d95db..f6382fe61a 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -37,8 +37,6 @@ class LyXScreen; */ class InsetText : public UpdatableInset { public: - /// - enum { TEXT_TO_INSET_OFFSET = 2 }; /// enum UpdateCodes { NONE = 0, @@ -46,7 +44,14 @@ public: FULL, CURSOR_PAR, CURSOR, - SELECTION + SELECTION, + FRAME + }; + /// + enum DrawFrame { + NEVER = 0, + LOCKED, + ALWAYS }; /// explicit @@ -132,15 +137,17 @@ public: /// void init(InsetText const * ins = 0); /// + void WriteParagraphData(Buffer const *, std::ostream &) const; + /// void SetParagraphData(LyXParagraph *); /// void SetAutoBreakRows(bool); /// - void SetDrawLockedFrame(bool); + void SetDrawFrame(BufferView *, DrawFrame); /// - void SetFrameColor(LColor::color); + void SetFrameColor(BufferView *, LColor::color); /// - LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const; +// LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const; /// LyXText * getLyXText(BufferView *) const; void deleteLyXText(BufferView *); @@ -151,15 +158,13 @@ protected: /// void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty); /// - void WriteParagraphData(Buffer const *, std::ostream &) const; - /// virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const; mutable int drawTextXOffset; mutable int drawTextYOffset; /// bool autoBreakRows; - bool drawLockedFrame; + DrawFrame drawFrame; /// LColor::color frame_color; /// @@ -189,6 +194,7 @@ private: /// string getText(int); /// + bool checkAndActivateInset(BufferView * bv, bool behind); bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0, int button = 0); /// @@ -214,6 +220,8 @@ private: mutable int last_height; mutable int top_y; /// + LyXParagraph * inset_par; + /// int inset_pos; /// mutable int inset_x; diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index cd73abe283..482037f17e 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -26,6 +26,7 @@ class BufferView; class Buffer; class Painter; +class LyXText; struct LaTeXFeatures; @@ -102,6 +103,9 @@ public: EXTERNAL_CODE }; + /// + enum { TEXT_TO_INSET_OFFSET = 2 }; + enum EDITABLE { NOT_EDITABLE = 0, IS_EDITABLE, @@ -181,9 +185,13 @@ public: virtual bool DirectWrite() const; /// Returns true if the inset should be centered alone - virtual bool display() const { return false; } + virtual bool display() const { return false; } /// Changes the display state of the inset - virtual void display(bool) {} + virtual void display(bool) {} + /// + /// returns true if this inset needs a row on it's own + /// + virtual bool needFullRow() const { return false; } /// virtual bool InsertInsetAllowed(Inset *) const { return false; } /// @@ -326,6 +334,11 @@ public: virtual bool isCursorVisible() const { return cursor_visible; } /// virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const; + /// + /// because we could have fake text insets and have to call this + /// inside them without cast!!! + virtual LyXText * getLyXText(BufferView *) const { return 0; } + virtual void deleteLyXText(BufferView *) {} protected: /// diff --git a/src/lyxtext.h b/src/lyxtext.h index 87ef88642f..4883211447 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -332,7 +332,7 @@ public: solution but faster. */ void GetVisibleRow(BufferView *, int y_offset, int x_offset, - Row * row_ptr, long y); + Row * row_ptr, long y, bool cleared=false); /* footnotes: */ /// diff --git a/src/mathed/formula.C b/src/mathed/formula.C index c27f4c293d..20d63d56eb 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -735,28 +735,38 @@ InsetFormula::LocalDispatch(BufferView * bv, case LFUN_RIGHT: { result = DISPATCH_RESULT(mathcursor->Right(sel)); + if (!sel && (result == DISPATCHED)) + result = DISPATCHED_NOUPDATE; break; } case LFUN_LEFTSEL: sel = true; case LFUN_LEFT: { result = DISPATCH_RESULT(mathcursor->Left(sel)); + if (!sel && (result == DISPATCHED)) + result = DISPATCHED_NOUPDATE; break; } case LFUN_UPSEL: sel = true; case LFUN_UP: result = DISPATCH_RESULT(mathcursor->Up(sel)); + if (!sel && (result == DISPATCHED)) + result = DISPATCHED_NOUPDATE; break; case LFUN_DOWNSEL: sel = true; case LFUN_DOWN: result = DISPATCH_RESULT(mathcursor->Down(sel)); + if (!sel && (result == DISPATCHED)) + result = DISPATCHED_NOUPDATE; break; case LFUN_HOME: mathcursor->Home(); + result = DISPATCHED_NOUPDATE; break; case LFUN_END: mathcursor->End(); + result = DISPATCHED_NOUPDATE; break; case LFUN_DELETE_LINE_FORWARD: //current_view->lockedInsetStoreUndo(Undo::INSERT); @@ -1190,7 +1200,7 @@ InsetFormula::LocalDispatch(BufferView * bv, if (mathcursor->Selection() || was_selection) ToggleInsetSelection(bv); - if (result == DISPATCHED) + if ((result == DISPATCHED) || (result == DISPATCHED_NOUPDATE)) ShowInsetCursor(bv); else bv->unlockInset(this); diff --git a/src/paragraph.C b/src/paragraph.C index 5cf057ce9c..8eac8d5ddd 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -4403,8 +4403,8 @@ void LyXParagraph::deleteInsetsLyXText(BufferView * bv) cit != insetlist.end(); ++cit) { if ((*cit).inset) { if ((*cit).inset->IsTextInset()) { - static_cast((*cit).inset)-> - deleteLyXText(bv); + static_cast + ((*cit).inset)->deleteLyXText(bv); } } } diff --git a/src/tabular.C b/src/tabular.C index 42853796d8..feb9c652b7 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -168,7 +168,7 @@ void LyXTabular::Init(int rows_arg, int columns_arg) for (i = 0; i < rows_; ++i) { for (j = 0; j < columns_; ++j) { cell_info[i][j].inset.setOwner(owner_); - cell_info[i][j].inset.SetDrawLockedFrame(true); + cell_info[i][j].inset.SetDrawFrame(0, InsetText::LOCKED); cell_info[i][j].cellno = cellno++; } } diff --git a/src/text.C b/src/text.C index 13ff3232f1..e769dc96e3 100644 --- a/src/text.C +++ b/src/text.C @@ -565,8 +565,9 @@ void LyXText::draw(BufferView * bview, Row const * row, } else #endif if (c == LyXParagraph::META_INSET) { - Inset const * tmpinset = row->par()->GetInset(pos); + Inset * tmpinset = row->par()->GetInset(pos); if (tmpinset) { + tmpinset->update(bview, font); tmpinset->draw(bview, font, offset+row->baseline(), x, cleared); } @@ -1095,25 +1096,30 @@ LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const par->Last(); // this is the usual handling int x = LeftMargin(bview, row); - while (x < width && i < last) { + bool doitonetime = true; + while (doitonetime || ((x < width) && (i < last))) { + doitonetime = false; char c = par->GetChar(i); if (IsNewlineChar(c)) { last_separator = i; x = width; // this means break } else if (c == LyXParagraph::META_INSET && - par->GetInset(i) && par->GetInset(i)->display()){ + par->GetInset(i)) { + // check wether a Display() inset is // valid here. if not, change it to // non-display - if (layout.isCommand() - || (layout.labeltype == LABEL_MANUAL - && i < BeginningOfMainBody(bview->buffer(), par))){ + if (par->GetInset(i)->display() && + (layout.isCommand() || + ((layout.labeltype == LABEL_MANUAL) && + (i < BeginningOfMainBody(bview->buffer(), par))))) { // display istn't allowd par->GetInset(i)->display(false); x += SingleWidth(bview, par, i, c); - } else { - // inset is display. So break the line here - if (i == pos){ + } else if (par->GetInset(i)->display() || + par->GetInset(i)->needFullRow()) { + // So break the line here + if (i == pos) { if (pos < last-1) { last_separator = i; if (IsLineSeparatorChar(par->GetChar(i+1))) @@ -1123,6 +1129,13 @@ LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const } else last_separator = i - 1; x = width; // this means break + } else { +#if 0 + last_separator = i; + x += width; +#else + x += SingleWidth(bview, par, i, c); +#endif } } else { if (IsLineSeparatorChar(c)) @@ -2761,7 +2774,8 @@ void LyXText::InsertChar(BufferView * bview, char c) // the display inset stuff if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET && cursor.row()->par()->GetInset(cursor.row()->pos()) - && cursor.row()->par()->GetInset(cursor.row()->pos())->display()) + && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() || + cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow())) cursor.row()->fill(-1); // to force a new break // get the cursor row fist @@ -3608,7 +3622,8 @@ void LyXText::Backspace(BufferView * bview) return; // force complete redo when erasing display insets // this is a cruel method but safe..... Matthias - if (cursor.par()->GetInset(cursor.pos())->display()){ + if (cursor.par()->GetInset(cursor.pos())->display() || + cursor.par()->GetInset(cursor.pos())->needFullRow()) { cursor.par()->Erase(cursor.pos()); RedoParagraph(bview); return; @@ -3787,7 +3802,7 @@ void LyXText::Backspace(BufferView * bview) void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, - Row * row_ptr, long y) + Row * row_ptr, long y, bool cleared) { /* returns a printed row */ Painter & pain = bview->painter(); @@ -3810,6 +3825,8 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, PrepareToPrint(bview, row_ptr, x, fill_separator, fill_hfill, fill_label_hfill); + if (inset_owner && (x < 0)) + x = 0; x += x_offset; // clear the area where we want to paint/print @@ -3825,7 +3842,9 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, { clear_area = inset->doClearArea(); } - if (clear_area) { + if (cleared) { // we don't need to clear it's already done!!! + clear_area = true; + } else if (clear_area) { int w; if (inset_owner) w = inset_owner->width(bview->painter(), font);