Fix for assert after left click on tree in generic dir dialog in native MSW build. Source cleaning and readability fixes.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30742 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba
2004-11-23 19:58:47 +00:00
parent f05ebffd6b
commit 44d60c0b26
3 changed files with 39 additions and 24 deletions

View File

@@ -201,18 +201,18 @@ size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayI
ItemCount volumeIndex = 1; ItemCount volumeIndex = 1;
OSErr err = noErr ; OSErr err = noErr ;
while( noErr == err ) while( noErr == err )
{ {
HFSUniStr255 volumeName ; HFSUniStr255 volumeName ;
FSRef fsRef ; FSRef fsRef ;
FSVolumeInfo volumeInfo ; FSVolumeInfo volumeInfo ;
err = FSGetVolumeInfo(0, volumeIndex, NULL, kFSVolInfoFlags , &volumeInfo , &volumeName, &fsRef); err = FSGetVolumeInfo(0, volumeIndex, NULL, kFSVolInfoFlags , &volumeInfo , &volumeName, &fsRef);
if( noErr == err ) if( noErr == err )
{ {
wxString path = wxMacFSRefToPath( &fsRef ) ; wxString path = wxMacFSRefToPath( &fsRef ) ;
wxString name = wxMacHFSUniStrToString( &volumeName ) ; wxString name = wxMacHFSUniStrToString( &volumeName ) ;
if ( (volumeInfo.flags & kFSVolFlagSoftwareLockedMask) || (volumeInfo.flags & kFSVolFlagHardwareLockedMask) ) if ( (volumeInfo.flags & kFSVolFlagSoftwareLockedMask) || (volumeInfo.flags & kFSVolFlagHardwareLockedMask) )
{ {
icon_ids.Add(wxFileIconsTable::cdrom); icon_ids.Add(wxFileIconsTable::cdrom);
@@ -222,11 +222,11 @@ size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayI
icon_ids.Add(wxFileIconsTable::drive); icon_ids.Add(wxFileIconsTable::drive);
} }
// todo other removable // todo other removable
paths.Add(path); paths.Add(path);
names.Add(name); names.Add(name);
volumeIndex++ ; volumeIndex++ ;
} }
} }
#elif defined(__UNIX__) #elif defined(__UNIX__)
@@ -383,7 +383,7 @@ void wxDirItemData::SetNewDirName(const wxString& path)
bool wxDirItemData::HasSubDirs() const bool wxDirItemData::HasSubDirs() const
{ {
if (m_path.IsEmpty()) if (m_path.empty())
return false; return false;
wxDir dir; wxDir dir;
@@ -398,7 +398,7 @@ bool wxDirItemData::HasSubDirs() const
bool wxDirItemData::HasFiles(const wxString& WXUNUSED(spec)) const bool wxDirItemData::HasFiles(const wxString& WXUNUSED(spec)) const
{ {
if (m_path.IsEmpty()) if (m_path.empty())
return false; return false;
wxDir dir; wxDir dir;
@@ -522,7 +522,7 @@ bool wxGenericDirCtrl::Create(wxWindow *parent,
m_treeCtrl = CreateTreeCtrl(this, wxID_TREECTRL, m_treeCtrl = CreateTreeCtrl(this, wxID_TREECTRL,
wxPoint(0,0), GetClientSize(), treeStyle); wxPoint(0,0), GetClientSize(), treeStyle);
if (!filter.IsEmpty() && (style & wxDIRCTRL_SHOW_FILTERS)) if (!filter.empty() && (style & wxDIRCTRL_SHOW_FILTERS))
m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL, wxDefaultPosition, wxDefaultSize, filterStyle); m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL, wxDefaultPosition, wxDefaultSize, filterStyle);
m_defaultPath = dir; m_defaultPath = dir;
@@ -642,7 +642,7 @@ void wxGenericDirCtrl::OnBeginEditItem(wxTreeEvent &event)
void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent &event) void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent &event)
{ {
if ((event.GetLabel().IsEmpty()) || if ((event.GetLabel().empty()) ||
(event.GetLabel() == _(".")) || (event.GetLabel() == _(".")) ||
(event.GetLabel() == _("..")) || (event.GetLabel() == _("..")) ||
(event.GetLabel().Find(wxT('/')) != wxNOT_FOUND) || (event.GetLabel().Find(wxT('/')) != wxNOT_FOUND) ||
@@ -905,7 +905,7 @@ wxTreeItemId wxGenericDirCtrl::FindChild(wxTreeItemId parentId, const wxString&
{ {
wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(childId); wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(childId);
if (data && !data->m_path.IsEmpty()) if (data && !data->m_path.empty())
{ {
wxString childPath(data->m_path); wxString childPath(data->m_path);
if (!wxEndsWithPathSeparator(childPath)) if (!wxEndsWithPathSeparator(childPath))
@@ -1625,13 +1625,13 @@ int wxFileIconsTable::GetIconID(const wxString& extension, const wxString& mime)
Create(); Create();
#if wxUSE_MIMETYPE #if wxUSE_MIMETYPE
if (!extension.IsEmpty()) if (!extension.empty())
{ {
wxFileIconEntry *entry = (wxFileIconEntry*) m_HashTable->Get(extension); wxFileIconEntry *entry = (wxFileIconEntry*) m_HashTable->Get(extension);
if (entry) return (entry -> id); if (entry) return (entry -> id);
} }
wxFileType *ft = (mime.IsEmpty()) ? wxFileType *ft = (mime.empty()) ?
wxTheMimeTypesManager -> GetFileTypeFromExtension(extension) : wxTheMimeTypesManager -> GetFileTypeFromExtension(extension) :
wxTheMimeTypesManager -> GetFileTypeFromMimeType(mime); wxTheMimeTypesManager -> GetFileTypeFromMimeType(mime);

View File

@@ -278,7 +278,13 @@ void wxGenericDirDialog::OnTreeSelected( wxTreeEvent &event )
if (!m_dirCtrl) if (!m_dirCtrl)
return; return;
wxDirItemData *data = (wxDirItemData*)m_dirCtrl->GetTreeCtrl()->GetItemData(event.GetItem()); wxTreeItemId item = event.GetItem();
wxDirItemData *data = NULL;
if(item.IsOk())
data = (wxDirItemData*)m_dirCtrl->GetTreeCtrl()->GetItemData(item);
if (data) if (data)
m_input->SetValue( data->m_path ); m_input->SetValue( data->m_path );
}; };

View File

@@ -1497,8 +1497,14 @@ wxTreeItemId wxTreeCtrl::GetFirstChild(const wxTreeItemId& item,
wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& WXUNUSED(item), wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& WXUNUSED(item),
wxTreeItemIdValue& cookie) const wxTreeItemIdValue& cookie) const
{ {
wxTreeItemId item(TreeView_GetNextSibling(GetHwnd(), wxTreeItemId fromCookie(cookie);
HITEM(wxTreeItemId(cookie))));
HTREEITEM hitem = HITEM(fromCookie);
hitem = TreeView_GetNextSibling(GetHwnd(), hitem);
wxTreeItemId item(hitem);
cookie = item.m_pItem; cookie = item.m_pItem;
return item; return item;
@@ -1519,11 +1525,14 @@ wxTreeItemId wxTreeCtrl::GetFirstChild(const wxTreeItemId& item,
wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& WXUNUSED(item), wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& WXUNUSED(item),
long& cookie) const long& cookie) const
{ {
wxTreeItemId item(TreeView_GetNextSibling wxTreeItemId fromCookie((void *)cookie);
(
GetHwnd(), HTREEITEM hitem = HITEM(fromCookie);
HITEM(wxTreeItemId((void *)cookie)
))); hitem = TreeView_GetNextSibling(GetHwnd(), hitem);
wxTreeItemId item(hitem);
cookie = (long)item.m_pItem; cookie = (long)item.m_pItem;
return item; return item;
@@ -1646,7 +1655,7 @@ wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent,
} }
UINT mask = 0; UINT mask = 0;
if ( !text.IsEmpty() ) if ( !text.empty() )
{ {
mask |= TVIF_TEXT; mask |= TVIF_TEXT;
tvIns.item.pszText = (wxChar *)text.c_str(); // cast is ok tvIns.item.pszText = (wxChar *)text.c_str(); // cast is ok