From ccfdb2a78a11ba65262fa28f40fdf83b2f405f26 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Wed, 21 Jun 2000 15:07:57 +0000 Subject: [PATCH] Various fixes in insettext/tabular to make update work selective. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@826 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 15 ++ src/BufferView.C | 6 + src/BufferView.h | 3 + src/BufferView_pimpl.C | 2 +- src/insets/figinset.C | 3 +- src/insets/figinset.h | 2 +- src/insets/inset.C | 11 +- src/insets/insetbutton.C | 4 +- src/insets/insetbutton.h | 2 +- src/insets/insetcite.C | 9 +- src/insets/insetcollapsable.C | 14 +- src/insets/insetcollapsable.h | 2 +- src/insets/inseterror.C | 4 +- src/insets/inseterror.h | 2 +- src/insets/insetfoot.C | 4 +- src/insets/insetfoot.h | 2 +- src/insets/insetgraphics.C | 5 +- src/insets/insetgraphics.h | 2 +- src/insets/insetinfo.C | 3 +- src/insets/insetinfo.h | 2 +- src/insets/insetlatexaccent.C | 5 +- src/insets/insetlatexaccent.h | 2 +- src/insets/insetquotes.C | 6 +- src/insets/insetquotes.h | 2 +- src/insets/insetspecialchar.C | 5 +- src/insets/insetspecialchar.h | 2 +- src/insets/insettabular.C | 51 ++-- src/insets/insettabular.h | 8 +- src/insets/insettext.C | 429 +++++++++++++++++----------------- src/insets/insettext.h | 53 +++-- src/insets/lyxinset.h | 15 +- src/lyxfunc.C | 4 +- src/lyxtext.h | 8 +- src/text.C | 15 +- src/text2.C | 15 +- 35 files changed, 394 insertions(+), 323 deletions(-) diff --git a/ChangeLog b/ChangeLog index c5d31555d4..7f16f75021 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2000-06-21 Juergen Vigna + + * src/text.C (GetVisibleRow): look if I should clear the area or not + using Inset::doClearArea() function. + + * src/insets/lyxinset.h: added doClearArea() function and + modified draw(Painter &, ...) to draw(BufferView *, ...) + + * src/text2.C (UpdateInset): return bool insted of int + +2000-06-20 Juergen Vigna + + * src/insets/insettext.C (SetParagraphData): set insetowner on + 2- paragraphs. + 2000-06-21 Lars Gullik Bjønnes * src/Timeout.[Ch]: Change to use signals instead of callbacks.  diff --git a/src/BufferView.C b/src/BufferView.C index 4fb7f0eb6d..1d8592f3c3 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -51,6 +51,12 @@ LyXScreen * BufferView::screen() const } +WorkArea * BufferView::workarea() const +{ + return pimpl_->workarea_; +} + + LyXView * BufferView::owner() const { return pimpl_->owner_; diff --git a/src/BufferView.h b/src/BufferView.h index e714c63d33..ed2e57805c 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -24,6 +24,7 @@ class LyXText; class TeXErrors; class Buffer; class LyXScreen; +class WorkArea; /// class BufferView { @@ -47,6 +48,8 @@ public: /// LyXScreen * screen() const; /// + WorkArea * workarea() const; + /// void buffer(Buffer * b); /// void resize(int, int, int, int); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 6f9ecaffa3..57f7f74d81 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -1302,7 +1302,7 @@ void BufferView::Pimpl::setState() void BufferView::Pimpl::insetSleep() { if (bv_->the_locking_inset && !bv_->inset_slept) { - bv_->the_locking_inset->GetCursorPos(bv_->slx, bv_->sly); + bv_->the_locking_inset->GetCursorPos(bv_, bv_->slx, bv_->sly); bv_->the_locking_inset->InsetUnlock(bv_); bv_->inset_slept = true; } diff --git a/src/insets/figinset.C b/src/insets/figinset.C index 546a92c80e..99e447c6c1 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -1034,10 +1034,11 @@ int InsetFig::width(Painter &, LyXFont const &) const } -void InsetFig::draw(Painter & pain, LyXFont const & f, +void InsetFig::draw(BufferView * bv, LyXFont const & f, int baseline, float & x) const { LyXFont font(f); + Painter & pain = bv->painter(); if (bitmap_waiting) getbitmaps(); diff --git a/src/insets/figinset.h b/src/insets/figinset.h index 8df0d8f94f..cb53c9218c 100644 --- a/src/insets/figinset.h +++ b/src/insets/figinset.h @@ -30,7 +30,7 @@ public: /// int width(Painter &, LyXFont const & font) const; /// - void draw(Painter &, LyXFont const & font, + void draw(BufferView *, LyXFont const & font, int baseline, float & x) const; /// void Write(Buffer const *, std::ostream &) const; diff --git a/src/insets/inset.C b/src/insets/inset.C index 19249a574e..35052a6dda 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -42,15 +42,6 @@ Inset::EDITABLE Inset::Editable() const } -bool Inset::IsTextInset() const -{ - return ((LyxCode() == TEXT_CODE) || - (LyxCode() == ERT_CODE) || - (LyxCode() == FOOT_CODE) || - (LyxCode() == MARGIN_CODE)); -} - - void Inset::Validate(LaTeXFeatures &) const { } @@ -145,7 +136,7 @@ void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int) } -void UpdatableInset::draw(Painter &, LyXFont const &, +void UpdatableInset::draw(BufferView *, LyXFont const &, int /* baseline */, float & x) const { if (scx) x += float(scx); diff --git a/src/insets/insetbutton.C b/src/insets/insetbutton.C index f167fe65be..327ab0b656 100644 --- a/src/insets/insetbutton.C +++ b/src/insets/insetbutton.C @@ -16,6 +16,7 @@ #include "insetbutton.h" #include "debug.h" +#include "BufferView.h" #include "Painter.h" using std::ostream; @@ -86,9 +87,10 @@ int InsetButton::width(Painter & pain, LyXFont const &) const } -void InsetButton::draw(Painter & pain, LyXFont const &, +void InsetButton::draw(BufferView * bv, LyXFont const &, int baseline, float & x) const { + Painter & pain = bv->painter(); // Draw it as a box with the LaTeX text LyXFont font(LyXFont::ALL_SANE); font.setColor(LColor::command).decSize(); diff --git a/src/insets/insetbutton.h b/src/insets/insetbutton.h index 917b57ff85..b88a83729c 100644 --- a/src/insets/insetbutton.h +++ b/src/insets/insetbutton.h @@ -33,7 +33,7 @@ public: /// int width(Painter &, LyXFont const &) const; /// - void draw(Painter &, LyXFont const &, int baseline, float & x) const; + void draw(BufferView *, LyXFont const &, int baseline, float & x) const; protected: /// This should provide the text for the button diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index 7b523bdfa0..3e657546d3 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -179,10 +179,11 @@ void InsetCitation::Edit( BufferView * bv, int, int, unsigned int ) if( citation_form->form->visible ) { fl_raise_form( citation_form->form ); } else { - fl_show_form( citation_form->form, - FL_PLACE_MOUSE, FL_FULLBORDER, - _("Citation") ); - } + fl_show_form(citation_form->form, + FL_PLACE_MOUSE | FL_FREE_SIZE, + FL_FULLBORDER, + _("Citation") ); + } } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 68f12ab101..03537313d3 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -135,9 +135,11 @@ void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const & font, } -void InsetCollapsable::draw(Painter & pain, LyXFont const & f, +void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, int baseline, float & x) const { + Painter & pain = bv->painter(); + button_length = width_collapsed(pain, labelfont) + 2; button_top_y = -ascent_collapsed(pain, f); button_bottom_y = descent_collapsed(pain, f); @@ -158,7 +160,7 @@ void InsetCollapsable::draw(Painter & pain, LyXFont const & f, x += TEXT_TO_INSET_OFFSET; drawTextXOffset = int(x) - top_x; - InsetText::draw(pain, f, baseline, x); + InsetText::draw(bv, f, baseline, x); } @@ -166,7 +168,7 @@ void InsetCollapsable::Edit(BufferView * bv, int x, int y, unsigned int button) { if (collapsed && autocollapse) { collapsed = false; - UpdateLocal(bv, true, false); + UpdateLocal(bv, FULL, false); InsetText::Edit(bv, 0, 0, button); } else if (!collapsed) { InsetText::Edit(bv, x, y, button); @@ -188,7 +190,7 @@ void InsetCollapsable::InsetUnlock(BufferView * bv) collapsed = true; } InsetText::InsetUnlock(bv); - UpdateLocal(bv, false, false); + UpdateLocal(bv, FULL, false); } @@ -208,10 +210,10 @@ void InsetCollapsable::InsetButtonRelease(BufferView * bv, if (collapsed) { collapsed = false; InsetText::InsetButtonRelease(bv, 0, 0, button); - UpdateLocal(bv, true, false); + UpdateLocal(bv, FULL, false); } else { collapsed = true; - UpdateLocal(bv, false, false); + UpdateLocal(bv, FULL, false); bv->unlockInset(this); } } else if (!collapsed && (x >= button_length) && (y >= button_top_y)) { diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index bf21fb5506..5107c44837 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -51,7 +51,7 @@ public: /// int width(Painter &, LyXFont const & f) const; /// - void draw(Painter & pain, const LyXFont &, int , float &) const; + void draw(BufferView *, const LyXFont &, int , float &) const; /// void Edit(BufferView *, int, int, unsigned int); /// diff --git a/src/insets/inseterror.C b/src/insets/inseterror.C index a01ca84781..cc7584a287 100644 --- a/src/insets/inseterror.C +++ b/src/insets/inseterror.C @@ -18,6 +18,7 @@ #include "gettext.h" #include "lyx_gui_misc.h" // CancelCloseBoxCB #include "Painter.h" +#include "BufferView.h" #include "font.h" using std::ostream; @@ -71,9 +72,10 @@ int InsetError::width(Painter &, LyXFont const & font) const } -void InsetError::draw(Painter & pain, LyXFont const & font, +void InsetError::draw(BufferView * bv, LyXFont const & font, int baseline, float & x) const { + Painter & pain = bv->painter(); LyXFont efont; efont.setSize(font.size()).decSize(); efont.setColor(LColor::error); diff --git a/src/insets/inseterror.h b/src/insets/inseterror.h index 0a47116373..1147e47e74 100644 --- a/src/insets/inseterror.h +++ b/src/insets/inseterror.h @@ -42,7 +42,7 @@ public: /// int width(Painter &, LyXFont const & font) const; /// - void draw(Painter &, LyXFont const & font, int baseline, float & x) const; + void draw(BufferView *, LyXFont const & font, int baseline, float & x) const; /// void Write(Buffer const *, std::ostream &) const; /// diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index 8ef185da8c..6c67189a5c 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -83,9 +83,9 @@ bool InsetFoot::InsertInsetAllowed(Inset * inset) const } -LyXFont InsetFoot::GetDrawFont(Buffer const * buf, LyXParagraph * p, int pos) const +LyXFont InsetFoot::GetDrawFont(BufferView * bv,LyXParagraph * p, int pos) const { - LyXFont fn = text->GetFont(buf, p, pos); + LyXFont fn = getLyXText(bv)->GetFont(bv->buffer(), p, pos); fn.decSize().decSize(); return fn; } diff --git a/src/insets/insetfoot.h b/src/insets/insetfoot.h index f396d5aa07..a5404b4556 100644 --- a/src/insets/insetfoot.h +++ b/src/insets/insetfoot.h @@ -45,7 +45,7 @@ public: /// bool InsertInsetAllowed(Inset * inset) const; /// - LyXFont GetDrawFont(Buffer const *, LyXParagraph * par, int pos) const; + LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; /// }; diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 39c3b19e63..35716df97f 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -15,6 +15,7 @@ #include #include "insets/insetgraphics.h" +#include "BufferView.h" #include "Painter.h" #include "form_graphics.h" #include "lyx_gui_misc.h" @@ -133,9 +134,11 @@ int InsetGraphics::width(Painter &, LyXFont const &) const } -void InsetGraphics::draw(Painter & pain, LyXFont const & font, +void InsetGraphics::draw(BufferView * bv, LyXFont const & font, int baseline, float & x) const { + Painter & pain = bv->painter(); + // This will draw the graphics. As for now we only draw a // placeholder rectangele. pain.rectangle(int(x), baseline - ascent(pain, font), diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index d5e5415354..76d2ec824e 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -35,7 +35,7 @@ public: /// int width(Painter &, LyXFont const &) const; /// - void draw(Painter &, LyXFont const &, + void draw(BufferView *, LyXFont const &, int baseline, float & x) const; /// void Edit(BufferView *, int, int, unsigned int); diff --git a/src/insets/insetinfo.C b/src/insets/insetinfo.C index 9433bf70a2..e57b91f042 100644 --- a/src/insets/insetinfo.C +++ b/src/insets/insetinfo.C @@ -75,9 +75,10 @@ int InsetInfo::width(Painter &, LyXFont const & font) const } -void InsetInfo::draw(Painter & pain, LyXFont const & f, +void InsetInfo::draw(BufferView * bv, LyXFont const & f, int baseline, float & x) const { + Painter & pain = bv->painter(); LyXFont font(f); /* Info-insets are never LaTeX, so just correct the font */ diff --git a/src/insets/insetinfo.h b/src/insets/insetinfo.h index ca32a853d5..ef1cf83e1a 100644 --- a/src/insets/insetinfo.h +++ b/src/insets/insetinfo.h @@ -44,7 +44,7 @@ public: /// int width(Painter &, LyXFont const &) const; /// - void draw(Painter &, LyXFont const &, int baseline, float & x) const; + void draw(BufferView *, LyXFont const &, int baseline, float & x) const; /// void Write(Buffer const *, std::ostream &) const; /// diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index c332b6030b..89fdbfc710 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -18,6 +18,7 @@ #include "debug.h" #include "lyxrc.h" #include "support/lstrings.h" +#include "BufferView.h" #include "Painter.h" #include "font.h" @@ -354,9 +355,11 @@ bool InsetLatexAccent::DisplayISO8859_9(Painter & pain, LyXFont const & font, } -void InsetLatexAccent::draw(Painter & pain, LyXFont const & font, +void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font, int baseline, float & x) const { + Painter & pain = bv->painter(); + if (lyxrc.font_norm == "iso8859-9") if (DisplayISO8859_9(pain, font, baseline, x)) return; diff --git a/src/insets/insetlatexaccent.h b/src/insets/insetlatexaccent.h index 8f83dd56da..5e44470376 100644 --- a/src/insets/insetlatexaccent.h +++ b/src/insets/insetlatexaccent.h @@ -41,7 +41,7 @@ public: /// int width(Painter &, LyXFont const &) const; /// - void draw(Painter &, LyXFont const &, int baseline, float & x) const; + void draw(BufferView *, LyXFont const &, int baseline, float & x) const; /// int Lbearing(LyXFont const & font) const; /// diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index 2e028cc40c..f2dfa4238e 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -197,13 +197,13 @@ LyXFont InsetQuotes::ConvertFont(LyXFont font) } -void InsetQuotes::draw(Painter & pain, LyXFont const & font, +void InsetQuotes::draw(BufferView * bv, LyXFont const & font, int baseline, float & x) const { string text = DispString(); - pain.text(int(x), baseline, text, font); - x += width(pain, font); + bv->painter().text(int(x), baseline, text, font); + x += width(bv->painter(), font); } diff --git a/src/insets/insetquotes.h b/src/insets/insetquotes.h index fd3565ba98..3c6a6f24b1 100644 --- a/src/insets/insetquotes.h +++ b/src/insets/insetquotes.h @@ -78,7 +78,7 @@ public: /// int width(Painter &, LyXFont const &) const; /// - void draw(Painter &, LyXFont const &, int baseline, float & x) const; + void draw(BufferView *, LyXFont const &, int baseline, float & x) const; /// LyXFont ConvertFont(LyXFont font); /// diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index cf8d0b6202..81431d769f 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -16,6 +16,7 @@ #include "insetspecialchar.h" #include "debug.h" #include "LaTeXFeatures.h" +#include "BufferView.h" #include "Painter.h" #include "font.h" @@ -71,10 +72,12 @@ int InsetSpecialChar::width(Painter &, LyXFont const & font) const } -void InsetSpecialChar::draw(Painter & pain, LyXFont const & f, +void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f, int baseline, float & x) const { + Painter & pain = bv->painter(); LyXFont font(f); + switch (kind) { case HYPHENATION: { diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index d9a737dd14..d02aec0d65 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -50,7 +50,7 @@ public: /// int width(Painter &, LyXFont const &) const; /// - void draw(Painter &, LyXFont const &, int baseline, float & x) const; + void draw(BufferView *, LyXFont const &, int baseline, float & x) const; /// void Write(Buffer const *, std::ostream &) const; /// Will not be used when lyxf3 diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 742ec1a1b7..fe873449d6 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -131,45 +131,34 @@ void InsetTabular::Read(Buffer const * buf, LyXLex & lex) } -int InsetTabular::ascent(Painter & pain, LyXFont const & font) const +int InsetTabular::ascent(Painter &, LyXFont const &) const { - if (init_inset) { - calculate_width_of_cells(pain, font); - init_inset = false; - } return tabular->GetAscentOfRow(0); } -int InsetTabular::descent(Painter & pain, LyXFont const & font) const +int InsetTabular::descent(Painter &, LyXFont const &) const { - if (init_inset) { - calculate_width_of_cells(pain, font); - init_inset = false; - } return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0); } -int InsetTabular::width(Painter & pain, LyXFont const & font) const +int InsetTabular::width(Painter &, LyXFont const &) const { - if (init_inset) { - calculate_width_of_cells(pain, font); - init_inset = false; - } return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH); } -void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline, +void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, float & x) const { + Painter & pain = bv->painter(); int i, j, cell=0; int nx; float cx; bool reinit = false; - UpdatableInset::draw(pain,font,baseline,x); + UpdatableInset::draw(bv,font,baseline,x); if (init_inset || (top_x != int(x)) || (top_baseline != baseline)) { // int ox = top_x; init_inset = false; @@ -177,7 +166,7 @@ void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline, top_baseline = baseline; // if (ox != top_x) // recomputeTextInsets(pain, font); - calculate_width_of_cells(pain, font); +// calculate_width_of_cells(pain, font); resetPos(pain); reinit = true; } @@ -190,7 +179,7 @@ void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline, cx = nx + tabular->GetBeginningOfTextInCell(cell); if (hasSelection()) DrawCellSelection(pain, nx, baseline, i, j, cell); - tabular->GetCellInset(cell)->draw(pain, font, baseline, cx); + tabular->GetCellInset(cell)->draw(bv, font, baseline, cx); DrawCellLines(pain, nx, baseline, i, cell); nx += tabular->GetWidthOfColumn(cell); ++cell; @@ -202,10 +191,12 @@ void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline, } -void InsetTabular::update(BufferView * bv, LyXFont const & font) const +void InsetTabular::update(BufferView * bv, LyXFont const & font, bool dodraw) { - if (init_inset) - recomputeTextInsets(bv, font); + if (init_inset) { + calculate_width_of_cells(bv, font, dodraw); +// recomputeTextInsets(bv, font); + } } @@ -324,8 +315,9 @@ void InsetTabular::InsetUnlock(BufferView * bv) void InsetTabular::UpdateLocal(BufferView * bv, bool what, bool mark_dirty) { - if (what) - calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE)); +// if (what) +// calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE)); + init_inset = what; bv->updateInset(this, mark_dirty); if (what) resetPos(bv->painter()); @@ -732,8 +724,8 @@ void InsetTabular::Validate(LaTeXFeatures & features) const } -void InsetTabular::calculate_width_of_cells(Painter & pain, - LyXFont const & font) const +void InsetTabular::calculate_width_of_cells(BufferView * bv, + LyXFont const & font, bool dodraw) const { int cell = -1; int maxAsc, maxDesc; @@ -746,9 +738,10 @@ void InsetTabular::calculate_width_of_cells(Painter & pain, continue; ++cell; inset = tabular->GetCellInset(cell); - maxAsc = max(maxAsc, inset->ascent(pain, font)); - maxDesc = max(maxDesc, inset->descent(pain, font)); - tabular->SetWidthOfCell(cell, inset->width(pain, font)); + inset->update(bv, font, dodraw); + maxAsc = max(maxAsc, inset->ascent(bv->painter(), font)); + maxDesc = max(maxDesc, inset->descent(bv->painter(), font)); + tabular->SetWidthOfCell(cell, inset->width(bv->painter(), font)); } tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT); tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT); diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 7c5b1340da..5247e02412 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -80,14 +80,16 @@ public: /// int width(Painter &, LyXFont const & f) const; /// - void draw(Painter & pain, const LyXFont &, int , float &) const; + void draw(BufferView *, const LyXFont &, int , float &) const; /// - void update(BufferView *, LyXFont const &) const; + void update(BufferView *, LyXFont const &, bool); /// const char * EditMessage() const; /// void Edit(BufferView *, int x, int y, unsigned int); /// + bool doClearArea() const { return !locked; }; + /// void InsetUnlock(BufferView *); /// void UpdateLocal(BufferView *, bool what, bool mark_dirty); @@ -150,7 +152,7 @@ public: LyXTabular * tabular; private: - void calculate_width_of_cells(Painter &, LyXFont const &) const; + void calculate_width_of_cells(BufferView *, LyXFont const &, bool =false) const; /// void DrawCellLines(Painter &, int x, int baseline, int row, int cell) const; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 0a39eccf90..695e923ba0 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -55,15 +55,13 @@ using std::min; using std::max; extern unsigned char getCurrentTextClass(Buffer *); -#warning BAAAAAAAADDDDDDD current_view (but Lars wanted it :) !!! -extern BufferView * current_view; +#define TEXT(a) getLyXText(a) InsetText::InsetText() { par = new LyXParagraph(); init(); - text = new LyXText(this); } @@ -72,7 +70,6 @@ InsetText::InsetText(InsetText const & ins) { par = 0; init(&ins); - text = new LyXText(this); autoBreakRows = ins.autoBreakRows; } @@ -80,18 +77,18 @@ InsetText::InsetText(InsetText const & ins) InsetText & InsetText::operator=(InsetText const & it) { init(&it); - text = new LyXText(this); autoBreakRows = it.autoBreakRows; return * this; } void InsetText::init(InsetText const * ins) { + insetAscent = insetDescent = insetWidth = 0; the_locking_inset = 0; cursor_visible = false; interline_space = 1; no_selection = false; - init_inset = true; + need_update = INIT; drawTextXOffset = drawTextYOffset = 0; autoBreakRows = drawLockedFrame = false; xpos = 0.0; @@ -101,7 +98,6 @@ void InsetText::init(InsetText const * ins) drawLockedFrame = ins->drawLockedFrame; } par->SetInsetOwner(this); -// selection_start_cursor = selection_end_cursor = cursor; frame_color = LColor::insetframe; locked = false; old_par = 0; @@ -188,86 +184,97 @@ void InsetText::Read(Buffer const * buf, LyXLex & lex) lex.printError("Missing \\end_inset at this point. " "Read: `$$Token'"); } - init_inset = true; + need_update = INIT; } int InsetText::ascent(Painter &, LyXFont const &) const { - long int y_temp = 0; - Row * row = text->GetRowNearY(y_temp); - return row->ascent_of_text() + 2; + return insetAscent; } int InsetText::descent(Painter &, LyXFont const &) const { - long int y = 0; - Row * row = text->GetRowNearY(y); - return text->height - row->ascent_of_text() + 2; + return insetDescent; } -int InsetText::width(Painter & pain, LyXFont const &) const +int InsetText::width(Painter &, LyXFont const &) const { - return std::max(static_cast(getMaxTextWidth(pain, this)), - text->width); + return insetWidth; } -void InsetText::draw(Painter & pain, LyXFont const & f, +void InsetText::draw(BufferView * bv, LyXFont const & f, int baseline, float & x) const { + Painter & pain = bv->painter(); + xpos = x; - UpdatableInset::draw(pain, f, baseline, x); + UpdatableInset::draw(bv, f, baseline, x); top_baseline = baseline; top_x = int(x); - if (the_locking_inset && (cpos() == inset_pos)) { - inset_x = cx() - top_x + drawTextXOffset; - inset_y = cy() + drawTextYOffset; + if (the_locking_inset && (cpos(bv) == inset_pos)) { + inset_x = cx(bv) - top_x + drawTextXOffset; + inset_y = cy(bv) + drawTextYOffset; } x += TEXT_TO_INSET_OFFSET; // place for border long int y = 0; - Row * row = text->GetRowNearY(y); + Row * row = TEXT(bv)->GetRowNearY(y); y += baseline - row->ascent_of_text() + 1; - while (row != 0) { - text->GetVisibleRow(current_view, y, x, row, y); - y += row->height(); - row = row->next(); + if (!locked || (need_update == FULL)) { + while (row != 0) { + TEXT(bv)->GetVisibleRow(bv, y, x, row, y); + y += row->height(); + row = row->next(); + } + if (drawLockedFrame && locked) { + pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f), + ascent(pain,f) + descent(pain, f), frame_color); + } + } else { + bv->screen()->Update(TEXT(bv)); } x += width(pain, f) - TEXT_TO_INSET_OFFSET; - if (drawLockedFrame && locked) { - pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f), - ascent(pain,f) + descent(pain, f), frame_color); - } } -void InsetText::update(BufferView * bv, LyXFont const &) const +void InsetText::update(BufferView * bv, LyXFont const &, bool dodraw) { - if (init_inset) { - text->init(bv); - init_inset = false; + if (need_update == INIT) { + deleteLyXText(bv); + need_update = FULL; + } + #if 0 - // Dump all rowinformation: - long y_dummy = 0; - Row * tmprow = text->GetRowNearY(y_dummy); - lyxerr << "Width = " << text->width << endl; - lyxerr << "Baseline Paragraph Pos Height Ascent Fill\n"; - while (tmprow) { - lyxerr << tmprow->baseline() << '\t' - << tmprow->par() << '\t' - << tmprow->pos() << '\t' - << tmprow->height() << '\t' - << tmprow->ascent_of_text() << '\t' - << tmprow->fill() << '\n'; - tmprow = tmprow->next(); - } - lyxerr.flush(); -#endif + switch(need_update) { + case NONE: // most common first + break; + case INIT: + need_update = NONE; + break; + case CURSOR_PAR: + need_update = NONE; + break; + case FULL: + TEXT(bv)->FullRebreak(bv); + need_update = NONE; + break; + default: + need_update = NONE; + break; } +#endif + TEXT(bv)->FullRebreak(bv); + + long int y_temp = 0; + Row * row = TEXT(bv)->GetRowNearY(y_temp); + insetAscent = row->ascent_of_text() + 2; + insetDescent = TEXT(bv)->height - row->ascent_of_text() + 2; + insetWidth = max(getMaxTextWidth(bv->painter(), this), TEXT(bv)->width); } @@ -279,7 +286,7 @@ char const * InsetText::EditMessage() const void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button) { - par->SetInsetOwner(this); +// par->SetInsetOwner(this); UpdatableInset::Edit(bv, x, y, button); if (!bv->lockInset(this)) { @@ -292,9 +299,9 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button) // setPos(bv->painter(), x, y); checkAndActivateInset(bv, x, y, button); // selection_start_cursor = selection_end_cursor = cursor; - text->sel_cursor = text->cursor; + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; bv->text->FinishUndo(); - UpdateLocal(bv, true, false); + UpdateLocal(bv, FULL, false); } @@ -307,10 +314,11 @@ void InsetText::InsetUnlock(BufferView * bv) HideInsetCursor(bv); lyxerr[Debug::INSETS] << "InsetText::InsetUnlock(" << this << ")" << endl; -// selection_start_cursor = selection_end_cursor = cursor; no_selection = false; locked = false; - UpdateLocal(bv, true, false); + TEXT(bv)->selection = 0; + UpdateLocal(bv, FULL, false); + bv->owner()->getToolbar()->combox->select(bv->text->cursor.par()->GetLayout()+1); } @@ -319,20 +327,20 @@ bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset) lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): "; if (!inset) return false; - if (inset == par->GetInset(cpos())) { + if (inset == cpar(bv)->GetInset(cpos(bv))) { lyxerr[Debug::INSETS] << "OK" << endl; the_locking_inset = inset; // resetPos(bv->painter()); - inset_x = cx() - top_x + drawTextXOffset; - inset_y = cy() + drawTextYOffset; - inset_pos = cpos(); + inset_x = cx(bv) - top_x + drawTextXOffset; + inset_y = cy(bv) + drawTextYOffset; + inset_pos = cpos(bv); return true; } else if (the_locking_inset && (the_locking_inset == inset)) { - if (cpos() == inset_pos) { + if (cpos(bv) == inset_pos) { lyxerr[Debug::INSETS] << "OK" << endl; // resetPos(bv->painter()); - inset_x = cx() - top_x + drawTextXOffset; - inset_y = cy() + drawTextYOffset; + inset_x = cx(bv) - top_x + drawTextXOffset; + inset_y = cy(bv) + drawTextYOffset; } else { lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl; } @@ -369,10 +377,10 @@ bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset) return the_locking_inset->UpdateInsetInInset(bv, inset); lyxerr[Debug::INSETS] << "InsetText::UpdateInsetInInset(" << inset << ")" << endl; - UpdateLocal(bv, true, false); - if (cpos() == inset_pos) { - inset_x = cx() - top_x + drawTextXOffset; - inset_y = cy() + drawTextYOffset; + UpdateLocal(bv, FULL, false); + if (cpos(bv) == inset_pos) { + inset_x = cx(bv) - top_x + drawTextXOffset; + inset_y = cy(bv) + drawTextYOffset; } return true; } @@ -380,29 +388,29 @@ bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset) void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) { - if (text->selection) { - text->selection = 0; - UpdateLocal(bv, false, false); + if (TEXT(bv)->selection) { + TEXT(bv)->selection = 0; + UpdateLocal(bv, FULL, false); } no_selection = false; // setPos(bv->painter(), x, y); // cursor.x_fix(-1); - text->SetCursorFromCoordinates(bv, x, y+bv->screen()->first); + TEXT(bv)->SetCursorFromCoordinates(bv, x, y+bv->screen()->first); if (the_locking_inset) { UpdatableInset * inset = 0; - if (par->GetChar(cpos()) == LyXParagraph::META_INSET) - inset = static_cast(par->GetInset(cpos())); + 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; } else if (inset) { // otherwise unlock the_locking_inset and lock the new inset the_locking_inset->InsetUnlock(bv); - inset_x = cx() - top_x + drawTextXOffset; - inset_y = cy() + drawTextYOffset; + 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, button); - UpdateLocal(bv, true, false); + UpdateLocal(bv, FULL, false); return; } // otherwise only unlock the_locking_inset @@ -410,16 +418,16 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) the_locking_inset = 0; } if (bv->the_locking_inset) { - if ((par->GetChar(cpos()) == LyXParagraph::META_INSET) && - par->GetInset(cpos()) && - (par->GetInset(cpos())->Editable() == Inset::HIGHLY_EDITABLE)) { + 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(par->GetInset(cpos())); - inset_x = cx() - top_x + drawTextXOffset; - inset_y = cy() + drawTextYOffset; + static_cast(cpar(bv)->GetInset(cpos(bv))); + 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, true, false); + UpdateLocal(bv, FULL, false); } } // selection_start_cursor = selection_end_cursor = cursor; @@ -433,13 +441,13 @@ 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); } else { - if (par->GetChar(cpos()) == LyXParagraph::META_INSET) { - inset = static_cast(par->GetInset(cpos())); + if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) { + inset = static_cast(cpar(bv)->GetInset(cpos(bv))); if (inset->Editable() == Inset::HIGHLY_EDITABLE) { inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button); } else { - inset_x = cx() - top_x + drawTextXOffset; - inset_y = cy() + drawTextYOffset; + inset_x = cx(bv) - top_x + drawTextXOffset; + inset_y = cy(bv) + drawTextYOffset; inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button); inset->Edit(bv, x - inset_x, y - inset_y, button); } @@ -501,7 +509,7 @@ InsetText::LocalDispatch(BufferView * bv, return result; else if (result == DISPATCHED) { the_locking_inset->ToggleInsetCursor(bv); - UpdateLocal(bv, false, false); + UpdateLocal(bv, FULL, false); the_locking_inset->ToggleInsetCursor(bv); return result; } else if (result == FINISHED) { @@ -509,7 +517,7 @@ InsetText::LocalDispatch(BufferView * bv, case -1: case LFUN_RIGHT: moveRight(bv); -// text->cursor.pos(inset_pos + 1); +// TEXT(bv)->cursor.pos(inset_pos + 1); // resetPos(bv->painter()); break; case LFUN_DOWN: @@ -540,121 +548,121 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); if (lyxrc.auto_region_delete) { - if (text->selection){ - text->CutSelection(bv, false); + if (TEXT(bv)->selection){ + TEXT(bv)->CutSelection(bv, false); } } - text->ClearSelection(); + TEXT(bv)->ClearSelection(); for (string::size_type i = 0; i < arg.length(); ++i) { - bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], text); + bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], TEXT(bv)); } } - UpdateLocal(bv, true, true); + UpdateLocal(bv, CURSOR_PAR, true); break; // --- Cursor Movements --------------------------------------------- case LFUN_RIGHTSEL: bv->text->FinishUndo(); moveRight(bv, false); - text->SetSelection(); - UpdateLocal(bv, false, false); + TEXT(bv)->SetSelection(); + UpdateLocal(bv, CURSOR_PAR, false); break; case LFUN_RIGHT: bv->text->FinishUndo(); result = moveRight(bv); - text->selection = 0; - text->sel_cursor = text->cursor; - UpdateLocal(bv, false, false); + TEXT(bv)->selection = 0; + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + UpdateLocal(bv, CURSOR_PAR, false); break; case LFUN_LEFTSEL: bv->text->FinishUndo(); moveLeft(bv, false); - text->SetSelection(); - UpdateLocal(bv, false, false); + TEXT(bv)->SetSelection(); + UpdateLocal(bv, CURSOR_PAR, false); break; case LFUN_LEFT: bv->text->FinishUndo(); result= moveLeft(bv); - text->selection = 0; - text->sel_cursor = text->cursor; - UpdateLocal(bv, false, false); + TEXT(bv)->selection = 0; + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + UpdateLocal(bv, CURSOR_PAR, false); break; case LFUN_DOWNSEL: bv->text->FinishUndo(); moveDown(bv); - text->SetSelection(); - UpdateLocal(bv, false, false); + TEXT(bv)->SetSelection(); + UpdateLocal(bv, CURSOR_PAR, false); break; case LFUN_DOWN: bv->text->FinishUndo(); result = moveDown(bv); - text->selection = 0; - text->sel_cursor = text->cursor; - UpdateLocal(bv, false, false); + TEXT(bv)->selection = 0; + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + UpdateLocal(bv, CURSOR_PAR, false); break; case LFUN_UPSEL: bv->text->FinishUndo(); moveUp(bv); - text->SetSelection(); - UpdateLocal(bv, false, false); + TEXT(bv)->SetSelection(); + UpdateLocal(bv, CURSOR_PAR, false); break; case LFUN_UP: bv->text->FinishUndo(); result = moveUp(bv); - text->selection = 0; - text->sel_cursor = text->cursor; - UpdateLocal(bv, false, false); + TEXT(bv)->selection = 0; + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + UpdateLocal(bv, CURSOR_PAR, false); break; case LFUN_HOME: bv->text->FinishUndo(); - text->CursorHome(bv); - text->selection = 0; - text->sel_cursor = text->cursor; - UpdateLocal(bv, false, false); + TEXT(bv)->CursorHome(bv); + TEXT(bv)->selection = 0; + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + UpdateLocal(bv, CURSOR_PAR, false); break; case LFUN_END: - text->CursorEnd(bv); - text->selection = 0; - text->sel_cursor = text->cursor; - UpdateLocal(bv, false, false); + TEXT(bv)->CursorEnd(bv); + TEXT(bv)->selection = 0; + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + UpdateLocal(bv, CURSOR_PAR, false); break; case LFUN_BACKSPACE: bv->text->SetUndo(bv->buffer(), Undo::DELETE, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); - text->Backspace(bv); - UpdateLocal(bv, true, true); + TEXT(bv)->Backspace(bv); + UpdateLocal(bv, CURSOR_PAR, true); break; case LFUN_DELETE: bv->text->SetUndo(bv->buffer(), Undo::DELETE, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); - text->Delete(bv); - UpdateLocal(bv, true, true); + TEXT(bv)->Delete(bv); + UpdateLocal(bv, CURSOR_PAR, true); break; case LFUN_CUT: bv->text->SetUndo(bv->buffer(), Undo::DELETE, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); - text->CutSelection(bv); - UpdateLocal(bv, true, true); + TEXT(bv)->CutSelection(bv); + UpdateLocal(bv, CURSOR_PAR, true); break; case LFUN_COPY: bv->text->FinishUndo(); - text->CopySelection(bv); - UpdateLocal(bv, true, false); + TEXT(bv)->CopySelection(bv); + UpdateLocal(bv, CURSOR_PAR, false); break; case LFUN_PASTE: bv->text->SetUndo(bv->buffer(), Undo::INSERT, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); - text->PasteSelection(bv); - UpdateLocal(bv, true, true); + TEXT(bv)->PasteSelection(bv); + UpdateLocal(bv, CURSOR_PAR, true); break; case LFUN_BREAKPARAGRAPH: if (!autoBreakRows) return DISPATCHED; - text->BreakParagraph(bv, 0); - UpdateLocal(bv, true, true); + TEXT(bv)->BreakParagraph(bv, 0); + UpdateLocal(bv, CURSOR_PAR, true); break; case LFUN_BREAKLINE: if (!autoBreakRows) @@ -662,12 +670,12 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->SetUndo(bv->buffer(), Undo::INSERT, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next); - text->InsertChar(bv, LyXParagraph::META_NEWLINE); - UpdateLocal(bv, true, true); + TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE); + UpdateLocal(bv, CURSOR_PAR, true); break; case LFUN_LAYOUT: { - static LyXTextClass::size_type cur_layout = par->layout; + static LyXTextClass::size_type cur_layout = cpar(bv)->layout; // Derive layout number from given argument (string) // and current buffer's textclass (number). */ @@ -694,9 +702,9 @@ InsetText::LocalDispatch(BufferView * bv, if (cur_layout != layout.second) { cur_layout = layout.second; - text->SetLayout(bv, layout.second); - bv->owner()->getToolbar()->combox->select(cpar()->GetLayout()+1); - UpdateLocal(bv, true, true); + TEXT(bv)->SetLayout(bv, layout.second); + bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1); + UpdateLocal(bv, CURSOR_PAR, true); } } break; @@ -722,7 +730,11 @@ int InsetText::Latex(Buffer const * buf, ostream & os, bool, bool) const void InsetText::Validate(LaTeXFeatures & features) const { - par->validate(features); + LyXParagraph * p = par; + while(p) { + p->validate(features); + p = p->next; + } } @@ -736,10 +748,10 @@ int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const } -void InsetText::GetCursorPos(int & x, int & y) const +void InsetText::GetCursorPos(BufferView * bv, int & x, int & y) const { - x = cx(); - y = cy(); + x = cx(bv); + y = cy(bv); } @@ -759,7 +771,7 @@ void InsetText::ToggleInsetCursor(BufferView * bv) return; } - LyXFont font = text->GetFont(bv->buffer(), cpar(), cpos()); + LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv)); int asc = lyxfont::maxAscent(font); int desc = lyxfont::maxDescent(font); @@ -767,7 +779,7 @@ void InsetText::ToggleInsetCursor(BufferView * bv) if (cursor_visible) bv->hideLockedInsetCursor(); else - bv->showLockedInsetCursor(cx(), cy(), + bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc); cursor_visible = !cursor_visible; } @@ -780,13 +792,13 @@ void InsetText::ShowInsetCursor(BufferView * bv) return; } if (!cursor_visible) { - LyXFont font = text->GetFont(bv->buffer(), cpar(), cpos()); + LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv)); int asc = lyxfont::maxAscent(font); int desc = lyxfont::maxDescent(font); - bv->fitLockedInsetCursor(cx(), cy(), asc, desc); - bv->showLockedInsetCursor(cx(), cy(), asc, desc); + bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc); + bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc); cursor_visible = true; } } @@ -806,13 +818,13 @@ void InsetText::HideInsetCursor(BufferView * bv) UpdatableInset::RESULT InsetText::moveRight(BufferView * bv, bool activate_inset) { - if (!cpar()->next && (cpos() >= cpar()->Last())) + if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last())) return FINISHED; if (activate_inset && checkAndActivateInset(bv)) { return DISPATCHED; } - text->CursorRight(bv); -// real_current_font = current_font = GetFont(bv->buffer(), cpar(), cpos()); + TEXT(bv)->CursorRight(bv); +// real_current_font = current_font = GetFont(bv->buffer(), cpar(bv), cpos(bv)); return DISPATCHED_NOUPDATE; } @@ -820,9 +832,9 @@ InsetText::moveRight(BufferView * bv, bool activate_inset) UpdatableInset::RESULT InsetText::moveLeft(BufferView * bv, bool activate_inset) { - if (!cpar()->previous && (cpos() <= 0)) + if (!cpar(bv)->previous && (cpos(bv) <= 0)) return FINISHED; - text->CursorLeft(bv); + TEXT(bv)->CursorLeft(bv); if (activate_inset) if (checkAndActivateInset(bv, -1, -1)) return DISPATCHED; @@ -833,9 +845,9 @@ InsetText::moveLeft(BufferView * bv, bool activate_inset) UpdatableInset::RESULT InsetText::moveUp(BufferView * bv) { - if (!crow()->previous()) + if (!crow(bv)->previous()) return FINISHED; - text->CursorUp(bv); + TEXT(bv)->CursorUp(bv); return DISPATCHED_NOUPDATE; } @@ -843,24 +855,13 @@ InsetText::moveUp(BufferView * bv) UpdatableInset::RESULT InsetText::moveDown(BufferView * bv) { - if (!crow()->next()) + if (!crow(bv)->next()) return FINISHED; - text->CursorDown(bv); + TEXT(bv)->CursorDown(bv); return DISPATCHED_NOUPDATE; } -bool InsetText::Delete() -{ - if ((par->GetChar(cpos())==LyXParagraph::META_INSET) && - !par->GetInset(cpos())->Deletable()) { - return false; - } - par->Erase(cpos()); - return true; -} - - bool InsetText::InsertInset(BufferView * bv, Inset * inset) { if (the_locking_inset) { @@ -875,10 +876,10 @@ bool InsetText::InsertInset(BufferView * bv, Inset * inset) UpdatableInset * i = static_cast(inset); i->setOwner(static_cast(this)); } - par->InsertChar(cpos(), LyXParagraph::META_INSET); - par->InsertInset(cpos(), inset); - text->selection = 0; - UpdateLocal(bv, true, true); + cpar(bv)->InsertChar(cpos(bv), LyXParagraph::META_INSET); + cpar(bv)->InsertInset(cpos(bv), inset); + TEXT(bv)->selection = 0; + UpdateLocal(bv, CURSOR_PAR, true); static_cast(inset)->Edit(bv, 0, 0, 0); return true; } @@ -902,21 +903,17 @@ UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c) void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall) { - text->SetFont(bv, font, toggleall); + TEXT(bv)->SetFont(bv, font, toggleall); } -void InsetText::UpdateLocal(BufferView * bv, bool what, bool mark_dirty) +void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty) { - if (what) { - text->FullRebreak(bv); - } + need_update = what; bv->updateInset(this, mark_dirty); -// if (flag) -// resetPos(bv->painter()); - if (old_par != cpar()) { - bv->owner()->getToolbar()->combox->select(cpar()->GetLayout()+1); - old_par = cpar(); + if (old_par != cpar(bv)) { + bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1); + old_par = cpar(bv); } } @@ -924,20 +921,20 @@ void InsetText::UpdateLocal(BufferView * bv, bool what, bool mark_dirty) bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y, int button) { - if (par->GetChar(cpos()) == LyXParagraph::META_INSET) { + if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) { UpdatableInset * inset = - static_cast(par->GetInset(cpos())); - LyXFont font = text->GetFont(bv->buffer(), cpar(), cpos()); + static_cast(cpar(bv)->GetInset(cpos(bv))); + LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv)); if (x < 0) x = inset->width(bv->painter(), font); if (y < 0) y = inset->descent(bv->painter(), font); - inset_x = cx() - top_x + drawTextXOffset; - inset_y = cy() + drawTextYOffset; + inset_x = cx(bv) - top_x + drawTextXOffset; + inset_y = cy(bv) + drawTextYOffset; inset->Edit(bv, x - inset_x, y - inset_y, button); if (!the_locking_inset) return false; - UpdateLocal(bv, true, false); + UpdateLocal(bv, CURSOR_PAR, false); return true; } return false; @@ -970,62 +967,74 @@ void InsetText::SetParagraphData(LyXParagraph *p) np->next = p->Clone(); np->next->previous = np; np = np->next; + np->SetInsetOwner(this); } - init_inset = true; + need_update = INIT; } void InsetText::SetAutoBreakRows(bool flag) { if (flag != autoBreakRows) { autoBreakRows = flag; - init_inset = true; + need_update = FULL; } } void InsetText::SetDrawLockedFrame(bool flag) { - if (flag != drawLockedFrame) { + if (flag != drawLockedFrame) drawLockedFrame = flag; - init_inset = true; - } } void InsetText::SetFrameColor(LColor::color col) { - if (frame_color != col) { + if (frame_color != col) frame_color = col; - init_inset = true; - } } -LyXFont InsetText::GetDrawFont(Buffer const * buf, LyXParagraph * par, int pos) const +LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const { - return text->GetFont(buf, par, pos); + return TEXT(bv)->GetFont(bv->buffer(), p, pos); } -int InsetText::cx() const +int InsetText::cx(BufferView * bv) const { - return text->cursor.x() + top_x + 1; + return TEXT(bv)->cursor.x() + top_x + 1; } -int InsetText::cy() const +int InsetText::cy(BufferView * bv) const { long int y_dummy = 0; - Row * tmprow = text->GetRowNearY(y_dummy); - return text->cursor.y() - tmprow->baseline(); + Row * tmprow = TEXT(bv)->GetRowNearY(y_dummy); + return TEXT(bv)->cursor.y() - tmprow->baseline(); +} + +int InsetText::cpos(BufferView * bv) const +{ + return TEXT(bv)->cursor.pos(); +} + +LyXParagraph * InsetText::cpar(BufferView * bv) const +{ + return TEXT(bv)->cursor.par(); } -int InsetText::cpos() const +Row * InsetText::crow(BufferView * bv) const { - return text->cursor.pos(); + return TEXT(bv)->cursor.row(); } -LyXParagraph * InsetText::cpar() const +LyXText * InsetText::getLyXText(BufferView * bv) const { - return text->cursor.par(); + if (cache.find(bv) != cache.end()) + return cache[bv]; + LyXText *lt = new LyXText(const_cast(this)); + lt->init(bv); + cache[bv] = lt; + return lt; } -Row * InsetText::crow() const +void InsetText::deleteLyXText(BufferView * bv) { - return text->cursor.row(); + cache.erase(bv); } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 40193fa3c3..b6a45ba050 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -29,6 +29,7 @@ class LyXCursor; class LyXParagraph; class LColor; class LyXText; +class LyXScreen; /** * A text inset is like a TeX box to write full text @@ -39,6 +40,13 @@ public: /// enum { TEXT_TO_INSET_OFFSET = 2 }; /// + enum UpdateCodes { + NONE = 0, + INIT, + FULL, + CURSOR_PAR + }; + /// explicit InsetText(); /// @@ -62,14 +70,18 @@ public: /// int width(Painter &, LyXFont const & f) const; /// - void draw(Painter & pain, LyXFont const &, int , float &) const; + void draw(BufferView *, LyXFont const &, int , float &) const; /// - void update(BufferView *, LyXFont const &) const; + void update(BufferView *, LyXFont const &, bool =false); /// char const * EditMessage() const; /// void Edit(BufferView *, int, int, unsigned int); /// + bool IsTextInset() const { return true; } + /// + bool doClearArea() const { return !locked; } + /// void InsetUnlock(BufferView *); /// bool LockInsetInInset(BufferView *, UpdatableInset *); @@ -100,7 +112,7 @@ public: /// Inset::Code LyxCode() const { return Inset::TEXT_CODE; } /// - void GetCursorPos(int & x, int & y) const; + void GetCursorPos(BufferView *, int & x, int & y) const; /// int InsetInInsetY(); /// @@ -124,21 +136,21 @@ public: /// void SetFrameColor(LColor::color); /// - LyXFont GetDrawFont(Buffer const *, LyXParagraph *, int pos) const; + LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const; /// + LyXText * getLyXText(BufferView *) const; + void deleteLyXText(BufferView *); + LyXParagraph * par; - /// protected: /// - void UpdateLocal(BufferView *, bool what, bool mark_dirty); + void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty); /// void WriteParagraphData(Buffer const *, std::ostream &) const; /// virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const; - LyXText * text; - /// mutable int drawTextXOffset; mutable int drawTextYOffset; /// @@ -148,6 +160,10 @@ protected: LColor::color frame_color; private: + /// + typedef std::map Cache; + /// + typedef Cache::value_type value_type; /// int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const; /// @@ -163,24 +179,27 @@ private: /// UpdatableInset::RESULT moveDown(BufferView *); /// - bool Delete(); - /// void SetCharFont(Buffer const *, int pos, LyXFont const & font); /// string getText(int); /// bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0, int button = 0); - int cx() const; - int cy() const; - int cpos() const; - LyXParagraph * cpar() const; - Row * crow() const; + /// + int cx(BufferView *) const; + int cy(BufferView *) const; + int cpos(BufferView *) const; + LyXParagraph * cpar(BufferView *) const; + Row * crow(BufferView *) const; /* Private structures and variables */ /// bool locked; /// + int insetAscent; + int insetDescent; + int insetWidth; + /// int inset_pos; /// mutable int inset_x; @@ -193,10 +212,12 @@ private: /// mutable float xpos; /// - mutable bool init_inset; + mutable UpdateCodes need_update; /// UpdatableInset * the_locking_inset; /// LyXParagraph * old_par; + /// The cache. + mutable Cache cache; }; #endif diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index a4fe8ad2b9..20117dae39 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -23,9 +23,9 @@ #include "lyxfont.h" #include "lyxlex.h" -class Painter; class BufferView; class Buffer; +class Painter; struct LaTeXFeatures; @@ -115,10 +115,11 @@ public: /// virtual int width(Painter &, LyXFont const &) const = 0; /// - virtual void draw(Painter &, LyXFont const &, + virtual void draw(BufferView *, LyXFont const &, int baseline, float & x) const = 0; /// update the inset representation - virtual void update(BufferView *, LyXFont const &) const {} + virtual void update(BufferView *, LyXFont const &, bool =false) + {} /// virtual LyXFont ConvertFont(LyXFont font); /// what appears in the minibuffer when opening @@ -134,7 +135,9 @@ public: /// This is caleld when the user moves the mouse inside an inset virtual void InsetMotionNotify(BufferView *, int , int , int) {} /// - bool IsTextInset() const; + virtual bool IsTextInset() const { return false; } + /// + virtual bool doClearArea() const { return true; } /// virtual bool AutoDelete() const; /// @@ -272,7 +275,7 @@ public: /// virtual void HideInsetCursor(BufferView *); /// - virtual void GetCursorPos(int &, int &) const {} + virtual void GetCursorPos(BufferView *, int &, int &) const {} /// virtual void InsetButtonPress(BufferView *, int x, int y, int button); /// @@ -287,7 +290,7 @@ public: /// virtual void Edit(BufferView *, int x, int y, unsigned int button); /// - virtual void draw(Painter &, LyXFont const &, + virtual void draw(BufferView *, LyXFont const &, int baseline, float & x) const; /// virtual void SetFont(BufferView *, LyXFont const &, diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 030c0d3a87..24aaf44d0c 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -542,7 +542,7 @@ string LyXFunc::Dispatch(int ac, int slx, sly; UpdatableInset * inset = owner->view()->the_locking_inset; - inset->GetCursorPos(slx, sly); + inset->GetCursorPos(owner->view(), slx, sly); owner->view()->unlockInset(inset); owner->view()->menuUndo(); if (owner->view()->text->cursor.par()-> @@ -561,7 +561,7 @@ string LyXFunc::Dispatch(int ac, int slx, sly; UpdatableInset * inset = owner->view()-> the_locking_inset; - inset->GetCursorPos(slx, sly); + inset->GetCursorPos(owner->view(), slx, sly); owner->view()->unlockInset(inset); owner->view()->menuRedo(); inset = static_cast( diff --git a/src/lyxtext.h b/src/lyxtext.h index eb91ea29cb..f79f60b073 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -21,12 +21,12 @@ #include "lyxcursor.h" #include "lyxparagraph.h" #include "layout.h" -#include "insets/insettext.h" class Buffer; class BufferParams; class Row; class BufferView; +class InsetText; /** @@ -63,7 +63,7 @@ public: mutable int number_of_rows; /// mutable long height; - mutable long width; + mutable int width; /// the current font settings mutable LyXFont current_font; /// the current font @@ -424,8 +424,8 @@ public: /* for the greater insets */ - /// returns 0 if inset wasn't found - int UpdateInset(BufferView *, Inset * inset); + /// returns false if inset wasn't found + bool UpdateInset(BufferView *, Inset *); /// void CheckParagraph(BufferView *, LyXParagraph * par, LyXParagraph::size_type pos); diff --git a/src/text.C b/src/text.C index bfb9ce4c63..4a87628de4 100644 --- a/src/text.C +++ b/src/text.C @@ -22,6 +22,7 @@ #include "lyxtext.h" #include "support/textutils.h" #include "insets/insetbib.h" +#include "insets/insettext.h" #include "lyx_gui_misc.h" #include "gettext.h" #include "bufferparams.h" @@ -566,8 +567,7 @@ void LyXText::draw(BufferView * bview, Row const * row, } else if (c == LyXParagraph::META_INSET) { Inset const * tmpinset = row->par()->GetInset(pos); if (tmpinset) { - tmpinset->draw(bview->painter(), font, - offset + row->baseline(), x); + tmpinset->draw(bview, font, offset+row->baseline(), x); } ++vpos; @@ -3799,7 +3799,13 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, else ww = bview->workWidth(); - if (bv_owner) + bool clear_area = true; + + if ((last == row_ptr->pos()) && + row_ptr->par()->GetInset(row_ptr->pos())) { + clear_area = row_ptr->par()->GetInset(row_ptr->pos())->doClearArea(); + } + if (bv_owner && clear_area) pain.fillRectangle(x_offset, y_offset, ww, row_ptr->height()); if (selection) { @@ -4314,8 +4320,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, else tmpx = x - lyxfont::width(layout.labelsep, font) - row_ptr->par()->bibkey->width(bview->painter(), font); - row_ptr->par()->bibkey->draw(pain, - font, + row_ptr->par()->bibkey->draw(bview, font, y_offset + row_ptr->baseline(), tmpx); } diff --git a/src/text2.C b/src/text2.C index 778e1dd368..43cf4ba959 100644 --- a/src/text2.C +++ b/src/text2.C @@ -22,6 +22,7 @@ #include "insets/inseterror.h" #include "insets/insetbib.h" #include "insets/insetspecialchar.h" +#include "insets/insettext.h" #include "layout.h" #include "LyXView.h" #include "support/textutils.h" @@ -1048,6 +1049,10 @@ void LyXText::RedoParagraphs(BufferView * bview, LyXCursor const & cur, bool LyXText::FullRebreak(BufferView * bview) { + if (!firstrow) { + init(bview); + return true; + } if (need_break_row) { BreakAgain(bview, need_break_row); need_break_row = 0; @@ -2649,14 +2654,14 @@ void LyXText::CheckParagraph(BufferView * bview, LyXParagraph * par, } -// returns 0 if inset wasn't found -int LyXText::UpdateInset(BufferView * bview, Inset * inset) +// returns false if inset wasn't found +bool LyXText::UpdateInset(BufferView * bview, Inset * inset) { // first check the current paragraph int pos = cursor.par()->GetPositionOfInset(inset); if (pos != -1){ CheckParagraph(bview, cursor.par(), pos); - return 1; + return true; } // check every paragraph @@ -2668,13 +2673,13 @@ int LyXText::UpdateInset(BufferView * bview, Inset * inset) pos = par->GetPositionOfInset(inset); if (pos != -1){ CheckParagraph(bview, par, pos); - return 1; + return true; } } par = par->Next(); } while (par); - return 0; + return false; } -- 2.39.2