From: Vadim Zeitlin Date: Sat, 27 Aug 2011 14:11:13 +0000 (+0000) Subject: Add wxTextEntry::AutoCompleteDirectories(). X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/03dede4dc15796ab5e3e49ef597ebbc461227bca Add wxTextEntry::AutoCompleteDirectories(). As we already had MSW-specific AutoCompleteFileNames(), we can just as well also add the also useful AutoCompleteDirectories() to be used with the text controls used for path entry. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68918 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index b6a0760c70..2789e3526c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -456,6 +456,7 @@ All (GUI): - Added wxTextCtrl::PositionToCoords() (Navaneeth). - Added support for wxHELP button to wxMessageDialog. - Added wxBannerWindow class. +- Added wxTextEntry::AutoCompleteDirectories(). - Support float, double and file name values in wxGenericValidator (troelsk). - Fix keyboard navigation in wxGrid with hidden columns (ivan_14_32). - Add wxDataViewEvent::IsEditCancelled() (Allonii). diff --git a/include/wx/msw/textentry.h b/include/wx/msw/textentry.h index a2f5f95be5..c42ef8d89d 100644 --- a/include/wx/msw/textentry.h +++ b/include/wx/msw/textentry.h @@ -75,7 +75,7 @@ protected: // wxUSE_OLE as OleInitialize() is not called then #if wxUSE_OLE virtual bool DoAutoCompleteStrings(const wxArrayString& choices); - virtual bool DoAutoCompleteFileNames(); + virtual bool DoAutoCompleteFileNames(int flags); virtual bool DoAutoCompleteCustom(wxTextCompleter *completer); #endif // wxUSE_OLE diff --git a/include/wx/textentry.h b/include/wx/textentry.h index 7601444ca8..2ede40d714 100644 --- a/include/wx/textentry.h +++ b/include/wx/textentry.h @@ -20,6 +20,7 @@ class WXDLLIMPEXP_FWD_CORE wxTextCompleter; class WXDLLIMPEXP_FWD_CORE wxTextEntryHintData; class WXDLLIMPEXP_FWD_CORE wxWindow; +#include "wx/filefn.h" // for wxFILE and wxDIR only #include "wx/gdicmn.h" // for wxPoint // ---------------------------------------------------------------------------- @@ -117,7 +118,10 @@ public: { return DoAutoCompleteStrings(choices); } bool AutoCompleteFileNames() - { return DoAutoCompleteFileNames(); } + { return DoAutoCompleteFileNames(wxFILE); } + + bool AutoCompleteDirectories() + { return DoAutoCompleteFileNames(wxDIR); } // notice that we take ownership of the pointer and will delete it // @@ -230,7 +234,8 @@ protected: // the other one(s) virtual bool DoAutoCompleteStrings(const wxArrayString& WXUNUSED(choices)) { return false; } - virtual bool DoAutoCompleteFileNames() { return false; } + virtual bool DoAutoCompleteFileNames(int WXUNUSED(flags)) // wxFILE | wxDIR + { return false; } virtual bool DoAutoCompleteCustom(wxTextCompleter *completer); diff --git a/interface/wx/textentry.h b/interface/wx/textentry.h index a2c7b7f8b6..b1b6a5d5cf 100644 --- a/interface/wx/textentry.h +++ b/interface/wx/textentry.h @@ -112,6 +112,27 @@ public: */ bool AutoCompleteFileNames(); + /** + Call this function to enable auto-completion of the text using the file + system directories. + + Unlike AutoCompleteFileNames() which completes both file names and + directories, this function only completes the directory names. + + Notice that currently this function is only implemented in wxMSW port + and does nothing under the other platforms. + + @since 2.9.3 + + @return + @true if the auto-completion was enabled or @false if the operation + failed, typically because auto-completion is not supported by the + current platform. + + @see AutoComplete() + */ + bool AutoCompleteDirectories(); + /** Returns @true if the selection can be copied to the clipboard. */ diff --git a/samples/widgets/widgets.cpp b/samples/widgets/widgets.cpp index 84943cbff7..7e54947dbd 100644 --- a/samples/widgets/widgets.cpp +++ b/samples/widgets/widgets.cpp @@ -99,6 +99,7 @@ enum TextEntry_DisableAutoComplete = TextEntry_Begin, TextEntry_AutoCompleteFixed, TextEntry_AutoCompleteFilenames, + TextEntry_AutoCompleteDirectories, TextEntry_AutoCompleteCustom, TextEntry_SetHint, @@ -174,6 +175,7 @@ protected: void OnDisableAutoComplete(wxCommandEvent& event); void OnAutoCompleteFixed(wxCommandEvent& event); void OnAutoCompleteFilenames(wxCommandEvent& event); + void OnAutoCompleteDirectories(wxCommandEvent& event); void OnAutoCompleteCustom(wxCommandEvent& event); void OnSetHint(wxCommandEvent& event); @@ -303,6 +305,7 @@ BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame) EVT_MENU(TextEntry_DisableAutoComplete, WidgetsFrame::OnDisableAutoComplete) EVT_MENU(TextEntry_AutoCompleteFixed, WidgetsFrame::OnAutoCompleteFixed) EVT_MENU(TextEntry_AutoCompleteFilenames, WidgetsFrame::OnAutoCompleteFilenames) + EVT_MENU(TextEntry_AutoCompleteDirectories, WidgetsFrame::OnAutoCompleteDirectories) EVT_MENU(TextEntry_AutoCompleteCustom, WidgetsFrame::OnAutoCompleteCustom) EVT_MENU(TextEntry_SetHint, WidgetsFrame::OnSetHint) @@ -418,6 +421,8 @@ WidgetsFrame::WidgetsFrame(const wxString& title) wxT("Fixed-&list auto-completion")); menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteFilenames, wxT("&Files names auto-completion")); + menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteDirectories, + wxT("&Directories names auto-completion")); menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteCustom, wxT("&Custom auto-completion")); menuTextEntry->AppendSeparator(); @@ -995,6 +1000,21 @@ void WidgetsFrame::OnAutoCompleteFilenames(wxCommandEvent& WXUNUSED(event)) } } +void WidgetsFrame::OnAutoCompleteDirectories(wxCommandEvent& WXUNUSED(event)) +{ + wxTextEntryBase *entry = CurrentPage()->GetTextEntry(); + wxCHECK_RET( entry, "menu item should be disabled" ); + + if ( entry->AutoCompleteDirectories() ) + { + wxLogMessage("Enabled auto completion of directories."); + } + else + { + wxLogMessage("AutoCompleteDirectories() failed."); + } +} + void WidgetsFrame::OnAutoCompleteCustom(wxCommandEvent& WXUNUSED(event)) { wxTextEntryBase *entry = CurrentPage()->GetTextEntry(); diff --git a/src/msw/textentry.cpp b/src/msw/textentry.cpp index 77bc4cd1bc..e993654d24 100644 --- a/src/msw/textentry.cpp +++ b/src/msw/textentry.cpp @@ -75,6 +75,10 @@ #define SHACF_FILESYS_ONLY 0x00000010 #endif +#ifndef SHACF_FILESYS_DIRS + #define SHACF_FILESYS_DIRS 0x00000020 +#endif + namespace { @@ -740,7 +744,7 @@ void wxTextEntry::GetSelection(long *from, long *to) const #ifdef HAS_AUTOCOMPLETE -bool wxTextEntry::DoAutoCompleteFileNames() +bool wxTextEntry::DoAutoCompleteFileNames(int flags) { typedef HRESULT (WINAPI *SHAutoComplete_t)(HWND, DWORD); static SHAutoComplete_t s_pfnSHAutoComplete = (SHAutoComplete_t)-1; @@ -760,7 +764,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); @@ -833,9 +848,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)