Changed caret to black and made it go when control isn't focussed

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15008 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2002-04-07 22:47:20 +00:00
parent 67c34f64d4
commit 968602f890
2 changed files with 39 additions and 11 deletions

View File

@ -249,6 +249,8 @@ public:
void OnMouse( wxMouseEvent &event ); void OnMouse( wxMouseEvent &event );
void OnChar( wxKeyEvent &event ); void OnChar( wxKeyEvent &event );
void OnIdle( wxIdleEvent &event ); void OnIdle( wxIdleEvent &event );
void OnSetFocus( wxFocusEvent& event );
void OnKillFocus( wxFocusEvent& event );
void RefreshLine( int n ); void RefreshLine( int n );
void RefreshDown( int n ); void RefreshDown( int n );

View File

@ -135,6 +135,8 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
EVT_CHAR(wxTextCtrl::OnChar) EVT_CHAR(wxTextCtrl::OnChar)
EVT_MOUSE_EVENTS(wxTextCtrl::OnMouse) EVT_MOUSE_EVENTS(wxTextCtrl::OnMouse)
EVT_IDLE(wxTextCtrl::OnIdle) EVT_IDLE(wxTextCtrl::OnIdle)
EVT_KILL_FOCUS(wxTextCtrl::OnKillFocus)
EVT_SET_FOCUS(wxTextCtrl::OnSetFocus)
EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
@ -214,7 +216,7 @@ bool wxTextCtrl::Create( wxWindow *parent,
if ((style & wxTE_MULTILINE) != 0) if ((style & wxTE_MULTILINE) != 0)
style |= wxALWAYS_SHOW_SB; style |= wxALWAYS_SHOW_SB;
wxTextCtrlBase::Create( parent, id, wxDefaultPosition, size, wxTextCtrlBase::Create( parent, id, pos /* wxDefaultPosition */, size,
style|wxVSCROLL|wxHSCROLL|wxNO_FULL_REPAINT_ON_RESIZE ); style|wxVSCROLL|wxHSCROLL|wxNO_FULL_REPAINT_ON_RESIZE );
SetBackgroundColour( *wxWHITE ); SetBackgroundColour( *wxWHITE );
@ -270,6 +272,13 @@ wxString wxTextCtrl::GetValue() const
void wxTextCtrl::SetValue(const wxString& value) void wxTextCtrl::SetValue(const wxString& value)
{ {
m_modified = TRUE; m_modified = TRUE;
if ((GetWindowStyle() & wxTE_MULTILINE) == 0)
{
if (value == GetValue())
return;
}
m_cursorX = 0; m_cursorX = 0;
m_cursorY = 0; m_cursorY = 0;
ClearSelection(); ClearSelection();
@ -1854,9 +1863,10 @@ void wxTextCtrl::OnPaint( wxPaintEvent &event )
DrawLine( dc, 0+2, i*m_lineHeight+2, m_lines[i].m_text, i ); DrawLine( dc, 0+2, i*m_lineHeight+2, m_lines[i].m_text, i );
} }
if (m_editable) if (m_editable && (FindFocus() == this))
{ {
dc.SetBrush( *wxRED_BRUSH ); ///dc.SetBrush( *wxRED_BRUSH );
dc.SetBrush( *wxBLACK_BRUSH );
// int xx = m_cursorX*m_charWidth; // int xx = m_cursorX*m_charWidth;
int xx = PosToPixel( m_cursorY, m_cursorX ); int xx = PosToPixel( m_cursorY, m_cursorX );
dc.DrawRectangle( xx+2, m_cursorY*m_lineHeight+2, 2, m_lineHeight ); dc.DrawRectangle( xx+2, m_cursorY*m_lineHeight+2, 2, m_lineHeight );
@ -2354,13 +2364,17 @@ void wxTextCtrl::MoveCursor( int new_x, int new_y, bool shift, bool centre )
Refresh( TRUE, &rect ); Refresh( TRUE, &rect );
wxClientDC dc(this); if (FindFocus() == this)
PrepareDC( dc ); {
dc.SetPen( *wxTRANSPARENT_PEN ); wxClientDC dc(this);
dc.SetBrush( *wxRED_BRUSH ); PrepareDC( dc );
// int xx = m_cursorX*m_charWidth; dc.SetPen( *wxTRANSPARENT_PEN );
int xx = PosToPixel( m_cursorY, m_cursorX ); //dc.SetBrush( *wxRED_BRUSH );
dc.DrawRectangle( xx+2, m_cursorY*m_lineHeight+2, 2, m_lineHeight ); dc.SetBrush( *wxBLACK_BRUSH );
// int xx = m_cursorX*m_charWidth;
int xx = PosToPixel( m_cursorY, m_cursorX );
dc.DrawRectangle( xx+2, m_cursorY*m_lineHeight+2, 2, m_lineHeight );
}
} }
int size_x = 0; int size_x = 0;
@ -2502,6 +2516,18 @@ void wxTextCtrl::Thaw()
{ {
} }
void wxTextCtrl::OnSetFocus( wxFocusEvent& event )
{
// To hide or show caret, as appropriate
Refresh();
}
void wxTextCtrl::OnKillFocus( wxFocusEvent& event )
{
// To hide or show caret, as appropriate
Refresh();
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// text control scrolling // text control scrolling
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------