From 59396417d3285f933762d252d33ed095e6ffe299 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 4 Nov 2007 23:08:26 +0000 Subject: [PATCH] added wxTextEntry::AutoCompleteFileNames() and implemented it for wxMSW git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49634 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 +- docs/latex/wx/text.tex | 31 +++++++++++++++++++++++++++++++ include/wx/msw/textentry.h | 2 ++ include/wx/textentry.h | 15 ++++++++++++++- src/msw/textentry.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index acacf85aa8..da71f63bd3 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -185,7 +185,7 @@ All (Unix): All (GUI): -- Added wxTextCtrl::AutoComplete() +- Added {wxTextCtrl,wxComboBox}::AutoComplete() and AutoCompleteFileNames() - Added wxH[V]ScrolledWindow (Brad Anderson, Bryan Petty). - Added wxDC::StretchBlit() for wxMac and wxMSW (Vince Harron). - Added support for drop down toolbar buttons (Tim Kosse). diff --git a/docs/latex/wx/text.tex b/docs/latex/wx/text.tex index 49dcf82973..142962440f 100644 --- a/docs/latex/wx/text.tex +++ b/docs/latex/wx/text.tex @@ -340,6 +340,37 @@ nothing under the other platforms. \newsince{2.9.0} +\wxheading{Return value} + +\true if the auto-completion was enabled or \false if the operation failed, +typically because auto-completion is not supported by the current platform. + +\wxheading{See also} + +\helpref{AutoCompleteFileNames}{wxtextctrlautocompletefilenames} + + +\membersection{wxTextCtrl::AutoCompleteFileNames}\label{wxtextctrlautocompletefilenames} + +\func{bool}{AutoCompleteFileNames}{\void} + +Call this function to enable auto-completion of the text typed in a single-line +text control using all valid file system paths. + +Notice that currently this function is only implemented in wxGTK2 port and does +nothing under the other platforms. + +\newsince{2.9.0} + +\wxheading{Return value} + +\true if the auto-completion was enabled or \false if the operation failed, +typically because auto-completion is not supported by the current platform. + +\wxheading{See also} + +\helpref{AutoComplete}{wxtextctrlautocomplete} + \membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy} diff --git a/include/wx/msw/textentry.h b/include/wx/msw/textentry.h index a39139df66..5466710e1e 100644 --- a/include/wx/msw/textentry.h +++ b/include/wx/msw/textentry.h @@ -42,6 +42,8 @@ public: { DoSetSelection(from, to); } virtual void GetSelection(long *from, long *to) const; + virtual bool AutoCompleteFileNames(); + virtual bool IsEditable() const; virtual void SetEditable(bool editable); diff --git a/include/wx/textentry.h b/include/wx/textentry.h index 4ac40164d9..6643ceed52 100644 --- a/include/wx/textentry.h +++ b/include/wx/textentry.h @@ -98,7 +98,20 @@ public: // auto-completion // --------------- - virtual void AutoComplete(const wxArrayString& WXUNUSED(choices)) { } + // these functions allow to auto-complete the text already entered into the + // control using either the given fixed list of strings, the paths from the + // file system or, in the future, an arbitrary user-defined completer + // + // they all return true if completion was enabled or false on error (most + // commonly meaning that this functionality is not available under the + // current platform) + + virtual bool AutoComplete(const wxArrayString& WXUNUSED(choices)) + { + return false; + } + + virtual bool AutoCompleteFileNames() { return false; } // status diff --git a/src/msw/textentry.cpp b/src/msw/textentry.cpp index e08b413d17..5e38009dde 100644 --- a/src/msw/textentry.cpp +++ b/src/msw/textentry.cpp @@ -30,9 +30,14 @@ #if wxUSE_TEXTCTRL || wxUSE_COMBOBOX #include "wx/textentry.h" +#include "wx/dynlib.h" #include "wx/msw/private.h" +#ifndef SHACF_FILESYS_ONLY + #define SHACF_FILESYS_ONLY 0x00000010 +#endif + #define GetEditHwnd() ((HWND)(GetEditHWND())) // ============================================================================ @@ -135,6 +140,39 @@ void wxTextEntry::GetSelection(long *from, long *to) const *to = dwEnd; } +bool wxTextEntry::AutoCompleteFileNames() +{ + 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) ) + { + s_pfnSHAutoComplete = NULL; + } + else + { + wxDL_INIT_FUNC(s_pfn, SHAutoComplete, s_dllShlwapi); + } + } + + if ( !s_pfnSHAutoComplete ) + return false; + + HRESULT hr = (*s_pfnSHAutoComplete)(GetEditHwnd(), SHACF_FILESYS_ONLY); + if ( FAILED(hr) ) + { + wxLogApiError(_T("SHAutoComplete()"), hr); + + return false; + } + + return true; +} + bool wxTextEntry::IsEditable() const { return !(::GetWindowLong(GetEditHwnd(), GWL_STYLE) & ES_READONLY);