X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/398eebb155b2a5804359a0f40935e75424e169e2..b85b06e13d22e7fc1604ec1a49caa1227a1b3d36:/src/generic/filectrlg.cpp?ds=inline diff --git a/src/generic/filectrlg.cpp b/src/generic/filectrlg.cpp index 1974401fab..4e3730f466 100644 --- a/src/generic/filectrlg.cpp +++ b/src/generic/filectrlg.cpp @@ -52,7 +52,7 @@ // ---------------------------------------------------------------------------- static -int wxCALLBACK wxFileDataNameCompare( long data1, long data2, long sortOrder) +int wxCALLBACK wxFileDataNameCompare( long data1, long data2, wxIntPtr sortOrder) { wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1); wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2); @@ -70,7 +70,7 @@ int wxCALLBACK wxFileDataNameCompare( long data1, long data2, long sortOrder) } static -int wxCALLBACK wxFileDataSizeCompare(long data1, long data2, long sortOrder) +int wxCALLBACK wxFileDataSizeCompare(long data1, long data2, wxIntPtr sortOrder) { wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1); wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2); @@ -92,7 +92,7 @@ int wxCALLBACK wxFileDataSizeCompare(long data1, long data2, long sortOrder) } static -int wxCALLBACK wxFileDataTypeCompare(long data1, long data2, long sortOrder) +int wxCALLBACK wxFileDataTypeCompare(long data1, long data2, wxIntPtr sortOrder) { wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1); wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2); @@ -114,7 +114,7 @@ int wxCALLBACK wxFileDataTypeCompare(long data1, long data2, long sortOrder) } static -int wxCALLBACK wxFileDataTimeCompare(long data1, long data2, long sortOrder) +int wxCALLBACK wxFileDataTimeCompare(long data1, long data2, wxIntPtr sortOrder) { wxFileData *fd1 = (wxFileData *)wxUIntToPtr(data1); wxFileData *fd2 = (wxFileData *)wxUIntToPtr(data2); @@ -193,7 +193,7 @@ void wxFileData::ReadData() m_type |= (fileAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0 ? is_dir : 0; wxString p, f, ext; - wxSplitPath(m_filePath, & p, & f, & ext); + wxFileName::SplitPath(m_filePath, & p, & f, & ext); if (wxStricmp(ext, wxT("exe")) == 0) m_type |= is_exe; @@ -912,6 +912,7 @@ bool wxGenericFileCtrl::Create( wxWindow *parent, this->m_style = style; m_inSelected = false; m_noSelChgEvent = false; + m_check = NULL; // check that the styles are not contradictory wxASSERT_MSG( !( ( m_style & wxFC_SAVE ) && ( m_style & wxFC_OPEN ) ), @@ -947,10 +948,11 @@ bool wxGenericFileCtrl::Create( wxWindow *parent, wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL ); if ( is_pda ) - staticsizer->Add( new wxStaticText( this, wxID_ANY, _( "Current directory:" ) ), 0, wxRIGHT, 10 ); + staticsizer->Add( new wxStaticText( this, wxID_ANY, _( "Current directory:" ) ), + wxSizerFlags().DoubleBorder(wxRIGHT) ); m_static = new wxStaticText( this, wxID_ANY, m_dir ); staticsizer->Add( m_static, 1 ); - mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10 ); + mainsizer->Add( staticsizer, wxSizerFlags().Expand().Border()); long style2 = wxLC_LIST; if ( !( m_style & wxFC_MULTIPLE ) ) @@ -979,33 +981,25 @@ bool wxGenericFileCtrl::Create( wxWindow *parent, wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); textsizer->Add( m_text, wxSizerFlags( 1 ).Centre().Border() ); + textsizer->Add( m_choice, wxSizerFlags( 1 ).Centre().Border() ); mainsizer->Add( textsizer, wxSizerFlags().Expand() ); - m_check = NULL; - textsizer->Add( m_choice, wxSizerFlags( 1 ).Centre().Border() ); } else // !is_pda { - mainsizer->Add( m_list, wxSizerFlags( 1 ).Expand().DoubleHorzBorder() ); - - wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); - textsizer->Add( m_text, wxSizerFlags( 1 ).Centre(). - DoubleBorder( wxLEFT | wxRIGHT | wxTOP ) ); - mainsizer->Add( textsizer, wxSizerFlags().Expand() ); - - wxSizerFlags flagsCentre; - flagsCentre.Centre().DoubleBorder(); + mainsizer->Add( m_list, wxSizerFlags( 1 ).Expand().Border() ); + mainsizer->Add( m_text, wxSizerFlags().Expand().Border() ); wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL ); - choicesizer->Add( m_choice, wxSizerFlags( flagsCentre ).Proportion( 1 ) ); + choicesizer->Add( m_choice, wxSizerFlags( 1 ).Centre() ); if ( !( m_style & wxFC_NOSHOWHIDDEN ) ) - { + { m_check = new wxCheckBox( this, ID_CHECK, _( "Show &hidden files" ) ); - choicesizer->Add( m_check, flagsCentre ); - } + choicesizer->Add( m_check, wxSizerFlags().Centre().DoubleBorder(wxLEFT) ); + } - mainsizer->Add( choicesizer, wxSizerFlags().Expand() ); + mainsizer->Add( choicesizer, wxSizerFlags().Expand().Border() ); } SetWildcard( wildCard ); @@ -1080,44 +1074,52 @@ wxFileName wxGenericFileCtrl::DoGetFileName() const return fn; } -void wxGenericFileCtrl::DoGetFilenames( wxArrayString& filenames, const bool fullPath ) const +// helper used in DoGetFilenames() and needed because Borland can't compile +// operator?: inline +static inline wxString GetFileNameOrPath(const wxFileName& fn, bool fullPath) { - filenames.Empty(); + return fullPath ? fn.GetFullPath() : fn.GetFullName(); +} + +void +wxGenericFileCtrl::DoGetFilenames(wxArrayString& filenames, bool fullPath) const +{ + filenames.clear(); const wxString dir = m_list->GetDir(); - const wxString value = m_text->GetValue(); + const wxString value = m_text->GetValue(); if ( !value.empty() ) { - if ( fullPath ) - filenames.Add( dir + value ); - else - filenames.Add( value ); + wxFileName fn(value); + if ( fn.IsRelative() ) + fn.MakeAbsolute(dir); + + filenames.push_back(GetFileNameOrPath(fn, fullPath)); return; } - if ( m_list->GetSelectedItemCount() == 0 ) - { + const int numSel = m_list->GetSelectedItemCount(); + if ( !numSel ) return; - } - filenames.Alloc( m_list->GetSelectedItemCount() ); + filenames.reserve(numSel); wxListItem item; item.m_mask = wxLIST_MASK_TEXT; - - item.m_itemId = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); - while ( item.m_itemId != -1 ) + item.m_itemId = -1; + for ( ;; ) { - m_list->GetItem( item ); + item.m_itemId = m_list->GetNextItem(item.m_itemId, wxLIST_NEXT_ALL, + wxLIST_STATE_SELECTED); + + if ( item.m_itemId == -1 ) + break; - if ( fullPath ) - filenames.Add( dir + item.m_text ); - else - filenames.Add( item.m_text ); + m_list->GetItem(item); - item.m_itemId = m_list->GetNextItem( item.m_itemId, - wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); + const wxFileName fn(dir, item.m_text); + filenames.push_back(GetFileNameOrPath(fn, fullPath)); } } @@ -1170,9 +1172,11 @@ bool wxGenericFileCtrl::SetFilename( const wxString& name ) void wxGenericFileCtrl::DoSetFilterIndex( int filterindex ) { - const wxString& str = (wx_static_cast(wxStringClientData *, - m_choice->GetClientObject( filterindex ))) - ->GetData(); + wxClientData *pcd = m_choice->GetClientObject( filterindex ); + if ( !pcd ) + return; + + const wxString& str = ((static_cast(pcd))->GetData()); m_list->SetWild( str ); m_filterIndex = filterindex; if ( str.Left( 2 ) == wxT( "*." ) ) @@ -1291,7 +1295,7 @@ void wxGenericFileCtrl::OnSelected( wxListEvent &event ) return; } - + m_ignoreChanges = true; m_text->SetValue( filename ); @@ -1424,7 +1428,7 @@ bool wxGenericFileCtrl::SetPath( const wxString& path ) return false; wxString ext; - wxSplitPath( path, &m_dir, &m_fileName, &ext ); + wxFileName::SplitPath( path, &m_dir, &m_fileName, &ext ); if ( !ext.empty() ) { m_fileName += wxT( "." );