]>
git.saurik.com Git - wxWidgets.git/blob - user/wxFile/dirctrl.cpp
2 * Author: Robert Roebling
4 * Copyright: (C) 1997,1998 Robert Roebling
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the wxWindows Licence, which
8 * you have received with this library (see Licence.htm).
13 #pragma implementation "dirctrl.h"
17 #include "wx/gdicmn.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 IMPLEMENT_DYNAMIC_CLASS(wxDirInfo
,wxObject
)
27 wxDirInfo::wxDirInfo( const wxString
&path
)
31 if (m_path
== "/") m_name
="The Computer";
33 if (m_path
== "/home")
37 wxGetHomeDir( &m_path
);
40 if (m_path
== "/proc") m_name
= "Info Filesystem";
42 if (m_path
== "/mnt") m_name
= "Mounted Devices";
44 if (m_path
== "/usr/X11R6") m_name
= "User X11";
46 if (m_path
== "/usr") m_name
= "User";
48 if (m_path
== "/var") m_name
= "Variables";
50 if (m_path
== "/usr/local") m_name
= "User local";
52 if (m_path
== "/mnt") m_name
= "Mounted Devices";
54 m_name
= wxFileNameFromPath( m_path
);
57 wxString
wxDirInfo::GetName(void) const
62 wxString
wxDirInfo::GetPath(void) const
67 //-----------------------------------------------------------------------------
69 //-----------------------------------------------------------------------------
71 IMPLEMENT_DYNAMIC_CLASS(wxDirCtrl
,wxTreeCtrl
)
73 BEGIN_EVENT_TABLE(wxDirCtrl
,wxTreeCtrl
)
74 EVT_TREE_ITEM_EXPANDED (-1, wxDirCtrl::OnExpandItem
)
75 EVT_TREE_ITEM_COLLAPSED (-1, wxDirCtrl::OnCollapseItem
)
76 EVT_TREE_DELETE_ITEM (-1, wxDirCtrl::OnDeleteItem
)
79 wxDirCtrl::wxDirCtrl(void)
84 wxDirCtrl::wxDirCtrl(wxWindow
*parent
, const wxWindowID id
, const wxString
&WXUNUSED(dir
),
85 const wxPoint
& pos
, const wxSize
& size
,
86 const long style
, const wxString
& name
)
88 wxTreeCtrl( parent
, id
, pos
, size
, style
, name
)
93 item
.m_mask
= wxTREE_MASK_TEXT
| wxTREE_MASK_CHILDREN
| wxTREE_MASK_DATA
;
94 item
.m_text
= "Sections";
96 m_rootId
= InsertItem( 0, item
);
98 // SetDropTarget( new wxFileDropTarget() );
101 void wxDirCtrl::OnExpandItem( const wxTreeEvent
&event
)
103 if (event
.m_item
.m_itemId
== m_rootId
)
107 item
.m_mask
= wxTREE_MASK_TEXT
| wxTREE_MASK_CHILDREN
| wxTREE_MASK_DATA
;
110 wxDirInfo
*info
= new wxDirInfo( "/" );
111 item
.m_text
= info
->GetName();
112 item
.m_data
= (long)info
;
113 InsertItem( m_rootId
, item
);
115 info
= new wxDirInfo( "/home" );
116 item
.m_text
= info
->GetName();
117 item
.m_data
= (long)info
;
118 InsertItem( m_rootId
, item
);
120 info
= new wxDirInfo( "/mnt" );
121 item
.m_text
= info
->GetName();
122 item
.m_data
= (long)info
;
123 InsertItem( m_rootId
, item
);
125 info
= new wxDirInfo( "/usr" );
126 item
.m_text
= info
->GetName();
127 item
.m_data
= (long)info
;
128 InsertItem( m_rootId
, item
);
130 info
= new wxDirInfo( "/usr/X11R6" );
131 item
.m_text
= info
->GetName();
132 item
.m_data
= (long)info
;
133 InsertItem( m_rootId
, item
);
135 info
= new wxDirInfo( "/usr/local" );
136 item
.m_text
= info
->GetName();
137 item
.m_data
= (long)info
;
138 InsertItem( m_rootId
, item
);
140 info
= new wxDirInfo( "/var" );
141 item
.m_text
= info
->GetName();
142 item
.m_data
= (long)info
;
143 InsertItem( m_rootId
, item
);
145 info
= new wxDirInfo( "/proc" );
146 item
.m_text
= info
->GetName();
147 item
.m_data
= (long)info
;
148 InsertItem( m_rootId
, item
);
153 wxDirInfo
*info
= (wxDirInfo
*)event
.m_item
.m_data
;
157 wxString search
,path
,filename
;
159 search
= info
->GetPath();
162 path
= wxFindFirstFile( search
, wxDIR
);
163 while (!path
.IsNull())
165 filename
= wxFileNameFromPath( path
);
166 if (m_showHidden
|| (filename
[0] != '.'))
168 if ((filename
!= ".") &&
169 (filename
!= "..") &&
171 (path
!= "/usr/X11R6") &&
172 (path
!= "/usr/local") &&
180 slist
.Add( path
); // ref counting in action !
182 path
= wxFindNextFile();
185 for (uint i
= 0; i
< slist
.Count(); i
++)
189 path
= wxFindFirstFile( search
, wxDIR
);
191 wxDirInfo
*child
= new wxDirInfo( slist
[i
] );
193 item
.m_mask
= wxTREE_MASK_TEXT
| wxTREE_MASK_CHILDREN
| wxTREE_MASK_DATA
;
194 item
.m_text
= child
->GetName();
196 if (!path
.IsNull()) item
.m_children
= 1;
197 item
.m_data
= (long)child
;
198 InsertItem( event
.m_item
.m_itemId
, item
);
202 void wxDirCtrl::OnCollapseItem( const wxTreeEvent
&event
)
204 DeleteChildren( event
.m_item
.m_itemId
);
207 void wxDirCtrl::OnDeleteItem( const wxTreeEvent
&event
)
209 wxDirInfo
*info
= (wxDirInfo
*)event
.m_item
.m_data
;
210 if (info
) delete info
;