]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/filedlg.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxFileDialog 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  21     #include "wx/msgdlg.h" 
  22     #include "wx/filedlg.h" 
  31 #include "wx/os2/private.h" 
  37 #include "wx/tokenzr.h" 
  39 #define wxMAXPATH                    1024 
  40 #define wxMAXFILE                    1024 
  58 IMPLEMENT_CLASS(wxFileDialog
, wxFileDialogBase
) 
  60 // ---------------------------------------------------------------------------- 
  62 // ---------------------------------------------------------------------------- 
  64 wxFileDialog::wxFileDialog ( 
  66 , const wxString
&                   rsMessage
 
  67 , const wxString
&                   rsDefaultDir
 
  68 , const wxString
&                   rsDefaultFileName
 
  69 , const wxString
&                   rsWildCard
 
  73     :wxFileDialogBase(pParent
, rsMessage
, rsDefaultDir
, rsDefaultFileName
, rsWildCard
, lStyle
, rPos
) 
  76     if ((m_dialogStyle 
& wxMULTIPLE
) && (m_dialogStyle 
& wxSAVE
)) 
  77         m_dialogStyle 
&= ~wxMULTIPLE
; 
  80 } // end of wxFileDialog::wxFileDialog 
  82 void wxFileDialog::GetPaths ( 
  83   wxArrayString
&                    rasPaths
 
  87     size_t                          nCount 
= m_fileNames
.GetCount(); 
  90     if (m_dir
.Last() != _T('\\')) 
  93     for ( size_t n 
= 0; n 
< nCount
; n
++ ) 
  95         rasPaths
.Add(sDir 
+ m_fileNames
[n
]); 
  97 } // end of wxFileDialog::GetPaths 
  99 int wxFileDialog::ShowModal() 
 102     wxString                        sFilterBuffer
; 
 103     wxChar
*                         pzFilterBuffer
; 
 104     static wxChar                   zFileNameBuffer
[wxMAXPATH
];           // the file-name 
 106     wxChar                          zTitleBuffer
[wxMAXFILE 
+ 1 + wxMAXEXT
];  // the file-name, without path 
 109     size_t                          nLen 
= m_dir
.length(); 
 114     memset(&vFileDlg
, '\0', sizeof(FILEDLG
)); 
 116         hWnd 
= (HWND
) m_parent
->GetHWND(); 
 117     if (!hWnd 
&& wxTheApp
->GetTopWindow()) 
 118         hWnd 
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND(); 
 121     *zFileNameBuffer 
= wxT('\0'); 
 122     *zTitleBuffer    
= wxT('\0'); 
 124     if (m_dialogStyle 
& wxSAVE
) 
 125         lFlags 
= FDS_SAVEAS_DIALOG
; 
 127         lFlags 
= FDS_OPEN_DIALOG
; 
 129     if ((m_dialogStyle 
& wxHIDE_READONLY
) || (m_dialogStyle 
& wxSAVE
)) 
 130         lFlags 
|= FDS_SAVEAS_DIALOG
; 
 131     if (m_dialogStyle 
& wxMULTIPLE 
) 
 132         lFlags 
|= FDS_OPEN_DIALOG 
| FDS_MULTIPLESEL
; 
 134     vFileDlg
.cbSize 
= sizeof(FILEDLG
); 
 135     vFileDlg
.fl 
= lFlags
; 
 136     vFileDlg
.pszTitle 
= zTitleBuffer
; 
 139     // Convert forward slashes to backslashes (file selector doesn't like 
 140     // forward slashes) and also squeeze multiple consecutive slashes into one 
 141     // as it doesn't like two backslashes in a row neither 
 144     for ( i 
= 0; i 
< nLen
; i
++ ) 
 146         wxChar                      ch 
= m_dir
[i
]; 
 152                 // Convert to backslash 
 162                     wxChar          chNext 
= m_dir
[i 
+ 1]; 
 164                     if (chNext 
!= _T('\\') && chNext 
!= _T('/')) 
 168                     // Ignore the next one, unless it is at the start of a UNC path 
 186     if ( wxStrlen(m_wildCard
) == 0 ) 
 189         sTheFilter 
= m_wildCard
; 
 191     pzFilterBuffer 
= strtok((char*)sTheFilter
.c_str(), "|"); 
 192     while(pzFilterBuffer 
!= NULL
) 
 194         if (nCount 
> 0 && !(nCount 
% 2)) 
 198             sDir 
+= pzFilterBuffer
; 
 200         pzFilterBuffer 
= strtok(NULL
, "|"); 
 207     wxStrcpy(vFileDlg
.szFullFile
, sDir
.c_str()); 
 208     sFilterBuffer 
= sDir
; 
 210     hWnd 
= ::WinFileDlg( HWND_DESKTOP
 
 214     if (hWnd 
&& vFileDlg
.lReturn 
== DID_OK
) 
 217         if ((m_dialogStyle 
& wxMULTIPLE 
) && vFileDlg
.ulFQFCount 
> 1) 
 219             for (int i 
= 0; i 
< (int)vFileDlg
.ulFQFCount
; i
++) 
 223                     m_dir 
= wxPathOnly(wxString((const char*)*vFileDlg
.papszFQFilename
[0])); 
 224                     m_path 
= (const char*)*vFileDlg
.papszFQFilename
[0]; 
 226                 m_fileName 
= wxFileNameFromPath(wxString((const char*)*vFileDlg
.papszFQFilename
[i
])); 
 227                 m_fileNames
.Add(m_fileName
); 
 229             ::WinFreeFileDlgList(vFileDlg
.papszFQFilename
); 
 231         else if (!(m_dialogStyle 
& wxSAVE
)) 
 233             m_path 
= vFileDlg
.szFullFile
; 
 234             m_fileName 
= wxFileNameFromPath(vFileDlg
.szFullFile
); 
 235             m_dir 
= wxPathOnly(vFileDlg
.szFullFile
); 
 239             const wxChar
*           pzExtension 
= NULL
; 
 241             wxStrcpy(zFileNameBuffer
, vFileDlg
.szFullFile
); 
 243             int                     nIdx 
= wxStrlen(zFileNameBuffer
) - 1; 
 246             wxSplitPath( zFileNameBuffer
 
 251             if (zFileNameBuffer
[nIdx
] == wxT('.') || sExt
.IsEmpty()) 
 253                 zFileNameBuffer
[nIdx
] = wxT('\0'); 
 256                 // User has typed a filename without an extension: 
 258                 // A filename can end in a "." here ("abc."), this means it 
 259                 // does not have an extension. Because later on a "." with 
 260                 // the default extension is appended we remove the "." if 
 261                 // filename ends with one (We don't want files called 
 264                 pzExtension 
= sFilterBuffer
.c_str(); 
 266                 for( int i 
= 0; i 
< (int)sFilterBuffer
.length(); i
++ ) 
 271                     pzExtension 
= wxStrrchr(pzExtension
, wxT('.')); 
 273                         !wxStrrchr(pzExtension
, wxT('*')) && 
 274                         !wxStrrchr(pzExtension
, wxT('?')) && 
 276                         pzExtension
[1] != wxT(' ') 
 280                         // Now concat extension to the fileName: 
 282                         m_path 
= wxString(zFileNameBuffer
) + pzExtension
; 
 288                 m_path 
= vFileDlg
.szFullFile
; 
 290             m_fileName 
= wxFileNameFromPath(vFileDlg
.szFullFile
); 
 291             m_dir 
= wxPathOnly(vFileDlg
.szFullFile
); 
 294             // === Simulating the wxOVERWRITE_PROMPT >>============================ 
 296             if ((m_dialogStyle 
& wxOVERWRITE_PROMPT
) && 
 297                 (m_dialogStyle 
& wxSAVE
) && 
 298                 (wxFileExists(m_path
.c_str()))) 
 300                 wxString            sMessageText
; 
 302                 sMessageText
.Printf( _("File '%s' already exists.\nDo you want to replace it?") 
 305                 if (wxMessageBox( sMessageText
 
 307                                  ,wxYES_NO 
| wxICON_EXCLAMATION
 
 317 } // end of wxFileDialog::ShowModal