]>
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"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 IMPLEMENT_DYNAMIC_CLASS(wxDirInfo
,wxObject
)
26 wxDirInfo::wxDirInfo( const wxString
&path
)
30 if (m_path
== "/") m_name
="The Computer";
32 if (m_path
== "/home")
41 if (m_path
== "/proc") m_name
= "Info Filesystem";
43 if (m_path
== "/mnt") m_name
= "Mounted Devices";
45 if (m_path
== "/usr/X11R6") m_name
= "User X11";
47 if (m_path
== "/usr") m_name
= "User";
49 if (m_path
== "/var") m_name
= "Variables";
51 if (m_path
== "/usr/local") m_name
= "User local";
53 if (m_path
== "/mnt") m_name
= "Mounted Devices";
55 m_name
= wxFileNameFromPath( m_path
);
58 wxString
wxDirInfo::GetName(void) const
63 wxString
wxDirInfo::GetPath(void) const
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
72 IMPLEMENT_DYNAMIC_CLASS(wxDirCtrl
,wxTreeCtrl
)
74 BEGIN_EVENT_TABLE(wxDirCtrl
,wxTreeCtrl
)
75 EVT_TREE_ITEM_EXPANDED (-1, wxDirCtrl::OnExpandItem
)
76 EVT_TREE_ITEM_COLLAPSED (-1, wxDirCtrl::OnCollapseItem
)
77 EVT_TREE_DELETE_ITEM (-1, wxDirCtrl::OnDeleteItem
)
78 EVT_MOUSE_EVENTS (wxDirCtrl::OnMouse
)
81 wxDirCtrl::wxDirCtrl(void)
86 wxDirCtrl::wxDirCtrl(wxWindow
*parent
, const wxWindowID id
, const wxString
&WXUNUSED(dir
),
87 const wxPoint
& pos
, const wxSize
& size
,
88 const long style
, const wxString
& name
)
90 wxTreeCtrl( parent
, id
, pos
, size
, style
, name
)
95 item
.m_mask
= wxTREE_MASK_TEXT
| wxTREE_MASK_CHILDREN
| wxTREE_MASK_DATA
;
96 item
.m_text
= "Sections";
99 wxDirInfo *info = new wxDirInfo( dir );
100 item.m_data = (long)info;
102 m_rootId
= InsertItem( 0, item
);
105 void wxDirCtrl::OnExpandItem( const wxTreeEvent
&event
)
107 if (event
.m_item
.m_itemId
== m_rootId
)
111 item
.m_mask
= wxTREE_MASK_TEXT
| wxTREE_MASK_CHILDREN
| wxTREE_MASK_DATA
;
114 wxDirInfo
*info
= new wxDirInfo( "/" );
115 item
.m_text
= info
->GetName();
116 item
.m_data
= (long)info
;
117 InsertItem( m_rootId
, item
);
119 info
= new wxDirInfo( "/home" );
120 item
.m_text
= info
->GetName();
121 item
.m_data
= (long)info
;
122 InsertItem( m_rootId
, item
);
124 info
= new wxDirInfo( "/mnt" );
125 item
.m_text
= info
->GetName();
126 item
.m_data
= (long)info
;
127 InsertItem( m_rootId
, item
);
129 info
= new wxDirInfo( "/usr" );
130 item
.m_text
= info
->GetName();
131 item
.m_data
= (long)info
;
132 InsertItem( m_rootId
, item
);
134 info
= new wxDirInfo( "/usr/X11R6" );
135 item
.m_text
= info
->GetName();
136 item
.m_data
= (long)info
;
137 InsertItem( m_rootId
, item
);
139 info
= new wxDirInfo( "/usr/local" );
140 item
.m_text
= info
->GetName();
141 item
.m_data
= (long)info
;
142 InsertItem( m_rootId
, item
);
144 info
= new wxDirInfo( "/var" );
145 item
.m_text
= info
->GetName();
146 item
.m_data
= (long)info
;
147 InsertItem( m_rootId
, item
);
149 info
= new wxDirInfo( "/proc" );
150 item
.m_text
= info
->GetName();
151 item
.m_data
= (long)info
;
152 InsertItem( m_rootId
, item
);
157 wxDirInfo
*info
= (wxDirInfo
*)event
.m_item
.m_data
;
161 wxString search
,path
,filename
;
163 search
= info
->GetPath();
166 path
= wxFindFirstFile( search
, wxDIR
);
167 while (!path
.IsNull())
169 filename
= wxFileNameFromPath( path
);
170 if (m_showHidden
|| (filename
[0] != '.'))
172 if ((filename
!= ".") &&
173 (filename
!= "..") &&
175 (path
!= "/usr/X11R6") &&
176 (path
!= "/usr/local") &&
183 slist
.Add( path
); // ref counting in action !
185 path
= wxFindNextFile();
188 for (uint i
= 0; i
< slist
.Count(); i
++)
192 path
= wxFindFirstFile( search
, wxDIR
);
194 wxDirInfo
*child
= new wxDirInfo( slist
[i
] );
196 item
.m_mask
= wxTREE_MASK_TEXT
| wxTREE_MASK_CHILDREN
| wxTREE_MASK_DATA
;
197 item
.m_text
= child
->GetName();
199 if (!path
.IsNull()) item
.m_children
= 1;
200 item
.m_data
= (long)child
;
201 InsertItem( event
.m_item
.m_itemId
, item
);
205 void wxDirCtrl::OnCollapseItem( const wxTreeEvent
&event
)
207 DeleteChildren( event
.m_item
.m_itemId
);
210 void wxDirCtrl::OnDeleteItem( const wxTreeEvent
&event
)
212 wxDirInfo
*info
= (wxDirInfo
*)event
.m_item
.m_data
;
213 if (info
) delete info
;
216 void wxDirCtrl::OnMouse( wxMouseEvent
&event
)
220 if (event
.LeftDown())
222 m_dragX
= event
.GetX();
223 m_dragY
= event
.GetY();
227 if (event
.Dragging())
229 if ((abs(m_dragX
-event
.GetX()) < 2) &&
230 (abs(m_dragY
-event
.GetY()) < 2)) return;
232 wxTextDragSource
drag( this );
233 drag
.SetTextData( "Oh, what a drag." );
234 drag
.Start( event
.GetX(), event
.GetY() );