1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFileDialog
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "filedlgg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #if !defined(__UNIX__) && !defined(__DOS__) && !defined(__WIN32__)
34 #error wxFileDialog currently only supports Unix, win32 and DOS
37 #include "wx/checkbox.h"
38 #include "wx/textctrl.h"
39 #include "wx/choice.h"
40 #include "wx/checkbox.h"
41 #include "wx/stattext.h"
42 #include "wx/filedlg.h"
46 #include "wx/listctrl.h"
47 #include "wx/msgdlg.h"
49 #include "wx/bmpbuttn.h"
50 #include "wx/tokenzr.h"
51 #include "wx/mimetype.h"
53 #include "wx/module.h"
54 #include "wx/config.h"
55 #include "wx/imaglist.h"
57 #include "wx/artprov.h"
60 #include "wx/tooltip.h"
63 #include <sys/types.h>
79 #if defined(__UNIX__) || defined(__DOS__)
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // the list ctrl fields in report view
100 //-----------------------------------------------------------------------------
102 //-----------------------------------------------------------------------------
107 wxFileData( const wxString
&name
, const wxString
&fname
);
108 wxString
GetName() const;
109 wxString
GetFullName() const;
110 wxString
GetHint() const;
111 wxString
GetEntry( FileListField num
) const;
113 bool IsDir() const { return m_isDir
; }
114 bool IsLink() const { return m_isLink
; }
115 bool IsExe() const { return m_isExe
; }
116 long GetSize() const { return m_size
; }
118 void MakeItem( wxListItem
&item
);
119 void SetNewName( const wxString
&name
, const wxString
&fname
);
130 wxString m_permissions
;
136 //-----------------------------------------------------------------------------
138 //-----------------------------------------------------------------------------
140 class wxFileCtrl
: public wxListCtrl
144 wxFileCtrl( wxWindow
*win
,
145 wxStaticText
*labelDir
,
147 const wxString
&wild
,
149 const wxPoint
&pos
= wxDefaultPosition
,
150 const wxSize
&size
= wxDefaultSize
,
151 long style
= wxLC_LIST
,
152 const wxValidator
&validator
= wxDefaultValidator
,
153 const wxString
&name
= wxT("filelist") );
154 virtual ~wxFileCtrl();
156 void ChangeToListMode();
157 void ChangeToReportMode();
158 void ChangeToIconMode();
159 void ShowHidden( bool show
= TRUE
);
160 long Add( wxFileData
*fd
, wxListItem
&item
);
162 virtual void StatusbarText( wxChar
*WXUNUSED(text
) ) {};
164 void GoToParentDir();
166 void GoToDir( const wxString
&dir
);
167 void SetWild( const wxString
&wild
);
168 void GetDir( wxString
&dir
);
169 void OnListDeleteItem( wxListEvent
&event
);
170 void OnListEndLabelEdit( wxListEvent
&event
);
172 // Associate commonly used UI controls with wxFileCtrl so that they can be
173 // disabled when they cannot be used (e.g. can't go to parent directory
174 // if wxFileCtrl already is in the root dir):
175 void SetGoToParentControl(wxWindow
*ctrl
) { m_goToParentControl
= ctrl
; }
176 void SetNewDirControl(wxWindow
*ctrl
) { m_newDirControl
= ctrl
; }
179 void FreeItemData(const wxListItem
& item
);
180 void FreeAllItemsData();
186 wxWindow
*m_goToParentControl
;
187 wxWindow
*m_newDirControl
;
189 // the label showing the current directory
190 wxStaticText
*m_labelDir
;
192 DECLARE_DYNAMIC_CLASS(wxFileCtrl
);
193 DECLARE_EVENT_TABLE()
196 // ----------------------------------------------------------------------------
197 // private classes - icons list management
198 // ----------------------------------------------------------------------------
200 class wxFileIconEntry
: public wxObject
203 wxFileIconEntry(int i
) { id
= i
; }
209 class wxFileIconsTable
214 int GetIconID(const wxString
& extension
, const wxString
& mime
= wxEmptyString
);
215 wxImageList
*GetImageList() { return &m_ImageList
; }
218 wxImageList m_ImageList
;
219 wxHashTable m_HashTable
;
222 static wxFileIconsTable
*g_IconsTable
= NULL
;
226 #define FI_EXECUTABLE 2
228 wxFileIconsTable::wxFileIconsTable() :
230 m_HashTable(wxKEY_STRING
)
232 m_HashTable
.DeleteContents(TRUE
);
234 m_ImageList
.Add(wxArtProvider::GetBitmap(wxART_FOLDER
, wxART_CMN_DIALOG
));
236 m_ImageList
.Add(wxArtProvider::GetBitmap(wxART_NORMAL_FILE
, wxART_CMN_DIALOG
));
238 if (GetIconID(wxEmptyString
, _T("application/x-executable")) == FI_UNKNOWN
)
240 m_ImageList
.Add(wxArtProvider::GetBitmap(wxART_EXECUTABLE_FILE
, wxART_CMN_DIALOG
));
241 m_HashTable
.Delete(_T("exe"));
242 m_HashTable
.Put(_T("exe"), new wxFileIconEntry(FI_EXECUTABLE
));
244 /* else put into list by GetIconID
245 (KDE defines application/x-executable for *.exe and has nice icon)
252 // VS: we don't need this function w/o wxMimeTypesManager because we'll only have
253 // one icon and we won't resize it
255 static wxBitmap
CreateAntialiasedBitmap(const wxImage
& img
)
257 wxImage
smallimg (16, 16);
258 unsigned char *p1
, *p2
, *ps
;
259 unsigned char mr
= img
.GetMaskRed(),
260 mg
= img
.GetMaskGreen(),
261 mb
= img
.GetMaskBlue();
264 unsigned sr
, sg
, sb
, smask
;
266 p1
= img
.GetData(), p2
= img
.GetData() + 3 * 32, ps
= smallimg
.GetData();
267 smallimg
.SetMaskColour(mr
, mr
, mr
);
269 for (y
= 0; y
< 16; y
++)
271 for (x
= 0; x
< 16; x
++)
273 sr
= sg
= sb
= smask
= 0;
274 if (p1
[0] != mr
|| p1
[1] != mg
|| p1
[2] != mb
)
275 sr
+= p1
[0], sg
+= p1
[1], sb
+= p1
[2];
278 if (p1
[0] != mr
|| p1
[1] != mg
|| p1
[2] != mb
)
279 sr
+= p1
[0], sg
+= p1
[1], sb
+= p1
[2];
282 if (p2
[0] != mr
|| p2
[1] != mg
|| p2
[2] != mb
)
283 sr
+= p2
[0], sg
+= p2
[1], sb
+= p2
[2];
286 if (p2
[0] != mr
|| p2
[1] != mg
|| p2
[2] != mb
)
287 sr
+= p2
[0], sg
+= p2
[1], sb
+= p2
[2];
292 ps
[0] = ps
[1] = ps
[2] = mr
;
294 ps
[0] = sr
>> 2, ps
[1] = sg
>> 2, ps
[2] = sb
>> 2;
297 p1
+= 32 * 3, p2
+= 32 * 3;
300 return wxBitmap(smallimg
);
303 // finds empty borders and return non-empty area of image:
304 static wxImage
CutEmptyBorders(const wxImage
& img
)
306 unsigned char mr
= img
.GetMaskRed(),
307 mg
= img
.GetMaskGreen(),
308 mb
= img
.GetMaskBlue();
309 unsigned char *dt
= img
.GetData(), *dttmp
;
310 unsigned w
= img
.GetWidth(), h
= img
.GetHeight();
312 unsigned top
, bottom
, left
, right
, i
;
315 #define MK_DTTMP(x,y) dttmp = dt + ((x + y * w) * 3)
316 #define NOEMPTY_PIX(empt) if (dttmp[0] != mr || dttmp[1] != mg || dttmp[2] != mb) {empt = FALSE; break;}
318 for (empt
= TRUE
, top
= 0; empt
&& top
< h
; top
++)
321 for (i
= 0; i
< w
; i
++, dttmp
+=3)
324 for (empt
= TRUE
, bottom
= h
-1; empt
&& bottom
> top
; bottom
--)
327 for (i
= 0; i
< w
; i
++, dttmp
+=3)
330 for (empt
= TRUE
, left
= 0; empt
&& left
< w
; left
++)
333 for (i
= 0; i
< h
; i
++, dttmp
+=3*w
)
336 for (empt
= TRUE
, right
= w
-1; empt
&& right
> left
; right
--)
339 for (i
= 0; i
< h
; i
++, dttmp
+=3*w
)
342 top
--, left
--, bottom
++, right
++;
344 return img
.GetSubImage(wxRect(left
, top
, right
- left
+ 1, bottom
- top
+ 1));
346 #endif // wxUSE_MIMETYPE
350 int wxFileIconsTable::GetIconID(const wxString
& extension
, const wxString
& mime
)
353 if (!extension
.IsEmpty())
355 wxFileIconEntry
*entry
= (wxFileIconEntry
*) m_HashTable
.Get(extension
);
356 if (entry
) return (entry
-> id
);
359 wxFileType
*ft
= (mime
.IsEmpty()) ?
360 wxTheMimeTypesManager
-> GetFileTypeFromExtension(extension
) :
361 wxTheMimeTypesManager
-> GetFileTypeFromMimeType(mime
);
363 if (ft
== NULL
|| (!ft
-> GetIcon(&ic
)) || (!ic
.Ok()))
365 int newid
= FI_UNKNOWN
;
366 m_HashTable
.Put(extension
, new wxFileIconEntry(newid
));
370 wxBitmap
myBitmap (ic
.GetWidth(), ic
.GetHeight() ) ;
372 memDC
.SelectObject( myBitmap
);
373 memDC
.DrawIcon(ic
,0,0);
374 memDC
.SelectObject( wxNullBitmap
);
375 wxImage img
= myBitmap
.ConvertToImage();
377 wxImage img
= ic
.ConvertToImage();
381 int id
= m_ImageList
.GetImageCount();
382 if (img
.GetWidth() == 16 && img
.GetHeight() == 16)
383 m_ImageList
.Add(wxBitmap(img
));
386 if (img
.GetWidth() != 32 || img
.GetHeight() != 32)
387 m_ImageList
.Add(CreateAntialiasedBitmap(CutEmptyBorders(img
).Rescale(32, 32)));
389 m_ImageList
.Add(CreateAntialiasedBitmap(img
));
391 m_HashTable
.Put(extension
, new wxFileIconEntry(id
));
394 #else // !wxUSE_MIMETYPE
396 if (extension
== wxT("exe"))
397 return FI_EXECUTABLE
;
400 #endif // wxUSE_MIMETYPE/!wxUSE_MIMETYPE
405 // ----------------------------------------------------------------------------
407 // ----------------------------------------------------------------------------
410 int ListCompare( long data1
, long data2
, long WXUNUSED(data
))
412 wxFileData
*fd1
= (wxFileData
*)data1
;
413 wxFileData
*fd2
= (wxFileData
*)data2
;
414 if (fd1
->GetName() == wxT("..")) return -1;
415 if (fd2
->GetName() == wxT("..")) return 1;
416 if (fd1
->IsDir() && !fd2
->IsDir()) return -1;
417 if (fd2
->IsDir() && !fd1
->IsDir()) return 1;
418 return wxStrcmp( fd1
->GetName(), fd2
->GetName() );
422 #define IsTopMostDir(dir) (dir == wxT("/"))
425 #if defined(__DOS__) || defined(__WINDOWS__)
426 #define IsTopMostDir(dir) (dir.IsEmpty())
429 #if defined(__DOS__) || defined(__WINDOWS__)
430 extern bool wxIsDriveAvailable(const wxString
& dirName
);
433 //-----------------------------------------------------------------------------
435 //-----------------------------------------------------------------------------
437 wxFileData::wxFileData( const wxString
&name
, const wxString
&fname
)
442 #if defined(__DOS__) || defined(__WINDOWS__)
443 // VS: In case the file is root directory of a volume (e.g. "C:"),
444 // we don't want it stat()ed, since the drive may not be in:
445 if (name
.length() == 2 && name
[1u] == wxT(':'))
448 m_isExe
= m_isLink
= FALSE
;
455 wxStat( m_fileName
, &buff
);
457 #if defined(__UNIX__) && (!defined( __EMX__ ) && !defined(__VMS))
459 lstat( m_fileName
.fn_str(), &lbuff
);
460 m_isLink
= S_ISLNK( lbuff
.st_mode
);
461 struct tm
*t
= localtime( &lbuff
.st_mtime
);
464 struct tm
*t
= localtime( &buff
.st_mtime
);
467 // struct passwd *user = getpwuid( buff.st_uid );
468 // struct group *grp = getgrgid( buff.st_gid );
471 m_isDir
= ((buff
.st_mode
& _S_IFDIR
) == _S_IFDIR
);
473 m_isDir
= S_ISDIR( buff
.st_mode
);
475 m_isExe
= ((buff
.st_mode
& wxS_IXUSR
) == wxS_IXUSR
);
477 m_size
= buff
.st_size
;
480 m_minute
= t
->tm_min
;
481 m_month
= t
->tm_mon
+1;
487 sprintf( buffer
, "%c%c%c",
488 ((( buff
.st_mode
& wxS_IRUSR
) == wxS_IRUSR
) ? 'r' : '-'),
489 ((( buff
.st_mode
& wxS_IWUSR
) == wxS_IWUSR
) ? 'w' : '-'),
490 ((( buff
.st_mode
& wxS_IXUSR
) == wxS_IXUSR
) ? 'x' : '-') );
492 m_permissions
= wxConvUTF8
.cMB2WC( buffer
);
494 m_permissions
= buffer
;
497 // m_permissions.sprintf( wxT("%c%c%c"),
498 // ((( buff.st_mode & S_IRUSR ) == S_IRUSR ) ? wxT('r') : wxT('-')),
499 // ((( buff.st_mode & S_IWUSR ) == S_IWUSR ) ? wxT('w') : wxT('-')),
500 // ((( buff.st_mode & S_IXUSR ) == S_IXUSR ) ? wxT('x') : wxT('-')) );
503 wxString
wxFileData::GetName() const
508 wxString
wxFileData::GetFullName() const
513 wxString
wxFileData::GetHint() const
515 wxString s
= m_fileName
;
517 if (m_isDir
) s
+= wxT("<DIR> ");
518 else if (m_isLink
) s
+= wxT("<LINK> ");
521 s
+= LongToString( m_size
);
524 s
+= IntToString( m_day
);
526 s
+= IntToString( m_month
);
528 s
+= IntToString( m_year
);
530 s
+= IntToString( m_hour
);
532 s
+= IntToString( m_minute
);
538 wxString
wxFileData::GetEntry( FileListField num
) const
553 s
.Printf(_T("%ld"), m_size
);
557 s
.Printf(_T("%02d.%02d.%d"), m_day
, m_month
, m_year
);
561 s
.Printf(_T("%02d:%02d"), m_hour
, m_minute
);
571 wxFAIL_MSG( _T("unexpected field in wxFileData::GetEntry()") );
577 void wxFileData::SetNewName( const wxString
&name
, const wxString
&fname
)
583 void wxFileData::MakeItem( wxListItem
&item
)
585 item
.m_text
= m_name
;
586 item
.ClearAttributes();
588 item
.SetTextColour(*wxRED
);
590 item
.SetTextColour(*wxBLUE
);
593 item
.m_image
= FI_FOLDER
;
595 item
.m_image
= FI_EXECUTABLE
;
596 else if (m_name
.Find(wxT('.')) != wxNOT_FOUND
)
597 item
.m_image
= g_IconsTable
->GetIconID(m_name
.AfterLast(wxT('.')));
599 item
.m_image
= FI_UNKNOWN
;
603 wxColour
*dg
= wxTheColourDatabase
->FindColour( _T("MEDIUM GREY") );
604 item
.SetTextColour(*dg
);
606 item
.m_data
= (long)this;
609 //-----------------------------------------------------------------------------
611 //-----------------------------------------------------------------------------
613 IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl
,wxListCtrl
)
615 BEGIN_EVENT_TABLE(wxFileCtrl
,wxListCtrl
)
616 EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem
)
617 EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit
)
621 wxFileCtrl::wxFileCtrl()
623 m_showHidden
= FALSE
;
626 wxFileCtrl::wxFileCtrl(wxWindow
*win
,
627 wxStaticText
*labelDir
,
629 const wxString
& wild
,
634 const wxValidator
&validator
,
635 const wxString
&name
)
636 : wxListCtrl(win
, id
, pos
, size
, style
, validator
, name
),
640 g_IconsTable
= new wxFileIconsTable
;
641 wxImageList
*imageList
= g_IconsTable
->GetImageList();
643 SetImageList( imageList
, wxIMAGE_LIST_SMALL
);
645 m_goToParentControl
=
646 m_newDirControl
= NULL
;
648 m_labelDir
= labelDir
;
650 m_showHidden
= showHidden
;
653 void wxFileCtrl::ChangeToListMode()
655 SetSingleStyle( wxLC_LIST
);
659 void wxFileCtrl::ChangeToReportMode()
661 SetSingleStyle( wxLC_REPORT
);
665 void wxFileCtrl::ChangeToIconMode()
667 SetSingleStyle( wxLC_ICON
);
671 void wxFileCtrl::ShowHidden( bool show
)
677 long wxFileCtrl::Add( wxFileData
*fd
, wxListItem
&item
)
680 item
.m_mask
= wxLIST_MASK_TEXT
+ wxLIST_MASK_DATA
+ wxLIST_MASK_IMAGE
;
681 fd
->MakeItem( item
);
682 long my_style
= GetWindowStyleFlag();
683 if (my_style
& wxLC_REPORT
)
685 ret
= InsertItem( item
);
686 for (int i
= 1; i
< FileList_Max
; i
++)
687 SetItem( item
.m_itemId
, i
, fd
->GetEntry((FileListField
)i
) );
689 else if (my_style
& wxLC_LIST
)
691 ret
= InsertItem( item
);
696 void wxFileCtrl::UpdateFiles()
698 // don't do anything before ShowModal() call which sets m_dirName
699 if ( m_dirName
.empty() )
702 wxBusyCursor bcur
; // this may take a while...
704 long my_style
= GetWindowStyleFlag();
705 int name_col_width
= 0;
706 if (my_style
& wxLC_REPORT
)
708 if (GetColumnCount() > 0)
709 name_col_width
= GetColumnWidth( 0 );
715 if (my_style
& wxLC_REPORT
)
717 if (name_col_width
< 140) name_col_width
= 140;
718 InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT
, name_col_width
);
719 InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT
, 60 );
720 InsertColumn( 2, _("Date"), wxLIST_FORMAT_LEFT
, 65 );
721 InsertColumn( 3, _("Time"), wxLIST_FORMAT_LEFT
, 50 );
723 InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT
, 120 );
726 wxFileData
*fd
= (wxFileData
*) NULL
;
731 #if defined(__DOS__) || defined(__WINDOWS__)
732 if ( IsTopMostDir(m_dirName
) )
734 // Pseudo-directory with all available drives listed...
735 for (int drive
= 1; drive
<= 26; drive
++)
738 path
.Printf(wxT("%c:\\"), (char)(drive
+ 'A' - 1));
739 if ( wxIsDriveAvailable(path
) )
742 fd
= new wxFileData(path
, path
);
752 if ( !IsTopMostDir(m_dirName
) )
754 wxString
p(wxPathOnly(m_dirName
));
756 if (p
.IsEmpty()) p
= wxT("/");
758 fd
= new wxFileData( wxT(".."), p
);
763 wxString
dirname(m_dirName
);
764 #if defined(__DOS__) || defined(__WINDOWS__)
765 if (dirname
.length() == 2 && dirname
[1u] == wxT(':'))
766 dirname
<< wxT('\\');
770 if ( dir
.IsOpened() )
772 wxString
dirPrefix(dirname
+ wxFILE_SEP_PATH
);
773 int hiddenFlag
= m_showHidden
? wxDIR_HIDDEN
: 0;
778 // Get the directories first (not matched against wildcards):
779 cont
= dir
.GetFirst(&f
, wxEmptyString
, wxDIR_DIRS
| hiddenFlag
);
782 fd
= new wxFileData(f
, dirPrefix
+ f
);
785 cont
= dir
.GetNext(&f
);
788 // Tokenize the wildcard string, so we can handle more than 1
789 // search pattern in a wildcard.
790 wxStringTokenizer
tokenWild(m_wild
, wxT(";"));
791 while ( tokenWild
.HasMoreTokens() )
793 cont
= dir
.GetFirst(&f
, tokenWild
.GetNextToken(),
794 wxDIR_FILES
| hiddenFlag
);
797 fd
= new wxFileData(f
, dirPrefix
+ f
);
800 cont
= dir
.GetNext(&f
);
806 SortItems((wxListCtrlCompare
)ListCompare
, 0);
808 if ( my_style
& wxLC_REPORT
)
810 SetColumnWidth(1, wxLIST_AUTOSIZE
);
811 SetColumnWidth(2, wxLIST_AUTOSIZE
);
812 SetColumnWidth(3, wxLIST_AUTOSIZE
);
815 // Finally, enable/disable context-dependent controls:
816 if ( m_goToParentControl
)
817 m_goToParentControl
->Enable(!IsTopMostDir(m_dirName
));
818 #if defined(__DOS__) || defined(__WINDOWS__)
819 if ( m_newDirControl
)
820 m_newDirControl
->Enable(!IsTopMostDir(m_dirName
));
824 void wxFileCtrl::SetWild( const wxString
&wild
)
830 void wxFileCtrl::MakeDir()
832 wxString
new_name( _("NewName") );
833 wxString
path( m_dirName
);
834 path
+= wxFILE_SEP_PATH
;
836 if (wxFileExists(path
))
838 // try NewName0, NewName1 etc.
841 new_name
= _("NewName");
843 num
.Printf( wxT("%d"), i
);
847 path
+= wxFILE_SEP_PATH
;
850 } while (wxFileExists(path
));
856 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
861 wxFileData
*fd
= new wxFileData( new_name
, path
);
865 long id
= Add( fd
, item
);
869 SortItems( (wxListCtrlCompare
) ListCompare
, 0 );
870 id
= FindItem( 0, (long)fd
);
876 void wxFileCtrl::GoToParentDir()
878 if (!IsTopMostDir(m_dirName
))
880 size_t len
= m_dirName
.Len();
881 if (m_dirName
[len
-1] == wxFILE_SEP_PATH
)
882 m_dirName
.Remove( len
-1, 1 );
883 wxString
fname( wxFileNameFromPath(m_dirName
) );
884 m_dirName
= wxPathOnly( m_dirName
);
886 if (m_dirName
.IsEmpty())
887 m_dirName
= wxT("/");
890 long id
= FindItem( 0, fname
);
893 SetItemState( id
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
897 m_labelDir
->SetLabel(m_dirName
);
901 void wxFileCtrl::GoToHomeDir()
903 wxString s
= wxGetUserHome( wxString() );
907 void wxFileCtrl::GoToDir( const wxString
&dir
)
911 SetItemState( 0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
914 m_labelDir
->SetLabel(dir
);
917 void wxFileCtrl::GetDir( wxString
&dir
)
922 void wxFileCtrl::FreeItemData(const wxListItem
& item
)
924 wxFileData
*fd
= (wxFileData
*)item
.m_data
;
928 void wxFileCtrl::OnListDeleteItem( wxListEvent
&event
)
930 FreeItemData(event
.m_item
);
933 void wxFileCtrl::FreeAllItemsData()
936 item
.m_mask
= wxLIST_MASK_DATA
;
938 item
.m_itemId
= GetNextItem( -1, wxLIST_NEXT_ALL
);
939 while ( item
.m_itemId
!= -1 )
943 item
.m_itemId
= GetNextItem( item
.m_itemId
, wxLIST_NEXT_ALL
);
947 void wxFileCtrl::OnListEndLabelEdit( wxListEvent
&event
)
949 wxFileData
*fd
= (wxFileData
*)event
.m_item
.m_data
;
952 if ((event
.GetLabel().IsEmpty()) ||
953 (event
.GetLabel() == _(".")) ||
954 (event
.GetLabel() == _("..")) ||
955 (event
.GetLabel().First( wxFILE_SEP_PATH
) != wxNOT_FOUND
))
957 wxMessageDialog
dialog(this, _("Illegal directory name."), _("Error"), wxOK
| wxICON_ERROR
);
963 wxString
new_name( wxPathOnly( fd
->GetFullName() ) );
964 new_name
+= wxFILE_SEP_PATH
;
965 new_name
+= event
.GetLabel();
969 if (wxFileExists(new_name
))
971 wxMessageDialog
dialog(this, _("File name exists already."), _("Error"), wxOK
| wxICON_ERROR
);
976 if (wxRenameFile(fd
->GetFullName(),new_name
))
978 fd
->SetNewName( new_name
, event
.GetLabel() );
979 SetItemState( event
.GetItem(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
980 EnsureVisible( event
.GetItem() );
984 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
990 wxFileCtrl::~wxFileCtrl()
995 //-----------------------------------------------------------------------------
997 //-----------------------------------------------------------------------------
999 #define ID_LIST_MODE (wxID_FILEDLGG )
1000 #define ID_REPORT_MODE (wxID_FILEDLGG + 1)
1001 #define ID_UP_DIR (wxID_FILEDLGG + 5)
1002 #define ID_PARENT_DIR (wxID_FILEDLGG + 6)
1003 #define ID_NEW_DIR (wxID_FILEDLGG + 7)
1004 #define ID_CHOICE (wxID_FILEDLGG + 8)
1005 #define ID_TEXT (wxID_FILEDLGG + 9)
1006 #define ID_LIST_CTRL (wxID_FILEDLGG + 10)
1007 #define ID_ACTIVATED (wxID_FILEDLGG + 11)
1008 #define ID_CHECK (wxID_FILEDLGG + 12)
1010 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
1012 BEGIN_EVENT_TABLE(wxFileDialog
,wxDialog
)
1013 EVT_BUTTON(ID_LIST_MODE
, wxFileDialog::OnList
)
1014 EVT_BUTTON(ID_REPORT_MODE
, wxFileDialog::OnReport
)
1015 EVT_BUTTON(ID_UP_DIR
, wxFileDialog::OnUp
)
1016 EVT_BUTTON(ID_PARENT_DIR
, wxFileDialog::OnHome
)
1017 EVT_BUTTON(ID_NEW_DIR
, wxFileDialog::OnNew
)
1018 EVT_BUTTON(wxID_OK
, wxFileDialog::OnListOk
)
1019 EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL
, wxFileDialog::OnSelected
)
1020 EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL
, wxFileDialog::OnActivated
)
1021 EVT_CHOICE(ID_CHOICE
,wxFileDialog::OnChoiceFilter
)
1022 EVT_TEXT_ENTER(ID_TEXT
,wxFileDialog::OnTextEnter
)
1023 EVT_TEXT(ID_TEXT
,wxFileDialog::OnTextChange
)
1024 EVT_CHECKBOX(ID_CHECK
,wxFileDialog::OnCheck
)
1027 long wxFileDialog::ms_lastViewStyle
= wxLC_LIST
;
1028 bool wxFileDialog::ms_lastShowHidden
= FALSE
;
1030 wxFileDialog::wxFileDialog(wxWindow
*parent
,
1031 const wxString
& message
,
1032 const wxString
& defaultDir
,
1033 const wxString
& defaultFile
,
1034 const wxString
& wildCard
,
1036 const wxPoint
& pos
)
1037 : wxDialog( parent
, -1, message
, pos
, wxDefaultSize
,
1038 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
1040 if (wxConfig::Get(FALSE
))
1042 wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ViewStyle"),
1044 wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ShowHidden"),
1045 &ms_lastShowHidden
);
1048 m_message
= message
;
1049 m_dialogStyle
= style
;
1051 if (m_dialogStyle
== 0)
1052 m_dialogStyle
= wxOPEN
;
1053 if ((m_dialogStyle
& wxMULTIPLE
) && !(m_dialogStyle
& wxOPEN
))
1054 m_dialogStyle
|= wxOPEN
;
1057 if ((m_dir
.empty()) || (m_dir
== wxT(".")))
1062 size_t len
= m_dir
.Len();
1063 if ((len
> 1) && (m_dir
[len
-1] == wxFILE_SEP_PATH
))
1064 m_dir
.Remove( len
-1, 1 );
1067 m_path
+= wxFILE_SEP_PATH
;
1068 m_path
+= defaultFile
;
1069 m_fileName
= defaultFile
;
1070 m_wildCard
= wildCard
;
1072 m_filterExtension
= wxEmptyString
;
1074 // interpret wildcards
1076 if (m_wildCard
.IsEmpty())
1077 m_wildCard
= _("All files (*)|*");
1079 wxStringTokenizer
tokens( m_wildCard
, wxT("|") );
1081 wxString firstWildText
;
1082 if (tokens
.CountTokens() == 1)
1084 firstWildText
= tokens
.GetNextToken();
1085 firstWild
= firstWildText
;
1089 wxASSERT_MSG( tokens
.CountTokens() % 2 == 0, wxT("Wrong file type descripition") );
1090 firstWildText
= tokens
.GetNextToken();
1091 firstWild
= tokens
.GetNextToken();
1093 if ( firstWild
.Left( 2 ) == wxT("*.") )
1094 m_filterExtension
= firstWild
.Mid( 1 );
1095 if ( m_filterExtension
== wxT(".*") )
1096 m_filterExtension
= wxEmptyString
;
1100 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1102 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
1104 wxBoxSizer
*buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
1106 wxBitmapButton
*but
;
1108 but
= new wxBitmapButton(this, ID_LIST_MODE
,
1109 wxArtProvider::GetBitmap(wxART_LIST_VIEW
, wxART_CMN_DIALOG
));
1111 but
->SetToolTip( _("View files as a list view") );
1113 buttonsizer
->Add( but
, 0, wxALL
, 5 );
1115 but
= new wxBitmapButton(this, ID_REPORT_MODE
,
1116 wxArtProvider::GetBitmap(wxART_REPORT_VIEW
, wxART_CMN_DIALOG
));
1118 but
->SetToolTip( _("View files as a detailed view") );
1120 buttonsizer
->Add( but
, 0, wxALL
, 5 );
1122 buttonsizer
->Add( 30, 5, 1 );
1124 wxWindow
*butDirUp
=
1125 new wxBitmapButton(this, ID_UP_DIR
,
1126 wxArtProvider::GetBitmap(wxART_GO_DIR_UP
, wxART_CMN_DIALOG
));
1128 butDirUp
->SetToolTip( _("Go to parent directory") );
1130 buttonsizer
->Add( butDirUp
, 0, wxALL
, 5 );
1132 #ifndef __DOS__ // VS: Home directory is meaningless in MS-DOS...
1133 but
= new wxBitmapButton(this, ID_PARENT_DIR
,
1134 wxArtProvider::GetBitmap(wxART_GO_HOME
, wxART_CMN_DIALOG
));
1136 but
->SetToolTip( _("Go to home directory") );
1138 buttonsizer
->Add( but
, 0, wxALL
, 5);
1140 buttonsizer
->Add( 20, 20 );
1143 wxWindow
*butNewDir
=
1144 new wxBitmapButton(this, ID_NEW_DIR
,
1145 wxArtProvider::GetBitmap(wxART_NEW_DIR
, wxART_CMN_DIALOG
));
1147 butNewDir
->SetToolTip( _("Create new directory") );
1149 buttonsizer
->Add( butNewDir
, 0, wxALL
, 5 );
1152 mainsizer
->Add( buttonsizer
, 0, wxALL
| wxEXPAND
, 0 );
1154 mainsizer
->Add( buttonsizer
, 0, wxALL
| wxEXPAND
, 5 );
1156 wxBoxSizer
*staticsizer
= new wxBoxSizer( wxHORIZONTAL
);
1158 staticsizer
->Add( new wxStaticText( this, -1, _("Current directory:") ), 0, wxRIGHT
, 10 );
1159 m_static
= new wxStaticText( this, -1, m_dir
);
1160 staticsizer
->Add( m_static
, 1 );
1161 mainsizer
->Add( staticsizer
, 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxBOTTOM
, 10 );
1163 long style2
= ms_lastViewStyle
| wxSUNKEN_BORDER
;
1164 if ( !(m_dialogStyle
& wxMULTIPLE
) )
1165 style2
|= wxLC_SINGLE_SEL
;
1167 m_list
= new wxFileCtrl( this, m_static
, ID_LIST_CTRL
,
1168 firstWild
, ms_lastShowHidden
,
1169 wxDefaultPosition
, wxSize(540,200),
1172 m_list
->SetNewDirControl(butNewDir
);
1173 m_list
->SetGoToParentControl(butDirUp
);
1177 // PDAs have a different screen layout
1178 mainsizer
->Add( m_list
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 5 );
1180 wxBoxSizer
*choicesizer
= new wxBoxSizer( wxHORIZONTAL
);
1181 m_choice
= new wxChoice( this, ID_CHOICE
);
1182 choicesizer
->Add( m_choice
, 1, wxCENTER
|wxALL
, 5 );
1183 mainsizer
->Add( choicesizer
, 0, wxEXPAND
);
1185 wxBoxSizer
*textsizer
= new wxBoxSizer( wxHORIZONTAL
);
1186 m_text
= new wxTextCtrl( this, ID_TEXT
, m_fileName
, wxDefaultPosition
, wxDefaultSize
, wxPROCESS_ENTER
);
1187 textsizer
->Add( m_text
, 1, wxCENTER
| wxALL
, 5 );
1188 mainsizer
->Add( textsizer
, 0, wxEXPAND
);
1190 m_check
= new wxCheckBox( this, ID_CHECK
, _("Show hidden files") );
1191 m_check
->SetValue( ms_lastShowHidden
);
1192 textsizer
->Add( m_check
, 0, wxCENTER
|wxALL
, 5 );
1194 buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
1195 buttonsizer
->Add( new wxButton( this, wxID_OK
, _("OK") ), 0, wxCENTER
| wxALL
, 5 );
1196 buttonsizer
->Add( new wxButton( this, wxID_CANCEL
, _("Cancel") ), 0, wxCENTER
| wxALL
, 5 );
1197 mainsizer
->Add( buttonsizer
, 0, wxALIGN_RIGHT
);
1201 mainsizer
->Add( m_list
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 10 );
1203 wxBoxSizer
*textsizer
= new wxBoxSizer( wxHORIZONTAL
);
1204 m_text
= new wxTextCtrl( this, ID_TEXT
, m_fileName
, wxDefaultPosition
, wxDefaultSize
, wxPROCESS_ENTER
);
1205 textsizer
->Add( m_text
, 1, wxCENTER
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
1206 textsizer
->Add( new wxButton( this, wxID_OK
, _("OK") ), 0, wxCENTER
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
1207 mainsizer
->Add( textsizer
, 0, wxEXPAND
);
1209 wxBoxSizer
*choicesizer
= new wxBoxSizer( wxHORIZONTAL
);
1210 m_choice
= new wxChoice( this, ID_CHOICE
);
1211 choicesizer
->Add( m_choice
, 1, wxCENTER
|wxALL
, 10 );
1212 m_check
= new wxCheckBox( this, ID_CHECK
, _("Show hidden files") );
1213 m_check
->SetValue( ms_lastShowHidden
);
1214 choicesizer
->Add( m_check
, 0, wxCENTER
|wxALL
, 10 );
1215 choicesizer
->Add( new wxButton( this, wxID_CANCEL
, _("Cancel") ), 0, wxCENTER
| wxALL
, 10 );
1216 mainsizer
->Add( choicesizer
, 0, wxEXPAND
);
1219 m_choice
->Append( firstWildText
, (void*) new wxString( firstWild
) );
1220 while (tokens
.HasMoreTokens())
1222 firstWildText
= tokens
.GetNextToken();
1223 firstWild
= tokens
.GetNextToken();
1224 m_choice
->Append( firstWildText
, (void*) new wxString( firstWild
) );
1226 m_choice
->SetSelection( 0 );
1228 SetAutoLayout( TRUE
);
1229 SetSizer( mainsizer
);
1231 mainsizer
->Fit( this );
1232 mainsizer
->SetSizeHints( this );
1239 wxFileDialog::~wxFileDialog()
1241 if (wxConfig::Get(FALSE
))
1243 wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ViewStyle"),
1245 wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ShowHidden"),
1250 int wxFileDialog::ShowModal()
1252 m_list
->GoToDir(m_dir
);
1253 m_text
->SetValue(m_fileName
);
1255 return wxDialog::ShowModal();
1258 void wxFileDialog::DoSetFilterIndex(int filterindex
)
1260 wxString
*str
= (wxString
*) m_choice
->GetClientData( filterindex
);
1261 m_list
->SetWild( *str
);
1262 m_filterIndex
= filterindex
;
1263 if ( str
->Left(2) == wxT("*.") )
1265 m_filterExtension
= str
->Mid(2);
1266 if (m_filterExtension
== _T("*"))
1267 m_filterExtension
.clear();
1271 m_filterExtension
.clear();
1275 void wxFileDialog::SetFilterIndex( int filterindex
)
1277 m_choice
->SetSelection( filterindex
);
1279 DoSetFilterIndex(filterindex
);
1282 void wxFileDialog::OnChoiceFilter( wxCommandEvent
&event
)
1284 DoSetFilterIndex((int)event
.GetInt());
1287 void wxFileDialog::OnCheck( wxCommandEvent
&event
)
1289 m_list
->ShowHidden( (ms_lastShowHidden
= event
.GetInt() != 0) );
1292 void wxFileDialog::OnActivated( wxListEvent
&event
)
1294 HandleAction( event
.m_item
.m_text
);
1297 void wxFileDialog::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
1299 wxCommandEvent
cevent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
1300 cevent
.SetEventObject( this );
1301 GetEventHandler()->ProcessEvent( cevent
);
1304 static bool ignoreChanges
= FALSE
;
1306 void wxFileDialog::OnTextChange( wxCommandEvent
&WXUNUSED(event
) )
1310 // Clear selections. Otherwise when the user types in a value they may
1311 // not get the file whose name they typed.
1312 if (m_list
->GetSelectedItemCount() > 0)
1314 long item
= m_list
->GetNextItem(-1, wxLIST_NEXT_ALL
,
1315 wxLIST_STATE_SELECTED
);
1316 while ( item
!= -1 )
1318 m_list
->SetItemState(item
,0, wxLIST_STATE_SELECTED
);
1319 item
= m_list
->GetNextItem(item
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
1325 void wxFileDialog::OnSelected( wxListEvent
&event
)
1327 wxString
filename( event
.m_item
.m_text
);
1328 if (filename
== wxT("..")) return;
1331 m_list
->GetDir( dir
);
1332 if (!IsTopMostDir(dir
))
1333 dir
+= wxFILE_SEP_PATH
;
1335 if (wxDirExists(dir
)) return;
1337 ignoreChanges
= TRUE
;
1338 m_text
->SetValue( filename
);
1339 ignoreChanges
= FALSE
;
1342 void wxFileDialog::HandleAction( const wxString
&fn
)
1344 wxString
filename( fn
);
1346 m_list
->GetDir( dir
);
1347 if (filename
.IsEmpty()) return;
1348 if (filename
== wxT(".")) return;
1350 if (filename
== wxT(".."))
1352 m_list
->GoToParentDir();
1358 if (filename
== wxT("~"))
1360 m_list
->GoToHomeDir();
1365 if (filename
[0u] == wxT('~'))
1367 filename
.Remove( 0, 1 );
1368 wxString
tmp( wxGetUserHome() );
1375 if ((filename
.Find(wxT('*')) != wxNOT_FOUND
) ||
1376 (filename
.Find(wxT('?')) != wxNOT_FOUND
))
1378 if (filename
.Find(wxFILE_SEP_PATH
) != wxNOT_FOUND
)
1380 wxMessageBox(_("Illegal file specification."), _("Error"), wxOK
| wxICON_ERROR
);
1383 m_list
->SetWild( filename
);
1387 if (!IsTopMostDir(dir
))
1388 dir
+= wxFILE_SEP_PATH
;
1389 if (!wxIsAbsolutePath(filename
))
1395 if (wxDirExists(filename
))
1397 m_list
->GoToDir( filename
);
1401 // append the default extension to the filename if it doesn't have any
1403 // VZ: the logic of testing for !wxFileExists() only for the open file
1404 // dialog is not entirely clear to me, why don't we allow saving to a
1405 // file without extension as well?
1406 if ( !(m_dialogStyle
& wxOPEN
) || !wxFileExists(filename
) )
1409 wxSplitPath(filename
, NULL
, NULL
, &ext
);
1412 // append the first extension of the filter string
1413 filename
+= m_filterExtension
.BeforeFirst(_T(';'));
1417 // check that the file [doesn't] exist if necessary
1418 if ( (m_dialogStyle
& wxSAVE
) &&
1419 (m_dialogStyle
& wxOVERWRITE_PROMPT
) &&
1420 wxFileExists( filename
) )
1423 msg
.Printf( _("File '%s' already exists, do you really want to "
1424 "overwrite it?"), filename
.c_str() );
1426 if (wxMessageBox(msg
, _("Confirm"), wxYES_NO
) != wxYES
)
1429 else if ( (m_dialogStyle
& wxOPEN
) &&
1430 (m_dialogStyle
& wxFILE_MUST_EXIST
) &&
1431 !wxFileExists(filename
) )
1433 wxMessageBox(_("Please choose an existing file."), _("Error"),
1434 wxOK
| wxICON_ERROR
);
1437 SetPath( filename
);
1439 // change to the directory where the user went if asked
1440 if ( m_dialogStyle
& wxCHANGE_DIR
)
1443 wxSplitPath(filename
, &cwd
, NULL
, NULL
);
1445 if ( cwd
!= wxGetWorkingDirectory() )
1447 wxSetWorkingDirectory(cwd
);
1451 wxCommandEvent event
;
1452 wxDialog::OnOK(event
);
1455 void wxFileDialog::OnListOk( wxCommandEvent
&WXUNUSED(event
) )
1457 HandleAction( m_text
->GetValue() );
1460 void wxFileDialog::OnList( wxCommandEvent
&WXUNUSED(event
) )
1462 m_list
->ChangeToListMode();
1463 ms_lastViewStyle
= wxLC_LIST
;
1467 void wxFileDialog::OnReport( wxCommandEvent
&WXUNUSED(event
) )
1469 m_list
->ChangeToReportMode();
1470 ms_lastViewStyle
= wxLC_REPORT
;
1474 void wxFileDialog::OnUp( wxCommandEvent
&WXUNUSED(event
) )
1476 m_list
->GoToParentDir();
1480 void wxFileDialog::OnHome( wxCommandEvent
&WXUNUSED(event
) )
1482 m_list
->GoToHomeDir();
1486 void wxFileDialog::OnNew( wxCommandEvent
&WXUNUSED(event
) )
1491 void wxFileDialog::SetPath( const wxString
& path
)
1493 // not only set the full path but also update filename and dir
1495 if ( !path
.empty() )
1498 wxSplitPath(path
, &m_dir
, &m_fileName
, &ext
);
1501 m_fileName
+= wxT(".");
1507 void wxFileDialog::GetPaths( wxArrayString
& paths
) const
1510 if (m_list
->GetSelectedItemCount() == 0)
1512 paths
.Add( GetPath() );
1516 paths
.Alloc( m_list
->GetSelectedItemCount() );
1519 m_list
->GetDir( dir
);
1521 if (dir
!= wxT("/"))
1523 dir
+= wxFILE_SEP_PATH
;
1526 item
.m_mask
= wxLIST_MASK_TEXT
;
1528 item
.m_itemId
= m_list
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
1529 while ( item
.m_itemId
!= -1 )
1531 m_list
->GetItem( item
);
1532 paths
.Add( dir
+ item
.m_text
);
1533 item
.m_itemId
= m_list
->GetNextItem( item
.m_itemId
,
1534 wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
1538 void wxFileDialog::GetFilenames(wxArrayString
& files
) const
1541 if (m_list
->GetSelectedItemCount() == 0)
1543 files
.Add( GetFilename() );
1546 files
.Alloc( m_list
->GetSelectedItemCount() );
1549 item
.m_mask
= wxLIST_MASK_TEXT
;
1551 item
.m_itemId
= m_list
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
1552 while ( item
.m_itemId
!= -1 )
1554 m_list
->GetItem( item
);
1555 files
.Add( item
.m_text
);
1556 item
.m_itemId
= m_list
->GetNextItem( item
.m_itemId
,
1557 wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
1563 // ----------------------------------------------------------------------------
1565 // ----------------------------------------------------------------------------
1568 wxFileSelectorEx(const wxChar
*message
,
1569 const wxChar
*default_path
,
1570 const wxChar
*default_filename
,
1571 int *WXUNUSED(indexDefaultExtension
),
1572 const wxChar
*wildcard
,
1577 // TODO: implement this somehow
1578 return wxFileSelector(message
, default_path
, default_filename
, wxT(""),
1579 wildcard
, flags
, parent
, x
, y
);
1582 wxString
wxFileSelector( const wxChar
*title
,
1583 const wxChar
*defaultDir
, const wxChar
*defaultFileName
,
1584 const wxChar
*defaultExtension
, const wxChar
*filter
, int flags
,
1585 wxWindow
*parent
, int x
, int y
)
1588 if ( defaultExtension
&& !filter
)
1589 filter2
= wxString(wxT("*.")) + wxString(defaultExtension
) ;
1593 wxString defaultDirString
;
1595 defaultDirString
= defaultDir
;
1597 wxString defaultFilenameString
;
1598 if (defaultFileName
)
1599 defaultFilenameString
= defaultFileName
;
1601 wxFileDialog
fileDialog( parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
) );
1603 if ( fileDialog
.ShowModal() == wxID_OK
)
1605 return fileDialog
.GetPath();
1609 return wxEmptyString
;
1613 static wxString
GetWildcardString(const wxChar
*ext
)
1618 if ( *ext
== wxT('.') )
1621 wild
<< _T("*.") << ext
;
1623 else // no extension specified
1625 wild
= wxFileSelectorDefaultWildcardStr
;
1631 wxString
wxLoadFileSelector(const wxChar
*what
,
1633 const wxChar
*nameDef
,
1637 if ( what
&& *what
)
1638 prompt
= wxString::Format(_("Load %s file"), what
);
1640 prompt
= _("Load file");
1642 return wxFileSelector(prompt
, NULL
, nameDef
, ext
,
1643 GetWildcardString(ext
), 0, parent
);
1646 wxString
wxSaveFileSelector(const wxChar
*what
,
1648 const wxChar
*nameDef
,
1652 if ( what
&& *what
)
1653 prompt
= wxString::Format(_("Save %s file"), what
);
1655 prompt
= _("Save file");
1657 return wxFileSelector(prompt
, NULL
, nameDef
, ext
,
1658 GetWildcardString(ext
), 0, parent
);
1661 // A module to allow icons table cleanup
1663 class wxFileDialogGenericModule
: public wxModule
1665 DECLARE_DYNAMIC_CLASS(wxFileDialogGenericModule
)
1667 wxFileDialogGenericModule() {}
1668 bool OnInit() { return TRUE
; }
1669 void OnExit() { if (g_IconsTable
) {delete g_IconsTable
; g_IconsTable
= NULL
;} }
1672 IMPLEMENT_DYNAMIC_CLASS(wxFileDialogGenericModule
, wxModule
)
1674 #endif // wxUSE_FILEDLG