X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/566a4f58b7d73b8a06ef62bf1fd58f9d6402aaac..f7770f09be0346f60e14f6dda75ded26927f07d3:/samples/richedit/wxllist.cpp diff --git a/samples/richedit/wxllist.cpp b/samples/richedit/wxllist.cpp index 6548ea34eb..ca7b2b7587 100644 --- a/samples/richedit/wxllist.cpp +++ b/samples/richedit/wxllist.cpp @@ -644,6 +644,8 @@ wxLayoutLine::wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist) } m_StyleInfo = llist->GetDefaultStyleInfo(); + + llist->IncNumLines(); } wxLayoutLine::~wxLayoutLine() @@ -1004,8 +1006,12 @@ wxLayoutLine::DeleteWord(CoordType xpos) wxLayoutLine * wxLayoutLine::DeleteLine(bool update, wxLayoutList *llist) { - if(m_Next) m_Next->m_Previous = m_Previous; - if(m_Previous) m_Previous->m_Next = m_Next; + // maintain linked list integrity + if(m_Next) + m_Next->m_Previous = m_Previous; + if(m_Previous) + m_Previous->m_Next = m_Next; + if(update) { m_Next->MoveLines(-1); @@ -1021,6 +1027,9 @@ wxLayoutLine::DeleteLine(bool update, wxLayoutList *llist) } wxLayoutLine *next = m_Next; delete this; + + llist->DecNumLines(); + return next; } @@ -1071,6 +1080,7 @@ wxLayoutLine::Layout(wxDC &dc, wxLayoutList *llist, wxPoint *cursorPos, wxPoint *cursorSize, + wxLayoutStyleInfo *cursorStyle, int cx, bool suppressSIupdate) { @@ -1134,6 +1144,8 @@ wxLayoutLine::Layout(wxDC &dc, str = WXLO_CURSORCHAR; dc.GetTextExtent(str, &width, &height, &descent); + if(cursorStyle) // set style info + *cursorStyle = llist->GetStyleInfo(); if ( cursorSize ) { // Just in case some joker inserted an empty string object: @@ -1144,14 +1156,15 @@ wxLayoutLine::Layout(wxDC &dc, cursorSize->x = width; cursorSize->y = height; } - + cursorFound = true; // no more checks } else { // on some other object CoordType top, bottom; // unused - *cursorSize = obj->GetSize(&top,&bottom); + if(cursorSize) + *cursorSize = obj->GetSize(&top,&bottom); cursorPos->y = m_Position.y; cursorFound = true; // no more checks } @@ -1509,6 +1522,7 @@ wxLayoutList::wxLayoutList() m_caret = NULL; #endif // WXLAYOUT_USE_CARET + m_numLines = 0; m_FirstLine = NULL; InvalidateUpdateRect(); Clear(); @@ -1518,6 +1532,8 @@ wxLayoutList::~wxLayoutList() { InternalClear(); m_FirstLine->DeleteLine(false, this); + + wxASSERT_MSG( m_numLines == 0, "line count calculation broken" ); } void @@ -1554,6 +1570,7 @@ wxLayoutList::InternalClear(void) m_DefaultStyleInfo.m_bg = *wxWHITE; m_CurrentStyleInfo = m_DefaultStyleInfo; + m_CursorStyleInfo = m_DefaultStyleInfo; } void @@ -1847,8 +1864,11 @@ wxLayoutList::MoveCursorWord(int n, bool untilNext) } else // backwards { - if ( isspace(*p) ) + // in these 2 cases we took 1 char too much + if ( (p < start) || isspace(*p) ) + { p++; + } } n > 0 ? n-- : n++; @@ -1944,15 +1964,21 @@ wxLayoutList::LineBreak(void) m_CursorLine = m_CursorLine->Break(m_CursorPos.x, this); if(setFirst) // we were at beginning of first line - m_FirstLine = m_CursorLine->GetPreviousLine(); + m_FirstLine = m_CursorLine; + wxASSERT(m_FirstLine); if(m_CursorPos.x != 0) m_CursorPos.y++; m_CursorPos.x = 0; - wxLayoutLine *prev = m_CursorLine->GetPreviousLine(); - wxCHECK_MSG(prev, false, "just broke the line, where is the previous one?"); - height += prev->GetHeight(); + // The following code will produce a height which is guaranteed to + // be too high: old lineheight + the height of both new lines. + // We can probably drop the old line height and start with height = + // 0. FIXME + wxLayoutLine *prev = m_CursorLine->GetPreviousLine(); + if(prev) + height += prev->GetHeight(); + height += m_CursorLine->GetHeight(); m_movedCursor = true; @@ -2151,13 +2177,25 @@ wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll, // The following Layout() calls will update our // m_CurrentStyleInfo if needed. if(line == m_CursorLine) + { line->Layout(dc, this, (wxPoint *)&m_CursorScreenPos, - (wxPoint *)&m_CursorSize, m_CursorPos.x); - if(cpos && line->GetLineNumber() == cpos->y) - line->Layout(dc, this, - cpos, - csize, cpos->x); + (wxPoint *)&m_CursorSize, + &m_CursorStyleInfo, + m_CursorPos.x); + // we cannot layout the line twice, so copy the coords: + if(cpos && line ->GetLineNumber() == cpos->y) + { + *cpos = m_CursorScreenPos; + if ( csize ) + *csize = m_CursorSize; + } + } + else + if(cpos && line->GetLineNumber() == cpos->y) + line->Layout(dc, this, + cpos, + csize, NULL, cpos->x); else line->Layout(dc, this); // little condition to speed up redrawing: @@ -2231,11 +2269,7 @@ wxLayoutList::Draw(wxDC &dc, } line->Draw(dc, this, offset); } -#if 0 - else - line->Layout(dc, this); -#endif - // little condition to speed up redrawing: + // little condition to speed up redrawing: if(bottom != -1 && line->GetPosition().y > bottom) break; line = line->GetNextLine(); } @@ -2274,15 +2308,22 @@ wxLayoutList::FindObjectScreen(wxDC &dc, wxPoint const pos, #endif line = line->GetNextLine(); } - if(line == NULL) + + if ( !line ) { - if(found) *found = false; + if ( found ) + *found = false; + return NULL; // not found } - if(cursorPos) cursorPos->y = line->GetLineNumber(); + + if ( cursorPos ) + cursorPos->y = line->GetLineNumber(); + // Now, find the object in the line: + ApplyStyle(line->GetStyleInfo(), dc); wxLOiterator i = line->FindObjectScreen(dc, pos.x, - cursorPos ? & cursorPos->x : NULL , + cursorPos ? &cursorPos->x : NULL, found); return (i == NULLIT) ? NULL : *i;