From d0bc78e2bf750babe62ea4af7df1d0252293e7d8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 24 May 2007 00:14:59 +0000 Subject: [PATCH] deprecate unneeded wxDIRCTRL_SHOW_FILTERS style, just always show the filters if they're present (modified patch 1719448) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46187 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 3 +++ docs/latex/wx/dirctrl.tex | 1 - include/wx/generic/dirctrlg.h | 4 ++- samples/widgets/dirctrl.cpp | 25 ++++++++++++++++--- src/generic/dirctrlg.cpp | 46 +++++++++++++++++++++-------------- src/xrc/xh_gdctl.cpp | 1 - 6 files changed, 56 insertions(+), 24 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index ff1fcb5b43..44c7cb03d1 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -72,6 +72,9 @@ Deprecated methods and their replacements - wxCreateGreyedImage() deprecated, use wxImage::ConvertToGreyscale() instead. - wxString::GetWriteBuf() and UngetWriteBuf() deprecated, using wxStringBuffer or wxStringBufferLength instead. +- wxDIRCTRL_SHOW_FILTERS style is deprecated, filters are alwsys shown if + specified so this style should simply be removed + Major new features in this release ---------------------------------- diff --git a/docs/latex/wx/dirctrl.tex b/docs/latex/wx/dirctrl.tex index a82963cb2d..1eafca210d 100644 --- a/docs/latex/wx/dirctrl.tex +++ b/docs/latex/wx/dirctrl.tex @@ -23,7 +23,6 @@ hierarchy, and optionally, a \helpref{wxChoice}{wxchoice} window containing a li \twocolitem{\indexit{wxDIRCTRL\_DIR\_ONLY}}{Only show directories, and not files.} \twocolitem{\indexit{wxDIRCTRL\_3D\_INTERNAL}}{Use 3D borders for internal controls.} \twocolitem{\indexit{wxDIRCTRL\_SELECT\_FIRST}}{When setting the default path, select the first file in the directory.} -\twocolitem{\indexit{wxDIRCTRL\_SHOW\_FILTERS}}{Show the drop-down filter list.} \twocolitem{\indexit{wxDIRCTRL\_EDIT\_LABELS}}{Allow the folder and file labels to be editable.} \end{twocollist} diff --git a/include/wx/generic/dirctrlg.h b/include/wx/generic/dirctrlg.h index f6afb9c3c6..2a6c450824 100644 --- a/include/wx/generic/dirctrlg.h +++ b/include/wx/generic/dirctrlg.h @@ -44,8 +44,10 @@ enum wxDIRCTRL_DIR_ONLY = 0x0010, // When setting the default path, select the first file in the directory wxDIRCTRL_SELECT_FIRST = 0x0020, - // Show the filter list +#if WXWIN_COMPATIBILITY_2_8 + // Unused, for compatibility only wxDIRCTRL_SHOW_FILTERS = 0x0040, +#endif // WXWIN_COMPATIBILITY_2_8 // Use 3D borders on internal controls wxDIRCTRL_3D_INTERNAL = 0x0080, // Editable labels diff --git a/samples/widgets/dirctrl.cpp b/samples/widgets/dirctrl.cpp index 472416f3ed..646d03ae9c 100644 --- a/samples/widgets/dirctrl.cpp +++ b/samples/widgets/dirctrl.cpp @@ -132,8 +132,9 @@ protected: wxCheckBox *m_chkDirOnly, *m_chk3D, *m_chkFirst, - *m_chkFilters, *m_chkLabels; + // filters + wxCheckBox *m_fltr[3]; private: DECLARE_EVENT_TABLE() @@ -182,10 +183,17 @@ void DirCtrlWidgetsPage::CreateContent() m_chkDirOnly = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_DIR_ONLY")); m_chk3D = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_3D_INTERNAL")); m_chkFirst = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_SELECT_FIRST")); - m_chkFilters = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_SHOW_FILTERS")); m_chkLabels = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_EDIT_LABELS")); sizerLeft->Add(sizerUseFlags, wxSizerFlags().Expand().Border()); + wxSizer *sizerFilters = + new wxStaticBoxSizer(wxVERTICAL, this, _T("&Filters")); + m_fltr[0] = CreateCheckBoxAndAddToSizer(sizerFilters, wxString::Format(wxT("all files (%s)|%s"), + wxFileSelectorDefaultWildcardStr, wxFileSelectorDefaultWildcardStr)); + m_fltr[1] = CreateCheckBoxAndAddToSizer(sizerFilters, wxT("C++ files (*.cpp; *.h)|*.cpp;*.h")); + m_fltr[2] = CreateCheckBoxAndAddToSizer(sizerFilters, wxT("PNG images (*.png)|*.png")); + sizerLeft->Add(sizerFilters, wxSizerFlags().Expand().Border()); + wxButton *btn = new wxButton(this, DirCtrlPage_Reset, _T("&Reset")); sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15); @@ -236,10 +244,21 @@ void DirCtrlWidgetsPage::CreateDirCtrl() ( m_chkDirOnly->IsChecked() ? wxDIRCTRL_DIR_ONLY : 0 ) | ( m_chk3D->IsChecked() ? wxDIRCTRL_3D_INTERNAL : 0 ) | ( m_chkFirst->IsChecked() ? wxDIRCTRL_SELECT_FIRST : 0 ) | - ( m_chkFilters->IsChecked() ? wxDIRCTRL_SHOW_FILTERS : 0 ) | ( m_chkLabels->IsChecked() ? wxDIRCTRL_EDIT_LABELS : 0 ) ); + wxString filter; + for (int i = 0; i < 3; ++i) + { + if (m_fltr[i]->IsChecked()) + { + if (!filter.IsEmpty()) + filter += wxT("|"); + filter += m_fltr[i]->GetLabel(); + } + } + dirCtrl->SetFilter(filter); + // update sizer's child window GetSizer()->Replace(m_dirCtrl, dirCtrl, true); diff --git a/src/generic/dirctrlg.cpp b/src/generic/dirctrlg.cpp index 34d7a5054b..a41fdba627 100644 --- a/src/generic/dirctrlg.cpp +++ b/src/generic/dirctrlg.cpp @@ -470,7 +470,6 @@ wxBEGIN_FLAGS( wxGenericDirCtrlStyle ) wxFLAGS_MEMBER(wxDIRCTRL_DIR_ONLY) wxFLAGS_MEMBER(wxDIRCTRL_3D_INTERNAL) wxFLAGS_MEMBER(wxDIRCTRL_SELECT_FIRST) - wxFLAGS_MEMBER(wxDIRCTRL_SHOW_FILTERS) wxEND_FLAGS( wxGenericDirCtrlStyle ) @@ -564,27 +563,17 @@ bool wxGenericDirCtrl::Create(wxWindow *parent, else treeStyle |= wxBORDER_SUNKEN; - long filterStyle = 0; - if ((style & wxDIRCTRL_3D_INTERNAL) == 0) - filterStyle |= wxNO_BORDER; - else - filterStyle |= wxBORDER_SUNKEN; - m_treeCtrl = CreateTreeCtrl(this, wxID_TREECTRL, wxPoint(0,0), GetClientSize(), treeStyle); - if (!filter.empty() && (style & wxDIRCTRL_SHOW_FILTERS)) - m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL, wxDefaultPosition, wxDefaultSize, filterStyle); + if (!filter.empty()) + m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL); m_defaultPath = dir; m_filter = filter; if (m_filter.empty()) -#ifdef __UNIX__ - m_filter = wxT("*"); -#else - m_filter = wxT("*.*"); -#endif + m_filter = wxFileSelectorDefaultWildcardStr; SetFilterIndex(defaultFilter); @@ -1182,6 +1171,14 @@ void wxGenericDirCtrl::SetFilter(const wxString& filter) { m_filter = filter; + if (!filter.empty() && !m_filterListCtrl) + m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL); + else if (filter.empty() && m_filterListCtrl) + { + m_filterListCtrl->Destroy(); + m_filterListCtrl = NULL; + } + wxString f, d; if (ExtractWildcard(m_filter, m_currentFilter, f, d)) m_currentFilterStr = f; @@ -1191,6 +1188,10 @@ void wxGenericDirCtrl::SetFilter(const wxString& filter) #else m_currentFilterStr = wxT("*.*"); #endif + // current filter index is meaningless after filter change, set it to zero + SetFilterIndex(0); + if (m_filterListCtrl) + m_filterListCtrl->FillFilterList(m_filter, 0); } // Extract description and actual filter from overall filter string @@ -1267,12 +1268,21 @@ BEGIN_EVENT_TABLE(wxDirFilterListCtrl, wxChoice) EVT_CHOICE(wxID_ANY, wxDirFilterListCtrl::OnSelFilter) END_EVENT_TABLE() -bool wxDirFilterListCtrl::Create(wxGenericDirCtrl* parent, const wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style) +bool wxDirFilterListCtrl::Create(wxGenericDirCtrl* parent, + const wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style) { m_dirCtrl = parent; + + // by default our border style is determined by the style of our parent + if ( !(style & wxBORDER_MASK) ) + { + style |= parent->HasFlag(wxDIRCTRL_3D_INTERNAL) ? wxBORDER_SUNKEN + : wxBORDER_NONE; + } + return wxChoice::Create(parent, id, pos, size, 0, NULL, style); } diff --git a/src/xrc/xh_gdctl.cpp b/src/xrc/xh_gdctl.cpp index 5a56eecdd5..bbd0a0df59 100644 --- a/src/xrc/xh_gdctl.cpp +++ b/src/xrc/xh_gdctl.cpp @@ -33,7 +33,6 @@ wxGenericDirCtrlXmlHandler::wxGenericDirCtrlXmlHandler() XRC_ADD_STYLE(wxDIRCTRL_DIR_ONLY); XRC_ADD_STYLE(wxDIRCTRL_3D_INTERNAL); XRC_ADD_STYLE(wxDIRCTRL_SELECT_FIRST); - XRC_ADD_STYLE(wxDIRCTRL_SHOW_FILTERS); XRC_ADD_STYLE(wxDIRCTRL_EDIT_LABELS); AddWindowStyles(); } -- 2.45.2