X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0e1f8ea4a3c2764ec89d95f4edef40257e32ac5b..404b319a85dadd7decf7a5a5331020520031a41c:/src/generic/dirctrlg.cpp diff --git a/src/generic/dirctrlg.cpp b/src/generic/dirctrlg.cpp index a12be2f6c4..78f8ffc252 100644 --- a/src/generic/dirctrlg.cpp +++ b/src/generic/dirctrlg.cpp @@ -55,7 +55,7 @@ #include "wx/osx/private.h" // includes mac headers #endif -#ifdef __WXMSW__ +#ifdef __WINDOWS__ #include #include "wx/msw/winundef.h" #include "wx/volume.h" @@ -71,7 +71,7 @@ #include #endif -#endif +#endif // __WINDOWS__ #if defined(__OS2__) || defined(__DOS__) #ifdef __OS2__ @@ -102,6 +102,12 @@ extern WXDLLEXPORT_DATA(const char) wxFileSelectorDefaultWildcardStr[]; bool wxIsDriveAvailable(const wxString& dirName); +// ---------------------------------------------------------------------------- +// events +// ---------------------------------------------------------------------------- + +wxDEFINE_EVENT( wxEVT_COMMAND_DIRCTRL_CHANGED, wxTreeEvent ); + // ---------------------------------------------------------------------------- // wxGetAvailableDrives, for WINDOWS, DOS, OS2, MAC, UNIX (returns "/") // ---------------------------------------------------------------------------- @@ -310,7 +316,7 @@ int setdrive(int WXUNUSED_IN_WINCE(drive)) #else newdrive[2] = wxT('\0'); #endif -#if defined(__WXMSW__) +#if defined(__WINDOWS__) if (::SetCurrentDirectory(newdrive)) #else // VA doesn't know what LPSTR is and has its own set @@ -441,6 +447,7 @@ BEGIN_EVENT_TABLE(wxGenericDirCtrl, wxControl) EVT_TREE_ITEM_COLLAPSED (wxID_TREECTRL, wxGenericDirCtrl::OnCollapseItem) EVT_TREE_BEGIN_LABEL_EDIT (wxID_TREECTRL, wxGenericDirCtrl::OnBeginEditItem) EVT_TREE_END_LABEL_EDIT (wxID_TREECTRL, wxGenericDirCtrl::OnEndEditItem) + EVT_TREE_SEL_CHANGED (wxID_TREECTRL, wxGenericDirCtrl::OnTreeSelChange) EVT_SIZE (wxGenericDirCtrl::OnSize) END_EVENT_TABLE() @@ -511,7 +518,7 @@ bool wxGenericDirCtrl::Create(wxWindow *parent, m_treeCtrl = CreateTreeCtrl(this, wxID_TREECTRL, wxPoint(0,0), GetClientSize(), treeStyle); - if (!filter.empty()) + if (!filter.empty() && (style & wxDIRCTRL_SHOW_FILTERS)) m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL); m_defaultPath = dir; @@ -666,7 +673,7 @@ void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent &event) } wxTreeItemId treeid = event.GetItem(); - wxDirItemData *data = (wxDirItemData*)m_treeCtrl->GetItemData( treeid ); + wxDirItemData *data = GetItemData( treeid ); wxASSERT( data ); wxString new_name( wxPathOnly( data->m_path ) ); @@ -694,6 +701,24 @@ void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent &event) } } +void wxGenericDirCtrl::OnTreeSelChange(wxTreeEvent &event) +{ + wxTreeEvent changedEvent(wxEVT_COMMAND_DIRCTRL_CHANGED, GetId()); + + changedEvent.SetEventObject(this); + changedEvent.SetItem(event.GetItem()); + changedEvent.SetClientObject(m_treeCtrl->GetItemData(event.GetItem())); + + if (GetEventHandler()->SafelyProcessEvent(changedEvent) && !changedEvent.IsAllowed()) + { + event.Veto(); + } + else + { + event.Skip(); + } +} + void wxGenericDirCtrl::OnExpandItem(wxTreeEvent &event) { wxTreeItemId parentId = event.GetItem(); @@ -716,7 +741,7 @@ void wxGenericDirCtrl::CollapseDir(wxTreeItemId parentId) { wxTreeItemId child; - wxDirItemData *data = (wxDirItemData *) m_treeCtrl->GetItemData(parentId); + wxDirItemData *data = GetItemData(parentId); if (!data->m_isExpanded) return; @@ -731,7 +756,7 @@ void wxGenericDirCtrl::CollapseDir(wxTreeItemId parentId) void wxGenericDirCtrl::PopulateNode(wxTreeItemId parentId) { - wxDirItemData *data = (wxDirItemData *) m_treeCtrl->GetItemData(parentId); + wxDirItemData *data = GetItemData(parentId); if (data->m_isExpanded) return; @@ -922,7 +947,7 @@ wxTreeItemId wxGenericDirCtrl::FindChild(wxTreeItemId parentId, const wxString& wxTreeItemId childId = m_treeCtrl->GetFirstChild(parentId, cookie); while (childId.IsOk()) { - wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(childId); + wxDirItemData* data = GetItemData(childId); if (data && !data->m_path.empty()) { @@ -973,7 +998,7 @@ bool wxGenericDirCtrl::ExpandPath(const wxString& path) if (!lastId.IsOk()) return false; - wxDirItemData *data = (wxDirItemData *) m_treeCtrl->GetItemData(lastId); + wxDirItemData *data = GetItemData(lastId); if (data->m_isDir) { m_treeCtrl->Expand(lastId); @@ -986,7 +1011,7 @@ bool wxGenericDirCtrl::ExpandPath(const wxString& path) bool selectedChild = false; while (childId.IsOk()) { - data = (wxDirItemData*) m_treeCtrl->GetItemData(childId); + data = GetItemData(childId); if (data && data->m_path != wxEmptyString && !data->m_isDir) { @@ -1038,6 +1063,18 @@ bool wxGenericDirCtrl::CollapsePath(const wxString& path) return true; } +wxDirItemData* wxGenericDirCtrl::GetItemData(wxTreeItemId itemId) +{ + return static_cast(m_treeCtrl->GetItemData(itemId)); +} + +wxString wxGenericDirCtrl::GetPath(wxTreeItemId itemId) const +{ + const wxDirItemData* + data = static_cast(m_treeCtrl->GetItemData(itemId)); + + return data->m_path; +} wxString wxGenericDirCtrl::GetPath() const { @@ -1050,8 +1087,7 @@ wxString wxGenericDirCtrl::GetPath() const { // return first string only wxTreeItemId treeid = items[0]; - wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(treeid); - return data->m_path; + return GetPath(treeid); } return wxEmptyString; @@ -1060,8 +1096,7 @@ wxString wxGenericDirCtrl::GetPath() const wxTreeItemId treeid = m_treeCtrl->GetSelection(); if (treeid) { - wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(treeid); - return data->m_path; + return GetPath(treeid); } else return wxEmptyString; @@ -1076,8 +1111,7 @@ void wxGenericDirCtrl::GetPaths(wxArrayString& paths) const for ( unsigned n = 0; n < items.size(); n++ ) { wxTreeItemId treeid = items[n]; - wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(treeid); - paths.Add(data->m_path); + paths.push_back(GetPath(treeid)); } } @@ -1170,7 +1204,7 @@ void wxGenericDirCtrl::FindChildFiles(wxTreeItemId treeid, int dirFlags, wxArray wxString dirName(data->m_path); -#if defined(__WXMSW__) || defined(__OS2__) +#if defined(__WINDOWS__) || defined(__OS2__) if (dirName.Last() == ':') dirName += wxString(wxFILE_SEP_PATH); #endif @@ -1217,7 +1251,7 @@ void wxGenericDirCtrl::SetFilter(const wxString& filter) { m_filter = filter; - if (!filter.empty() && !m_filterListCtrl) + if (!filter.empty() && !m_filterListCtrl && HasFlag(wxDIRCTRL_SHOW_FILTERS)) m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL); else if (filter.empty() && m_filterListCtrl) { @@ -1572,7 +1606,7 @@ wxImageList *wxFileIconsTable::GetSmallImageList() return m_smallImageList; } -#if wxUSE_MIMETYPE && wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB) +#if wxUSE_MIMETYPE && wxUSE_IMAGE && (!defined(__WINDOWS__) || wxUSE_WXDIB) // VS: we don't need this function w/o wxMimeTypesManager because we'll only have // one icon and we won't resize it @@ -1732,7 +1766,7 @@ int wxFileIconsTable::GetIconID(const wxString& extension, const wxString& mime) { m_smallImageList->Add(bmp); } -#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB) +#if wxUSE_IMAGE && (!defined(__WINDOWS__) || wxUSE_WXDIB) else { wxImage img = bmp.ConvertToImage();