diff --git a/TODO b/TODO index 35e2fb8a40..98cb867e39 100644 --- a/TODO +++ b/TODO @@ -8,8 +8,11 @@ samples: wxTextCtrl -* display corrupted when typing text in quickly -* text ctrl display pb when text is truncated +* display corrupted when typing text in quickly (single line) +? text ctrl display pb when text is truncated +* too much is refreshed when double clicking (word select) + +!! own ScrollWindow() for horz scrolling as we must always scroll by char! All diff --git a/samples/univ/univ.cpp b/samples/univ/univ.cpp index fcd86615f0..9456dd9d2f 100644 --- a/samples/univ/univ.cpp +++ b/samples/univ/univ.cpp @@ -384,7 +384,7 @@ MyUnivFrame::MyUnivFrame(const wxString& title) new wxTextCtrl(this, -1, _T("Hello, Universe!"), wxPoint(550, 150), wxDefaultSize); #else // TEST_TEXT_ONLY -#if 1 +#if 0 wxTextCtrl *text = new wxTextCtrl(this, -1, _T("Hello, Universe!"), wxPoint(10, 40)); text->SetFont(wxFont(24, wxFONTFAMILY_DEFAULT, diff --git a/src/generic/scrolwin.cpp b/src/generic/scrolwin.cpp index 013f51b037..ca86484221 100644 --- a/src/generic/scrolwin.cpp +++ b/src/generic/scrolwin.cpp @@ -80,25 +80,22 @@ public: case wxEVT_SCROLLWIN_THUMBTRACK: case wxEVT_SCROLLWIN_THUMBRELEASE: m_scrollHelper->HandleOnScroll((wxScrollWinEvent&)event); - break; + return TRUE; case wxEVT_PAINT: m_scrollHelper->HandleOnPaint((wxPaintEvent&)event); - break; + return TRUE; case wxEVT_SIZE: m_scrollHelper->HandleOnSize((wxSizeEvent&)event); - break; + return FALSE; case wxEVT_CHAR: m_scrollHelper->HandleOnChar((wxKeyEvent&)event); - break; - - default: - return FALSE; + return !event.GetSkipped(); } - return TRUE; + return FALSE; } private: diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index cdb327c0fd..d5907c0114 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -356,7 +356,7 @@ void wxTextCtrl::Replace(long from, long to, const wxString& text) _T("can't have more than one line in this wxTextCtrl")); // update the current position - SetInsertionPoint(from + text.length()); + DoSetInsertionPoint(from + text.length()); // and the selection (do it after setting the cursor to have correct value // for selection anchor) @@ -631,7 +631,7 @@ void wxTextCtrl::Replace(long from, long to, const wxString& text) // update the current position: note that we always put the cursor at the // end of the replacement text - SetInsertionPoint(from + text.length()); + DoSetInsertionPoint(from + text.length()); // and the selection (do it after setting the cursor to have correct value // for selection anchor) @@ -681,16 +681,24 @@ void wxTextCtrl::SetInsertionPoint(long pos) { DoSetInsertionPoint(pos); } + + ClearSelection(); } void wxTextCtrl::InitInsertionPoint() { // so far always put it in the beginning DoSetInsertionPoint(0); + + // this will also set the selection anchor correctly + ClearSelection(); } void wxTextCtrl::DoSetInsertionPoint(long pos) { + wxASSERT_MSG( pos >= 0 && pos <= GetLastPosition(), + _T("DoSetInsertionPoint() can only be called with valid pos") ); + m_curPos = pos; PositionToXY(m_curPos, &m_curCol, &m_curRow); @@ -1133,7 +1141,7 @@ void wxTextCtrl::ShowPosition(long pos) { // scroll down: the current item should appear at the // bottom of the view - Scroll(0, m_curRow - (yEnd - yStart)); + Scroll(0, m_curRow - (yEnd - yStart) + 1); } } } @@ -1329,7 +1337,7 @@ wxSize wxTextCtrl::DoGetBestClientSize() const int wChar = GetCharWidth(), hChar = GetCharHeight(); - int widthMin = wxMin(10*wChar, 100); + int widthMin = wxMax(10*wChar, 100); if ( w < widthMin ) w = widthMin; if ( h < hChar ) @@ -2222,14 +2230,12 @@ void wxTextCtrl::DoDraw(wxControlRenderer *renderer) rectTextArea.y += pt.y; rgnUpdate.Intersect(rectTextArea); -#if 0 // even though the drawing is already clipped to the update region, we must // explicitly clip it to the rect we will use as otherwise parts of letters // might be drawn outside of it (if even a small part of a charater is // inside, HitTest() will return its column and DrawText() can't draw only // the part of the character, of course) dc.SetClippingRegion(m_rectText); -#endif // 0 // adjust for scrolling DoPrepareDC(dc); @@ -2315,9 +2321,13 @@ void wxTextCtrl::ShowCaret(bool show) wxCaret *caret = GetCaret(); if ( caret ) { - // position it correctly - caret->Move(m_rectText.x + GetCaretPosition() - m_ofsHorz, - m_rectText.y + m_curRow*GetCharHeight()); + // position it correctly (taking scrolling into account) + wxCoord xCaret, yCaret; + CalcUnscrolledPosition(m_rectText.x + GetCaretPosition() - m_ofsHorz, + m_rectText.y + m_curRow*GetCharHeight(), + &xCaret, + &yCaret); + caret->Move(xCaret, yCaret); // and show it there caret->Show(show); @@ -2468,7 +2478,7 @@ bool wxTextCtrl::PerformAction(const wxControlAction& actionOrig, else // cursor movement command { // just go there - SetInsertionPoint(newPos); + DoSetInsertionPoint(newPos); if ( sel ) { diff --git a/src/univ/themes/win32.cpp b/src/univ/themes/win32.cpp index d4d9703096..ac887692ab 100644 --- a/src/univ/themes/win32.cpp +++ b/src/univ/themes/win32.cpp @@ -1736,7 +1736,7 @@ wxRect wxWin32Renderer::GetTextTotalArea(const wxTextCtrl *text, { // this is what Windows does wxRect rectTotal = rect; - rectTotal.Inflate(1); + rectTotal.Inflate(10); rectTotal.height++; return rectTotal; @@ -1748,7 +1748,7 @@ wxRect wxWin32Renderer::GetTextClientArea(const wxTextCtrl *text, // undo GetTextTotalArea() wxRect rectText = rect; rectText.height--; - rectText.Inflate(-1); + rectText.Inflate(-10); return rectText; }