1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxFileDialog 
   4 // Author:      Robert Roebling 
   8 // Copyright:   (c) Robert Roebling 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "filedlgg.h" 
  16 // For compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  24 #error wxFileDialog currently only supports unix 
  27 #include "wx/filedlg.h" 
  31 #include "wx/msgdlg.h" 
  33 #include "wx/bmpbuttn.h" 
  34 #include "wx/tokenzr.h" 
  35 #include "wx/mimetype.h" 
  37 #include "wx/module.h" 
  38 #include "wx/config.h" 
  42     #include "wx/tooltip.h" 
  45 #include <sys/types.h> 
  53 #include "wx/generic/home.xpm" 
  54 #include "wx/generic/listview.xpm" 
  55 #include "wx/generic/repview.xpm" 
  56 #include "wx/generic/new_dir.xpm" 
  57 #include "wx/generic/dir_up.xpm" 
  58 #include "wx/generic/folder.xpm" 
  59 #include "wx/generic/deffile.xpm" 
  60 #include "wx/generic/exefile.xpm" 
  62 // ---------------------------------------------------------------------------- 
  63 // private classes - icons list management 
  64 // ---------------------------------------------------------------------------- 
  66 class wxFileIconEntry 
: public wxObject
 
  69         wxFileIconEntry(int i
) { id 
= i
; } 
  75 class wxFileIconsTable
 
  81         int GetIconID(const wxString
& extension
, const wxString
& mime 
= wxEmptyString
); 
  82         wxImageList 
*GetImageList() { return &m_ImageList
; } 
  85         wxImageList m_ImageList
; 
  86         wxHashTable m_HashTable
; 
  89 static wxFileIconsTable 
*g_IconsTable 
= NULL
; 
  93 #define FI_EXECUTABLE 2 
  95 wxFileIconsTable::wxFileIconsTable() : 
  97                     m_HashTable(wxKEY_STRING
) 
  99     m_HashTable
.DeleteContents(TRUE
); 
 100     m_ImageList
.Add(wxBitmap(folder_xpm
));  // FI_FOLDER 
 101     m_ImageList
.Add(wxBitmap(deffile_xpm
)); // FI_UNKNOWN 
 102     if (GetIconID(wxEmptyString
, _T("application/x-executable")) == FI_UNKNOWN
)  
 104         m_ImageList
.Add(wxBitmap(exefile_xpm
));  
 105         m_HashTable
.Delete(_T("exe")); 
 106         m_HashTable
.Put(_T("exe"), new wxFileIconEntry(FI_EXECUTABLE
)); 
 108     /* else put into list by GetIconID 
 109        (KDE defines application/x-executable for *.exe and has nice icon) 
 115 static wxBitmap 
CreateAntialiasedBitmap(const wxImage
& img
) 
 117     wxImage 
small(16, 16); 
 118     unsigned char *p1
, *p2
, *ps
; 
 119     unsigned char mr 
= img
.GetMaskRed(),  
 120                   mg 
= img
.GetMaskGreen(),  
 121                   mb 
= img
.GetMaskBlue(); 
 124     unsigned sr
, sg
, sb
, smask
; 
 126     p1 
= img
.GetData(), p2 
= img
.GetData() + 3 * 32, ps 
= small
.GetData(); 
 127     small
.SetMaskColour(mr
, mr
, mr
); 
 129     for (y 
= 0; y 
< 16; y
++) 
 131         for (x 
= 0; x 
< 16; x
++) 
 133             sr 
= sg 
= sb 
= smask 
= 0; 
 134             if (p1
[0] != mr 
|| p1
[1] != mg 
|| p1
[2] != mb
) 
 135                 sr 
+= p1
[0], sg 
+= p1
[1], sb 
+= p1
[2]; 
 138             if (p1
[0] != mr 
|| p1
[1] != mg 
|| p1
[2] != mb
) 
 139                 sr 
+= p1
[0], sg 
+= p1
[1], sb 
+= p1
[2]; 
 142             if (p2
[0] != mr 
|| p2
[1] != mg 
|| p2
[2] != mb
) 
 143                 sr 
+= p2
[0], sg 
+= p2
[1], sb 
+= p2
[2]; 
 146             if (p2
[0] != mr 
|| p2
[1] != mg 
|| p2
[2] != mb
) 
 147                 sr 
+= p2
[0], sg 
+= p2
[1], sb 
+= p2
[2]; 
 152                 ps
[0] = ps
[1] = ps
[2] = mr
; 
 154                 ps
[0] = sr 
>> 2, ps
[1] = sg 
>> 2, ps
[2] = sb 
>> 2; 
 157         p1 
+= 32 * 3, p2 
+= 32 * 3; 
 160     return small
.ConvertToBitmap(); 
 164 int wxFileIconsTable::GetIconID(const wxString
& extension
, const wxString
& mime
) 
 166     if (!extension
.IsEmpty()) 
 168         wxFileIconEntry 
*entry 
= (wxFileIconEntry
*) m_HashTable
.Get(extension
); 
 169         if (entry
) return (entry 
-> id
); 
 172     wxFileType 
*ft 
= (mime
.IsEmpty()) ?  
 173                    wxTheMimeTypesManager 
-> GetFileTypeFromExtension(extension
) : 
 174                    wxTheMimeTypesManager 
-> GetFileTypeFromMimeType(mime
); 
 176     if (ft 
== NULL 
|| (!ft 
-> GetIcon(&ic
)) || (!ic
.Ok())) 
 178         int newid 
= FI_UNKNOWN
; 
 179         m_HashTable
.Put(extension
, new wxFileIconEntry(newid
)); 
 185     int id 
= m_ImageList
.GetImageCount(); 
 186     if (img
.GetWidth() == 16 && img
.GetHeight() == 16) 
 187         m_ImageList
.Add(img
.ConvertToBitmap()); 
 190         if (img
.GetWidth() != 32 || img
.GetHeight() != 32) 
 192         m_ImageList
.Add(CreateAntialiasedBitmap(img
)); 
 194     m_HashTable
.Put(extension
, new wxFileIconEntry(id
)); 
 200 // ---------------------------------------------------------------------------- 
 202 // ---------------------------------------------------------------------------- 
 205 int ListCompare( long data1
, long data2
, long WXUNUSED(data
) ) 
 207      wxFileData 
*fd1 
= (wxFileData
*)data1 
; 
 208      wxFileData 
*fd2 
= (wxFileData
*)data2 
; 
 209      if (fd1
->GetName() == wxT("..")) return -1; 
 210      if (fd2
->GetName() == wxT("..")) return 1; 
 211      if (fd1
->IsDir() && !fd2
->IsDir()) return -1; 
 212      if (fd2
->IsDir() && !fd1
->IsDir()) return 1; 
 213      return wxStrcmp( fd1
->GetName(), fd2
->GetName() ); 
 216 //----------------------------------------------------------------------------- 
 218 //----------------------------------------------------------------------------- 
 220 IMPLEMENT_DYNAMIC_CLASS(wxFileData
,wxObject
); 
 222 wxFileData::wxFileData( const wxString 
&name
, const wxString 
&fname 
) 
 228     stat( m_fileName
.fn_str(), &buff 
); 
 232     lstat( m_fileName
.fn_str(), &lbuff 
); 
 233     m_isLink 
= S_ISLNK( lbuff
.st_mode 
); 
 234     struct tm 
*t 
= localtime( &lbuff
.st_mtime 
); 
 237     struct tm 
*t 
= localtime( &buff
.st_mtime 
); 
 240 //  struct passwd *user = getpwuid( buff.st_uid ); 
 241 //  struct group *grp = getgrgid( buff.st_gid ); 
 243     m_isDir 
= S_ISDIR( buff
.st_mode 
); 
 244     m_isExe 
= ((buff
.st_mode 
& S_IXUSR 
) == S_IXUSR 
); 
 246     m_size 
= buff
.st_size
; 
 249     m_minute 
= t
->tm_min
; 
 250     m_month 
= t
->tm_mon
+1; 
 255     m_permissions
.sprintf( wxT("%c%c%c"), 
 256      ((( buff
.st_mode 
& S_IRUSR 
) == S_IRUSR 
) ? wxT('r') : wxT('-')), 
 257      ((( buff
.st_mode 
& S_IWUSR 
) == S_IWUSR 
) ? wxT('w') : wxT('-')), 
 258      ((( buff
.st_mode 
& S_IXUSR 
) == S_IXUSR 
) ? wxT('x') : wxT('-')) ); 
 261 wxString 
wxFileData::GetName() const 
 266 wxString 
wxFileData::GetFullName() const 
 271 wxString 
wxFileData::GetHint() const 
 273     wxString s 
= m_fileName
; 
 275     if (m_isDir
) s 
+= _("<DIR> "); 
 276     else if (m_isLink
) s 
+= _("<LINK> "); 
 279         s 
+= LongToString( m_size 
); 
 282     s 
+= IntToString( m_day 
); 
 284     s 
+= IntToString( m_month 
); 
 286     s 
+= IntToString( m_year 
); 
 288     s 
+= IntToString( m_hour 
); 
 290     s 
+= IntToString( m_minute 
); 
 296 wxString 
wxFileData::GetEntry( int num 
) 
 308             if (m_isDir
) s 
= _("<DIR>"); 
 309             else if (m_isLink
) s 
= _("<LINK>"); 
 310             else s 
= LongToString( m_size 
); 
 315             if (m_day 
< 10) s 
= wxT("0"); else s 
= wxT(""); 
 316             s 
+= IntToString( m_day 
); 
 318             if (m_month 
< 10) s 
+= wxT("0"); 
 319             s 
+= IntToString( m_month 
); 
 321             s 
+= IntToString( m_year 
); 
 326             if (m_hour 
< 10) s 
= wxT("0"); else s 
= wxT(""); 
 327             s 
+= IntToString( m_hour 
); 
 329             if (m_minute 
< 10) s 
+= wxT("0"); 
 330             s 
+= IntToString( m_minute 
); 
 343 bool wxFileData::IsDir() 
 348 bool wxFileData::IsExe() 
 353 bool wxFileData::IsLink() 
 358 long wxFileData::GetSize() 
 363 void wxFileData::SetNewName( const wxString 
&name
, const wxString 
&fname 
) 
 369 void wxFileData::MakeItem( wxListItem 
&item 
) 
 371     item
.m_text 
= m_name
; 
 372     item
.ClearAttributes(); 
 373     if (IsExe()) item
.SetTextColour(*wxRED
); 
 374     if (IsDir()) item
.SetTextColour(*wxBLUE
); 
 377         item
.m_image 
= FI_FOLDER
; 
 379         item
.m_image 
= FI_EXECUTABLE
; 
 380     else if (m_name
.Find(wxT('.')) != wxNOT_FOUND
) 
 381         item
.m_image 
= g_IconsTable 
-> GetIconID(m_name
.AfterLast(wxT('.'))); 
 383         item
.m_image 
= FI_UNKNOWN
; 
 387         wxColour 
*dg 
= wxTheColourDatabase
->FindColour( "MEDIUM GREY" ); 
 388         item
.SetTextColour(*dg
); 
 390     item
.m_data 
= (long)this; 
 393 //----------------------------------------------------------------------------- 
 395 //----------------------------------------------------------------------------- 
 397 IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl
,wxListCtrl
); 
 399 BEGIN_EVENT_TABLE(wxFileCtrl
,wxListCtrl
) 
 400     EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem
) 
 401     EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit
) 
 406 wxFileCtrl::wxFileCtrl() 
 408     m_dirName 
= wxT("/"); 
 409     m_showHidden 
= FALSE
; 
 412 wxFileCtrl::wxFileCtrl( wxWindow 
*win
, wxWindowID id
, 
 413     const wxString 
&dirName
, const wxString 
&wild
, 
 414     const wxPoint 
&pos
, const wxSize 
&size
, 
 415     long style
, const wxValidator 
&validator
, const wxString 
&name 
) : 
 416   wxListCtrl( win
, id
, pos
, size
, style
, validator
, name 
) 
 418     if (! g_IconsTable
) g_IconsTable 
= new wxFileIconsTable
; 
 419     wxImageList 
*imageList 
= g_IconsTable 
-> GetImageList(); 
 421     SetImageList( imageList
, wxIMAGE_LIST_SMALL 
); 
 425     m_showHidden 
= FALSE
; 
 429 void wxFileCtrl::ChangeToListMode() 
 431     SetSingleStyle( wxLC_LIST 
); 
 435 void wxFileCtrl::ChangeToReportMode() 
 437     SetSingleStyle( wxLC_REPORT 
); 
 441 void wxFileCtrl::ChangeToIconMode() 
 443     SetSingleStyle( wxLC_ICON 
); 
 447 void wxFileCtrl::ShowHidden( bool show 
) 
 453 long wxFileCtrl::Add( wxFileData 
*fd
, wxListItem 
&item 
) 
 456     item
.m_mask 
= wxLIST_MASK_TEXT 
+ wxLIST_MASK_DATA 
+ wxLIST_MASK_IMAGE
; 
 457     fd
->MakeItem( item 
); 
 458     long my_style 
= GetWindowStyleFlag(); 
 459     if (my_style 
& wxLC_REPORT
) 
 461         ret 
= InsertItem( item 
); 
 462         for (int i 
= 1; i 
< 5; i
++) SetItem( item
.m_itemId
, i
, fd
->GetEntry( i
) ); 
 464     else if (my_style 
& wxLC_LIST
) 
 466         ret 
= InsertItem( item 
); 
 471 void wxFileCtrl::Update() 
 473     long my_style 
= GetWindowStyleFlag(); 
 474     int name_col_width 
= 0; 
 475     if (my_style 
& wxLC_REPORT
) 
 477         if (GetColumnCount() > 0) 
 478             name_col_width 
= GetColumnWidth( 0 ); 
 482     if (my_style 
& wxLC_REPORT
) 
 484         if (name_col_width 
< 140) name_col_width 
= 140; 
 485         InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT
, name_col_width 
); 
 486         InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT
, 60 ); 
 487         InsertColumn( 2, _("Date"), wxLIST_FORMAT_LEFT
, 65 ); 
 488         InsertColumn( 3, _("Time"), wxLIST_FORMAT_LEFT
, 50 ); 
 489         InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT
, 120 ); 
 491     wxFileData 
*fd 
= (wxFileData 
*) NULL
; 
 496     if (m_dirName 
!= wxT("/")) 
 498         wxString 
p( wxPathOnly(m_dirName
) ); 
 499         if (p
.IsEmpty()) p 
= wxT("/"); 
 500         fd 
= new wxFileData( wxT(".."), p 
); 
 505     wxString res 
= m_dirName 
+ wxT("/*"); 
 506     wxString 
f( wxFindFirstFile( res
.GetData(), wxDIR 
) ); 
 509         res 
= wxFileNameFromPath( f 
); 
 510         fd 
= new wxFileData( res
, f 
); 
 511         wxString s 
= fd
->GetName(); 
 512         if (m_showHidden 
|| (s
[0] != wxT('.'))) 
 517         f 
= wxFindNextFile(); 
 520     res 
= m_dirName 
+ wxT("/") + m_wild
; 
 521     f 
= wxFindFirstFile( res
.GetData(), wxFILE 
); 
 524         res 
= wxFileNameFromPath( f 
); 
 525         fd 
= new wxFileData( res
, f 
); 
 526         wxString s 
= fd
->GetName(); 
 527         if (m_showHidden 
|| (s
[0] != wxT('.'))) 
 532         f 
= wxFindNextFile(); 
 535     SortItems( ListCompare
, 0 ); 
 537     SetColumnWidth( 1, wxLIST_AUTOSIZE 
); 
 538     SetColumnWidth( 2, wxLIST_AUTOSIZE 
); 
 539     SetColumnWidth( 3, wxLIST_AUTOSIZE 
); 
 542 void wxFileCtrl::SetWild( const wxString 
&wild 
) 
 548 void wxFileCtrl::MakeDir() 
 550     wxString 
new_name( wxT("NewName") ); 
 551     wxString 
path( m_dirName 
); 
 554     if (wxFileExists(path
)) 
 556         // try NewName0, NewName1 etc. 
 559             new_name 
= _("NewName"); 
 561             num
.Printf( wxT("%d"), i 
); 
 568         } while (wxFileExists(path
)); 
 574         wxMessageDialog 
dialog(this, _("Operation not permitted."), _("Error"), wxOK 
| wxICON_ERROR 
); 
 579     wxFileData 
*fd 
= new wxFileData( new_name
, path 
); 
 583     long id 
= Add( fd
, item 
); 
 587         SortItems( ListCompare
, 0 ); 
 588         id 
= FindItem( 0, (long)fd 
); 
 594 void wxFileCtrl::GoToParentDir() 
 596     if (m_dirName 
!= wxT("/")) 
 598         wxString 
fname( wxFileNameFromPath(m_dirName
) ); 
 599         m_dirName 
= wxPathOnly( m_dirName 
); 
 600         if (m_dirName
.IsEmpty()) m_dirName 
= wxT("/"); 
 602         long id 
= FindItem( 0, fname 
); 
 605             SetItemState( id
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED 
); 
 611 void wxFileCtrl::GoToHomeDir() 
 613     wxString s 
= wxGetUserHome( wxString() ); 
 616     SetItemState( 0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED 
); 
 620 void wxFileCtrl::GoToDir( const wxString 
&dir 
) 
 624     SetItemState( 0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED 
); 
 628 void wxFileCtrl::GetDir( wxString 
&dir 
) 
 633 void wxFileCtrl::OnListDeleteItem( wxListEvent 
&event 
) 
 635     wxFileData 
*fd 
= (wxFileData
*)event
.m_item
.m_data
; 
 639 void wxFileCtrl::OnListEndLabelEdit( wxListEvent 
&event 
) 
 641     wxFileData 
*fd 
= (wxFileData
*)event
.m_item
.m_data
; 
 644     if ((event
.GetLabel().IsEmpty()) || 
 645         (event
.GetLabel() == _(".")) || 
 646         (event
.GetLabel() == _("..")) || 
 647         (event
.GetLabel().First( wxT("/") ) != wxNOT_FOUND
)) 
 649         wxMessageDialog 
dialog(this, _("Illegal directory name."), _("Error"), wxOK 
| wxICON_ERROR 
); 
 655     wxString 
new_name( wxPathOnly( fd
->GetFullName() ) ); 
 656     new_name 
+= wxT("/"); 
 657     new_name 
+= event
.GetLabel(); 
 661     if (wxFileExists(new_name
)) 
 663         wxMessageDialog 
dialog(this, _("File name exists already."), _("Error"), wxOK 
| wxICON_ERROR 
); 
 668     if (wxRenameFile(fd
->GetFullName(),new_name
)) 
 670         fd
->SetNewName( new_name
, event
.GetLabel() ); 
 671         SetItemState( event
.GetItem(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED 
); 
 672         EnsureVisible( event
.GetItem() ); 
 676         wxMessageDialog 
dialog(this, _("Operation not permitted."), _("Error"), wxOK 
| wxICON_ERROR 
); 
 682 //----------------------------------------------------------------------------- 
 684 //----------------------------------------------------------------------------- 
 686 #define  ID_LIST_MODE     wxID_FILEDLGG 
 687 #define  ID_REPORT_MODE   wxID_FILEDLGG + 1 
 688 #define  ID_UP_DIR        wxID_FILEDLGG + 5 
 689 #define  ID_PARENT_DIR    wxID_FILEDLGG + 6 
 690 #define  ID_NEW_DIR       wxID_FILEDLGG + 7 
 691 #define  ID_CHOICE        wxID_FILEDLGG + 8 
 692 #define  ID_TEXT          wxID_FILEDLGG + 9 
 693 #define  ID_LIST_CTRL     wxID_FILEDLGG + 10 
 694 #define  ID_ACTIVATED     wxID_FILEDLGG + 11 
 695 #define  ID_CHECK         wxID_FILEDLGG + 12 
 697 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
) 
 699 BEGIN_EVENT_TABLE(wxFileDialog
,wxDialog
) 
 700         EVT_BUTTON(ID_LIST_MODE
, wxFileDialog::OnList
) 
 701         EVT_BUTTON(ID_REPORT_MODE
, wxFileDialog::OnReport
) 
 702         EVT_BUTTON(ID_UP_DIR
, wxFileDialog::OnUp
) 
 703         EVT_BUTTON(ID_PARENT_DIR
, wxFileDialog::OnHome
) 
 704         EVT_BUTTON(ID_NEW_DIR
, wxFileDialog::OnNew
) 
 705         EVT_BUTTON(wxID_OK
, wxFileDialog::OnListOk
) 
 706         EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL
, wxFileDialog::OnSelected
) 
 707         EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL
, wxFileDialog::OnActivated
) 
 708         EVT_CHOICE(ID_CHOICE
,wxFileDialog::OnChoice
) 
 709         EVT_TEXT_ENTER(ID_TEXT
,wxFileDialog::OnTextEnter
) 
 710         EVT_CHECKBOX(ID_CHECK
,wxFileDialog::OnCheck
) 
 713 long wxFileDialog::s_lastViewStyle 
= wxLC_LIST
; 
 714 bool wxFileDialog::s_lastShowHidden 
= FALSE
; 
 716 wxFileDialog::wxFileDialog(wxWindow 
*parent
, 
 717                  const wxString
& message
, 
 718                  const wxString
& defaultDir
, 
 719                  const wxString
& defaultFile
, 
 720                  const wxString
& wildCard
, 
 722                  const wxPoint
& pos 
) : 
 723   wxDialog( parent
, -1, message
, pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE 
| wxRESIZE_BORDER 
) 
 727     if (wxConfig::Get(FALSE
)) 
 729         wxConfig::Get() -> Read(wxT("/wxWindows/wxFileDialog/ViewStyle"), &s_lastViewStyle
); 
 730         wxConfig::Get() -> Read(wxT("/wxWindows/wxFileDialog/ShowHidden"), &s_lastShowHidden
); 
 734     m_dialogStyle 
= style
; 
 736     if (m_dialogStyle 
== 0) m_dialogStyle 
= wxOPEN
; 
 737     if ((m_dialogStyle 
& wxMULTIPLE 
) && !(m_dialogStyle 
& wxOPEN
)) 
 738         m_dialogStyle 
|= wxOPEN
; 
 741     if ((m_dir
.IsEmpty()) || (m_dir 
== wxT("."))) 
 744         m_dir 
= getcwd( buf
, sizeof(buf
) ); 
 748     m_path 
+= defaultFile
; 
 749     m_fileName 
= defaultFile
; 
 750     m_wildCard 
= wildCard
; 
 752     m_filterExtension 
= wxEmptyString
; 
 754     // interpret wildcards 
 756     if (m_wildCard
.IsEmpty()) 
 757         m_wildCard 
= _("All files (*)|*"); 
 759     wxStringTokenizer 
tokens( m_wildCard
, wxT("|") ); 
 761     wxString firstWildText
; 
 762     if (tokens
.CountTokens() == 1) 
 764         firstWildText 
= tokens
.GetNextToken(); 
 765         firstWild 
= firstWildText
; 
 769         wxASSERT_MSG( tokens
.CountTokens() % 2 == 0, wxT("Wrong file type descripition") ); 
 770         firstWildText 
= tokens
.GetNextToken(); 
 771         firstWild 
= tokens
.GetNextToken(); 
 773     if ( firstWild
.Left( 2 ) == wxT("*.") ) 
 774         m_filterExtension 
= firstWild
.Mid( 1 ); 
 775     if ( m_filterExtension 
== ".*" ) m_filterExtension 
= wxEmptyString
; 
 779     wxBoxSizer 
*mainsizer 
= new wxBoxSizer( wxVERTICAL 
); 
 781     wxBoxSizer 
*buttonsizer 
= new wxBoxSizer( wxHORIZONTAL 
); 
 785     but 
= new wxBitmapButton( this, ID_LIST_MODE
, wxBitmap( listview_xpm 
) ); 
 787     but
->SetToolTip( _("View files as a list view") ); 
 789     buttonsizer
->Add( but
, 0, wxALL
, 5 ); 
 791     but 
= new wxBitmapButton( this, ID_REPORT_MODE
, wxBitmap( repview_xpm 
) ); 
 793     but
->SetToolTip( _("View files as a detailed view") ); 
 795     buttonsizer
->Add( but
, 0, wxALL
, 5 ); 
 797     buttonsizer
->Add( 30, 5, 1 ); 
 799     but 
= new wxBitmapButton( this, ID_UP_DIR
, wxBitmap( dir_up_xpm 
) ); 
 801     but
->SetToolTip( _("Go to parent directory") ); 
 803     buttonsizer
->Add( but
, 0, wxALL
, 5 ); 
 805     but 
= new wxBitmapButton( this, ID_PARENT_DIR
, wxBitmap(home_xpm
) ); 
 807     but
->SetToolTip( _("Go to home directory") ); 
 809     buttonsizer
->Add( but
, 0, wxALL
, 5); 
 811     buttonsizer
->Add( 20, 20 ); 
 813     but 
= new wxBitmapButton( this, ID_NEW_DIR
, wxBitmap(new_dir_xpm
) ); 
 815     but
->SetToolTip( _("Create new directory") ); 
 817     buttonsizer
->Add( but
, 0, wxALL
, 5 ); 
 819     mainsizer
->Add( buttonsizer
, 0, wxALL 
| wxEXPAND
, 5 ); 
 821     wxBoxSizer 
*staticsizer 
= new wxBoxSizer( wxHORIZONTAL 
); 
 822     staticsizer
->Add( new wxStaticText( this, -1, _("Current directory:") ), 0, wxRIGHT
, 10 ); 
 823     m_static 
= new wxStaticText( this, -1, m_dir 
); 
 824     staticsizer
->Add( m_static
, 1 ); 
 825     mainsizer
->Add( staticsizer
, 0, wxEXPAND 
| wxLEFT
|wxRIGHT
|wxBOTTOM
, 10 ); 
 827     if (m_dialogStyle 
& wxMULTIPLE
) 
 828         m_list 
= new wxFileCtrl( this, ID_LIST_CTRL
, m_dir
, firstWild
, wxDefaultPosition
, 
 829                                  wxSize(440,180), s_lastViewStyle 
| wxSUNKEN_BORDER 
); 
 831         m_list 
= new wxFileCtrl( this, ID_LIST_CTRL
, m_dir
, firstWild
, wxDefaultPosition
, 
 832                                  wxSize(440,180), s_lastViewStyle 
| wxSUNKEN_BORDER 
| wxLC_SINGLE_SEL 
); 
 833     m_list 
-> ShowHidden(s_lastShowHidden
); 
 834     mainsizer
->Add( m_list
, 1, wxEXPAND 
| wxLEFT
|wxRIGHT
, 10 ); 
 836     wxBoxSizer 
*textsizer 
= new wxBoxSizer( wxHORIZONTAL 
); 
 837     m_text 
= new wxTextCtrl( this, ID_TEXT
, m_fileName
, wxDefaultPosition
, wxDefaultSize
, wxPROCESS_ENTER 
); 
 838     textsizer
->Add( m_text
, 1, wxCENTER 
| wxLEFT
|wxRIGHT
|wxTOP
, 10 ); 
 839     textsizer
->Add( new wxButton( this, wxID_OK
, _("OK") ), 0, wxCENTER 
| wxLEFT
|wxRIGHT
|wxTOP
, 10 ); 
 840     mainsizer
->Add( textsizer
, 0, wxEXPAND 
); 
 842     wxBoxSizer 
*choicesizer 
= new wxBoxSizer( wxHORIZONTAL 
); 
 843     m_choice 
= new wxChoice( this, ID_CHOICE 
); 
 844     choicesizer
->Add( m_choice
, 1, wxCENTER
|wxALL
, 10 ); 
 845     m_check 
= new wxCheckBox( this, ID_CHECK
, _("Show hidden files") ); 
 846     m_check
->SetValue( s_lastShowHidden 
); 
 847     choicesizer
->Add( m_check
, 0, wxCENTER
|wxALL
, 10 ); 
 848     choicesizer
->Add( new wxButton( this, wxID_CANCEL
, _("Cancel") ), 0, wxCENTER 
| wxALL
, 10 ); 
 849     mainsizer
->Add( choicesizer
, 0, wxEXPAND 
); 
 851     m_choice
->Append( firstWildText
, (void*) new wxString( firstWild 
) ); 
 852     while (tokens
.HasMoreTokens()) 
 854         firstWildText 
= tokens
.GetNextToken(); 
 855         firstWild 
= tokens
.GetNextToken(); 
 856         m_choice
->Append( firstWildText
, (void*) new wxString( firstWild 
) ); 
 858     m_choice
->SetSelection( 0 ); 
 860     SetAutoLayout( TRUE 
); 
 861     SetSizer( mainsizer 
); 
 863     mainsizer
->Fit( this ); 
 864     mainsizer
->SetSizeHints( this ); 
 868     if (m_fileName
.IsEmpty()) 
 876 wxFileDialog::~wxFileDialog() 
 878     if (wxConfig::Get(FALSE
)) 
 880         wxConfig::Get() -> Write(wxT("/wxWindows/wxFileDialog/ViewStyle"), s_lastViewStyle
); 
 881         wxConfig::Get() -> Write(wxT("/wxWindows/wxFileDialog/ShowHidden"), s_lastShowHidden
); 
 885 void wxFileDialog::OnChoice( wxCommandEvent 
&event 
) 
 887     int index 
= (int)event
.GetInt(); 
 888     wxString 
*str 
= (wxString
*) m_choice
->GetClientData( index 
); 
 889     m_list
->SetWild( *str 
); 
 890     m_filterIndex 
= index
; 
 891     if ( str 
-> Left( 2 ) == wxT("*.") ) 
 893         m_filterExtension 
= str 
-> Mid( 1 ); 
 894         if (m_filterExtension 
== ".*") m_filterExtension 
= wxEmptyString
; 
 897         m_filterExtension 
= wxEmptyString
; 
 900 void wxFileDialog::OnCheck( wxCommandEvent 
&event 
) 
 902     m_list
->ShowHidden( (s_lastShowHidden 
= event
.GetInt() != 0) ); 
 905 void wxFileDialog::OnActivated( wxListEvent 
&event 
) 
 907     HandleAction( event
.m_item
.m_text 
); 
 910 void wxFileDialog::OnTextEnter( wxCommandEvent 
&WXUNUSED(event
) ) 
 912     wxCommandEvent 
cevent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
); 
 913     cevent
.SetEventObject( this ); 
 914     GetEventHandler()->ProcessEvent( cevent 
); 
 917 void wxFileDialog::OnSelected( wxListEvent 
&event 
) 
 919     if (FindFocus() != m_list
) return; 
 921     wxString 
filename( event
.m_item
.m_text 
); 
 922     if (filename 
== wxT("..")) return; 
 925     m_list
->GetDir( dir 
); 
 926     if (dir 
!= wxT("/")) dir 
+= wxT("/"); 
 928     if (wxDirExists(dir
)) return; 
 930     m_text
->SetValue( filename 
); 
 933 void wxFileDialog::HandleAction( const wxString 
&fn 
) 
 935     wxString 
filename( fn 
); 
 937     m_list
->GetDir( dir 
); 
 938     if (filename
.IsEmpty()) return; 
 939     if (filename 
== wxT(".")) return; 
 941     if (filename 
== wxT("..")) 
 943         m_list
->GoToParentDir(); 
 945         m_list
->GetDir( dir 
); 
 946         m_static
->SetLabel( dir 
); 
 950     if (filename 
== wxT("~")) 
 952         m_list
->GoToHomeDir(); 
 954         m_list
->GetDir( dir 
); 
 955         m_static
->SetLabel( dir 
); 
 959     if (filename
[0] == wxT('~')) 
 961         filename
.Remove( 0, 1 ); 
 962         wxString 
tmp( wxGetUserHome() ); 
 968     if ((filename
.Find(wxT('*')) != wxNOT_FOUND
) || 
 969         (filename
.Find(wxT('?')) != wxNOT_FOUND
)) 
 971         if (filename
.Find(wxT('/')) != wxNOT_FOUND
) 
 973             wxMessageBox(_("Illegal file specification."), _("Error"), wxOK 
| wxICON_ERROR 
); 
 976         m_list
->SetWild( filename 
); 
 980     if (dir 
!= wxT("/")) dir 
+= wxT("/"); 
 981     if (filename
[0] != wxT('/')) 
 987     if (wxDirExists(filename
)) 
 989         m_list
->GoToDir( filename 
); 
 990         m_list
->GetDir( dir 
); 
 991         m_static
->SetLabel( dir 
); 
 996     if ( (m_dialogStyle 
& wxSAVE
) && (m_dialogStyle 
& wxOVERWRITE_PROMPT
) ) 
 998         if (filename
.Find( wxT('.') ) == wxNOT_FOUND 
|| 
 999                 filename
.AfterLast( wxT('.') ).Find( wxT('/') ) != wxNOT_FOUND
) 
1000             filename 
<< m_filterExtension
; 
1001         if (wxFileExists( filename 
)) 
1004             msg
.Printf( _("File '%s' already exists, do you really want to " 
1005                          "overwrite it?"), filename
.c_str() ); 
1007             if (wxMessageBox(msg
, _("Confirm"), wxYES_NO
) != wxYES
) 
1011     else if ( m_dialogStyle 
& wxOPEN 
) 
1013         if ( !wxFileExists( filename 
) ) 
1014             if (filename
.Find( wxT('.') ) == wxNOT_FOUND 
|| 
1015                   filename
.AfterLast( wxT('.') ).Find( wxT('/') ) != wxNOT_FOUND
) 
1016                 filename 
<< m_filterExtension
; 
1018         if ( m_dialogStyle 
& wxFILE_MUST_EXIST 
) 
1020             if ( !wxFileExists( filename 
) ) 
1022                 wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK 
| wxICON_ERROR 
); 
1028     SetPath( filename 
); 
1030     wxCommandEvent event
; 
1031     wxDialog::OnOK(event
); 
1034 void wxFileDialog::OnListOk( wxCommandEvent 
&WXUNUSED(event
) ) 
1036     HandleAction( m_text
->GetValue() ); 
1039 void wxFileDialog::OnList( wxCommandEvent 
&WXUNUSED(event
) ) 
1041     m_list
->ChangeToListMode(); 
1042     s_lastViewStyle 
= wxLC_LIST
; 
1046 void wxFileDialog::OnReport( wxCommandEvent 
&WXUNUSED(event
) ) 
1048     m_list
->ChangeToReportMode(); 
1049     s_lastViewStyle 
= wxLC_REPORT
; 
1053 void wxFileDialog::OnUp( wxCommandEvent 
&WXUNUSED(event
) ) 
1055     m_list
->GoToParentDir(); 
1058     m_list
->GetDir( dir 
); 
1059     m_static
->SetLabel( dir 
); 
1062 void wxFileDialog::OnHome( wxCommandEvent 
&WXUNUSED(event
) ) 
1064     m_list
->GoToHomeDir(); 
1067     m_list
->GetDir( dir 
); 
1068     m_static
->SetLabel( dir 
); 
1071 void wxFileDialog::OnNew( wxCommandEvent 
&WXUNUSED(event
) ) 
1076 void wxFileDialog::SetPath( const wxString
& path 
) 
1078     // not only set the full path but also update filename and dir 
1083         wxSplitPath(path
, &m_dir
, &m_fileName
, &ext
); 
1086             m_fileName 
+= wxT("."); 
1092 void wxFileDialog::GetPaths( wxArrayString
& paths 
) const 
1095     if (m_list
->GetSelectedItemCount() == 0) 
1097         paths
.Add( GetPath() ); 
1101     paths
.Alloc( m_list
->GetSelectedItemCount() ); 
1104     m_list
->GetDir( dir 
); 
1105     if (dir 
!= wxT("/")) dir 
+= wxT("/"); 
1108     item
.m_mask 
= wxLIST_MASK_TEXT
; 
1110     item
.m_itemId 
= m_list
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED 
); 
1111     while ( item
.m_itemId 
!= -1 ) { 
1112         m_list
->GetItem( item 
); 
1113         paths
.Add( dir 
+ item
.m_text 
); 
1114         item
.m_itemId 
= m_list
->GetNextItem( item
.m_itemId 
+ 1, 
1115             wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED 
); 
1119 void wxFileDialog::GetFilenames(wxArrayString
& files
) const 
1122     if (m_list
->GetSelectedItemCount() == 0) 
1124         files
.Add( GetFilename() ); 
1127     files
.Alloc( m_list
->GetSelectedItemCount() ); 
1130     item
.m_mask 
= wxLIST_MASK_TEXT
; 
1132     item
.m_itemId 
= m_list
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED 
); 
1133     while ( item
.m_itemId 
!= -1 ) { 
1134         m_list
->GetItem( item 
); 
1135         files
.Add( item
.m_text 
); 
1136         item
.m_itemId 
= m_list
->GetNextItem( item
.m_itemId 
+ 1, 
1137             wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED 
); 
1143 // ---------------------------------------------------------------------------- 
1145 // ---------------------------------------------------------------------------- 
1148 wxFileSelectorEx(const wxChar 
*message
, 
1149                  const wxChar 
*default_path
, 
1150                  const wxChar 
*default_filename
, 
1151                  int *WXUNUSED(indexDefaultExtension
), 
1152                  const wxChar 
*wildcard
, 
1157     // TODO: implement this somehow 
1158     return wxFileSelector(message
, default_path
, default_filename
, wxT(""), 
1159                           wildcard
, flags
, parent
, x
, y
); 
1162 wxString 
wxFileSelector( const wxChar 
*title
, 
1163                       const wxChar 
*defaultDir
, const wxChar 
*defaultFileName
, 
1164                       const wxChar 
*defaultExtension
, const wxChar 
*filter
, int flags
, 
1165                       wxWindow 
*parent
, int x
, int y 
) 
1168     if ( defaultExtension 
&& !filter 
) 
1169         filter2 
= wxString(wxT("*.")) + wxString(defaultExtension
) ; 
1173     wxString defaultDirString
; 
1175         defaultDirString 
= defaultDir
; 
1177     wxString defaultFilenameString
; 
1178     if (defaultFileName
) 
1179         defaultFilenameString 
= defaultFileName
; 
1181     wxFileDialog 
fileDialog( parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
) ); 
1183     if ( fileDialog
.ShowModal() == wxID_OK 
) 
1185         return fileDialog
.GetPath(); 
1189         return wxEmptyString
; 
1193 wxString 
wxLoadFileSelector( const wxChar 
*what
, const wxChar 
*extension
, const wxChar 
*default_name
, wxWindow 
*parent 
) 
1195     wxChar 
*ext 
= (wxChar 
*)extension
; 
1198     wxString str 
= _("Load %s file"); 
1199     wxSprintf(prompt
, str
, what
); 
1201     if (*ext 
== wxT('.')) ext
++; 
1203     wxSprintf(wild
, wxT("*.%s"), ext
); 
1205     return wxFileSelector (prompt
, (const wxChar 
*) NULL
, default_name
, ext
, wild
, 0, parent
); 
1208 wxString 
wxSaveFileSelector(const wxChar 
*what
, const wxChar 
*extension
, const wxChar 
*default_name
, 
1211     wxChar 
*ext 
= (wxChar 
*)extension
; 
1214     wxString str 
= _("Save %s file"); 
1215     wxSprintf(prompt
, str
, what
); 
1217     if (*ext 
== wxT('.')) ext
++; 
1219     wxSprintf(wild
, wxT("*.%s"), ext
); 
1221     return wxFileSelector (prompt
, (const wxChar 
*) NULL
, default_name
, ext
, wild
, 0, parent
); 
1229 // A module to allow icons table cleanup 
1231 class wxFileDialogGenericModule
: public wxModule
 
1233 DECLARE_DYNAMIC_CLASS(wxFileDialogGenericModule
) 
1235     wxFileDialogGenericModule() {} 
1236     bool OnInit() { return TRUE
; } 
1237     void OnExit() { if (g_IconsTable
) {delete g_IconsTable
; g_IconsTable 
= NULL
;} } 
1240 IMPLEMENT_DYNAMIC_CLASS(wxFileDialogGenericModule
, wxModule
)