From 5f6475c145b713efc0c3d8b482338438e927b763 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 29 Jul 2006 19:19:50 +0000 Subject: [PATCH] moved combobox styles from defs.to to combobox.h; added wxTE/wxCB_FILENAME styles (MSW only for now); show them in the widgets sample and use for file/dir pickers text controls git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40367 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + docs/latex/wx/combobox.tex | 3 +++ docs/latex/wx/text.tex | 3 +++ include/wx/combobox.h | 9 ++++++++ include/wx/defs.h | 8 ------- include/wx/msw/wrapshl.h | 9 ++++++++ include/wx/pickerbase.h | 15 +++++++----- include/wx/textctrl.h | 5 +--- samples/widgets/combobox.cpp | 15 ++++++++---- samples/widgets/textctrl.cpp | 17 +++++++++++--- src/common/filepickercmn.cpp | 18 +++++++++------ src/common/pickerbase.cpp | 8 ++++--- src/msw/combobox.cpp | 11 +++++++-- src/msw/textctrl.cpp | 5 +++- src/msw/utilsgui.cpp | 44 ++++++++++++++++++++++++++++++++++++ src/xrc/xh_combo.cpp | 3 ++- src/xrc/xh_text.cpp | 1 + 17 files changed, 136 insertions(+), 39 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 68ebeca0f8..b76b7c8695 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -97,6 +97,7 @@ All (GUI): - Added wxDC::GradientFillLinear/Concentric(). - Added wxHyperlinkCtrl (Francesco Montorsi). - Added clipboard events (wxEVT_COMMAND_TEXT_COPY/CUT/PASTE). +- Added wxTE_FILENAME and wxCB_FILENAME (MSW-only for now) - Allow to reorder wxGrid columns by drag-and-drop (Santiago Palacios). - Added wxRadioBox::SetItemToolTip(). - Added support for CMYK JPEG images loading (Robert Wruck). diff --git a/docs/latex/wx/combobox.tex b/docs/latex/wx/combobox.tex index c74acfe298..3272ba83a2 100644 --- a/docs/latex/wx/combobox.tex +++ b/docs/latex/wx/combobox.tex @@ -31,6 +31,9 @@ select (even from a program) a string which is not in the choices list.} the event wxEVT\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key is either processed internally by the control or used for navigation between dialog controls). Windows only.} +\twocolitem{\windowstyle{wxTE\_FILENAME}}{Should be used for the controls +containing file names. This currently just enables file names auto-completion +(and only under Windows for now) but can have other effects in the future.} \end{twocollist} See also \helpref{window styles overview}{windowstyles}. diff --git a/docs/latex/wx/text.tex b/docs/latex/wx/text.tex index 5992858843..e44427d4ff 100644 --- a/docs/latex/wx/text.tex +++ b/docs/latex/wx/text.tex @@ -53,6 +53,9 @@ used, so that text won't be wrapped. No effect under wxGTK1.} \twocolitem{\windowstyle{wxTE\_WORDWRAP}}{Wrap the lines too long to be shown entirely at word boundaries (wxUniv and wxGTK2 only).} \twocolitem{\windowstyle{wxTE\_BESTWRAP}}{Wrap the lines at word boundaries or at any other character if there are words longer than the window width (this is the default).} \twocolitem{\windowstyle{wxTE\_CAPITALIZE}}{On PocketPC and Smartphone, causes the first letter to be capitalized.} +\twocolitem{\windowstyle{wxTE\_FILENAME}}{Should be used for the text controls +containing file names. This currently just enables file names auto-completion +(and only under Windows for now) but can have other effects in the future.} \end{twocollist} See also \helpref{window styles overview}{windowstyles} and \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlctor}. diff --git a/include/wx/combobox.h b/include/wx/combobox.h index 6b361163ea..c4ce9f63da 100644 --- a/include/wx/combobox.h +++ b/include/wx/combobox.h @@ -16,6 +16,15 @@ #if wxUSE_COMBOBOX +/* + * wxComboBox style flags + */ +#define wxCB_SIMPLE 0x0004 +#define wxCB_SORT 0x0008 +#define wxCB_READONLY 0x0010 +#define wxCB_DROPDOWN 0x0020 +#define wxCB_FILENAME 0x0040 + extern WXDLLEXPORT_DATA(const wxChar) wxComboBoxNameStr[]; // ---------------------------------------------------------------------------- diff --git a/include/wx/defs.h b/include/wx/defs.h index 021c098b39..ce4b3748d3 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -1570,14 +1570,6 @@ enum wxBorder #define wxPASSWORD 0x0800 /* wxTE_PASSWORD */ #endif -/* - * wxComboBox style flags - */ -#define wxCB_SIMPLE 0x0004 -#define wxCB_SORT 0x0008 -#define wxCB_READONLY 0x0010 -#define wxCB_DROPDOWN 0x0020 - /* * wxRadioBox style flags */ diff --git a/include/wx/msw/wrapshl.h b/include/wx/msw/wrapshl.h index 3a0e143d76..5cef66c033 100644 --- a/include/wx/msw/wrapshl.h +++ b/include/wx/msw/wrapshl.h @@ -20,6 +20,8 @@ #include +#include "wx/msw/winundef.h" + // ---------------------------------------------------------------------------- // wxItemIdList implements RAII on top of ITEMIDLIST // ---------------------------------------------------------------------------- @@ -77,5 +79,12 @@ private: DECLARE_NO_COPY_CLASS(wxItemIdList) }; +// enable autocompleting filenames in the text control with given HWND +// +// this only works on systems with shlwapi.dll 5.0 or later +// +// implemented in src/msw/utilsgui.cpp +extern bool wxEnableFileNameAutoComplete(HWND hwnd); + #endif // _WX_MSW_WRAPSHL_H_ diff --git a/include/wx/pickerbase.h b/include/wx/pickerbase.h index 2176cfc5dd..e6a441fc26 100644 --- a/include/wx/pickerbase.h +++ b/include/wx/pickerbase.h @@ -41,12 +41,15 @@ public: // if present, intercepts wxPB_USE_TEXTCTRL style and creates the text control // The 3rd argument is the initial wxString to display in the text control - bool CreateBase(wxWindow *parent, wxWindowID id, - const wxString& text = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxButtonNameStr); + bool CreateBase(wxWindow *parent, + wxWindowID id, + const wxString& text = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxButtonNameStr, + long textstyle = 0); public: // public API diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index 65e6b90d54..86079e2ded 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -73,10 +73,7 @@ const wxTextCoord wxInvalidTextCoord = -2; // wxTextCtrl style flags // ---------------------------------------------------------------------------- -// the flag bit 0x0001 s free but should be used only for the things which -// don't make sense for a text control used by wxTextEntryDialog because they -// would otherwise conflict with wxOK, wxCANCEL, wxCENTRE - +#define wxTE_FILENAME 0x0001 #define wxTE_NO_VSCROLL 0x0002 #define wxTE_AUTO_SCROLL 0x0008 diff --git a/samples/widgets/combobox.cpp b/samples/widgets/combobox.cpp index 14e4333caf..4d2e59e1c6 100644 --- a/samples/widgets/combobox.cpp +++ b/samples/widgets/combobox.cpp @@ -134,7 +134,8 @@ protected: // the checkboxes for styles wxCheckBox *m_chkSort, - *m_chkReadonly; + *m_chkReadonly, + *m_chkFilename; // the combobox itself and the sizer it is in wxComboBox *m_combobox; @@ -211,7 +212,8 @@ ComboboxWidgetsPage::ComboboxWidgetsPage(WidgetsBookCtrl *book, { // init everything m_chkSort = - m_chkReadonly = (wxCheckBox *)NULL; + m_chkReadonly = + m_chkFilename = (wxCheckBox *)NULL; m_combobox = (wxComboBox *)NULL; m_sizerCombo = (wxSizer *)NULL; @@ -247,6 +249,7 @@ void ComboboxWidgetsPage::CreateContent() m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Sort items")); m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Read only")); + m_chkFilename = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&File name")); sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer sizerLeft->Add(m_radioKind, 0, wxGROW | wxALL, 5); @@ -343,6 +346,7 @@ void ComboboxWidgetsPage::Reset() { m_chkSort->SetValue(false); m_chkReadonly->SetValue(false); + m_chkFilename->SetValue(false); } void ComboboxWidgetsPage::CreateCombo() @@ -353,6 +357,8 @@ void ComboboxWidgetsPage::CreateCombo() flags |= wxCB_SORT; if ( m_chkReadonly->GetValue() ) flags |= wxCB_READONLY; + if ( m_chkFilename->GetValue() ) + flags |= wxCB_FILENAME; switch ( m_radioKind->GetSelection() ) { @@ -509,8 +515,9 @@ void ComboboxWidgetsPage::OnUpdateUIInsertionPointText(wxUpdateUIEvent& event) void ComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event) { - if (m_combobox) - event.Enable( m_chkSort->GetValue() || m_chkReadonly->GetValue() ); + event.Enable( m_chkSort->GetValue() || + m_chkReadonly->GetValue() || + m_chkFilename->GetValue() ); } void ComboboxWidgetsPage::OnUpdateUIInsert(wxUpdateUIEvent& event) diff --git a/samples/widgets/textctrl.cpp b/samples/widgets/textctrl.cpp index 0d2e8e293c..7d0536507a 100644 --- a/samples/widgets/textctrl.cpp +++ b/samples/widgets/textctrl.cpp @@ -106,6 +106,7 @@ static const struct ControlValues bool password; bool readonly; + bool filename; WrapStyle wrapStyle; @@ -117,6 +118,7 @@ static const struct ControlValues TextLines_Multi, // multiline false, // not password false, // not readonly + false, // not filename WrapStyle_Word, // wrap on word boundaries #ifdef __WXMSW__ TextKind_Plain // plain EDIT control @@ -201,7 +203,8 @@ protected: // the checkboxes controlling text ctrl styles wxCheckBox *m_chkPassword, - *m_chkReadonly; + *m_chkReadonly, + *m_chkFilename; // under MSW we test rich edit controls as well here #ifdef __WXMSW__ @@ -359,7 +362,8 @@ TextWidgetsPage::TextWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) m_radioTextLines = (wxRadioBox *)NULL; m_chkPassword = - m_chkReadonly = (wxCheckBox *)NULL; + m_chkReadonly = + m_chkFilename = (wxCheckBox *)NULL; m_text = m_textPosCur = @@ -405,6 +409,9 @@ void TextWidgetsPage::CreateContent() m_chkReadonly = CreateCheckBoxAndAddToSizer( sizerLeft, _T("&Read-only mode") ); + m_chkFilename = CreateCheckBoxAndAddToSizer( + sizerLeft, _T("&Filename control") + ); sizerLeft->AddSpacer(5); static const wxString wrap[] = @@ -604,6 +611,7 @@ void TextWidgetsPage::Reset() m_chkPassword->SetValue(DEFAULTS.password); m_chkReadonly->SetValue(DEFAULTS.readonly); + m_chkFilename->SetValue(DEFAULTS.filename); m_radioWrap->SetSelection(DEFAULTS.wrapStyle); @@ -633,6 +641,8 @@ void TextWidgetsPage::CreateText() flags |= wxTE_PASSWORD; if ( m_chkReadonly->GetValue() ) flags |= wxTE_READONLY; + if ( m_chkFilename->GetValue() ) + flags |= wxTE_FILENAME; switch ( m_radioWrap->GetSelection() ) { @@ -870,8 +880,9 @@ void TextWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event) #ifdef __WXMSW__ (m_radioKind->GetSelection() != DEFAULTS.textKind) || #endif // __WXMSW__ - (m_chkReadonly->GetValue() != DEFAULTS.readonly) || (m_chkPassword->GetValue() != DEFAULTS.password) || + (m_chkReadonly->GetValue() != DEFAULTS.readonly) || + (m_chkFilename->GetValue() != DEFAULTS.filename) || (m_radioWrap->GetSelection() != DEFAULTS.wrapStyle) ); } diff --git a/src/common/filepickercmn.cpp b/src/common/filepickercmn.cpp index 53514e3643..1282f2386d 100644 --- a/src/common/filepickercmn.cpp +++ b/src/common/filepickercmn.cpp @@ -45,17 +45,21 @@ IMPLEMENT_DYNAMIC_CLASS(wxFileDirPickerEvent, wxCommandEvent) // wxFileDirPickerCtrlBase // ---------------------------------------------------------------------------- -bool wxFileDirPickerCtrlBase::CreateBase( wxWindow *parent, wxWindowID id, - const wxString &path, const wxString &message, - const wxString &wildcard, - const wxPoint &pos, const wxSize &size, - long style, const wxValidator& validator, - const wxString &name ) +bool wxFileDirPickerCtrlBase::CreateBase(wxWindow *parent, + wxWindowID id, + const wxString &path, + const wxString &message, + const wxString &wildcard, + const wxPoint &pos, + const wxSize &size, + long style, + const wxValidator& validator, + const wxString &name ) { wxASSERT_MSG(path.empty() || CheckPath(path), wxT("Invalid initial path!")); if (!wxPickerBase::CreateBase(parent, id, path, pos, size, - style, validator, name)) + style, validator, name, wxTE_FILENAME)) return false; if (!HasFlag(wxFLP_OPEN) && !HasFlag(wxFLP_SAVE)) diff --git a/src/common/pickerbase.cpp b/src/common/pickerbase.cpp index e550e651c7..db435a8eca 100644 --- a/src/common/pickerbase.cpp +++ b/src/common/pickerbase.cpp @@ -59,7 +59,8 @@ bool wxPickerBase::CreateBase(wxWindow *parent, const wxSize& size, long style, const wxValidator& validator, - const wxString& name) + const wxString& name, + long textstyle) { // remove any border style from our style as wxPickerBase's window must be // invisible (user styles must be set on the textctrl or the platform-dependent picker) @@ -75,8 +76,9 @@ bool wxPickerBase::CreateBase(wxWindow *parent, // NOTE: the style of this class (wxPickerBase) and the style of the // attached text control are different: GetTextCtrlStyle() extracts // the styles related to the textctrl from the styles passed here - m_text = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, - wxDefaultSize, GetTextCtrlStyle(style)); + m_text = new wxTextCtrl(this, wxID_ANY, wxEmptyString, + wxDefaultPosition, wxDefaultSize, + GetTextCtrlStyle(style) | textstyle); if (!m_text) { wxFAIL_MSG( wxT("wxPickerBase's textctrl creation failed") ); diff --git a/src/msw/combobox.cpp b/src/msw/combobox.cpp index 25a2c9cd67..8d049cb564 100644 --- a/src/msw/combobox.cpp +++ b/src/msw/combobox.cpp @@ -42,6 +42,7 @@ // include "properly" #include "wx/msw/wrapcctl.h" +#include "wx/msw/wrapshl.h" #if wxUSE_TOOLTIPS #include "wx/tooltip.h" @@ -417,8 +418,14 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, // edit control, we must subclass it as well if ( !(style & wxCB_READONLY) ) { - gs_wndprocEdit = wxSetWindowProc((HWND)GetEditHWND(), - wxComboEditWndProc); + const HWND hwndEdit = (HWND)GetEditHWND(); + + gs_wndprocEdit = wxSetWindowProc(hwndEdit, wxComboEditWndProc); + + if ( style & wxCB_FILENAME ) + { + wxEnableFileNameAutoComplete(hwndEdit); + } } // and finally, show the control diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 1b08d80b6d..15311c9683 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -50,7 +50,7 @@ #include #include "wx/msw/private.h" -#include "wx/msw/winundef.h" +#include "wx/msw/wrapshl.h" #include #include @@ -518,6 +518,9 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, } #endif // wxUSE_RICHEDIT + if ( style & wxTE_FILENAME ) + wxEnableFileNameAutoComplete(GetHwnd()); + gs_wndprocEdit = wxSetWindowProc((HWND)GetHwnd(), wxTextCtrlWndProc); diff --git a/src/msw/utilsgui.cpp b/src/msw/utilsgui.cpp index 7926bdb330..ee1e45a8f9 100644 --- a/src/msw/utilsgui.cpp +++ b/src/msw/utilsgui.cpp @@ -30,6 +30,8 @@ #include "wx/utils.h" #endif //WX_PRECOMP +#include "wx/dynlib.h" + #include "wx/msw/private.h" // includes // ============================================================================ @@ -452,3 +454,45 @@ void wxDrawLine(HDC hdc, int x1, int y1, int x2, int y2) } +// ---------------------------------------------------------------------------- +// Shell API wrappers +// ---------------------------------------------------------------------------- + +extern bool wxEnableFileNameAutoComplete(HWND hwnd) +{ + typedef HRESULT (WINAPI *SHAutoComplete_t)(HWND, DWORD); + + static SHAutoComplete_t s_pfnSHAutoComplete = NULL; + static bool s_initialized = false; + + if ( !s_initialized ) + { + s_initialized = true; + + wxLogNull nolog; + wxDynamicLibrary dll(_T("shlwapi.dll")); + if ( dll.IsLoaded() ) + { + s_pfnSHAutoComplete = + (SHAutoComplete_t)dll.GetSymbol(_T("SHAutoComplete")); + if ( s_pfnSHAutoComplete ) + { + // won't be unloaded until the process termination, no big deal + dll.Detach(); + } + } + } + + if ( !s_pfnSHAutoComplete ) + return false; + + HRESULT hr = s_pfnSHAutoComplete(hwnd, 0x10 /* SHACF_FILESYS_ONLY */); + if ( FAILED(hr) ) + { + wxLogApiError(_T("SHAutoComplete"), hr); + return false; + } + + return true; +} + diff --git a/src/xrc/xh_combo.cpp b/src/xrc/xh_combo.cpp index f8d20a6900..119afc17fe 100644 --- a/src/xrc/xh_combo.cpp +++ b/src/xrc/xh_combo.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: src/xrc/xh_combo.cpp -// Purpose: XRC resource for wxRadioBox +// Purpose: XRC resource for wxComboBox // Author: Bob Mitchell // Created: 2000/03/21 // RCS-ID: $Id$ @@ -34,6 +34,7 @@ wxComboBoxXmlHandler::wxComboBoxXmlHandler() XRC_ADD_STYLE(wxCB_SORT); XRC_ADD_STYLE(wxCB_READONLY); XRC_ADD_STYLE(wxCB_DROPDOWN); + XRC_ADD_STYLE(wxCB_FILENAME); AddWindowStyles(); } diff --git a/src/xrc/xh_text.cpp b/src/xrc/xh_text.cpp index e369cb4f79..0fa4c91eb0 100644 --- a/src/xrc/xh_text.cpp +++ b/src/xrc/xh_text.cpp @@ -27,6 +27,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxTextCtrlXmlHandler, wxXmlResourceHandler) wxTextCtrlXmlHandler::wxTextCtrlXmlHandler() : wxXmlResourceHandler() { + XRC_ADD_STYLE(wxTE_FILENAME); XRC_ADD_STYLE(wxTE_NO_VSCROLL); XRC_ADD_STYLE(wxTE_AUTO_SCROLL); XRC_ADD_STYLE(wxTE_PROCESS_ENTER); -- 2.45.2