#include "dirctrl.h"
#include "wx/gdicmn.h"
#include "wx/utils.h"
+#include "wx/dnd.h"
//-----------------------------------------------------------------------------
// wxDirInfo
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";
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)
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 )
:
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;
(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 += "/*";
};
};
-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;
};
-