X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5bf75ae769e352f9f47cc967e67470e35256ca18..6151e1445bdca0dfca660e3851aa3705bfd543de:/src/msw/textctrl.cpp diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 14801b5eac..6e285fabad 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -177,7 +177,9 @@ void wxTextCtrl::Init() { #if wxUSE_RICHEDIT m_verRichEdit = 0; -#endif + + m_suppressNextUpdate = FALSE; +#endif // wxUSE_RICHEDIT } bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, @@ -300,9 +302,9 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, #if wxUSE_RICHEDIT if ( IsRich() ) { - // enable the events we're interested in: we want to get EN_CHANGE and - // EN_UPDATE as for the normal controls - LPARAM mask = ENM_CHANGE | ENM_UPDATE; + // enable the events we're interested in: we want to get EN_CHANGE as + // for the normal controls + LPARAM mask = ENM_CHANGE; if ( GetRichVersion() == 1 ) { @@ -551,6 +553,15 @@ DWORD CALLBACK wxRichEditStreamIn(DWORD dwCookie, BYTE *buf, LONG cb, LONG *pcb) extern long wxEncodingToCodepage(wxFontEncoding encoding); // from utils.cpp +#ifdef __WXWINE__ +bool wxTextCtrl::StreamIn(const wxString& value, + wxFontEncoding WXUNUSED(encoding), + bool selectionOnly) +{ + return FALSE; +} +#else + #if wxUSE_UNICODE_MSLU bool wxTextCtrl::StreamIn(const wxString& value, wxFontEncoding WXUNUSED(encoding), @@ -615,6 +626,9 @@ bool wxTextCtrl::StreamIn(const wxString& value, return TRUE; } +#endif + // __WXWINE__ + #endif // wxUSE_RICHEDIT void wxTextCtrl::WriteText(const wxString& value) @@ -652,7 +666,7 @@ void wxTextCtrl::DoWriteText(const wxString& value, bool selectionOnly) } #endif // wxUSE_UNICODE_MSLU -#if !wxUSE_UNICODE +#if !wxUSE_UNICODE && !defined(__WXWINE__) // next check if the text we're inserting must be shown in a non // default charset -- this only works for RichEdit > 1.0 if ( GetRichVersion() > 1 ) @@ -676,15 +690,18 @@ void wxTextCtrl::DoWriteText(const wxString& value, bool selectionOnly) if ( !done ) #endif // wxUSE_RICHEDIT { - if ( !selectionOnly ) +#if wxUSE_RICHEDIT + // rich edit text control sends us 2 EN_CHANGE events when we send + // WM_SETTEXT to it, we have to suppress one of them to make wxTextCtrl + // behaviour consistent + if ( IsRich() ) { - //SetSelection(-1, -1); - // This eliminates an annoying flashing effect - // when replacing all text. - Clear(); + m_suppressNextUpdate = TRUE; } +#endif // wxUSE_RICHEDIT - ::SendMessage(GetHwnd(), EM_REPLACESEL, 0, (LPARAM)valueDos.c_str()); + ::SendMessage(GetHwnd(), selectionOnly ? EM_REPLACESEL : WM_SETTEXT, + 0, (LPARAM)valueDos.c_str()); } AdjustSpaceLimit(); @@ -700,6 +717,16 @@ void wxTextCtrl::AppendText(const wxString& text) void wxTextCtrl::Clear() { ::SetWindowText(GetHwnd(), wxT("")); + +#if wxUSE_RICHEDIT + if ( !IsRich() ) +#endif // wxUSE_RICHEDIT + { + // rich edit controls send EN_UPDATE from WM_SETTEXT handler themselves + // but the normal ones don't -- make Clear() behaviour consistent by + // always sending this event + SendUpdateEvent(); + } } #ifdef __WIN32__ @@ -1162,24 +1189,42 @@ bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* pMsg) } else // no Alt { - if ( wxIsCtrlDown() ) - { - switch ( vkey ) - { - case 'C': - case 'V': - case 'X': - case VK_INSERT: - case VK_DELETE: - case VK_HOME: - case VK_END: - return FALSE; - } - } - else if ( wxIsShiftDown() ) + // we want to process some Ctrl-foo and Shift-bar but no key + // combinations without either Ctrl or Shift nor with both of them + // pressed + const int ctrl = wxIsCtrlDown(), + shift = wxIsShiftDown(); + switch ( ctrl + shift ) { - if ( vkey == VK_INSERT || vkey == VK_DELETE ) - return FALSE; + default: + wxFAIL_MSG( _T("how many modifiers have we got?") ); + // fall through + + case 0: + case 2: + break; + + case 1: + // either Ctrl or Shift pressed + if ( ctrl ) + { + switch ( vkey ) + { + case 'C': + case 'V': + case 'X': + case VK_INSERT: + case VK_DELETE: + case VK_HOME: + case VK_END: + return FALSE; + } + } + else // Shift is pressed + { + if ( vkey == VK_INSERT || vkey == VK_DELETE ) + return FALSE; + } } } } @@ -1260,9 +1305,27 @@ long wxTextCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) // text control event processing // ---------------------------------------------------------------------------- +bool wxTextCtrl::SendUpdateEvent() +{ + // is event reporting suspended? + if ( m_suppressNextUpdate ) + { + // do process the next one + m_suppressNextUpdate = FALSE; + + return FALSE; + } + + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId()); + InitCommandEvent(event); + event.SetString(GetValue()); + + return ProcessCommand(event); +} + bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { - switch (param) + switch ( param ) { case EN_SETFOCUS: case EN_KILLFOCUS: @@ -1270,22 +1333,17 @@ bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS : wxEVT_SET_FOCUS, m_windowId); - event.SetEventObject( this ); + event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); } break; case EN_CHANGE: - { - wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); - InitCommandEvent(event); - event.SetString(GetValue()); - ProcessCommand(event); - } + SendUpdateEvent(); break; case EN_MAXTEXT: - // the text size limit has been hit - increase it + // the text size limit has been hit -- try to increase it if ( !AdjustSpaceLimit() ) { wxCommandEvent event(wxEVT_COMMAND_TEXT_MAXLEN, m_windowId); @@ -1295,13 +1353,7 @@ bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) } break; - // the other notification messages are not processed - case EN_UPDATE: - case EN_ERRSPACE: - case EN_HSCROLL: - case EN_VSCROLL: - return FALSE; - + // the other edit notification messages are not processed default: return FALSE; } @@ -1516,10 +1568,11 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) bool wxTextCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) { +#ifndef __WXWINE__ NMHDR *hdr = (NMHDR* )lParam; switch ( hdr->code ) { - case EN_MSGFILTER: + case EN_MSGFILTER: { const MSGFILTER *msgf = (MSGFILTER *)lParam; UINT msg = msgf->msg; @@ -1602,7 +1655,8 @@ bool wxTextCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) } return TRUE; } - +#endif + // not processed, leave it to the base class return wxTextCtrlBase::MSWOnNotify(idCtrl, lParam, result); } @@ -1655,8 +1709,13 @@ bool wxTextCtrl::SetForegroundColour(const wxColour& colour) // styling support for rich edit controls // ---------------------------------------------------------------------------- +#if wxUSE_RICHEDIT + bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) { +#ifdef __WXWINE__ + return FALSE; +#else if ( !IsRich() ) { // can't do it with normal text control @@ -1786,6 +1845,7 @@ bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) } return ok; +#endif } bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) @@ -1801,6 +1861,8 @@ bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) return TRUE; } +#endif + // ---------------------------------------------------------------------------- // wxRichEditModule // ----------------------------------------------------------------------------