]>
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_DELETE_ITEM (-1, wxDirCtrl::OnDeleteItem
)
77 EVT_MOUSE_EVENTS (wxDirCtrl::OnMouse
)
80 wxDirCtrl::wxDirCtrl(void)
85 wxDirCtrl::wxDirCtrl(wxWindow
*parent
, const wxWindowID id
, const wxString
&dir
,
86 const wxPoint
& pos
, const wxSize
& size
,
87 const long style
, const wxString
& name
)
89 wxTreeCtrl( parent
, id
, pos
, size
, style
, name
)
94 item
.m_mask
= wxTREE_MASK_TEXT
| wxTREE_MASK_CHILDREN
| wxTREE_MASK_DATA
;
95 item
.m_text
= "root.";
97 wxDirInfo
*info
= new wxDirInfo( dir
);
98 item
.m_data
= (long)info
;
100 long root_id
= InsertItem( 0, item
);
102 info
= new wxDirInfo( "/" );
103 item
.m_text
= info
->GetName();
104 item
.m_data
= (long)info
;
105 InsertItem( root_id
, item
);
107 info
= new wxDirInfo( "/home" );
108 item
.m_text
= info
->GetName();
109 item
.m_data
= (long)info
;
110 InsertItem( root_id
, item
);
112 info
= new wxDirInfo( "/mnt" );
113 item
.m_text
= info
->GetName();
114 item
.m_data
= (long)info
;
115 InsertItem( root_id
, item
);
117 info
= new wxDirInfo( "/usr" );
118 item
.m_text
= info
->GetName();
119 item
.m_data
= (long)info
;
120 InsertItem( root_id
, item
);
122 info
= new wxDirInfo( "/usr/X11R6" );
123 item
.m_text
= info
->GetName();
124 item
.m_data
= (long)info
;
125 InsertItem( root_id
, item
);
127 info
= new wxDirInfo( "/usr/local" );
128 item
.m_text
= info
->GetName();
129 item
.m_data
= (long)info
;
130 InsertItem( root_id
, item
);
132 info
= new wxDirInfo( "/var" );
133 item
.m_text
= info
->GetName();
134 item
.m_data
= (long)info
;
135 InsertItem( root_id
, item
);
137 info
= new wxDirInfo( "/proc" );
138 item
.m_text
= info
->GetName();
139 item
.m_data
= (long)info
;
140 InsertItem( root_id
, item
);
143 void wxDirCtrl::OnExpandItem( const wxTreeEvent
&event
)
145 wxDirInfo
*info
= (wxDirInfo
*)event
.m_item
.m_data
;
149 wxString search
,path
,filename
;
151 search
= info
->GetPath();
154 path
= wxFindFirstFile( search
, wxDIR
);
155 while (!path
.IsNull())
157 filename
= wxFileNameFromPath( path
);
158 if (m_showHidden
|| (filename
[0] != '.'))
160 if ((filename
!= ".") &&
161 (filename
!= "..") &&
163 (path
!= "/usr/X11R6") &&
164 (path
!= "/usr/local") &&
171 slist
.Add( path
); // ref counting in action !
173 path
= wxFindNextFile();
176 for (int i
= 0; i
< slist
.Count(); i
++)
180 path
= wxFindFirstFile( search
, wxDIR
);
182 wxDirInfo
*child
= new wxDirInfo( slist
[i
] );
184 item
.m_mask
= wxTREE_MASK_TEXT
| wxTREE_MASK_CHILDREN
| wxTREE_MASK_DATA
;
185 item
.m_text
= child
->GetName();
187 if (!path
.IsNull()) item
.m_children
= 1;
188 item
.m_data
= (long)child
;
189 InsertItem( event
.m_item
.m_itemId
, item
);
193 void wxDirCtrl::OnDeleteItem( const wxTreeEvent
&event
)
195 wxDirInfo
*info
= (wxDirInfo
*)event
.m_item
.m_data
;
196 if (info
) delete info
;
199 void wxDirCtrl::OnMouse( wxMouseEvent
&event
)
203 if (event
.LeftDown())
205 m_dragX
= event
.GetX();
206 m_dragY
= event
.GetY();
210 if (event
.Dragging())
212 if ((abs(m_dragX
-event
.GetX()) < 2) &&
213 (abs(m_dragY
-event
.GetY()) < 2)) return;
215 wxTextDragSource
drag( this );
216 drag
.SetTextData( "Oh, what a drag." );
217 drag
.Start( event
.GetX(), event
.GetY() );