rename wxFileList to wxFileListCtrl
[wxWidgets.git] / src / generic / filectrlg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/filectrlg.cpp
3 // Purpose: wxGenericFileCtrl Implementation
4 // Author: Diaa M. Sami
5 // Created: 2007-07-07
6 // RCS-ID: $Id$
7 // Copyright: (c) Diaa M. Sami
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #if wxUSE_FILECTRL
18
19 #include "wx/generic/filectrlg.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/settings.h"
23 #include "wx/sizer.h"
24 #include "wx/stattext.h"
25 #include "wx/checkbox.h"
26 #include "wx/msgdlg.h"
27 #include "wx/log.h"
28 #include "wx/filedlg.h"
29 #endif
30
31 #include "wx/filename.h"
32 #include "wx/clntdata.h"
33 #include "wx/file.h" // for wxS_IXXX constants only
34 #include "wx/generic/dirctrlg.h" // for wxFileIconsTable
35 #include "wx/dir.h"
36 #include "wx/tokenzr.h"
37
38 #ifdef __WXMSW__
39 #include "wx/msw/wrapwin.h"
40 #endif
41
42 #if defined(__WXWINCE__)
43 #define IsTopMostDir(dir) (dir == wxT("\\") || dir == wxT("/"))
44 #elif (defined(__DOS__) || defined(__WINDOWS__) || defined (__OS2__))
45 #define IsTopMostDir(dir) (dir.empty())
46 #else
47 #define IsTopMostDir(dir) (dir == wxT("/"))
48 #endif
49
50
51 // ----------------------------------------------------------------------------
52 // private functions
53 // ----------------------------------------------------------------------------
54
55 static
56 int wxCALLBACK wxFileDataNameCompare( long data1, long data2, long sortOrder)
57 {
58 wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1);
59 wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2);
60
61 if (fd1->GetFileName() == wxT(".."))
62 return -sortOrder;
63 if (fd2->GetFileName() == wxT(".."))
64 return sortOrder;
65 if (fd1->IsDir() && !fd2->IsDir())
66 return -sortOrder;
67 if (fd2->IsDir() && !fd1->IsDir())
68 return sortOrder;
69
70 return sortOrder*wxStrcmp( fd1->GetFileName(), fd2->GetFileName() );
71 }
72
73 static
74 int wxCALLBACK wxFileDataSizeCompare(long data1, long data2, long sortOrder)
75 {
76 wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1);
77 wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2);
78
79 if (fd1->GetFileName() == wxT(".."))
80 return -sortOrder;
81 if (fd2->GetFileName() == wxT(".."))
82 return sortOrder;
83 if (fd1->IsDir() && !fd2->IsDir())
84 return -sortOrder;
85 if (fd2->IsDir() && !fd1->IsDir())
86 return sortOrder;
87 if (fd1->IsLink() && !fd2->IsLink())
88 return -sortOrder;
89 if (fd2->IsLink() && !fd1->IsLink())
90 return sortOrder;
91
92 return fd1->GetSize() > fd2->GetSize() ? sortOrder : -sortOrder;
93 }
94
95 static
96 int wxCALLBACK wxFileDataTypeCompare(long data1, long data2, long sortOrder)
97 {
98 wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1);
99 wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2);
100
101 if (fd1->GetFileName() == wxT(".."))
102 return -sortOrder;
103 if (fd2->GetFileName() == wxT(".."))
104 return sortOrder;
105 if (fd1->IsDir() && !fd2->IsDir())
106 return -sortOrder;
107 if (fd2->IsDir() && !fd1->IsDir())
108 return sortOrder;
109 if (fd1->IsLink() && !fd2->IsLink())
110 return -sortOrder;
111 if (fd2->IsLink() && !fd1->IsLink())
112 return sortOrder;
113
114 return sortOrder*wxStrcmp( fd1->GetFileType(), fd2->GetFileType() );
115 }
116
117 static
118 int wxCALLBACK wxFileDataTimeCompare(long data1, long data2, long sortOrder)
119 {
120 wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1);
121 wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2);
122
123 if (fd1->GetFileName() == wxT(".."))
124 return -sortOrder;
125 if (fd2->GetFileName() == wxT(".."))
126 return sortOrder;
127 if (fd1->IsDir() && !fd2->IsDir())
128 return -sortOrder;
129 if (fd2->IsDir() && !fd1->IsDir())
130 return sortOrder;
131
132 return fd1->GetDateTime().IsLaterThan(fd2->GetDateTime()) ? sortOrder : -sortOrder;
133 }
134
135 // defined in src/generic/dirctrlg.cpp
136 extern size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayInt &icon_ids);
137
138 //-----------------------------------------------------------------------------
139 // wxFileData
140 //-----------------------------------------------------------------------------
141
142 wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, fileType type, int image_id )
143 {
144 Init();
145 m_fileName = fileName;
146 m_filePath = filePath;
147 m_type = type;
148 m_image = image_id;
149
150 ReadData();
151 }
152
153 void wxFileData::Init()
154 {
155 m_size = 0;
156 m_type = wxFileData::is_file;
157 m_image = wxFileIconsTable::file;
158 }
159
160 void wxFileData::Copy( const wxFileData& fileData )
161 {
162 m_fileName = fileData.GetFileName();
163 m_filePath = fileData.GetFilePath();
164 m_size = fileData.GetSize();
165 m_dateTime = fileData.GetDateTime();
166 m_permissions = fileData.GetPermissions();
167 m_type = fileData.GetType();
168 m_image = fileData.GetImageId();
169 }
170
171 void wxFileData::ReadData()
172 {
173 if (IsDrive())
174 {
175 m_size = 0;
176 return;
177 }
178
179 #if defined(__DOS__) || (defined(__WINDOWS__) && !defined(__WXWINCE__)) || defined(__OS2__)
180 // c:\.. is a drive don't stat it
181 if ((m_fileName == wxT("..")) && (m_filePath.length() <= 5))
182 {
183 m_type = is_drive;
184 m_size = 0;
185 return;
186 }
187 #endif // __DOS__ || __WINDOWS__
188
189 #ifdef __WXWINCE__
190
191 // WinCE
192
193 DWORD fileAttribs = GetFileAttributes(m_filePath.fn_str());
194 m_type |= (fileAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0 ? is_dir : 0;
195
196 wxString p, f, ext;
197 wxSplitPath(m_filePath, & p, & f, & ext);
198 if (wxStricmp(ext, wxT("exe")) == 0)
199 m_type |= is_exe;
200
201 // Find out size
202 m_size = 0;
203 HANDLE fileHandle = CreateFile(m_filePath.fn_str(),
204 GENERIC_READ,
205 FILE_SHARE_READ,
206 NULL,
207 OPEN_EXISTING,
208 FILE_ATTRIBUTE_NORMAL,
209 NULL);
210
211 if (fileHandle != INVALID_HANDLE_VALUE)
212 {
213 m_size = GetFileSize(fileHandle, 0);
214 CloseHandle(fileHandle);
215 }
216
217 m_dateTime = wxFileModificationTime(m_filePath);
218
219 #else
220
221 // OTHER PLATFORMS
222
223 wxStructStat buff;
224
225 #if defined(__UNIX__) && (!defined( __OS2__ ) && !defined(__VMS))
226 lstat( m_filePath.fn_str(), &buff );
227 m_type |= S_ISLNK( buff.st_mode ) != 0 ? is_link : 0;
228 #else // no lstat()
229 // only translate to file charset if we don't go by our
230 // wxStat implementation
231 #ifndef wxNEED_WX_UNISTD_H
232 wxStat( m_filePath.fn_str() , &buff );
233 #else
234 wxStat( m_filePath, &buff );
235 #endif
236 #endif
237
238 m_type |= (buff.st_mode & S_IFDIR) != 0 ? is_dir : 0;
239 m_type |= (buff.st_mode & wxS_IXUSR) != 0 ? is_exe : 0;
240
241 m_size = buff.st_size;
242
243 m_dateTime = buff.st_mtime;
244 #endif
245 // __WXWINCE__
246
247 #if defined(__UNIX__)
248 m_permissions.Printf(_T("%c%c%c%c%c%c%c%c%c"),
249 buff.st_mode & wxS_IRUSR ? _T('r') : _T('-'),
250 buff.st_mode & wxS_IWUSR ? _T('w') : _T('-'),
251 buff.st_mode & wxS_IXUSR ? _T('x') : _T('-'),
252 buff.st_mode & wxS_IRGRP ? _T('r') : _T('-'),
253 buff.st_mode & wxS_IWGRP ? _T('w') : _T('-'),
254 buff.st_mode & wxS_IXGRP ? _T('x') : _T('-'),
255 buff.st_mode & wxS_IROTH ? _T('r') : _T('-'),
256 buff.st_mode & wxS_IWOTH ? _T('w') : _T('-'),
257 buff.st_mode & wxS_IXOTH ? _T('x') : _T('-'));
258 #elif defined(__WIN32__)
259 DWORD attribs = ::GetFileAttributes(m_filePath.c_str());
260 if (attribs != (DWORD)-1)
261 {
262 m_permissions.Printf(_T("%c%c%c%c"),
263 attribs & FILE_ATTRIBUTE_ARCHIVE ? _T('A') : _T(' '),
264 attribs & FILE_ATTRIBUTE_READONLY ? _T('R') : _T(' '),
265 attribs & FILE_ATTRIBUTE_HIDDEN ? _T('H') : _T(' '),
266 attribs & FILE_ATTRIBUTE_SYSTEM ? _T('S') : _T(' '));
267 }
268 #endif
269
270 // try to get a better icon
271 if (m_image == wxFileIconsTable::file)
272 {
273 if (m_fileName.Find(wxT('.'), true) != wxNOT_FOUND)
274 {
275 m_image = wxTheFileIconsTable->GetIconID( m_fileName.AfterLast(wxT('.')));
276 } else if (IsExe())
277 {
278 m_image = wxFileIconsTable::executable;
279 }
280 }
281 }
282
283 wxString wxFileData::GetFileType() const
284 {
285 if (IsDir())
286 return _("<DIR>");
287 else if (IsLink())
288 return _("<LINK>");
289 else if (IsDrive())
290 return _("<DRIVE>");
291 else if (m_fileName.Find(wxT('.'), true) != wxNOT_FOUND)
292 return m_fileName.AfterLast(wxT('.'));
293
294 return wxEmptyString;
295 }
296
297 wxString wxFileData::GetModificationTime() const
298 {
299 // want time as 01:02 so they line up nicely, no %r in WIN32
300 return m_dateTime.FormatDate() + wxT(" ") + m_dateTime.Format(wxT("%I:%M:%S %p"));
301 }
302
303 wxString wxFileData::GetHint() const
304 {
305 wxString s = m_filePath;
306 s += wxT(" ");
307
308 if (IsDir())
309 s += _("<DIR>");
310 else if (IsLink())
311 s += _("<LINK>");
312 else if (IsDrive())
313 s += _("<DRIVE>");
314 else // plain file
315 s += wxString::Format(wxPLURAL("%ld byte", "%ld bytes", m_size),
316 wxLongLong(m_size).ToString().c_str());
317
318 s += wxT(' ');
319
320 if ( !IsDrive() )
321 {
322 s << GetModificationTime()
323 << wxT(" ")
324 << m_permissions;
325 }
326
327 return s;
328 }
329
330 wxString wxFileData::GetEntry( fileListFieldType num ) const
331 {
332 wxString s;
333 switch ( num )
334 {
335 case FileList_Name:
336 s = m_fileName;
337 break;
338
339 case FileList_Size:
340 if (!IsDir() && !IsLink() && !IsDrive())
341 s = wxLongLong(m_size).ToString();
342 break;
343
344 case FileList_Type:
345 s = GetFileType();
346 break;
347
348 case FileList_Time:
349 if (!IsDrive())
350 s = GetModificationTime();
351 break;
352
353 #if defined(__UNIX__) || defined(__WIN32__)
354 case FileList_Perm:
355 s = m_permissions;
356 break;
357 #endif // defined(__UNIX__) || defined(__WIN32__)
358
359 default:
360 wxFAIL_MSG( _T("unexpected field in wxFileData::GetEntry()") );
361 }
362
363 return s;
364 }
365
366 void wxFileData::SetNewName( const wxString &filePath, const wxString &fileName )
367 {
368 m_fileName = fileName;
369 m_filePath = filePath;
370 }
371
372 void wxFileData::MakeItem( wxListItem &item )
373 {
374 item.m_text = m_fileName;
375 item.ClearAttributes();
376 if (IsExe())
377 item.SetTextColour(*wxRED);
378 if (IsDir())
379 item.SetTextColour(*wxBLUE);
380
381 item.m_image = m_image;
382
383 if (IsLink())
384 {
385 wxColour dg = wxTheColourDatabase->Find( _T("MEDIUM GREY") );
386 if ( dg.Ok() )
387 item.SetTextColour(dg);
388 }
389 item.m_data = wxPtrToUInt(this);
390 }
391
392 //-----------------------------------------------------------------------------
393 // wxFileListCtrl
394 //-----------------------------------------------------------------------------
395
396 static bool ignoreChanges = false;
397
398 IMPLEMENT_DYNAMIC_CLASS(wxFileListCtrl,wxListCtrl)
399
400 BEGIN_EVENT_TABLE(wxFileListCtrl,wxListCtrl)
401 EVT_LIST_DELETE_ITEM(wxID_ANY, wxFileListCtrl::OnListDeleteItem)
402 EVT_LIST_DELETE_ALL_ITEMS(wxID_ANY, wxFileListCtrl::OnListDeleteAllItems)
403 EVT_LIST_END_LABEL_EDIT(wxID_ANY, wxFileListCtrl::OnListEndLabelEdit)
404 EVT_LIST_COL_CLICK(wxID_ANY, wxFileListCtrl::OnListColClick)
405 END_EVENT_TABLE()
406
407
408 wxFileListCtrl::wxFileListCtrl()
409 {
410 m_showHidden = false;
411 m_sort_foward = 1;
412 m_sort_field = wxFileData::FileList_Name;
413 }
414
415 wxFileListCtrl::wxFileListCtrl(wxWindow *win,
416 wxWindowID id,
417 const wxString& wild,
418 bool showHidden,
419 const wxPoint& pos,
420 const wxSize& size,
421 long style,
422 const wxValidator &validator,
423 const wxString &name)
424 : wxListCtrl(win, id, pos, size, style, validator, name),
425 m_wild(wild)
426 {
427 wxImageList *imageList = wxTheFileIconsTable->GetSmallImageList();
428
429 SetImageList( imageList, wxIMAGE_LIST_SMALL );
430
431 m_showHidden = showHidden;
432
433 m_sort_foward = 1;
434 m_sort_field = wxFileData::FileList_Name;
435
436 m_dirName = wxT("*");
437
438 if (style & wxLC_REPORT)
439 ChangeToReportMode();
440 }
441
442 void wxFileListCtrl::ChangeToListMode()
443 {
444 ClearAll();
445 SetSingleStyle( wxLC_LIST );
446 UpdateFiles();
447 }
448
449 void wxFileListCtrl::ChangeToReportMode()
450 {
451 ClearAll();
452 SetSingleStyle( wxLC_REPORT );
453
454 // do this since WIN32 does mm/dd/yy UNIX does mm/dd/yyyy
455 // don't hardcode since mm/dd is dd/mm elsewhere
456 int w, h;
457 wxDateTime dt(22, wxDateTime::Dec, 2002, 22, 22, 22);
458 wxString txt = dt.FormatDate() + wxT("22") + dt.Format(wxT("%I:%M:%S %p"));
459 GetTextExtent(txt, &w, &h);
460
461 InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT, w );
462 InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT, w/2 );
463 InsertColumn( 2, _("Type"), wxLIST_FORMAT_LEFT, w/2 );
464 InsertColumn( 3, _("Modified"), wxLIST_FORMAT_LEFT, w );
465 #if defined(__UNIX__)
466 GetTextExtent(wxT("Permissions 2"), &w, &h);
467 InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT, w );
468 #elif defined(__WIN32__)
469 GetTextExtent(wxT("Attributes 2"), &w, &h);
470 InsertColumn( 4, _("Attributes"), wxLIST_FORMAT_LEFT, w );
471 #endif
472
473 UpdateFiles();
474 }
475
476 void wxFileListCtrl::ChangeToSmallIconMode()
477 {
478 ClearAll();
479 SetSingleStyle( wxLC_SMALL_ICON );
480 UpdateFiles();
481 }
482
483 void wxFileListCtrl::ShowHidden( bool show )
484 {
485 m_showHidden = show;
486 UpdateFiles();
487 }
488
489 long wxFileListCtrl::Add( wxFileData *fd, wxListItem &item )
490 {
491 long ret = -1;
492 item.m_mask = wxLIST_MASK_TEXT + wxLIST_MASK_DATA + wxLIST_MASK_IMAGE;
493 fd->MakeItem( item );
494 long my_style = GetWindowStyleFlag();
495 if (my_style & wxLC_REPORT)
496 {
497 ret = InsertItem( item );
498 for (int i = 1; i < wxFileData::FileList_Max; i++)
499 SetItem( item.m_itemId, i, fd->GetEntry((wxFileData::fileListFieldType)i) );
500 }
501 else if ((my_style & wxLC_LIST) || (my_style & wxLC_SMALL_ICON))
502 {
503 ret = InsertItem( item );
504 }
505 return ret;
506 }
507
508 void wxFileListCtrl::UpdateItem(const wxListItem &item)
509 {
510 wxFileData *fd = (wxFileData*)GetItemData(item);
511 wxCHECK_RET(fd, wxT("invalid filedata"));
512
513 fd->ReadData();
514
515 SetItemText(item, fd->GetFileName());
516 SetItemImage(item, fd->GetImageId());
517
518 if (GetWindowStyleFlag() & wxLC_REPORT)
519 {
520 for (int i = 1; i < wxFileData::FileList_Max; i++)
521 SetItem( item.m_itemId, i, fd->GetEntry((wxFileData::fileListFieldType)i) );
522 }
523 }
524
525 void wxFileListCtrl::UpdateFiles()
526 {
527 // don't do anything before ShowModal() call which sets m_dirName
528 if ( m_dirName == wxT("*") )
529 return;
530
531 wxBusyCursor bcur; // this may take a while...
532
533 DeleteAllItems();
534
535 wxListItem item;
536 item.m_itemId = 0;
537 item.m_col = 0;
538
539 #if (defined(__WINDOWS__) || defined(__DOS__) || defined(__WXMAC__) || defined(__OS2__)) && !defined(__WXWINCE__)
540 if ( IsTopMostDir(m_dirName) )
541 {
542 wxArrayString names, paths;
543 wxArrayInt icons;
544 size_t n, count = wxGetAvailableDrives(paths, names, icons);
545
546 for (n=0; n<count; n++)
547 {
548 wxFileData *fd = new wxFileData(paths[n], names[n], wxFileData::is_drive, icons[n]);
549 if (Add(fd, item) != -1)
550 item.m_itemId++;
551 else
552 delete fd;
553 }
554 }
555 else
556 #endif // defined(__DOS__) || defined(__WINDOWS__)
557 {
558 // Real directory...
559 if ( !IsTopMostDir(m_dirName) && !m_dirName.empty() )
560 {
561 wxString p(wxPathOnly(m_dirName));
562 #if (defined(__UNIX__) || defined(__WXWINCE__)) && !defined(__OS2__)
563 if (p.empty()) p = wxT("/");
564 #endif // __UNIX__
565 wxFileData *fd = new wxFileData(p, wxT(".."), wxFileData::is_dir, wxFileIconsTable::folder);
566 if (Add(fd, item) != -1)
567 item.m_itemId++;
568 else
569 delete fd;
570 }
571
572 wxString dirname(m_dirName);
573 #if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
574 if (dirname.length() == 2 && dirname[1u] == wxT(':'))
575 dirname << wxT('\\');
576 #endif // defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
577
578 if (dirname.empty())
579 dirname = wxFILE_SEP_PATH;
580
581 wxLogNull logNull;
582 wxDir dir(dirname);
583
584 if ( dir.IsOpened() )
585 {
586 wxString dirPrefix(dirname);
587 if (dirPrefix.Last() != wxFILE_SEP_PATH)
588 dirPrefix += wxFILE_SEP_PATH;
589
590 int hiddenFlag = m_showHidden ? wxDIR_HIDDEN : 0;
591
592 bool cont;
593 wxString f;
594
595 // Get the directories first (not matched against wildcards):
596 cont = dir.GetFirst(&f, wxEmptyString, wxDIR_DIRS | hiddenFlag);
597 while (cont)
598 {
599 wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_dir, wxFileIconsTable::folder);
600 if (Add(fd, item) != -1)
601 item.m_itemId++;
602 else
603 delete fd;
604
605 cont = dir.GetNext(&f);
606 }
607
608 // Tokenize the wildcard string, so we can handle more than 1
609 // search pattern in a wildcard.
610 wxStringTokenizer tokenWild(m_wild, wxT(";"));
611 while ( tokenWild.HasMoreTokens() )
612 {
613 cont = dir.GetFirst(&f, tokenWild.GetNextToken(),
614 wxDIR_FILES | hiddenFlag);
615 while (cont)
616 {
617 wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_file, wxFileIconsTable::file);
618 if (Add(fd, item) != -1)
619 item.m_itemId++;
620 else
621 delete fd;
622
623 cont = dir.GetNext(&f);
624 }
625 }
626 }
627 }
628
629 SortItems(m_sort_field, m_sort_foward);
630 }
631
632 void wxFileListCtrl::SetWild( const wxString &wild )
633 {
634 if (wild.Find(wxT('|')) != wxNOT_FOUND)
635 return;
636
637 m_wild = wild;
638 UpdateFiles();
639 }
640
641 void wxFileListCtrl::MakeDir()
642 {
643 wxString new_name( _("NewName") );
644 wxString path( m_dirName );
645 path += wxFILE_SEP_PATH;
646 path += new_name;
647 if (wxFileExists(path))
648 {
649 // try NewName0, NewName1 etc.
650 int i = 0;
651 do {
652 new_name = _("NewName");
653 wxString num;
654 num.Printf( wxT("%d"), i );
655 new_name += num;
656
657 path = m_dirName;
658 path += wxFILE_SEP_PATH;
659 path += new_name;
660 i++;
661 } while (wxFileExists(path));
662 }
663
664 wxLogNull log;
665 if (!wxMkdir(path))
666 {
667 wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
668 dialog.ShowModal();
669 return;
670 }
671
672 wxFileData *fd = new wxFileData( path, new_name, wxFileData::is_dir, wxFileIconsTable::folder );
673 wxListItem item;
674 item.m_itemId = 0;
675 item.m_col = 0;
676 long id = Add( fd, item );
677
678 if (id != -1)
679 {
680 SortItems(m_sort_field, m_sort_foward);
681 id = FindItem( 0, wxPtrToUInt(fd) );
682 EnsureVisible( id );
683 EditLabel( id );
684 }
685 else
686 delete fd;
687 }
688
689 void wxFileListCtrl::GoToParentDir()
690 {
691 if (!IsTopMostDir(m_dirName))
692 {
693 size_t len = m_dirName.length();
694 if (wxEndsWithPathSeparator(m_dirName))
695 m_dirName.Remove( len-1, 1 );
696 wxString fname( wxFileNameFromPath(m_dirName) );
697 m_dirName = wxPathOnly( m_dirName );
698 #if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__)
699 if (!m_dirName.empty())
700 {
701 if (m_dirName.Last() == wxT('.'))
702 m_dirName = wxEmptyString;
703 }
704 #elif defined(__UNIX__)
705 if (m_dirName.empty())
706 m_dirName = wxT("/");
707 #endif
708 UpdateFiles();
709 long id = FindItem( 0, fname );
710 if (id != wxNOT_FOUND)
711 {
712 ignoreChanges = true;
713 SetItemState( id, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
714 EnsureVisible( id );
715 ignoreChanges = false;
716 }
717 }
718 }
719
720 void wxFileListCtrl::GoToHomeDir()
721 {
722 wxString s = wxGetUserHome( wxString() );
723 GoToDir(s);
724 }
725
726 void wxFileListCtrl::GoToDir( const wxString &dir )
727 {
728 if (!wxDirExists(dir)) return;
729
730 m_dirName = dir;
731 UpdateFiles();
732
733 ignoreChanges = true;
734 SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
735 ignoreChanges = false;
736
737 EnsureVisible( 0 );
738 }
739
740 void wxFileListCtrl::FreeItemData(wxListItem& item)
741 {
742 if ( item.m_data )
743 {
744 wxFileData *fd = (wxFileData*)item.m_data;
745 delete fd;
746
747 item.m_data = 0;
748 }
749 }
750
751 void wxFileListCtrl::OnListDeleteItem( wxListEvent &event )
752 {
753 FreeItemData(event.m_item);
754 }
755
756 void wxFileListCtrl::OnListDeleteAllItems( wxListEvent & WXUNUSED(event) )
757 {
758 FreeAllItemsData();
759 }
760
761 void wxFileListCtrl::FreeAllItemsData()
762 {
763 wxListItem item;
764 item.m_mask = wxLIST_MASK_DATA;
765
766 item.m_itemId = GetNextItem( -1, wxLIST_NEXT_ALL );
767 while ( item.m_itemId != -1 )
768 {
769 GetItem( item );
770 FreeItemData(item);
771 item.m_itemId = GetNextItem( item.m_itemId, wxLIST_NEXT_ALL );
772 }
773 }
774
775 void wxFileListCtrl::OnListEndLabelEdit( wxListEvent &event )
776 {
777 wxFileData *fd = (wxFileData*)event.m_item.m_data;
778 wxASSERT( fd );
779
780 if ((event.GetLabel().empty()) ||
781 (event.GetLabel() == wxT(".")) ||
782 (event.GetLabel() == wxT("..")) ||
783 (event.GetLabel().First( wxFILE_SEP_PATH ) != wxNOT_FOUND))
784 {
785 wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR );
786 dialog.ShowModal();
787 event.Veto();
788 return;
789 }
790
791 wxString new_name( wxPathOnly( fd->GetFilePath() ) );
792 new_name += wxFILE_SEP_PATH;
793 new_name += event.GetLabel();
794
795 wxLogNull log;
796
797 if (wxFileExists(new_name))
798 {
799 wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR );
800 dialog.ShowModal();
801 event.Veto();
802 }
803
804 if (wxRenameFile(fd->GetFilePath(),new_name))
805 {
806 fd->SetNewName( new_name, event.GetLabel() );
807
808 ignoreChanges = true;
809 SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
810 ignoreChanges = false;
811
812 UpdateItem( event.GetItem() );
813 EnsureVisible( event.GetItem() );
814 }
815 else
816 {
817 wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
818 dialog.ShowModal();
819 event.Veto();
820 }
821 }
822
823 void wxFileListCtrl::OnListColClick( wxListEvent &event )
824 {
825 int col = event.GetColumn();
826
827 switch (col)
828 {
829 case wxFileData::FileList_Name :
830 case wxFileData::FileList_Size :
831 case wxFileData::FileList_Type :
832 case wxFileData::FileList_Time : break;
833 default : return;
834 }
835
836 if ((wxFileData::fileListFieldType)col == m_sort_field)
837 m_sort_foward = !m_sort_foward;
838 else
839 m_sort_field = (wxFileData::fileListFieldType)col;
840
841 SortItems(m_sort_field, m_sort_foward);
842 }
843
844 void wxFileListCtrl::SortItems(wxFileData::fileListFieldType field, bool forward)
845 {
846 m_sort_field = field;
847 m_sort_foward = forward;
848 const long sort_dir = forward ? 1 : -1;
849
850 switch (m_sort_field)
851 {
852 case wxFileData::FileList_Size :
853 wxListCtrl::SortItems(wxFileDataSizeCompare, sort_dir);
854 break;
855
856 case wxFileData::FileList_Type :
857 wxListCtrl::SortItems(wxFileDataTypeCompare, sort_dir);
858 break;
859
860 case wxFileData::FileList_Time :
861 wxListCtrl::SortItems(wxFileDataTimeCompare, sort_dir);
862 break;
863
864 case wxFileData::FileList_Name :
865 default :
866 wxListCtrl::SortItems(wxFileDataNameCompare, sort_dir);
867 break;
868 }
869 }
870
871 wxFileListCtrl::~wxFileListCtrl()
872 {
873 // Normally the data are freed via an EVT_LIST_DELETE_ALL_ITEMS event and
874 // wxFileListCtrl::OnListDeleteAllItems. But if the event is generated after
875 // the destruction of the wxFileListCtrl we need to free any data here:
876 FreeAllItemsData();
877 }
878
879 #define ID_CHOICE (wxID_FILECTRL + 1)
880 #define ID_TEXT (wxID_FILECTRL + 2)
881 #define ID_FILELIST_CTRL (wxID_FILECTRL + 3)
882 #define ID_CHECK (wxID_FILECTRL + 4)
883
884 ///////////////////////////////////////////////////////////////////////////////
885 // wxGenericFileCtrl implementation
886 ///////////////////////////////////////////////////////////////////////////////
887
888 IMPLEMENT_DYNAMIC_CLASS( wxGenericFileCtrl, wxPanel )
889
890 BEGIN_EVENT_TABLE( wxGenericFileCtrl, wxPanel )
891 EVT_LIST_ITEM_SELECTED( ID_FILELIST_CTRL, wxGenericFileCtrl::OnSelected )
892 EVT_LIST_ITEM_ACTIVATED( ID_FILELIST_CTRL, wxGenericFileCtrl::OnActivated )
893 EVT_CHOICE( ID_CHOICE, wxGenericFileCtrl::OnChoiceFilter )
894 EVT_TEXT_ENTER( ID_TEXT, wxGenericFileCtrl::OnTextEnter )
895 EVT_TEXT( ID_TEXT, wxGenericFileCtrl::OnTextChange )
896 EVT_CHECKBOX( ID_CHECK, wxGenericFileCtrl::OnCheck )
897 END_EVENT_TABLE()
898
899 bool wxGenericFileCtrl::Create( wxWindow *parent,
900 wxWindowID id,
901 const wxString& defaultDirectory,
902 const wxString& defaultFileName,
903 const wxString& wildCard,
904 long style,
905 const wxPoint& pos,
906 const wxSize& size,
907 const wxString& name )
908 {
909 this->m_style = style;
910 m_inSelected = false;
911 m_noSelChgEvent = false;
912
913 // check that the styles are not contradictory
914 wxASSERT_MSG( !( ( m_style & wxFC_SAVE ) && ( m_style & wxFC_OPEN ) ),
915 wxT( "can't specify both wxFC_SAVE and wxFC_OPEN at once" ) );
916
917 wxASSERT_MSG( !( ( m_style & wxFC_SAVE ) && ( m_style & wxFC_MULTIPLE ) ),
918 wxT( "wxFC_MULTIPLE can't be used with wxFC_SAVE" ) );
919
920 wxPanel::Create( parent, id, pos, size, wxTAB_TRAVERSAL, name );
921
922 m_dir = defaultDirectory;
923
924 m_ignoreChanges = true;
925
926 if ( ( m_dir.empty() ) || ( m_dir == wxT( "." ) ) )
927 {
928 m_dir = wxGetCwd();
929 if ( m_dir.empty() )
930 m_dir = wxFILE_SEP_PATH;
931 }
932
933 const size_t len = m_dir.length();
934 if ( ( len > 1 ) && ( wxEndsWithPathSeparator( m_dir ) ) )
935 m_dir.Remove( len - 1, 1 );
936
937 m_filterExtension = wxEmptyString;
938
939 // layout
940
941 const bool is_pda = ( wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA );
942
943 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
944
945 wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL );
946 if ( is_pda )
947 staticsizer->Add( new wxStaticText( this, wxID_ANY, _( "Current directory:" ) ), 0, wxRIGHT, 10 );
948 m_static = new wxStaticText( this, wxID_ANY, m_dir );
949 staticsizer->Add( m_static, 1 );
950 mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10 );
951
952 long style2 = wxLC_LIST;
953 if ( !( m_style & wxFC_MULTIPLE ) )
954 style2 |= wxLC_SINGLE_SEL;
955
956 #ifdef __WXWINCE__
957 style2 |= wxSIMPLE_BORDER;
958 #else
959 style2 |= wxSUNKEN_BORDER;
960 #endif
961
962 m_list = new wxFileListCtrl( this, ID_FILELIST_CTRL,
963 wxEmptyString, false,
964 wxDefaultPosition, wxSize( 400, 140 ),
965 style2 );
966
967 m_text = new wxTextCtrl( this, ID_TEXT, wxEmptyString,
968 wxDefaultPosition, wxDefaultSize,
969 wxTE_PROCESS_ENTER );
970 m_choice = new wxChoice( this, ID_CHOICE );
971
972 if ( is_pda )
973 {
974 // PDAs have a different screen layout
975 mainsizer->Add( m_list, wxSizerFlags( 1 ).Expand().HorzBorder() );
976
977 wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
978 textsizer->Add( m_text, wxSizerFlags( 1 ).Centre().Border() );
979 mainsizer->Add( textsizer, wxSizerFlags().Expand() );
980
981 m_check = NULL;
982 textsizer->Add( m_choice, wxSizerFlags( 1 ).Centre().Border() );
983 }
984 else // !is_pda
985 {
986 mainsizer->Add( m_list, wxSizerFlags( 1 ).Expand().DoubleHorzBorder() );
987
988 wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
989 textsizer->Add( m_text, wxSizerFlags( 1 ).Centre().
990 DoubleBorder( wxLEFT | wxRIGHT | wxTOP ) );
991 mainsizer->Add( textsizer, wxSizerFlags().Expand() );
992
993 wxSizerFlags flagsCentre;
994 flagsCentre.Centre().DoubleBorder();
995
996 wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL );
997 choicesizer->Add( m_choice, wxSizerFlags( flagsCentre ).Proportion( 1 ) );
998
999 if ( !( m_style & wxFC_NOSHOWHIDDEN ) )
1000 {
1001 m_check = new wxCheckBox( this, ID_CHECK, _( "Show &hidden files" ) );
1002 choicesizer->Add( m_check, flagsCentre );
1003 }
1004
1005 mainsizer->Add( choicesizer, wxSizerFlags().Expand() );
1006 }
1007
1008 SetWildcard( wildCard );
1009
1010 SetAutoLayout( true );
1011 SetSizer( mainsizer );
1012
1013 if ( !is_pda )
1014 {
1015 mainsizer->Fit( this );
1016 }
1017
1018 m_list->GoToDir( m_dir );
1019 UpdateControls();
1020 m_text->SetValue( m_fileName );
1021
1022 m_ignoreChanges = false;
1023
1024 // must be after m_ignoreChanges = false
1025 SetFilename( defaultFileName );
1026
1027 return true;
1028 }
1029
1030 wxString wxGenericFileCtrl::GetPath() const
1031 {
1032 return DoGetFilename( true );
1033 }
1034
1035 wxString wxGenericFileCtrl::GetFilename() const
1036 {
1037 return DoGetFilename( false );
1038 }
1039
1040 wxString wxGenericFileCtrl::DoGetFilename( const bool fullPath ) const
1041 {
1042 wxASSERT_MSG( ( m_style & wxFC_MULTIPLE ) == 0,
1043 wxT( "With controls that has wxFC_MULTIPLE style " )
1044 wxT( "use GetFilenames/GetPaths to get all filenames/paths selected" ) );
1045
1046 const wxString value = m_text->GetValue();
1047
1048 if ( !value.empty() )
1049 return value;
1050 return fullPath ? ( GetProperFileListDir() + value ) : value;
1051 }
1052
1053 void wxGenericFileCtrl::DoGetFilenames( wxArrayString& filenames, const bool fullPath ) const
1054 {
1055 filenames.Empty();
1056
1057 const wxString dir = GetProperFileListDir();
1058 const wxString value = m_text->GetValue();
1059
1060 if ( !value.empty() )
1061 {
1062 if ( fullPath )
1063 filenames.Add( dir + value );
1064 else
1065 filenames.Add( value );
1066 return;
1067 }
1068
1069 if ( m_list->GetSelectedItemCount() == 0 )
1070 {
1071 return;
1072 }
1073
1074 filenames.Alloc( m_list->GetSelectedItemCount() );
1075
1076 wxListItem item;
1077 item.m_mask = wxLIST_MASK_TEXT;
1078
1079 item.m_itemId = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
1080 while ( item.m_itemId != -1 )
1081 {
1082 m_list->GetItem( item );
1083
1084 if ( fullPath )
1085 filenames.Add( dir + item.m_text );
1086 else
1087 filenames.Add( item.m_text );
1088
1089 item.m_itemId = m_list->GetNextItem( item.m_itemId,
1090 wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
1091 }
1092 }
1093
1094 bool wxGenericFileCtrl::SetDirectory( const wxString& dir )
1095 {
1096 m_ignoreChanges = true;
1097 m_list->GoToDir( dir );
1098 UpdateControls();
1099 m_ignoreChanges = false;
1100
1101 return wxFileName( dir ).SameAs( m_list->GetDir() );
1102 }
1103
1104 wxString wxGenericFileCtrl::GetDirectory() const
1105 {
1106 return m_list->GetDir();
1107 }
1108
1109 bool wxGenericFileCtrl::SetFilename( const wxString& name )
1110 {
1111 const long item = m_list->FindItem( -1, name );
1112
1113 if ( item == -1 ) // file not found either because it doesn't exist or the
1114 // current filter doesn't show it.
1115 return false;
1116
1117 m_noSelChgEvent = true;
1118
1119 // Deselect selected items
1120 {
1121 const int numSelectedItems = m_list->GetSelectedItemCount();
1122
1123 if ( numSelectedItems > 0 )
1124 {
1125 long itemIndex = -1;
1126
1127 for ( ;; )
1128 {
1129 itemIndex = m_list->GetNextItem( itemIndex, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
1130 if ( itemIndex == -1 )
1131 break;
1132
1133 m_list->SetItemState( itemIndex, 0, wxLIST_STATE_SELECTED );
1134 }
1135 }
1136 }
1137
1138 m_list->SetItemState( item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
1139 m_list->EnsureVisible( item );
1140
1141 m_noSelChgEvent = false;
1142
1143 return true;
1144 }
1145
1146 void wxGenericFileCtrl::DoSetFilterIndex( int filterindex )
1147 {
1148 const wxString& str = (wx_static_cast(wxStringClientData *,
1149 m_choice->GetClientObject( filterindex )))
1150 ->GetData();
1151 m_list->SetWild( str );
1152 m_filterIndex = filterindex;
1153 if ( str.Left( 2 ) == wxT( "*." ) )
1154 {
1155 m_filterExtension = str.Mid( 1 );
1156 if ( m_filterExtension == _T( ".*" ) )
1157 m_filterExtension.clear();
1158 }
1159 else
1160 {
1161 m_filterExtension.clear();
1162 }
1163 }
1164
1165 void wxGenericFileCtrl::SetWildcard( const wxString& wildCard )
1166 {
1167 if ( wildCard.empty() || wildCard == wxFileSelectorDefaultWildcardStr )
1168 {
1169 m_wildCard = wxString::Format( _( "All files (%s)|%s" ),
1170 wxFileSelectorDefaultWildcardStr,
1171 wxFileSelectorDefaultWildcardStr );
1172 }
1173 else
1174 m_wildCard = wildCard;
1175
1176 wxArrayString wildDescriptions, wildFilters;
1177 const size_t count = wxParseCommonDialogsFilter( m_wildCard,
1178 wildDescriptions,
1179 wildFilters );
1180 wxCHECK_RET( count, wxT( "wxFileDialog: bad wildcard string" ) );
1181
1182 m_choice->Clear();
1183
1184 for ( size_t n = 0; n < count; n++ )
1185 {
1186 m_choice->Append(wildDescriptions[n], new wxStringClientData(wildFilters[n]));
1187 }
1188
1189 SetFilterIndex( 0 );
1190 }
1191
1192 void wxGenericFileCtrl::SetFilterIndex( int filterindex )
1193 {
1194 m_choice->SetSelection( filterindex );
1195
1196 DoSetFilterIndex( filterindex );
1197 }
1198
1199 void wxGenericFileCtrl::OnChoiceFilter( wxCommandEvent &event )
1200 {
1201 DoSetFilterIndex( ( int )event.GetInt() );
1202 }
1203
1204 void wxGenericFileCtrl::OnCheck( wxCommandEvent &event )
1205 {
1206 m_list->ShowHidden( event.GetInt() != 0 );
1207 }
1208
1209 void wxGenericFileCtrl::OnActivated( wxListEvent &event )
1210 {
1211 HandleAction( event.m_item.m_text );
1212 }
1213
1214 void wxGenericFileCtrl::OnTextEnter( wxCommandEvent &WXUNUSED( event ) )
1215 {
1216 HandleAction( m_text->GetValue() );
1217 }
1218
1219 void wxGenericFileCtrl::OnTextChange( wxCommandEvent &WXUNUSED( event ) )
1220 {
1221 if ( !m_ignoreChanges )
1222 {
1223 // Clear selections. Otherwise when the user types in a value they may
1224 // not get the file whose name they typed.
1225 if ( m_list->GetSelectedItemCount() > 0 )
1226 {
1227 long item = m_list->GetNextItem( -1, wxLIST_NEXT_ALL,
1228 wxLIST_STATE_SELECTED );
1229 while ( item != -1 )
1230 {
1231 m_list->SetItemState( item, 0, wxLIST_STATE_SELECTED );
1232 item = m_list->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
1233 }
1234 }
1235 }
1236 }
1237
1238 void wxGenericFileCtrl::OnSelected( wxListEvent &event )
1239 {
1240 if ( m_ignoreChanges )
1241 return;
1242
1243 if ( m_inSelected )
1244 return;
1245
1246 m_inSelected = true;
1247 const wxString filename( event.m_item.m_text );
1248
1249 #ifdef __WXWINCE__
1250 // No double-click on most WinCE devices, so do action immediately.
1251 HandleAction( filename );
1252 #else
1253 if ( filename == wxT( ".." ) )
1254 {
1255 m_inSelected = false;
1256 return;
1257 }
1258
1259 wxString dir = m_list->GetDir();
1260 if ( !IsTopMostDir( dir ) )
1261 dir += wxFILE_SEP_PATH;
1262 dir += filename;
1263 if ( wxDirExists( dir ) )
1264 {
1265 m_inSelected = false;
1266
1267 return;
1268 }
1269
1270
1271 m_ignoreChanges = true;
1272 m_text->SetValue( filename );
1273
1274 if ( m_list->GetSelectedItemCount() > 1 )
1275 {
1276 m_text->Clear();
1277 }
1278
1279 if ( !m_noSelChgEvent )
1280 GenerateSelectionChangedEvent( this, this );
1281
1282 m_ignoreChanges = false;
1283 #endif
1284 m_inSelected = false;
1285 }
1286
1287 void wxGenericFileCtrl::HandleAction( const wxString &fn )
1288 {
1289 if ( m_ignoreChanges )
1290 return;
1291
1292 wxString filename( fn );
1293 if ( filename.empty() )
1294 {
1295 return;
1296 }
1297 if ( filename == wxT( "." ) ) return;
1298
1299 wxString dir = m_list->GetDir();
1300
1301 // "some/place/" means they want to chdir not try to load "place"
1302 const bool want_dir = filename.Last() == wxFILE_SEP_PATH;
1303 if ( want_dir )
1304 filename = filename.RemoveLast();
1305
1306 if ( filename == wxT( ".." ) )
1307 {
1308 m_ignoreChanges = true;
1309 m_list->GoToParentDir();
1310
1311 GenerateFolderChangedEvent( this, this );
1312
1313 UpdateControls();
1314 m_ignoreChanges = false;
1315 return;
1316 }
1317
1318 #ifdef __UNIX__
1319 if ( filename == wxT( "~" ) )
1320 {
1321 m_ignoreChanges = true;
1322 m_list->GoToHomeDir();
1323
1324 GenerateFolderChangedEvent( this, this );
1325
1326 UpdateControls();
1327 m_ignoreChanges = false;
1328 return;
1329 }
1330
1331 if ( filename.BeforeFirst( wxT( '/' ) ) == wxT( "~" ) )
1332 {
1333 filename = wxString( wxGetUserHome() ) + filename.Remove( 0, 1 );
1334 }
1335 #endif // __UNIX__
1336
1337 if ( !( m_style & wxFC_SAVE ) )
1338 {
1339 if ( ( filename.Find( wxT( '*' ) ) != wxNOT_FOUND ) ||
1340 ( filename.Find( wxT( '?' ) ) != wxNOT_FOUND ) )
1341 {
1342 if ( filename.Find( wxFILE_SEP_PATH ) != wxNOT_FOUND )
1343 {
1344 wxMessageBox( _( "Illegal file specification." ),
1345 _( "Error" ), wxOK | wxICON_ERROR, this );
1346 return;
1347 }
1348 m_list->SetWild( filename );
1349 return;
1350 }
1351 }
1352
1353 if ( !IsTopMostDir( dir ) )
1354 dir += wxFILE_SEP_PATH;
1355 if ( !wxIsAbsolutePath( filename ) )
1356 {
1357 dir += filename;
1358 filename = dir;
1359 }
1360
1361 if ( wxDirExists( filename ) )
1362 {
1363 m_ignoreChanges = true;
1364 m_list->GoToDir( filename );
1365 UpdateControls();
1366
1367 GenerateFolderChangedEvent( this, this );
1368
1369 m_ignoreChanges = false;
1370 return;
1371 }
1372
1373 // they really wanted a dir, but it doesn't exist
1374 if ( want_dir )
1375 {
1376 wxMessageBox( _( "Directory doesn't exist." ), _( "Error" ),
1377 wxOK | wxICON_ERROR, this );
1378 return;
1379 }
1380
1381 // append the default extension to the filename if it doesn't have any
1382 //
1383 // VZ: the logic of testing for !wxFileExists() only for the open file
1384 // dialog is not entirely clear to me, why don't we allow saving to a
1385 // file without extension as well?
1386 if ( !( m_style & wxFC_OPEN ) || !wxFileExists( filename ) )
1387 {
1388 filename = wxFileDialogBase::AppendExtension( filename, m_filterExtension );
1389 GenerateFileActivatedEvent( this, this, wxFileName( filename ).GetFullName() );
1390 return;
1391 }
1392
1393 GenerateFileActivatedEvent( this, this );
1394 }
1395
1396 bool wxGenericFileCtrl::SetPath( const wxString& path )
1397 {
1398 if ( !wxFileName::FileExists( ( path ) ) )
1399 return false;
1400
1401 wxString ext;
1402 wxSplitPath( path, &m_dir, &m_fileName, &ext );
1403 if ( !ext.empty() )
1404 {
1405 m_fileName += wxT( "." );
1406 m_fileName += ext;
1407 }
1408
1409 SetDirectory( m_dir );
1410 SetFilename( m_fileName );
1411
1412 return true;
1413 }
1414
1415 void wxGenericFileCtrl::GetPaths( wxArrayString& paths ) const
1416 {
1417 DoGetFilenames( paths, true );
1418 }
1419
1420 void wxGenericFileCtrl::GetFilenames( wxArrayString& files ) const
1421 {
1422 DoGetFilenames( files, false );
1423 }
1424
1425 void wxGenericFileCtrl::UpdateControls()
1426 {
1427 const wxString dir = m_list->GetDir();
1428 m_static->SetLabel( dir );
1429 }
1430
1431 void wxGenericFileCtrl::GoToParentDir()
1432 {
1433 m_list->GoToParentDir();
1434 UpdateControls();
1435 }
1436
1437 void wxGenericFileCtrl::GoToHomeDir()
1438 {
1439 m_list->GoToHomeDir();
1440 UpdateControls();
1441 }
1442
1443 wxString wxGenericFileCtrl::GetProperFileListDir() const
1444 {
1445 wxString dir = m_list->GetDir();
1446 #ifdef __UNIX__
1447 if ( dir != wxT( "/" ) )
1448 #elif defined(__WXWINCE__)
1449 if ( dir != wxT( "/" ) && dir != wxT( "\\" ) )
1450 #endif
1451 dir += wxFILE_SEP_PATH;
1452
1453 return dir;
1454 }
1455
1456 #endif // wxUSE_FILECTRL