]> git.saurik.com Git - wxWidgets.git/commitdiff
1. wxLayoutList::GetNumLines() and MoveCursorToEnd() added (and work)
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 11 Jun 1999 12:10:26 +0000 (12:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 11 Jun 1999 12:10:26 +0000 (12:10 +0000)
2. FindObjectScreen() applies the line style - corrects "mouse click mis
   positions the cursor" bug

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2762 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/richedit/wxllist.cpp
samples/richedit/wxllist.h
samples/richedit/wxlwindow.cpp

index f6b6032c9cc2e63fffa75440edd588c6a92de1c6..ca7b2b7587e42e84f579dfe351c4e9d657be68fd 100644 (file)
@@ -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;
 }
 
@@ -1513,6 +1522,7 @@ wxLayoutList::wxLayoutList()
    m_caret = NULL;
 #endif // WXLAYOUT_USE_CARET
 
+   m_numLines = 0;
    m_FirstLine = NULL;
    InvalidateUpdateRect();
    Clear();
@@ -1522,6 +1532,8 @@ wxLayoutList::~wxLayoutList()
 {
    InternalClear();
    m_FirstLine->DeleteLine(false, this);
+
+   wxASSERT_MSG( m_numLines == 0, "line count calculation broken" );
 }
 
 void
@@ -2296,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;
 
index 63be75e0d15b580b9e76633384f97bf306f8623f..9c70ecbf407274cc0d533dd36c0a6b7771bbf634 100644 (file)
@@ -798,14 +798,24 @@ public:
          MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x);
       }
 
-   /// Move cursor to begin of line.
+   /// Move cursor to the start of line.
    void MoveCursorToBeginOfLine(void)
       { MoveCursorHorizontally(-m_CursorPos.x); }
 
+   /// get the number of lines in the list
+   size_t GetNumLines() const { return m_numLines; }
+
    /// Returns current cursor position.
    const wxPoint &GetCursorPos(wxDC &dc) const { return m_CursorPos; }
    const wxPoint &GetCursorPos() const { return m_CursorPos; }
 
+   /// move cursor to the end of text
+   void MoveCursorToEnd(void)
+   {
+      MoveCursorTo(wxPoint(0, GetNumLines() - 1));
+      MoveCursorToEndOfLine();
+   }
+
    //@}
 
    /**@name Editing functions.
@@ -1109,16 +1119,24 @@ public:
    void Debug(void);
 #endif
 
+   // for wxLayoutLine usage only
+   void IncNumLines() { m_numLines++; }
+   void DecNumLines() { m_numLines--; }
+
 private:
    /// Clear the list.
    void InternalClear(void);
 
    /// The list of lines.
    wxLayoutLine *m_FirstLine;
+   /// The number of lines in the list (store instead recalculating for speed)
+   size_t m_numLines;
+
    /// The update rectangle which needs to be refreshed:
    wxRect  m_UpdateRect;
    /// Is the update rectangle valid?
    bool    m_UpdateRectValid;
+
    /**@name Cursor Management */
    //@{
    /// Where the text cursor (column,line) is.
index 6b154206c22c8280a5e8deb3648434dcb4e6259c..b8a8c1278273d8980c5a5d8cf1e79030fc7a9345 100644 (file)
@@ -304,7 +304,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
              else
              {
                 // click beyond the end of the text
-                m_llist->MoveCursorTo(m_llist->GetSize());
+                m_llist->MoveCursorToEnd();
              }
 
              // clicking a mouse removes the selection
@@ -490,7 +490,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
       break;
    case WXK_END:
       if ( ctrlDown )
-         m_llist->MoveCursorTo(m_llist->GetSize());
+         m_llist->MoveCursorToEnd();
       else
          m_llist->MoveCursorToEndOfLine();
       break;