From: Karsten Ballüder Date: Fri, 14 May 1999 09:35:54 +0000 (+0000) Subject: The new layout mechanism is better than the old one. :-) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/b86cda55e5b5eac4ed523d5ace9f829542e9fce2 The new layout mechanism is better than the old one. :-) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2458 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/user/wxLayout/TODO b/user/wxLayout/TODO index 4aeb15de8e..ef25ed089b 100644 --- a/user/wxLayout/TODO +++ b/user/wxLayout/TODO @@ -20,36 +20,14 @@ Adding many lines makes it terribly slow. Printing produces empty pages only. -Formatting of first text in message in M is broken. -Large images in last line don't get displayed properly. -Taking last line's height as default for next is rubbish, -use "default height" and adjust as necessary. - Selections: - moving in negative direction doesn't work - selection state not properly reset, only works once - selecting non-text objects is strange -wxllist::GetSize() requires extra Layout() call, which should not be -necessary. Find out why this is so. -YES, it is necessary, because the normal drawing only happens within -the visible window. -I must find a way to re-Layout() objects. This is only required after -their sizes change: -- Just mark them as dirty: - - mark current line as dirty when editing it (so width gets recalculated) - - mark all following lines as dirty when changing font settings - - Let Layout() work only on the dirty lines. - !!! GOOD: this can also be used to recalculate the wxLayoutObjectCmds' - fonts! :-) - -- cursor screen positioning ignores font sizes once again :-( - --> UpdateCursorScreenPos() cannot work as it ignores previous font formatting commands. - Either draw cursor when drawing text, or wait for new wxLayoutObjectCmd to be fully - implemented. - -RECENTLY FIXED (?) - - delete in empty line doesn't work +- Changing default settings in Clear() or changing/inserting/deleting + a wxLayoutObject needs to update the m_StyleInfo in all lines, only + then can we start using that one. - update rectangle (needs support in wxllist and wxWindows) --> needs a bit of fixing still @@ -57,12 +35,8 @@ RECENTLY FIXED (?) offset handling seems a bit dodgy, white shadow to top/left of cursor - replacement of llist in window - - undo - UNDO - DragNDrop -- More optimisations: - - let each line have a pointer to the last layoutcommand and let that - one only store the settings that changed, then we no longer need to - recalculate all the lines - + - Update docs, do full rtf/html editing. + - Verify html export. diff --git a/user/wxLayout/wxllist.cpp b/user/wxLayout/wxllist.cpp index aadf0b416e..5df8c17524 100644 --- a/user/wxLayout/wxllist.cpp +++ b/user/wxLayout/wxllist.cpp @@ -400,7 +400,6 @@ wxLayoutLine::wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist) m_LineNumber = m_Previous->GetLineNumber()+1; m_Next = m_Previous->GetNextLine(); m_Previous->m_Next = this; - m_Height = m_Previous->GetHeight(); } if(m_Next) { @@ -491,12 +490,10 @@ wxLayoutLine::FindObjectScreen(wxDC &dc, for(i = m_ObjectList.begin(); i != NULLIT; i++) { -//FIXME! (**i).Layout(dc, NULL); width = (**i).GetWidth(); if( x <= xpos && xpos <= x + width ) { *cxpos = cx + (**i).GetOffsetScreen(dc, xpos-x); -// WXLO_DEBUG(("wxLayoutLine::FindObjectScreen: cursor xpos = %ld", *cxpos)); if(found) *found = true; return i; } @@ -546,6 +543,8 @@ wxLayoutLine::Insert(CoordType xpos, wxLayoutObject *obj) { wxASSERT(xpos >= 0); wxASSERT(obj != NULL); + //FIXME: this could be optimised, for now be prudent: + m_Dirty = true; CoordType offset; wxLOiterator i = FindObject(xpos, &offset); if(i == NULLIT) @@ -600,6 +599,8 @@ bool wxLayoutLine::Insert(CoordType xpos, wxString text) { wxASSERT(xpos >= 0); + //FIXME: this could be optimised, for now be prudent: + m_Dirty = true; CoordType offset; wxLOiterator i = FindObject(xpos, &offset); if(i != NULLIT && (**i).GetType() == WXLO_TYPE_TEXT) @@ -621,6 +622,8 @@ wxLayoutLine::Delete(CoordType xpos, CoordType npos) wxASSERT(xpos >= 0); wxASSERT(npos >= 0); + //FIXME: this could be optimised, for now be prudent: + m_Dirty = true; wxLOiterator i = FindObject(xpos, &offset); while(npos > 0) { @@ -674,6 +677,8 @@ wxLayoutLine::DeleteWord(CoordType xpos) { wxASSERT(xpos >= 0); CoordType offset; + //FIXME: this could be optimised, for now be prudent: + m_Dirty = true; wxLOiterator i = FindObject(xpos, &offset); @@ -804,6 +809,8 @@ wxLayoutLine::Layout(wxDC &dc, wxPoint size; bool cursorFound = false; + m_Dirty = false; + if(cursorPos) { *cursorPos = m_Position; @@ -869,18 +876,10 @@ wxLayoutLine::Layout(wxDC &dc, if(m_Height == 0) { - if(GetPreviousLine()) // empty line - { - m_Height = GetPreviousLine()->GetHeight(); - m_BaseLine = GetPreviousLine()->m_BaseLine; - } - else - { - CoordType width, height, descent; - dc.GetTextExtent(WXLO_CURSORCHAR, &width, &height, &descent); - m_Height = height; - m_BaseLine = m_Height - descent; - } + CoordType width, height, descent; + dc.GetTextExtent(WXLO_CURSORCHAR, &width, &height, &descent); + m_Height = height; + m_BaseLine = m_Height - descent; } @@ -911,6 +910,8 @@ wxLayoutLine * wxLayoutLine::Break(CoordType xpos, wxLayoutList *llist) { wxASSERT(xpos >= 0); + //FIXME: this could be optimised, for now be prudent: + m_Dirty = true; if(xpos == 0) { // insert an empty line before this one @@ -971,6 +972,8 @@ wxLayoutLine::MergeNextLine(wxLayoutList *llist) wxASSERT(GetNextLine()); wxLayoutObjectList &list = GetNextLine()->m_ObjectList; wxLOiterator i; + //FIXME: this could be optimised, for now be prudent: + m_Dirty = true; for(i = list.begin(); i != list.end();) { @@ -1530,23 +1533,34 @@ wxLayoutList::GetCursorScreenPos(wxDC &dc) return m_CursorScreenPos; } +/* + Is called before each Draw(). Now, it will re-layout all lines which + have changed. +*/ void -wxLayoutList::Layout(wxDC &dc, CoordType bottom) +wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll) { wxLayoutLine *line = m_FirstLine; - + // first, make sure everything is calculated - this might not be // needed, optimise it later - ApplyStyle(&m_DefaultSetting, dc); + //FIXME This doesn't work yet, needs updating afterr default + //settings for list or a wxLayoutObjectCmd have changed: + // ApplyStyle(&m_DefaultSetting, dc); while(line) { - line->GetStyleInfo() = m_CurrentSetting; - if(line == m_CursorLine) - line->Layout(dc, this, (wxPoint *)&m_CursorScreenPos, (wxPoint *)&m_CursorSize, m_CursorPos.x); - else - line->Layout(dc, this); - // little condition to speed up redrawing: - if(bottom != -1 && line->GetPosition().y > bottom) break; + if(forceAll || line->IsDirty()) + { + line->GetStyleInfo() = m_CurrentSetting; + if(line == m_CursorLine) + line->Layout(dc, this, (wxPoint *)&m_CursorScreenPos, + (wxPoint *)&m_CursorSize, m_CursorPos.x); + else + line->Layout(dc, this); + line->RecalculatePosition(this); + // little condition to speed up redrawing: + if(bottom != -1 && line->GetPosition().y > bottom) break; + } line = line->GetNextLine(); } @@ -1569,8 +1583,9 @@ wxLayoutList::Draw(wxDC &dc, { wxLayoutLine *line = m_FirstLine; + Layout(dc); ApplyStyle(&m_DefaultSetting, dc); - wxBrush brush(m_DefaultSetting.m_bg, wxSOLID); + wxBrush brush(m_CurrentSetting.m_bg, wxSOLID); dc.SetBrush(brush); while(line) diff --git a/user/wxLayout/wxllist.h b/user/wxLayout/wxllist.h index d4cb9ce009..52c87053db 100644 --- a/user/wxLayout/wxllist.h +++ b/user/wxLayout/wxllist.h @@ -603,7 +603,9 @@ public: void Debug(void); #endif wxLayoutStyleInfo &GetStyleInfo() { return m_StyleInfo; } - + + /// Returns dirty state + bool IsDirty(void) const { return m_Dirty; } private: /// Destructor is private. Use DeleteLine() to remove it. ~wxLayoutLine(); @@ -848,8 +850,9 @@ public: actually draw it. @param dc the wxDC to draw on @param bottom optional y coordinate where to stop calculating + @param forceAll force re-layout of all lines */ - void Layout(wxDC &dc, CoordType bottom = -1); + void Layout(wxDC &dc, CoordType bottom = -1, bool forceAll = false); /** Calculates new sizes for everything in the list, like Layout() but this is needed after the list got changed.