From 8190b05419a5b2058f7015d08e0653a2e8a4bc78 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2000 16:55:41 +0000 Subject: [PATCH] horz scrolling in etxt ctrl works better git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8704 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- TODO | 11 ++++++++--- samples/univ/univ.cpp | 4 ++-- src/univ/textctrl.cpp | 46 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/TODO b/TODO index 38e1a901a8..2194eeaf0b 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,9 @@ +---------------------------------------------------------------------------- +TEST +---------------------------------------------------------------------------- + + how Paste/Cut work with undo/redo in wxTextCtrl? + ---------------------------------------------------------------------------- TODO ---------------------------------------------------------------------------- @@ -8,12 +14,11 @@ samples: wxTextCtrl -* display corrupted when typing text in quickly (single line) +*! display corrupted when typing text in quickly (caret problem?) +* scrollbars don't disappear after deleting long 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 ! wxThemeSettings diff --git a/samples/univ/univ.cpp b/samples/univ/univ.cpp index e00aa20cfa..3f6704cf29 100644 --- a/samples/univ/univ.cpp +++ b/samples/univ/univ.cpp @@ -389,8 +389,6 @@ MyUnivFrame::MyUnivFrame(const wxString& title) #if 0 wxTextCtrl *text = new wxTextCtrl(this, -1, _T("Hello, Universe!"), wxPoint(10, 40)); - text->SetFont(wxFont(24, wxFONTFAMILY_DEFAULT, - wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); wxSize sizeText = text->GetBestSize(); sizeText.x = 200; text->SetSize(sizeText); @@ -408,6 +406,8 @@ MyUnivFrame::MyUnivFrame(const wxString& title) TestTextCtrlReplace(text, "first\nsecond\n\nthird line"); #endif #endif + text->SetFont(wxFont(24, wxFONTFAMILY_DEFAULT, + wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); text->SetFocus(); //text->SetEditable(FALSE); #endif // !TEST_TEXT_ONLY/TEST_TEXT_ONLY diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index 3c51883d19..3f3148b5ba 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -1303,18 +1303,19 @@ void wxTextCtrl::ShowPosition(long pos) return; } + wxRect rectText = GetRealTextArea(); + + // scroll the position vertically into view: if it is currently above + // it, make it the first one, otherwise the last one if ( m_scrollRangeY ) { - // scroll the position vertically into view: if it is currently - // above it, make it the first one, otherwise the last one if ( row < yStart ) { Scroll(0, row); } - else + else // we are currently in or below the view area { - int yEnd = yStart + - GetRealTextArea().height / GetCharHeight() - 1; + int yEnd = yStart + rectText.height / GetCharHeight() - 1; if ( yEnd < row ) { // scroll down: the current item should appear at the @@ -1324,9 +1325,34 @@ void wxTextCtrl::ShowPosition(long pos) } } + // scroll the position horizontally into view if ( m_scrollRangeX ) { - // TODO + // unlike for the rows, xStart doesn't correspond to the starting + // column as they all have different widths, so we need to + // translate everything to pixels + + // we want the text between posLeft and posRight be entirely inside + // the view (i.e. the current character) + wxString line = GetLineText(row); + wxCoord posLeft = GetTextWidth(line.Left(col)); + + // make xStart the first visible pixel (and not position) + int wChar = GetCharWidth(); + xStart *= GetCharWidth(); + + if ( posLeft < xStart ) + { + Scroll(posLeft / wChar, row); + } + else // maybe we're beyond the right border of the view? + { + wxCoord posRight = posLeft + GetTextWidth(line[(size_t)col]); + if ( posRight > xStart + rectText.width ) + { + Scroll(posRight / wChar, row); + } + } } } //else: multiline but no scrollbars, hence nothing to do @@ -2502,11 +2528,17 @@ void wxTextCtrl::DoDrawTextInRect(wxDC& dc, const wxRect& rectUpdate) if ( colEnd > m_colLastVisible ) colEnd = m_colLastVisible; + + // we don't draw the last character because it may be shown only + // partially in single line mode (in multi line we can't avoid + // showing parts of characters anyhow) + if ( colEnd > colStart ) + colEnd--; } // extract the part of line we need to redraw wxString textLine = GetLineText(line); - wxString text = textLine.Mid(colStart, colEnd - colStart); + wxString text = textLine.Mid(colStart, colEnd - colStart + 1); // now deal with the selection int selStart, selEnd;