From 8fd0a9f2d7ec245952903a359b1b2910e7d6ebd1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Thu, 19 Oct 2000 09:11:39 +0000 Subject: [PATCH] Finally text-insets should draw correctly (also selections), some small fixes. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1140 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 24 +++++++++++++++ src/insets/insettext.C | 67 +++++++++++++++++++++++++----------------- src/lyxfunc.C | 2 ++ src/lyxtext.h | 3 +- src/screen.C | 43 ++++++++++++--------------- src/support/lyxlib.h | 1 + src/tabular.C | 4 +-- src/text2.C | 2 ++ 8 files changed, 91 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index e3d13e736a..e4bdcde29f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2000-10-19 Juergen Vigna + + * src/lyxfunc.C (MenuNew): small fix (form John) + + * src/screen.C (Update): removed unneeded code. + + * src/tabular.C (Ascii): refixed int != uint bug! + + * src/support/lyxlib.h: added sys/types.h include for now permits + compiling, but I don't like this! + +2000-10-18 Juergen Vigna + + * src/text2.C (ClearSelection): if we clear the selection we need + more refresh so set the status aprpriate + + * src/insets/insettext.C (draw): hopefully finally fixed draw + problems! + +2000-10-12 Juergen Vigna + + * src/insets/insettext.C (draw): another small fix and make a block + so that variables are localized. + 2000-10-18 Angus Leeming * src/support/lstrings.C (lowercase, uppercase): use explicit casts to remove compiler warnings. diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 21285dbe8a..e4d88f5b06 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -313,37 +313,43 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, return; } x += TEXT_TO_INSET_OFFSET; - int y = 0; - Row * row = TEXT(bv)->GetRowNearY(y); - int y_offset = baseline - row->ascent_of_text(); - int ph = pain.paperHeight(); - y += y_offset; - while ((row != 0) && ((y+row->height()) <= 0)) { - y += row->height(); - row = row->next(); - } - y -= y_offset; - TEXT(bv)->first = y; - if (cleared || !locked || (need_update == FULL)) { - int first = y; - y = 0; - while ((row != 0) && (y < ph)) { - TEXT(bv)->GetVisibleRow(bv, y+first+y_offset, int(x), row, - y+first, cleared); + { + int y = 0; + Row * row = TEXT(bv)->GetRowNearY(y); + int y_offset = baseline - row->ascent_of_text(); + int ph = pain.paperHeight(); + int first = 0; + y = y_offset; + while ((row != 0) && ((y+row->height()) <= 0)) { y += row->height(); + first += row->height(); row = row->next(); } - } else if (need_update == SELECTION) { - bv->screen()->ToggleToggle(TEXT(bv), y+y_offset, int(x)); - } else { - locked = false; - if (need_update == CURSOR) { - bv->screen()->ToggleSelection(TEXT(bv), true, y+y_offset, int(x)); - TEXT(bv)->ClearSelection(); - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + if (y_offset < 0) + y_offset = y; + TEXT(bv)->first = first; + if (cleared || !locked || (need_update == FULL)) { + int yf = y_offset; + y = 0; + while ((row != 0) && (yf < ph)) { + TEXT(bv)->GetVisibleRow(bv, y+y_offset, int(x), row, + y+first, cleared); + y += row->height(); + yf += row->height(); + row = row->next(); + } + } else if (need_update == SELECTION) { + bv->screen()->ToggleToggle(TEXT(bv), y_offset, int(x)); + } else { + locked = false; + if (need_update == CURSOR) { + bv->screen()->ToggleSelection(TEXT(bv), true, y_offset,int(x)); + TEXT(bv)->ClearSelection(); + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + } + bv->screen()->Update(TEXT(bv), y_offset, int(x)); + locked = true; } - bv->screen()->Update(TEXT(bv), y, int(x)); - locked = true; } TEXT(bv)->refresh_y = 0; TEXT(bv)->status = LyXText::UNCHANGED; @@ -813,6 +819,7 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->FinishUndo(); result= moveLeft(bv); TEXT(bv)->ClearSelection(); + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; UpdateLocal(bv, CURSOR, false); break; case LFUN_DOWNSEL: @@ -825,6 +832,7 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->FinishUndo(); result = moveDown(bv); TEXT(bv)->ClearSelection(); + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; UpdateLocal(bv, CURSOR, false); break; case LFUN_UPSEL: @@ -837,15 +845,20 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->FinishUndo(); result = moveUp(bv); TEXT(bv)->ClearSelection(); + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; UpdateLocal(bv, CURSOR, false); break; case LFUN_HOME: bv->text->FinishUndo(); TEXT(bv)->CursorHome(bv); + TEXT(bv)->ClearSelection(); + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; UpdateLocal(bv, CURSOR, false); break; case LFUN_END: TEXT(bv)->CursorEnd(bv); + TEXT(bv)->ClearSelection(); + TEXT(bv)->sel_cursor = TEXT(bv)->cursor; UpdateLocal(bv, CURSOR, false); break; case LFUN_BACKSPACE: diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 2cc20d2d7a..066f0ce726 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -3182,6 +3182,8 @@ void LyXFunc::MenuNew(bool fromTemplate) fname = fileDlg.Select(_("Choose template"), lyxrc.template_path, "*.lyx"); + if (fname.empty()) + return; templname = fname; AllowInput(owner->view()); } diff --git a/src/lyxtext.h b/src/lyxtext.h index 8bf6cceb93..7a7d551ced 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -66,7 +66,8 @@ public: /// the current font mutable LyXFont real_current_font; /// first visible pixel-row is set from LyXScreen!!! - unsigned int first; + // unsigned is wrong here for text-insets! + int first; /// BufferView * bv_owner; /// diff --git a/src/screen.C b/src/screen.C index db8701de19..d232e94c28 100644 --- a/src/screen.C +++ b/src/screen.C @@ -148,7 +148,7 @@ void LyXScreen::Draw(LyXText * text, unsigned int y) { if (cursor_visible) HideCursor(); - unsigned int old_first = text->first; + int old_first = text->first; text->first = y; // is any optimiziation possible? @@ -221,7 +221,7 @@ bool LyXScreen::FitManualCursor(LyXText * text, { int newtop = text->first; - if (y + desc - text->first >= owner.height()) + if (y + desc - text->first >= (int)owner.height()) newtop = y - 3 * owner.height() / 4; // the scroll region must be so big!! else if (y - asc < (int)text->first && text->first > 0) { @@ -242,10 +242,10 @@ bool LyXScreen::FitManualCursor(LyXText * text, void LyXScreen::ShowManualCursor(LyXText const * text, int x, int y, int asc, int desc, Cursor_Shape shape) { - unsigned int y1 = max(y - text->first - asc, 0U); + unsigned int y1 = max(y - text->first - asc, 0); typedef unsigned int uint; - unsigned int y2 = min(y - text->first + desc, owner.height()); + unsigned int y2 = min(y - text->first + desc, (int)owner.height()); // Secure against very strange situations y2 = max(y2, y1); @@ -360,8 +360,9 @@ unsigned int LyXScreen::TopCursorVisible(LyXText const * text) else newtop = text->cursor.y() - 3 * owner.height() / 4; /* the scroll region must be so big!! */ - } else if (text->cursor.y() - text->cursor.row()->baseline() < text->first - && text->first > 0) { + } else if ((int)(text->cursor.y() - text->cursor.row()->baseline()) < + text->first && text->first > 0) + { if (text->cursor.row()->height() < owner.height() && text->cursor.row()->height() > owner.height() / 4) newtop = text->cursor.y() - text->cursor.row()->baseline(); @@ -382,7 +383,7 @@ unsigned int LyXScreen::TopCursorVisible(LyXText const * text) bool LyXScreen::FitCursor(LyXText * text) { // Is a change necessary? - unsigned int newtop = TopCursorVisible(text); + int newtop = TopCursorVisible(text); bool result = (newtop != text->first); if (result) Draw(text, newtop); @@ -396,19 +397,10 @@ void LyXScreen::Update(LyXText * text, int y_offset, int x_offset) case LyXText::NEED_MORE_REFRESH: { int y = max(int(text->refresh_y - text->first), 0); - int height; - if (text->inset_owner) - height = text->inset_owner->ascent(owner.owner(), - text->real_current_font) - + text->inset_owner->descent(owner.owner(), - text->real_current_font); - else - height = owner.height(); DrawFromTo(text, y, owner.height(), y_offset, x_offset); text->refresh_y = 0; text->status = LyXText::UNCHANGED; - expose(0, y, - owner.workWidth(), owner.height() - y); + expose(0, y, owner.workWidth(), owner.height() - y); } break; case LyXText::NEED_VERY_LITTLE_REFRESH: @@ -435,13 +427,14 @@ void LyXScreen::ToggleSelection(LyXText * text, bool kill_selection, // only if there is a selection if (!text->selection) return; - int bottom = min(max(text->sel_end_cursor.y() + int bottom = min(max((int)(text->sel_end_cursor.y() - text->sel_end_cursor.row()->baseline() - + text->sel_end_cursor.row()->height(), text->first), - text->first + owner.height()); - int top = min(max(text->sel_start_cursor.y() - - text->sel_start_cursor.row()->baseline(), text->first), - text->first + owner.height()); + + text->sel_end_cursor.row()->height()), text->first), + (int)(text->first + owner.height())); + int top = min(max((int)(text->sel_start_cursor.y() - + text->sel_start_cursor.row()->baseline()), + text->first), + (int)(text->first + owner.height())); if (kill_selection) text->selection = 0; @@ -467,8 +460,8 @@ void LyXScreen::ToggleToggle(LyXText * text, int y_offset, int x_offset) typedef unsigned int uint; - bottom = min(max(uint(bottom), text->first), text->first + owner.height()); - top = min(max(uint(top), text->first), text->first + owner.height()); + bottom = min(max(bottom, text->first), (int)(text->first + owner.height())); + top = min(max(top, text->first), (int)(text->first + owner.height())); DrawFromTo(text, top - text->first, bottom - text->first, y_offset, x_offset); diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index a159ee30d0..4f955a4486 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -13,6 +13,7 @@ #define LYX_LIB_H #include "LString.h" +#include // Where can I put this? I found the occurence of the same code // three/four times. Don't you think it better to use a macro definition diff --git a/src/tabular.C b/src/tabular.C index 7cc4caf165..2b456f217f 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -2425,11 +2425,11 @@ int LyXTabular::Ascii(Buffer const * buf, ostream & os) const continue; ostringstream sstr; GetCellInset(cell)->Ascii(buf, sstr, 0); - string::size_type len = sstr.str().length(); + int len = int(sstr.str().length()); int const n = cells_in_multicolumn(cell); for (int k = j; (len > 0) && (k < (j + n - 1)); ++k) len -= clen[k]; - if (len > clen[j + n - 1]) + if (len > int(clen[j + n - 1])) clen[j + n - 1] = len; } } diff --git a/src/text2.C b/src/text2.C index 3071fa4997..d7047c5c30 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1203,6 +1203,8 @@ string const LyXText::selectionAsString(Buffer const * buffer) const void LyXText::ClearSelection() const { + if (selection) + status = LyXText::NEED_MORE_REFRESH; selection = false; mark_set = false; } -- 2.39.2