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