// Author: Harm van der Heijden, Robert Roebling, Julian Smart
// Modified by:
// Created: 12/12/98
-// RCS-ID: $Id$
// Copyright: (c) Harm van der Heijden, Robert Roebling and Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/osx/private.h" // includes mac headers
#endif
-#ifdef __WXMSW__
+#ifdef __WINDOWS__
#include <windows.h>
#include "wx/msw/winundef.h"
#include "wx/volume.h"
#include <ctype.h>
#endif
-#endif
+#endif // __WINDOWS__
#if defined(__OS2__) || defined(__DOS__)
#ifdef __OS2__
bool wxIsDriveAvailable(const wxString& dirName);
+// ----------------------------------------------------------------------------
+// events
+// ----------------------------------------------------------------------------
+
+wxDEFINE_EVENT( wxEVT_DIRCTRL_SELECTIONCHANGED, wxTreeEvent );
+wxDEFINE_EVENT( wxEVT_DIRCTRL_FILEACTIVATED, wxTreeEvent );
+
// ----------------------------------------------------------------------------
// wxGetAvailableDrives, for WINDOWS, DOS, OS2, MAC, UNIX (returns "/")
// ----------------------------------------------------------------------------
}
}
-#elif defined(__UNIX__) || defined(__WXPALMOS__)
+#elif defined(__UNIX__)
paths.Add(wxT("/"));
names.Add(wxT("/"));
icon_ids.Add(wxFileIconsTable::computer);
bool wxIsDriveAvailable(const wxString& dirName)
{
- // FIXME_MGL - this method leads to hang up under Watcom for some reason
+ // FIXME: this method leads to hang up under Watcom for some reason
#ifdef __WATCOMC__
wxUnusedVar(dirName);
#else
#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
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_TREE_ITEM_ACTIVATED (wxID_TREECTRL, wxGenericDirCtrl::OnItemActivated)
EVT_SIZE (wxGenericDirCtrl::OnSize)
END_EVENT_TABLE()
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;
}
wxTreeItemId treeid = event.GetItem();
- wxDirItemData *data = (wxDirItemData*)m_treeCtrl->GetItemData( treeid );
+ wxDirItemData *data = GetItemData( treeid );
wxASSERT( data );
wxString new_name( wxPathOnly( data->m_path ) );
}
}
+void wxGenericDirCtrl::OnTreeSelChange(wxTreeEvent &event)
+{
+ wxTreeEvent changedEvent(wxEVT_DIRCTRL_SELECTIONCHANGED, 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::OnItemActivated(wxTreeEvent &event)
+{
+ wxTreeItemId treeid = event.GetItem();
+ const wxDirItemData *data = GetItemData(treeid);
+
+ if (data->m_isDir)
+ {
+ // is dir
+ event.Skip();
+ }
+ else
+ {
+ // is file
+ wxTreeEvent changedEvent(wxEVT_DIRCTRL_FILEACTIVATED, GetId());
+
+ changedEvent.SetEventObject(this);
+ changedEvent.SetItem(treeid);
+ changedEvent.SetClientObject(m_treeCtrl->GetItemData(treeid));
+
+ if (GetEventHandler()->SafelyProcessEvent(changedEvent) && !changedEvent.IsAllowed())
+ event.Veto();
+ else
+ event.Skip();
+ }
+}
+
void wxGenericDirCtrl::OnExpandItem(wxTreeEvent &event)
{
wxTreeItemId parentId = event.GetItem();
{
wxTreeItemId child;
- wxDirItemData *data = (wxDirItemData *) m_treeCtrl->GetItemData(parentId);
+ wxDirItemData *data = GetItemData(parentId);
if (!data->m_isExpanded)
return;
void wxGenericDirCtrl::PopulateNode(wxTreeItemId parentId)
{
- wxDirItemData *data = (wxDirItemData *) m_treeCtrl->GetItemData(parentId);
+ wxDirItemData *data = GetItemData(parentId);
if (data->m_isExpanded)
return;
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())
{
if (!lastId.IsOk())
return false;
- wxDirItemData *data = (wxDirItemData *) m_treeCtrl->GetItemData(lastId);
+ wxDirItemData *data = GetItemData(lastId);
if (data->m_isDir)
{
m_treeCtrl->Expand(lastId);
bool selectedChild = false;
while (childId.IsOk())
{
- data = (wxDirItemData*) m_treeCtrl->GetItemData(childId);
+ data = GetItemData(childId);
if (data && data->m_path != wxEmptyString && !data->m_isDir)
{
return true;
}
+wxDirItemData* wxGenericDirCtrl::GetItemData(wxTreeItemId itemId)
+{
+ return static_cast<wxDirItemData*>(m_treeCtrl->GetItemData(itemId));
+}
+
+wxString wxGenericDirCtrl::GetPath(wxTreeItemId itemId) const
+{
+ const wxDirItemData*
+ data = static_cast<wxDirItemData*>(m_treeCtrl->GetItemData(itemId));
+
+ return data->m_path;
+}
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;
wxTreeItemId treeid = m_treeCtrl->GetSelection();
if (treeid)
{
- wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(treeid);
- return data->m_path;
+ return GetPath(treeid);
}
else
return wxEmptyString;
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));
}
}
wxString dirName(data->m_path);
-#if defined(__WXMSW__) || defined(__OS2__)
+#if defined(__WINDOWS__) || defined(__OS2__)
if (dirName.Last() == ':')
dirName += wxString(wxFILE_SEP_PATH);
#endif
{
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)
{
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
{
m_smallImageList->Add(bmp);
}
-#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
+#if wxUSE_IMAGE && (!defined(__WINDOWS__) || wxUSE_WXDIB)
else
{
wxImage img = bmp.ConvertToImage();