X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3febfc6bd7a341ed22022fae22e866f5b06c8ec5..8a82c9ecc9a2cba9727b538c818ebdba243eacbc:/src/univ/textctrl.cpp diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index a56e610f6b..1ac457b944 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -6,7 +6,7 @@ // Created: 15.09.00 // RCS-ID: $Id$ // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com) -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// /* @@ -117,7 +117,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "univtextctrl.h" #endif @@ -150,6 +150,10 @@ #include "wx/cmdproc.h" +#if wxUSE_CLIPBOARD +#include "wx/dataobj.h" +#endif + // turn extra wxTextCtrl-specific debugging on/off #define WXDEBUG_TEXT @@ -604,8 +608,6 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) EVT_CHAR(wxTextCtrl::OnChar) EVT_SIZE(wxTextCtrl::OnSize) - - EVT_IDLE(wxTextCtrl::OnIdle) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) @@ -661,11 +663,14 @@ bool wxTextCtrl::Create(wxWindow *parent, style |= wxALWAYS_SHOW_SB; } + // wxTE_WORDWRAP is 0 for now so we don't need the code below +#if 0 if ( style & wxTE_WORDWRAP ) { // wrapping words means wrapping, hence no horz scrollbar style &= ~wxHSCROLL; } +#endif // 0 // TODO: support wxTE_NO_VSCROLL (?) @@ -684,6 +689,11 @@ bool wxTextCtrl::Create(wxWindow *parent, // create data object for single line controls m_data.sdata = new wxTextSingleLineData; } + +#if wxUSE_TWO_WINDOWS + if ((style & wxBORDER_MASK) == 0) + style |= wxBORDER_SUNKEN; +#endif if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) @@ -725,6 +735,9 @@ bool wxTextCtrl::Create(wxWindow *parent, CreateInputHandler(wxINP_HANDLER_TEXTCTRL); + wxSizeEvent sizeEvent(GetSize(), GetId()); + GetEventHandler()->ProcessEvent(sizeEvent); + return TRUE; } @@ -1854,7 +1867,9 @@ wxPoint wxTextCtrl::GetCaretPosition() const // pos may be -1 to show the current position void wxTextCtrl::ShowPosition(wxTextPos pos) { - HideCaret(); + bool showCaret = GetCaret() && GetCaret()->IsVisible(); + if (showCaret) + HideCaret(); if ( IsSingleLine() ) { @@ -1974,7 +1989,8 @@ void wxTextCtrl::ShowPosition(wxTextPos pos) } //else: multiline but no scrollbars, hence nothing to do - ShowCaret(); + if (showCaret) + ShowCaret(); } // ---------------------------------------------------------------------------- @@ -2433,7 +2449,7 @@ void wxTextCtrl::UpdateLastVisible() SData().m_colLastVisible += SData().m_colStart; wxLogTrace(_T("text"), _T("Last visible column/position is %d/%ld"), - SData().m_colLastVisible, SData().m_posLastVisible); + (int) SData().m_colLastVisible, (long) SData().m_posLastVisible); } void wxTextCtrl::OnSize(wxSizeEvent& event) @@ -3559,7 +3575,7 @@ void wxTextCtrl::UpdateScrollbars() MData().m_updateScrollbarY = FALSE; } -void wxTextCtrl::OnIdle(wxIdleEvent& event) +void wxTextCtrl::OnInternalIdle() { // notice that single line text control never has scrollbars if ( !IsSingleLine() && @@ -3567,8 +3583,7 @@ void wxTextCtrl::OnIdle(wxIdleEvent& event) { UpdateScrollbars(); } - - event.Skip(); + wxControl::OnInternalIdle(); } bool wxTextCtrl::SendAutoScrollEvents(wxScrollWinEvent& event) const @@ -4105,6 +4120,7 @@ void wxTextCtrl::DoDraw(wxControlRenderer *renderer) // the update region is in window coords and text area is in the client // ones, so it must be shifted before computing intersection wxRegion rgnUpdate = GetUpdateRegion(); + wxRect rectTextArea = GetRealTextArea(); wxPoint pt = GetClientAreaOrigin(); wxRect rectTextAreaAdjusted = rectTextArea; @@ -4169,7 +4185,7 @@ void wxTextCtrl::DoDraw(wxControlRenderer *renderer) // show caret first time only: we must show it after drawing the text or // the display can be corrupted when it's hidden - if ( !m_hasCaret && GetCaret() ) + if ( !m_hasCaret && GetCaret() && (FindFocus() == this) ) { ShowCaret(); @@ -4212,7 +4228,10 @@ bool wxTextCtrl::Enable(bool enable) if ( !wxTextCtrlBase::Enable(enable) ) return FALSE; - ShowCaret(enable); + if (FindFocus() == this && GetCaret() && + ((enable && !GetCaret()->IsVisible()) || + (!enable && GetCaret()->IsVisible()))) + ShowCaret(enable); return TRUE; } @@ -4248,7 +4267,9 @@ void wxTextCtrl::ShowCaret(bool show) caret->Move(GetCaretPosition()); // and show it there - caret->Show(show); + if ((show && !caret->IsVisible()) || + (!show && caret->IsVisible())) + caret->Show(show); } } @@ -4709,7 +4730,7 @@ wxTextPos wxStdTextCtrlInputHandler::HitTest(const wxTextCtrl *text, return pos; } -bool wxStdTextCtrlInputHandler::HandleKey(wxControl *control, +bool wxStdTextCtrlInputHandler::HandleKey(wxInputConsumer *consumer, const wxKeyEvent& event, bool pressed) { @@ -4826,22 +4847,22 @@ bool wxStdTextCtrlInputHandler::HandleKey(wxControl *control, if ( (action != wxACTION_NONE) && (action != wxACTION_TEXT_PREFIX_SEL) ) { - control->PerformAction(action, -1, str); + consumer->PerformAction(action, -1, str); return TRUE; } - return wxStdInputHandler::HandleKey(control, event, pressed); + return wxStdInputHandler::HandleKey(consumer, event, pressed); } -bool wxStdTextCtrlInputHandler::HandleMouse(wxControl *control, +bool wxStdTextCtrlInputHandler::HandleMouse(wxInputConsumer *consumer, const wxMouseEvent& event) { if ( event.LeftDown() ) { wxASSERT_MSG( !m_winCapture, _T("left button going down twice?") ); - wxTextCtrl *text = wxStaticCast(control, wxTextCtrl); + wxTextCtrl *text = wxStaticCast(consumer->GetInputWindow(), wxTextCtrl); m_winCapture = text; m_winCapture->CaptureMouse(); @@ -4857,7 +4878,7 @@ bool wxStdTextCtrlInputHandler::HandleMouse(wxControl *control, else if ( event.LeftDClick() ) { // select the word the cursor is on - control->PerformAction(wxACTION_TEXT_SEL_WORD); + consumer->PerformAction(wxACTION_TEXT_SEL_WORD); } else if ( event.LeftUp() ) { @@ -4870,10 +4891,10 @@ bool wxStdTextCtrlInputHandler::HandleMouse(wxControl *control, } } - return wxStdInputHandler::HandleMouse(control, event); + return wxStdInputHandler::HandleMouse(consumer, event); } -bool wxStdTextCtrlInputHandler::HandleMouseMove(wxControl *control, +bool wxStdTextCtrlInputHandler::HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event) { if ( m_winCapture ) @@ -4887,17 +4908,29 @@ bool wxStdTextCtrlInputHandler::HandleMouseMove(wxControl *control, } } - return wxStdInputHandler::HandleMouseMove(control, event); + return wxStdInputHandler::HandleMouseMove(consumer, event); } -bool wxStdTextCtrlInputHandler::HandleFocus(wxControl *control, - const wxFocusEvent& event) +bool +wxStdTextCtrlInputHandler::HandleFocus(wxInputConsumer *consumer, + const wxFocusEvent& event) { - wxTextCtrl *text = wxStaticCast(control, wxTextCtrl); + wxTextCtrl *text = wxStaticCast(consumer->GetInputWindow(), wxTextCtrl); // the selection appearance changes depending on whether we have the focus text->RefreshSelection(); + if (event.GetEventType() == wxEVT_SET_FOCUS) + { + if (text->GetCaret() && !text->GetCaret()->IsVisible()) + text->ShowCaret(); + } + else + { + if (text->GetCaret() && text->GetCaret()->IsVisible()) + text->HideCaret(); + } + // never refresh entirely return FALSE; }