From e80ad470cbc712632e53f9b2b240ce5d8dc06459 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Mon, 26 Jun 2000 15:10:49 +0000 Subject: [PATCH] Fixed update of insets in insets. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@835 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 9 ++ forms/cite.fd | 170 +++++++++++++++++----------------- src/insets/inset.C | 2 +- src/insets/insetcite.C | 7 +- src/insets/insetcollapsable.C | 11 ++- src/insets/insetcollapsable.h | 2 + src/insets/insetfoot.h | 1 - src/insets/insettabular.C | 2 +- src/insets/insettext.C | 50 ++++++---- src/insets/insettext.h | 3 + src/insets/lyxinset.h | 2 +- src/lyxrow.C | 14 ++- src/lyxrow.h | 6 ++ src/lyxtext.h | 2 +- src/text.C | 13 ++- src/text2.C | 2 +- 16 files changed, 180 insertions(+), 116 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8910e6d1fa..49ef11e540 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2000-06-26 Juergen Vigna + + * src/lyxrow.C (width): added this functions and variable. + + * src/insets/insetcite.C (create_form_citation_form): some Gravity + changes. + + * src/text.C (SetHeightOfRow): fixed calcualting of width. + 2000-06-26 Jean-Marc Lasgouttes * src/BufferView.h: add a magic "friend" declaration to please diff --git a/forms/cite.fd b/forms/cite.fd index 74cfed86de..a5543f2096 100644 --- a/forms/cite.fd +++ b/forms/cite.fd @@ -78,11 +78,29 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: @4-> shortcut: -resize: FL_RESIZE_NONE +resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity -name: addBtn +name: bibBrsr callback: citation_cb -argument: InsetCitation::ADD +argument: InsetCitation::BIBBRSR + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 200 40 40 40 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: Button +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_South FL_South +name: bibBrsr +callback: citation_cb +argument: InsetCitation::BIBBRSR -------------------- class: FL_BUTTON @@ -96,11 +114,29 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: @9+ shortcut: -resize: FL_RESIZE_NONE +resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity -name: delBtn +name: bibBrsr +callback: citation_cb +argument: InsetCitation::BIBBRSR + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 200 90 40 40 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: Button +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_South FL_South +name: bibBrsr callback: citation_cb -argument: InsetCitation::DELETE +argument: InsetCitation::BIBBRSR -------------------- class: FL_BUTTON @@ -114,11 +150,29 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: @8-> shortcut: -resize: FL_RESIZE_NONE +resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity -name: upBtn +name: bibBrsr callback: citation_cb -argument: InsetCitation::UP +argument: InsetCitation::BIBBRSR + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 200 140 40 40 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: Button +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_South FL_South +name: bibBrsr +callback: citation_cb +argument: InsetCitation::BIBBRSR -------------------- class: FL_BUTTON @@ -132,11 +186,29 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: @2-> shortcut: -resize: FL_RESIZE_NONE +resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity -name: downBtn +name: bibBrsr +callback: citation_cb +argument: InsetCitation::BIBBRSR + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 200 190 40 40 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: Button +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_South FL_South +name: bibBrsr callback: citation_cb -argument: InsetCitation::DOWN +argument: InsetCitation::BIBBRSR -------------------- class: FL_BROWSER @@ -174,77 +246,5 @@ name: style callback: argument: --------------------- -class: FL_INPUT -type: NORMAL_INPUT -box: 100 620 250 30 -boxtype: FL_DOWN_BOX -colors: FL_COL1 FL_MCOL -alignment: FL_ALIGN_LEFT -style: FL_NORMAL_STYLE -size: FL_DEFAULT_SIZE -lcol: FL_BLACK -label: Text before -shortcut: -resize: FL_RESIZE_X -gravity: FL_NoGravity FL_NoGravity -name: textBefore -callback: -argument: - --------------------- -class: FL_INPUT -type: NORMAL_INPUT -box: 100 660 250 30 -boxtype: FL_DOWN_BOX -colors: FL_COL1 FL_MCOL -alignment: FL_ALIGN_LEFT -style: FL_NORMAL_STYLE -size: FL_DEFAULT_SIZE -lcol: FL_BLACK -label: Text after -shortcut: -resize: FL_RESIZE_X -gravity: FL_NoGravity FL_NoGravity -name: textAftr -callback: -argument: - --------------------- -class: FL_BUTTON -type: RETURN_BUTTON -box: 190 730 110 40 -boxtype: FL_UP_BOX -colors: FL_COL1 FL_COL1 -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_DEFAULT_SIZE -lcol: FL_BLACK -label: OK -shortcut: ^M -resize: FL_RESIZE_ALL -gravity: FL_SouthEast FL_SouthEast -name: ok -callback: citation_cb -argument: InsetCitation::OK - --------------------- -class: FL_BUTTON -type: NORMAL_BUTTON -box: 310 730 110 40 -boxtype: FL_UP_BOX -colors: FL_COL1 FL_COL1 -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_DEFAULT_SIZE -lcol: FL_BLACK -label: Cancel -shortcut: ^[ -resize: FL_RESIZE_ALL -gravity: FL_SouthEast FL_SouthEast -name: cancel -callback: citation_cb -argument: InsetCitation::CANCEL - ============================== -create_the_forms +-------------------- diff --git a/src/insets/inset.C b/src/insets/inset.C index 35052a6dda..775921433e 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -137,7 +137,7 @@ void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int) void UpdatableInset::draw(BufferView *, LyXFont const &, - int /* baseline */, float & x) const + int /* baseline */, float & x, bool/*cleared*/) const { if (scx) x += float(scx); // ATTENTION: don't do the following here!!! diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index 7117bd9063..579f55c1e9 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -66,21 +66,25 @@ FD_citation_form *create_form_citation_form(void) fdui->addBtn = obj = fl_add_button(FL_NORMAL_BUTTON,200,40,40,40,"@4->"); + fl_set_object_gravity(obj, FL_South, FL_South); fl_set_object_resize(obj, FL_RESIZE_NONE); fl_set_object_callback(obj,citation_cb,InsetCitation::ADD); fdui->delBtn = obj = fl_add_button(FL_NORMAL_BUTTON,200,90,40,40,"@9+"); + fl_set_object_gravity(obj, FL_South, FL_South); fl_set_object_resize(obj, FL_RESIZE_NONE); fl_set_object_callback(obj,citation_cb,InsetCitation::DELETE); fdui->upBtn = obj = fl_add_button(FL_NORMAL_BUTTON,200,140,40,40,"@8->"); + fl_set_object_gravity(obj, FL_South, FL_South); fl_set_object_resize(obj, FL_RESIZE_NONE); fl_set_object_callback(obj,citation_cb,InsetCitation::UP); fdui->downBtn = obj = fl_add_button(FL_NORMAL_BUTTON,200,190,40,40,"@2->"); + fl_set_object_gravity(obj, FL_South, FL_South); fl_set_object_resize(obj, FL_RESIZE_NONE); fl_set_object_callback(obj,citation_cb,InsetCitation::DOWN); @@ -102,6 +106,7 @@ FD_citation_form *create_form_citation_form(void) fdui->textAftr = obj = fl_add_input(FL_NORMAL_INPUT,100,660,250,30,_("Text after")); + fl_set_object_gravity(obj, FL_SouthWest, FL_SouthEast); fl_set_object_resize(obj, FL_RESIZE_X); fdui->ok = obj = @@ -384,7 +389,7 @@ void InsetCitation::setSize( FD_citation_form * form, fl_set_form_size( form->form, 430, formHeight ); // No resizing is alowed in the y-direction - fl_set_form_minsize( form->form, 300, formHeight ); + fl_set_form_minsize( form->form, 430, formHeight ); fl_set_form_maxsize( form->form, 1000, formHeight ); int ypos = 0; diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 24457fba6d..4d1d4c3973 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -29,7 +29,7 @@ InsetCollapsable::InsetCollapsable() : InsetText() autocollapse = true; autoBreakRows = true; framecolor = LColor::footnoteframe; - widthOffset = 6; // 2+2 (behind+back), 1+1 (frame) + widthOffset = 2 * TEXT_TO_INSET_OFFSET + 2; // 1+1 (frame) button_length = button_top_y = button_bottom_y = 0; setInsetName("Collapsable"); } @@ -153,11 +153,10 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, draw_collapsed(pain, f, baseline, x); x -= TEXT_TO_INSET_OFFSET; - int w = InsetText::width(pain, f) + 2 * TEXT_TO_INSET_OFFSET; + int w = InsetText::width(pain, f) + (2 * TEXT_TO_INSET_OFFSET); int h = ascent(pain,f) + descent(pain, f); int save_x = static_cast(x); x += TEXT_TO_INSET_OFFSET; - drawTextXOffset = int(x) - top_x; InsetText::draw(bv, f, baseline, x, cleared); pain.rectangle(save_x, baseline - ascent(pain, f), w, h, framecolor); } @@ -251,3 +250,9 @@ int InsetCollapsable::getMaxTextWidth(Painter & pain, return getMaxWidth(pain, inset) - width_collapsed(pain, labelfont) - widthOffset; } + +void InsetCollapsable::update(BufferView * bv, LyXFont const & font, bool dodraw) +{ + drawTextXOffset = width_collapsed(bv->painter(), font); + InsetText::update(bv, font, dodraw); +} diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 73bbc42d4e..a290e8e59c 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -53,6 +53,8 @@ public: /// void draw(BufferView *, const LyXFont &, int , float &, bool) const; /// + void update(BufferView *, LyXFont const &, bool =false); + /// void Edit(BufferView *, int, int, unsigned int); /// EDITABLE Editable() const; diff --git a/src/insets/insetfoot.h b/src/insets/insetfoot.h index a5404b4556..938226e015 100644 --- a/src/insets/insetfoot.h +++ b/src/insets/insetfoot.h @@ -46,7 +46,6 @@ public: bool InsertInsetAllowed(Inset * inset) const; /// LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const; - /// }; #endif diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 2acf665178..cbffdc4647 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -157,7 +157,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, int nx; float cx; - UpdatableInset::draw(bv,font,baseline,x); + UpdatableInset::draw(bv,font,baseline,x,cleared); if ((need_update == INIT)|| (top_x != int(x)) || (top_baseline != baseline)) { need_update = FULL; top_x = int(x); diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 44d5163933..427e4689f0 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -83,6 +83,7 @@ InsetText & InsetText::operator=(InsetText const & it) void InsetText::init(InsetText const * ins) { + top_y = last_width = last_height = 0; insetAscent = insetDescent = insetWidth = 0; the_locking_inset = 0; cursor_visible = false; @@ -216,11 +217,11 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, { Painter & pain = bv->painter(); - xpos = x; - UpdatableInset::draw(bv, f, baseline, x); - - if (!cleared && locked && ((need_update==FULL) || (top_x!=int(x)) || - (top_baseline!=baseline))) { + if (!cleared && ((need_update==FULL) || (top_x!=int(x)) || + (top_baseline!=baseline))) { +#if 0 + // && locked && ((need_update==FULL) || (top_x!=int(x)) || + // (top_baseline!=baseline))) { need_update = NONE; top_x = int(x); top_baseline = baseline; @@ -232,9 +233,24 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, width(pain, f), ascent(pain,f)+descent(pain, f), frame_color); return; +#else + pain.fillRectangle(top_x+drawTextXOffset, top_y, last_width, + last_height); + need_update = FULL; +#endif } + + if (!cleared && (need_update == NONE)) + return; + + xpos = x; + UpdatableInset::draw(bv, f, baseline, x, cleared); + top_baseline = baseline; top_x = int(x); + top_y = baseline - ascent(pain, f); + last_width = width(pain, f); + last_height = ascent(pain, f) + descent(pain, f); if (the_locking_inset && (cpos(bv) == inset_pos)) { inset_x = cx(bv) - top_x + drawTextXOffset; @@ -295,7 +311,8 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool dodraw) 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()), TEXT(bv)->width) + + insetWidth = max(textWidth(bv->painter()), + static_cast(TEXT(bv)->width)) + (2 * TEXT_TO_INSET_OFFSET); } @@ -336,12 +353,10 @@ void InsetText::InsetUnlock(BufferView * bv) the_locking_inset = 0; } HideInsetCursor(bv); - lyxerr[Debug::INSETS] << "InsetText::InsetUnlock(" << this << - ")" << endl; no_selection = false; locked = false; TEXT(bv)->selection = 0; - UpdateLocal(bv, FULL, false); + UpdateLocal(bv, CURSOR_PAR, false); bv->owner()->getToolbar()->combox->select(bv->text->cursor.par()->GetLayout()+1); } @@ -384,9 +399,11 @@ bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset, return false; if (the_locking_inset == inset) { the_locking_inset->InsetUnlock(bv); + TEXT(bv)->UpdateInset(bv, inset); the_locking_inset = 0; if (lr) moveRight(bv, false); + UpdateLocal(bv, FULL, false); return true; } return the_locking_inset->UnlockInsetInInset(bv, inset, lr); @@ -399,9 +416,8 @@ bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset) return false; if (the_locking_inset != inset) return the_locking_inset->UpdateInsetInInset(bv, inset); - lyxerr[Debug::INSETS] << "InsetText::UpdateInsetInInset(" << inset << - ")" << endl; - UpdateLocal(bv, FULL, false); +// UpdateLocal(bv, FULL, false); + TEXT(bv)->UpdateInset(bv, inset); if (cpos(bv) == inset_pos) { inset_x = cx(bv) - top_x + drawTextXOffset; inset_y = cy(bv) + drawTextYOffset; @@ -530,17 +546,13 @@ InsetText::LocalDispatch(BufferView * bv, if (result == DISPATCHED_NOUPDATE) return result; else if (result == DISPATCHED) { - the_locking_inset->ToggleInsetCursor(bv); - UpdateLocal(bv, FULL, false); - the_locking_inset->ToggleInsetCursor(bv); + UpdateLocal(bv, CURSOR_PAR, false); return result; } else if (result == FINISHED) { switch(action) { case -1: case LFUN_RIGHT: - moveRight(bv); -// TEXT(bv)->cursor.pos(inset_pos + 1); -// resetPos(bv->painter()); + moveRight(bv, false); break; case LFUN_DOWN: moveDown(bv); @@ -969,7 +981,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y, int InsetText::getMaxTextWidth(Painter & pain, UpdatableInset const * inset) const { - return getMaxWidth(pain, inset) - 4; // 2+2 width of eventual border + return getMaxWidth(pain, inset) - (2 * TEXT_TO_INSET_OFFSET); } void InsetText::SetParagraphData(LyXParagraph *p) diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 50cfd1044e..98c44b5147 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -203,6 +203,9 @@ private: int insetAscent; int insetDescent; int insetWidth; + mutable int last_width; + mutable int last_height; + mutable int top_y; /// int inset_pos; /// diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index 6f13fa4f83..2955938572 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -291,7 +291,7 @@ public: virtual void Edit(BufferView *, int x, int y, unsigned int button); /// virtual void draw(BufferView *, LyXFont const &, - int baseline, float & x) const; + int baseline, float & x, bool cleared) const; /// virtual void SetFont(BufferView *, LyXFont const &, bool toggleall = false); diff --git a/src/lyxrow.C b/src/lyxrow.C index 497748628f..f5b816e511 100644 --- a/src/lyxrow.C +++ b/src/lyxrow.C @@ -14,7 +14,7 @@ Row::Row() - : par_(0), pos_(0), fill_(0), height_(0), + : par_(0), pos_(0), fill_(0), height_(0), width_(0), ascent_of_text_(0), baseline_(0), next_(0), previous_(0) {} @@ -73,6 +73,18 @@ unsigned short Row::height() const } +void Row::width(unsigned int w) +{ + width_ = w; +} + + +unsigned int Row::width() const +{ + return width_; +} + + void Row::ascent_of_text(unsigned short a) { ascent_of_text_ = a; diff --git a/src/lyxrow.h b/src/lyxrow.h index e480cfaf18..9da3170342 100644 --- a/src/lyxrow.h +++ b/src/lyxrow.h @@ -38,6 +38,10 @@ public: /// unsigned short height() const; /// + void width(unsigned int w); + /// + unsigned int width() const; + /// void ascent_of_text(unsigned short a); /// unsigned short ascent_of_text() const; @@ -64,6 +68,8 @@ private: /// unsigned short height_; /// + unsigned int width_; + /// unsigned short ascent_of_text_; /// unsigned int baseline_; diff --git a/src/lyxtext.h b/src/lyxtext.h index 938752c3e0..87ef88642f 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -63,7 +63,7 @@ public: mutable int number_of_rows; /// mutable long height; - mutable int width; + mutable unsigned int width; /// the current font settings mutable LyXFont current_font; /// the current font diff --git a/src/text.C b/src/text.C index d77d5f4644..00250ee27a 100644 --- a/src/text.C +++ b/src/text.C @@ -1675,7 +1675,18 @@ void LyXText::SetHeightOfRow(BufferView * bview, Row * row_ptr) const row_ptr->baseline(maxasc + labeladdon); height += row_ptr->height(); - width = maxwidth; + float x, dummy; + PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy); + row_ptr->width(maxwidth+x); + if (inset_owner) { + Row * r = firstrow; + width = 0; + while(r) { + if (r->width() > width) + width = r->width(); + r = r->next(); + } + } } diff --git a/src/text2.C b/src/text2.C index ab6d84ba49..ecf2b2eb2b 100644 --- a/src/text2.C +++ b/src/text2.C @@ -70,7 +70,7 @@ void LyXText::init() number_of_rows = 0; refresh_y = 0; height = 0; - width = -1; + width = 0; first = 0; status = LyXText::UNCHANGED; // set cursor at the very top position -- 2.39.5