X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/23645bfa01b6450257f140a30c87565225b1ef4a..d5e64615977c6839abe565919e8da50ffda40604:/src/univ/textctrl.cpp diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index 2f552fe063..3111cdf4bd 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 @@ -129,6 +129,8 @@ #if wxUSE_TEXTCTRL +#include + #ifndef WX_PRECOMP #include "wx/log.h" @@ -150,6 +152,10 @@ #include "wx/cmdproc.h" +#if wxUSE_CLIPBOARD +#include "wx/dataobj.h" +#endif + // turn extra wxTextCtrl-specific debugging on/off #define WXDEBUG_TEXT @@ -522,6 +528,8 @@ public: virtual bool CanUndo() const; virtual bool Do(wxTextCtrl *text); + virtual bool Do() { return wxTextCtrlCommand::Do(); } + virtual bool Undo() { return wxTextCtrlCommand::Undo(); } virtual bool Undo(wxTextCtrl *text); private: @@ -545,6 +553,8 @@ public: virtual bool CanUndo() const; virtual bool Do(wxTextCtrl *text); + virtual bool Do() { return wxTextCtrlCommand::Do(); } + virtual bool Undo() { return wxTextCtrlCommand::Undo(); } virtual bool Undo(wxTextCtrl *text); private: @@ -604,8 +614,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 +669,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 +695,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 +741,9 @@ bool wxTextCtrl::Create(wxWindow *parent, CreateInputHandler(wxINP_HANDLER_TEXTCTRL); + wxSizeEvent sizeEvent(GetSize(), GetId()); + GetEventHandler()->ProcessEvent(sizeEvent); + return TRUE; } @@ -1566,6 +1585,11 @@ bool wxTextCtrl::IsEditable() const return m_isEditable && IsEnabled(); } +void wxTextCtrl::MarkDirty() +{ + m_isModified = TRUE; +} + void wxTextCtrl::DiscardEdits() { m_isModified = FALSE; @@ -1854,7 +1878,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 +2000,8 @@ void wxTextCtrl::ShowPosition(wxTextPos pos) } //else: multiline but no scrollbars, hence nothing to do - ShowCaret(); + if (showCaret) + ShowCaret(); } // ---------------------------------------------------------------------------- @@ -2318,7 +2345,7 @@ wxSize wxTextCtrl::DoGetBestClientSize() const lines = 5; else if ( lines > 10 ) lines = 10; - h *= 10; + h *= lines; } wxRect rectText; @@ -2433,7 +2460,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 +3586,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 +3594,7 @@ void wxTextCtrl::OnIdle(wxIdleEvent& event) { UpdateScrollbars(); } - - event.Skip(); + wxControl::OnInternalIdle(); } bool wxTextCtrl::SendAutoScrollEvents(wxScrollWinEvent& event) const @@ -4105,6 +4131,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 +4196,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 +4239,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 +4278,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); } } @@ -4890,14 +4922,26 @@ bool wxStdTextCtrlInputHandler::HandleMouseMove(wxInputConsumer *consumer, return wxStdInputHandler::HandleMouseMove(consumer, event); } -bool wxStdTextCtrlInputHandler::HandleFocus(wxInputConsumer *consumer, - const wxFocusEvent& event) +bool +wxStdTextCtrlInputHandler::HandleFocus(wxInputConsumer *consumer, + const wxFocusEvent& event) { 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; }