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