X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c801d85f158c4cba50b588807daabdcbd0ed3853..38cfbffa153c8835025b4207faaf0a12b0b53e6f:/user/wxFile/dirctrl.cpp diff --git a/user/wxFile/dirctrl.cpp b/user/wxFile/dirctrl.cpp index 54cc5b683d..16ad375642 100644 --- a/user/wxFile/dirctrl.cpp +++ b/user/wxFile/dirctrl.cpp @@ -16,6 +16,7 @@ #include "dirctrl.h" #include "wx/gdicmn.h" #include "wx/utils.h" +#include "wx/dnd.h" //----------------------------------------------------------------------------- // wxDirInfo @@ -32,10 +33,8 @@ wxDirInfo::wxDirInfo( const wxString &path ) if (m_path == "/home") { m_name = "My Home"; - m_path += "/"; - char buf[300]; - wxGetHomeDir( buf ); - m_path = buf; + m_path = ""; + wxGetHomeDir( &m_path ); } else if (m_path == "/proc") m_name = "Info Filesystem"; @@ -73,8 +72,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxDirCtrl,wxTreeCtrl) BEGIN_EVENT_TABLE(wxDirCtrl,wxTreeCtrl) EVT_TREE_ITEM_EXPANDED (-1, wxDirCtrl::OnExpandItem) + EVT_TREE_ITEM_COLLAPSED (-1, wxDirCtrl::OnCollapseItem) EVT_TREE_DELETE_ITEM (-1, wxDirCtrl::OnDeleteItem) - EVT_MOUSE_EVENTS (wxDirCtrl::OnMouse) END_EVENT_TABLE() wxDirCtrl::wxDirCtrl(void) @@ -82,7 +81,7 @@ wxDirCtrl::wxDirCtrl(void) m_showHidden = FALSE; }; -wxDirCtrl::wxDirCtrl(wxWindow *parent, const wxWindowID id, const wxString &dir, +wxDirCtrl::wxDirCtrl(wxWindow *parent, const wxWindowID id, const wxString &WXUNUSED(dir), const wxPoint& pos, const wxSize& size, const long style, const wxString& name ) : @@ -92,56 +91,65 @@ wxDirCtrl::wxDirCtrl(wxWindow *parent, const wxWindowID id, const wxString &dir, wxTreeItem item; item.m_mask = wxTREE_MASK_TEXT | wxTREE_MASK_CHILDREN | wxTREE_MASK_DATA; - item.m_text = "root."; + item.m_text = "Sections"; item.m_children = 1; - wxDirInfo *info = new wxDirInfo( dir ); - item.m_data = (long)info; + m_rootId = InsertItem( 0, item ); - long root_id = InsertItem( 0, item ); - - info = new wxDirInfo( "/" ); - item.m_text = info->GetName(); - item.m_data = (long)info; - InsertItem( root_id, item ); +// SetDropTarget( new wxFileDropTarget() ); +}; + +void wxDirCtrl::OnExpandItem( const wxTreeEvent &event ) +{ + if (event.m_item.m_itemId == m_rootId) + { + + wxTreeItem item; + item.m_mask = wxTREE_MASK_TEXT | wxTREE_MASK_CHILDREN | wxTREE_MASK_DATA; + item.m_children = 1; + + wxDirInfo *info = new wxDirInfo( "/" ); + item.m_text = info->GetName(); + item.m_data = (long)info; + InsertItem( m_rootId, item ); - info = new wxDirInfo( "/home" ); - item.m_text = info->GetName(); - item.m_data = (long)info; - InsertItem( root_id, item ); + info = new wxDirInfo( "/home" ); + item.m_text = info->GetName(); + item.m_data = (long)info; + InsertItem( m_rootId, item ); - info = new wxDirInfo( "/mnt" ); - item.m_text = info->GetName(); - item.m_data = (long)info; - InsertItem( root_id, item ); + info = new wxDirInfo( "/mnt" ); + item.m_text = info->GetName(); + item.m_data = (long)info; + InsertItem( m_rootId, item ); - info = new wxDirInfo( "/usr" ); - item.m_text = info->GetName(); - item.m_data = (long)info; - InsertItem( root_id, item ); + info = new wxDirInfo( "/usr" ); + item.m_text = info->GetName(); + item.m_data = (long)info; + InsertItem( m_rootId, item ); - info = new wxDirInfo( "/usr/X11R6" ); - item.m_text = info->GetName(); - item.m_data = (long)info; - InsertItem( root_id, item ); + info = new wxDirInfo( "/usr/X11R6" ); + item.m_text = info->GetName(); + item.m_data = (long)info; + InsertItem( m_rootId, item ); - info = new wxDirInfo( "/usr/local" ); - item.m_text = info->GetName(); - item.m_data = (long)info; - InsertItem( root_id, item ); + info = new wxDirInfo( "/usr/local" ); + item.m_text = info->GetName(); + item.m_data = (long)info; + InsertItem( m_rootId, item ); - info = new wxDirInfo( "/var" ); - item.m_text = info->GetName(); - item.m_data = (long)info; - InsertItem( root_id, item ); + info = new wxDirInfo( "/var" ); + item.m_text = info->GetName(); + item.m_data = (long)info; + InsertItem( m_rootId, item ); - info = new wxDirInfo( "/proc" ); - item.m_text = info->GetName(); - item.m_data = (long)info; - InsertItem( root_id, item ); -}; + info = new wxDirInfo( "/proc" ); + item.m_text = info->GetName(); + item.m_data = (long)info; + InsertItem( m_rootId, item ); + + return; + }; -void wxDirCtrl::OnExpandItem( const wxTreeEvent &event ) -{ wxDirInfo *info = (wxDirInfo *)event.m_item.m_data; if (!info) return; @@ -168,12 +176,13 @@ void wxDirCtrl::OnExpandItem( const wxTreeEvent &event ) (path != "/proc") && (path != "/mnt") ) - slist.Add( path ); // ref counting in action ! + + slist.Add( path ); // ref counting in action ! }; path = wxFindNextFile(); }; - for (int i = 0; i < slist.Count(); i++) + for (uint i = 0; i < slist.Count(); i++) { search = slist[i]; search += "/*"; @@ -190,31 +199,13 @@ void wxDirCtrl::OnExpandItem( const wxTreeEvent &event ) }; }; -void wxDirCtrl::OnDeleteItem( const wxTreeEvent &event ) +void wxDirCtrl::OnCollapseItem( const wxTreeEvent &event ) { - wxDirInfo *info = (wxDirInfo *)event.m_item.m_data; - if (info) delete info; + DeleteChildren( event.m_item.m_itemId ); }; -void wxDirCtrl::OnMouse( wxMouseEvent &event ) +void wxDirCtrl::OnDeleteItem( const wxTreeEvent &event ) { - event.Skip(TRUE); - - if (event.LeftDown()) - { - m_dragX = event.GetX(); - m_dragY = event.GetY(); - return; - }; - - if (event.Dragging()) - { - if ((abs(m_dragX-event.GetX()) < 2) && - (abs(m_dragY-event.GetY()) < 2)) return; - - wxTextDragSource drag( this ); - drag.SetTextData( "Oh, what a drag." ); - drag.Start( event.GetX(), event.GetY() ); - }; + wxDirInfo *info = (wxDirInfo *)event.m_item.m_data; + if (info) delete info; }; -