1. fix for custom event handler in wxScrollWindow which was eating events

2. fix for (initial) selection anchor position in wxTextCtrl


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8659 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-10-30 21:15:15 +00:00
parent 9686c81605
commit f6c8b8f53d
5 changed files with 33 additions and 23 deletions

7
TODO
View File

@@ -8,8 +8,11 @@ samples:
wxTextCtrl wxTextCtrl
* display corrupted when typing text in quickly * display corrupted when typing text in quickly (single line)
* text ctrl display pb when text is truncated ? 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 All

View File

@@ -384,7 +384,7 @@ MyUnivFrame::MyUnivFrame(const wxString& title)
new wxTextCtrl(this, -1, _T("Hello, Universe!"), new wxTextCtrl(this, -1, _T("Hello, Universe!"),
wxPoint(550, 150), wxDefaultSize); wxPoint(550, 150), wxDefaultSize);
#else // TEST_TEXT_ONLY #else // TEST_TEXT_ONLY
#if 1 #if 0
wxTextCtrl *text = new wxTextCtrl(this, -1, _T("Hello, Universe!"), wxTextCtrl *text = new wxTextCtrl(this, -1, _T("Hello, Universe!"),
wxPoint(10, 40)); wxPoint(10, 40));
text->SetFont(wxFont(24, wxFONTFAMILY_DEFAULT, text->SetFont(wxFont(24, wxFONTFAMILY_DEFAULT,

View File

@@ -80,25 +80,22 @@ public:
case wxEVT_SCROLLWIN_THUMBTRACK: case wxEVT_SCROLLWIN_THUMBTRACK:
case wxEVT_SCROLLWIN_THUMBRELEASE: case wxEVT_SCROLLWIN_THUMBRELEASE:
m_scrollHelper->HandleOnScroll((wxScrollWinEvent&)event); m_scrollHelper->HandleOnScroll((wxScrollWinEvent&)event);
break; return TRUE;
case wxEVT_PAINT: case wxEVT_PAINT:
m_scrollHelper->HandleOnPaint((wxPaintEvent&)event); m_scrollHelper->HandleOnPaint((wxPaintEvent&)event);
break; return TRUE;
case wxEVT_SIZE: case wxEVT_SIZE:
m_scrollHelper->HandleOnSize((wxSizeEvent&)event); m_scrollHelper->HandleOnSize((wxSizeEvent&)event);
break; return FALSE;
case wxEVT_CHAR: case wxEVT_CHAR:
m_scrollHelper->HandleOnChar((wxKeyEvent&)event); m_scrollHelper->HandleOnChar((wxKeyEvent&)event);
break; return !event.GetSkipped();
default:
return FALSE;
} }
return TRUE; return FALSE;
} }
private: private:

View File

@@ -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")); _T("can't have more than one line in this wxTextCtrl"));
// update the current position // 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 // and the selection (do it after setting the cursor to have correct value
// for selection anchor) // 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 // update the current position: note that we always put the cursor at the
// end of the replacement text // 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 // and the selection (do it after setting the cursor to have correct value
// for selection anchor) // for selection anchor)
@@ -681,16 +681,24 @@ void wxTextCtrl::SetInsertionPoint(long pos)
{ {
DoSetInsertionPoint(pos); DoSetInsertionPoint(pos);
} }
ClearSelection();
} }
void wxTextCtrl::InitInsertionPoint() void wxTextCtrl::InitInsertionPoint()
{ {
// so far always put it in the beginning // so far always put it in the beginning
DoSetInsertionPoint(0); DoSetInsertionPoint(0);
// this will also set the selection anchor correctly
ClearSelection();
} }
void wxTextCtrl::DoSetInsertionPoint(long pos) void wxTextCtrl::DoSetInsertionPoint(long pos)
{ {
wxASSERT_MSG( pos >= 0 && pos <= GetLastPosition(),
_T("DoSetInsertionPoint() can only be called with valid pos") );
m_curPos = pos; m_curPos = pos;
PositionToXY(m_curPos, &m_curCol, &m_curRow); 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 // scroll down: the current item should appear at the
// bottom of the view // 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(), int wChar = GetCharWidth(),
hChar = GetCharHeight(); hChar = GetCharHeight();
int widthMin = wxMin(10*wChar, 100); int widthMin = wxMax(10*wChar, 100);
if ( w < widthMin ) if ( w < widthMin )
w = widthMin; w = widthMin;
if ( h < hChar ) if ( h < hChar )
@@ -2222,14 +2230,12 @@ void wxTextCtrl::DoDraw(wxControlRenderer *renderer)
rectTextArea.y += pt.y; rectTextArea.y += pt.y;
rgnUpdate.Intersect(rectTextArea); rgnUpdate.Intersect(rectTextArea);
#if 0
// even though the drawing is already clipped to the update region, we must // 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 // 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 // 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 // inside, HitTest() will return its column and DrawText() can't draw only
// the part of the character, of course) // the part of the character, of course)
dc.SetClippingRegion(m_rectText); dc.SetClippingRegion(m_rectText);
#endif // 0
// adjust for scrolling // adjust for scrolling
DoPrepareDC(dc); DoPrepareDC(dc);
@@ -2315,9 +2321,13 @@ void wxTextCtrl::ShowCaret(bool show)
wxCaret *caret = GetCaret(); wxCaret *caret = GetCaret();
if ( caret ) if ( caret )
{ {
// position it correctly // position it correctly (taking scrolling into account)
caret->Move(m_rectText.x + GetCaretPosition() - m_ofsHorz, wxCoord xCaret, yCaret;
m_rectText.y + m_curRow*GetCharHeight()); CalcUnscrolledPosition(m_rectText.x + GetCaretPosition() - m_ofsHorz,
m_rectText.y + m_curRow*GetCharHeight(),
&xCaret,
&yCaret);
caret->Move(xCaret, yCaret);
// and show it there // and show it there
caret->Show(show); caret->Show(show);
@@ -2468,7 +2478,7 @@ bool wxTextCtrl::PerformAction(const wxControlAction& actionOrig,
else // cursor movement command else // cursor movement command
{ {
// just go there // just go there
SetInsertionPoint(newPos); DoSetInsertionPoint(newPos);
if ( sel ) if ( sel )
{ {

View File

@@ -1736,7 +1736,7 @@ wxRect wxWin32Renderer::GetTextTotalArea(const wxTextCtrl *text,
{ {
// this is what Windows does // this is what Windows does
wxRect rectTotal = rect; wxRect rectTotal = rect;
rectTotal.Inflate(1); rectTotal.Inflate(10);
rectTotal.height++; rectTotal.height++;
return rectTotal; return rectTotal;
@@ -1748,7 +1748,7 @@ wxRect wxWin32Renderer::GetTextClientArea(const wxTextCtrl *text,
// undo GetTextTotalArea() // undo GetTextTotalArea()
wxRect rectText = rect; wxRect rectText = rect;
rectText.height--; rectText.height--;
rectText.Inflate(-1); rectText.Inflate(-10);
return rectText; return rectText;
} }