X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9d7de3c2b84dc40d969d5f993247df02c18b3d3f..cf31a1d7b60feddf23cc30259c6d909d4736ca56:/src/msw/textctrl.cpp diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 27a8a37462..c1511e337f 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -438,12 +438,16 @@ void wxTextCtrl::SetValue(const wxString& value) WriteText(value); + // mark the control as being not dirty - we changed its text, not the + // user + DiscardEdits(); + // for compatibility, don't move the cursor when doing SetValue() SetInsertionPoint(0); } } -#if wxUSE_RICHEDIT && !wxUSE_UNICODE +#if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU) DWORD CALLBACK wxRichEditStreamIn(DWORD dwCookie, BYTE *buf, LONG cb, LONG *pcb) { @@ -466,6 +470,11 @@ DWORD CALLBACK wxRichEditStreamIn(DWORD dwCookie, BYTE *buf, LONG cb, LONG *pcb) extern long wxEncodingToCodepage(wxFontEncoding encoding); // from strconv.cpp +#if wxUSE_UNICODE_MSLU +bool wxTextCtrl::StreamIn(const wxString& value, wxFontEncoding WXUNUSED(encoding)) +{ + const wchar_t *wpc = value.c_str(); +#else bool wxTextCtrl::StreamIn(const wxString& value, wxFontEncoding encoding) { // we have to use EM_STREAMIN to force richedit control 2.0+ to show any @@ -491,6 +500,7 @@ bool wxTextCtrl::StreamIn(const wxString& value, wxFontEncoding encoding) // finally, stream it in the control const wchar_t *wpc = wchBuf; +#endif // wxUSE_UNICODE_MSLU EDITSTREAM eds; wxZeroMemory(eds); @@ -526,8 +536,17 @@ void wxTextCtrl::WriteText(const wxString& value) { long start, end; GetSelection(&start, &end); - SetStyle(start, end, m_defaultStyle ); + SetStyle(start, end, m_defaultStyle); + } + +#if wxUSE_UNICODE_MSLU + // RichEdit doesn't have Unicode version of EM_REPLACESEL on Win9x, + // but EM_STREAMIN works + if ( wxGetOsVersion() == wxWIN95 && GetRichVersion() > 1 ) + { + done = StreamIn(valueDos, wxFONTENCODING_SYSTEM); } +#endif // wxUSE_UNICODE_MSLU #if !wxUSE_UNICODE // next check if the text we're inserting must be shown in a non @@ -655,14 +674,6 @@ void wxTextCtrl::SetEditable(bool editable) void wxTextCtrl::SetInsertionPoint(long pos) { SetSelection(pos, pos); - -#if wxUSE_RICHEDIT - if ( !IsRich() ) -#endif - { - static const wxChar *nothing = _T(""); - SendMessage(GetHwnd(), EM_REPLACESEL, 0, (LPARAM)nothing); - } } void wxTextCtrl::SetInsertionPointEnd() @@ -802,7 +813,41 @@ void wxTextCtrl::DoSetSelection(long from, long to, bool scrollCaret) if ( scrollCaret ) { +#if wxUSE_RICHEDIT + // EM_SCROLLCARET doesn't work for me with the richedit controls + // unless it has focus although I don't see any mention of it in the + // docs - this is the only workaround I found. Of course it's not + // perfect as it adds the dummy focus set/kill events but it's still + // better than nothing + HWND hwndFocusOld; + if ( IsRich() ) + { + hwndFocusOld = ::GetFocus(); + if ( hwndFocusOld == GetHwnd() ) + { + // don't change focus + hwndFocusOld = 0; + } + + if ( hwndFocusOld ) + { + ::SetFocus(GetHwnd()); + } + } + else // not rich + { + hwndFocusOld = 0; + } +#endif // wxUSE_RICHEDIT + SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0); + +#if wxUSE_RICHEDIT + if ( hwndFocusOld ) + { + ::SetFocus(hwndFocusOld); + } +#endif // wxUSE_RICHEDIT } #else // Win16 // WPARAM is 0: selection is scrolled into view @@ -817,7 +862,7 @@ void wxTextCtrl::DoSetSelection(long from, long to, bool scrollCaret) void wxTextCtrl::Replace(long from, long to, const wxString& value) { // Set selection and remove it - DoSetSelection(from, to, FALSE); + DoSetSelection(from, to, FALSE /* don't scroll caret into view */); SendMessage(GetHwnd(), EM_REPLACESEL, #ifdef __WIN32__ @@ -1505,7 +1550,7 @@ bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) if ( changeSel ) { - DoSetSelection(start, end, FALSE); + DoSetSelection(start, end, FALSE /* don't scroll caret into view */); } // initialize CHARFORMAT struct