X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/96506d1d5826c388c94ce36bbafac516fb8cdbfd..ba8ac2c7c30f6a18ac1fae70162be008c3fc378d:/src/msw/textentry.cpp diff --git a/src/msw/textentry.cpp b/src/msw/textentry.cpp index e3afd0eae0..5e1b753ee7 100644 --- a/src/msw/textentry.cpp +++ b/src/msw/textentry.cpp @@ -35,18 +35,27 @@ #include "wx/msw/private.h" +#if wxUSE_UXTHEME + #include "wx/msw/uxtheme.h" +#endif + #define GetEditHwnd() ((HWND)(GetEditHWND())) // ---------------------------------------------------------------------------- // wxIEnumString implements IEnumString interface // ---------------------------------------------------------------------------- -#if wxUSE_OLE +// standard VC6 SDK (WINVER == 0x0400) does not know about IAutoComplete +#if wxUSE_OLE && (WINVER >= 0x0500) + #define HAS_AUTOCOMPLETE +#endif + +#ifdef HAS_AUTOCOMPLETE #include "wx/msw/ole/oleutils.h" #include -#if defined(__MINGW32__) +#if defined(__MINGW32__) || defined (__WATCOMC__) // needed for IID_IAutoComplete, IID_IAutoComplete2 and ACO_AUTOSUGGEST #include #endif @@ -90,7 +99,7 @@ public: if ( m_index == count ) return S_FALSE; - const wxWX2WCbuf wcbuf(m_strings[m_index].wc_str()); + const wxWX2WCbuf wcbuf = m_strings[m_index].wc_str(); const size_t size = (wcslen(wcbuf) + 1)*sizeof(wchar_t); void *olestr = CoTaskMemAlloc(size); if ( !olestr ) @@ -98,7 +107,7 @@ public: memcpy(olestr, wcbuf, size); - *rgelt++ = wx_static_cast(LPOLESTR, olestr); + *rgelt++ = static_cast(olestr); ++(*pceltFetched); } @@ -140,10 +149,17 @@ public: } private: + // dtor doesn't have to be virtual as we're only ever deleted from our own + // Release() and are not meant to be derived form anyhow, but making it + // virtual silences gcc warnings; making it private makes it impossible to + // (mistakenly) delete us directly instead of calling Release() + virtual ~wxIEnumString() { } + + const wxArrayString m_strings; unsigned m_index; - DECLARE_NO_COPY_CLASS(wxIEnumString) + wxDECLARE_NO_COPY_CLASS(wxIEnumString); }; BEGIN_IID_TABLE(wxIEnumString) @@ -153,7 +169,7 @@ END_IID_TABLE; IMPLEMENT_IUNKNOWN_METHODS(wxIEnumString) -#endif // wxUSE_OLE +#endif // HAS_AUTOCOMPLETE // ============================================================================ // wxTextEntry implementation @@ -168,7 +184,7 @@ void wxTextEntry::WriteText(const wxString& text) ::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str()); } -wxString wxTextEntry::GetValue() const +wxString wxTextEntry::DoGetValue() const { return wxGetWindowText(GetEditHWND()); } @@ -231,6 +247,11 @@ bool wxTextEntry::CanRedo() const void wxTextEntry::SetInsertionPoint(long pos) { + // calling DoSetSelection(-1, -1) would select everything which is not what + // we want here + if ( pos == -1 ) + pos = GetLastPosition(); + // be careful to call DoSetSelection() which is overridden in wxTextCtrl // and not just SetSelection() here DoSetSelection(pos, pos); @@ -276,17 +297,15 @@ void wxTextEntry::GetSelection(long *from, long *to) const // ---------------------------------------------------------------------------- #if wxUSE_OLE - bool wxTextEntry::AutoCompleteFileNames() { +#ifdef HAS_AUTOCOMPLETE typedef HRESULT (WINAPI *SHAutoComplete_t)(HWND, DWORD); static SHAutoComplete_t s_pfnSHAutoComplete = (SHAutoComplete_t)-1; static wxDynamicLibrary s_dllShlwapi; if ( s_pfnSHAutoComplete == (SHAutoComplete_t)-1 ) { - wxLogNull noLog; - - if ( !s_dllShlwapi.Load(_T("shlwapi.dll"), wxDL_VERBATIM) ) + if ( !s_dllShlwapi.Load(_T("shlwapi.dll"), wxDL_VERBATIM | wxDL_QUIET) ) { s_pfnSHAutoComplete = NULL; } @@ -306,12 +325,15 @@ bool wxTextEntry::AutoCompleteFileNames() return false; } - return true; +#else // !HAS_AUTOCOMPLETE + return false; +#endif // HAS_AUTOCOMPLETE/!HAS_AUTOCOMPLETE } bool wxTextEntry::AutoComplete(const wxArrayString& choices) { +#ifdef HAS_AUTOCOMPLETE // create an object exposing IAutoComplete interface (don't go for // IAutoComplete2 immediately as, presumably, it might be not available on // older systems as otherwise why do we have both -- although in practice I @@ -323,7 +345,7 @@ bool wxTextEntry::AutoComplete(const wxArrayString& choices) NULL, CLSCTX_INPROC_SERVER, IID_IAutoComplete, - wx_reinterpret_cast(void **, &pAutoComplete) + reinterpret_cast(&pAutoComplete) ); if ( FAILED(hr) ) { @@ -347,7 +369,7 @@ bool wxTextEntry::AutoComplete(const wxArrayString& choices) hr = pAutoComplete->QueryInterface ( IID_IAutoComplete2, - wx_reinterpret_cast(void **, &pAutoComplete2) + reinterpret_cast(&pAutoComplete2) ); if ( SUCCEEDED(hr) ) { @@ -359,10 +381,13 @@ bool wxTextEntry::AutoComplete(const wxArrayString& choices) // do it immediately, presumably the edit control itself keeps a reference // to the auto completer object pAutoComplete->Release(); - return true; -} +#else // !HAS_AUTOCOMPLETE + wxUnusedVar(choices); + return false; +#endif // HAS_AUTOCOMPLETE/!HAS_AUTOCOMPLETE +} #endif // wxUSE_OLE // ---------------------------------------------------------------------------- @@ -395,4 +420,44 @@ void wxTextEntry::SetMaxLength(unsigned long len) ::SendMessage(GetEditHwnd(), EM_LIMITTEXT, len, 0); } +// ---------------------------------------------------------------------------- +// hints +// ---------------------------------------------------------------------------- + +#if wxUSE_UXTHEME + +#ifndef EM_SETCUEBANNER + #define EM_SETCUEBANNER 0x1501 + #define EM_GETCUEBANNER 0x1502 +#endif + +bool wxTextEntry::SetHint(const wxString& hint) +{ + if ( wxUxThemeEngine::GetIfActive() ) + { + // notice that this message always works with Unicode strings + if ( ::SendMessage(GetEditHwnd(), EM_SETCUEBANNER, + 0, (LPARAM)(const wchar_t *)hint.wc_str()) ) + return true; + } + + return wxTextEntryBase::SetHint(hint); +} + +wxString wxTextEntry::GetHint() const +{ + if ( wxUxThemeEngine::GetIfActive() ) + { + wchar_t buf[256]; + if ( ::SendMessage(GetEditHwnd(), EM_GETCUEBANNER, + (WPARAM)buf, WXSIZEOF(buf)) ) + return wxString(buf); + } + + return wxTextEntryBase::GetHint(); +} + + +#endif // wxUSE_UXTHEME + #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX