X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/32bd17fcb5c038bb4e64ac1b849cbb8175f29cad..43f4e852a1b2ac37c3db6a2b87315192ac549191:/src/msw/textentry.cpp?ds=sidebyside diff --git a/src/msw/textentry.cpp b/src/msw/textentry.cpp index be0e6dbb45..a91e8f33ca 100644 --- a/src/msw/textentry.cpp +++ b/src/msw/textentry.cpp @@ -34,6 +34,8 @@ #include "wx/textcompleter.h" #include "wx/dynlib.h" +#include + #include "wx/msw/private.h" #if wxUSE_UXTHEME @@ -55,11 +57,14 @@ #include "wx/msw/ole/oleutils.h" #include -#include #if defined(__MINGW32__) || defined (__WATCOMC__) || defined(__CYGWIN__) // needed for IID_IAutoComplete, IID_IAutoComplete2 and ACO_AUTOSUGGEST #include + + #ifndef ACO_AUTOAPPEND + #define ACO_AUTOAPPEND 0x02 + #endif #endif #ifndef ACO_UPDOWNKEYDROPSLIST @@ -70,12 +75,31 @@ #define SHACF_FILESYS_ONLY 0x00000010 #endif -DEFINE_GUID(CLSID_AutoComplete, - 0x00bb2763, 0x6a77, 0x11d0, 0xa5, 0x35, 0x00, 0xc0, 0x4f, 0xd7, 0xd0, 0x62); +#ifndef SHACF_FILESYS_DIRS + #define SHACF_FILESYS_DIRS 0x00000020 +#endif namespace { +// Normally this interface and its IID are defined in shobjidl.h header file +// included in the platform SDK but MinGW and Cygwin don't have it so redefine +// the interface ourselves and, as long as we do it all, do it for all +// compilers to ensure we have the same behaviour for all of them and to avoid +// the need to check for concrete compilers and maybe even their versions. +class IAutoCompleteDropDown : public IUnknown +{ +public: + virtual HRESULT wxSTDCALL GetDropDownStatus(DWORD *, LPWSTR *) = 0; + virtual HRESULT wxSTDCALL ResetEnumerator() = 0; +}; + +DEFINE_GUID(wxIID_IAutoCompleteDropDown, + 0x3cd141f4, 0x3c6a, 0x11d2, 0xbc, 0xaa, 0x00, 0xc0, 0x4f, 0xd9, 0x29, 0xdb); + +DEFINE_GUID(wxCLSID_AutoComplete, + 0x00bb2763, 0x6a77, 0x11d0, 0xa5, 0x35, 0x00, 0xc0, 0x4f, 0xd7, 0xd0, 0x62); + // Small helper class which can be used to ensure thread safety even when // wxUSE_THREADS==0 (and hence wxCriticalSection does nothing). class CSLock @@ -349,7 +373,7 @@ public: // apparently. HRESULT hr = CoCreateInstance ( - CLSID_AutoComplete, + wxCLSID_AutoComplete, NULL, CLSCTX_INPROC_SERVER, IID_IAutoComplete, @@ -384,7 +408,7 @@ public: // provided IAutoComplete always implements IAutoCompleteDropDown too. hr = m_autoComplete->QueryInterface ( - IID_IAutoCompleteDropDown, + wxIID_IAutoCompleteDropDown, reinterpret_cast(&m_autoCompleteDropDown) ); if ( FAILED(hr) ) @@ -494,27 +518,6 @@ public: } private: - // Trivial wxTextCompleter implementation which always returns the same - // fixed array of completions. - class wxTextCompleterFixed : public wxTextCompleterSimple - { - public: - void SetCompletions(const wxArrayString& strings) - { - m_strings = strings; - } - - virtual void GetCompletions(const wxString& WXUNUSED(prefix), - wxArrayString& res) - { - res = m_strings; - } - - private: - wxArrayString m_strings; - }; - - // Must be called after changing the values to be returned by wxIEnumString // to really make the changes stick. void DoRefresh() @@ -622,7 +625,7 @@ wxTextEntry::~wxTextEntry() void wxTextEntry::WriteText(const wxString& text) { - ::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str()); + ::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, wxMSW_CONV_LPARAM(text)); } wxString wxTextEntry::DoGetValue() const @@ -741,7 +744,9 @@ void wxTextEntry::GetSelection(long *from, long *to) const #ifdef HAS_AUTOCOMPLETE -bool wxTextEntry::DoAutoCompleteFileNames() +#if wxUSE_DYNLIB_CLASS + +bool wxTextEntry::DoAutoCompleteFileNames(int flags) { typedef HRESULT (WINAPI *SHAutoComplete_t)(HWND, DWORD); static SHAutoComplete_t s_pfnSHAutoComplete = (SHAutoComplete_t)-1; @@ -761,7 +766,18 @@ bool wxTextEntry::DoAutoCompleteFileNames() if ( !s_pfnSHAutoComplete ) return false; - HRESULT hr = (*s_pfnSHAutoComplete)(GetEditHwnd(), SHACF_FILESYS_ONLY); + DWORD dwFlags = 0; + if ( flags & wxFILE ) + dwFlags |= SHACF_FILESYS_ONLY; + else if ( flags & wxDIR ) + dwFlags |= SHACF_FILESYS_DIRS; + else + { + wxFAIL_MSG(wxS("No flags for file name auto completion?")); + return false; + } + + HRESULT hr = (*s_pfnSHAutoComplete)(GetEditHwnd(), dwFlags); if ( FAILED(hr) ) { wxLogApiError(wxT("SHAutoComplete()"), hr); @@ -777,6 +793,8 @@ bool wxTextEntry::DoAutoCompleteFileNames() return true; } +#endif // wxUSE_DYNLIB_CLASS + wxTextAutoCompleteData *wxTextEntry::GetOrCreateCompleter() { if ( !m_autoCompleteData ) @@ -834,9 +852,9 @@ bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer) // We still need to define stubs as we declared these overrides in the header. -bool wxTextEntry::DoAutoCompleteFileNames() +bool wxTextEntry::DoAutoCompleteFileNames(int flags) { - return wxTextEntryBase::DoAutoCompleteFileNames(); + return wxTextEntryBase::DoAutoCompleteFileNames(flags); } bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString& choices) @@ -846,7 +864,7 @@ bool wxTextEntry::DoAutoCompleteStrings(const wxArrayString& choices) bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer) { - return wxTextCompleter::DoAutoCompleteCustom(completer); + return wxTextEntryBase::DoAutoCompleteCustom(completer); } #endif // HAS_AUTOCOMPLETE/!HAS_AUTOCOMPLETE @@ -938,9 +956,12 @@ bool wxTextEntry::DoSetMargins(const wxPoint& margins) if ( margins.x != -1 ) { - // left margin + // Set both horizontal margins to the given value, we don't distinguish + // between left and right margin at wx API level and it seems to be + // better to change both of them than only left one. ::SendMessage(GetEditHwnd(), EM_SETMARGINS, - EC_LEFTMARGIN, MAKELONG(margins.x, 0)); + EC_LEFTMARGIN | EC_RIGHTMARGIN, + MAKELONG(margins.x, margins.x)); } if ( margins.y != -1 )