X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b4a11fe85cb632368ba8426204598806460b7679..0cf3e587a2ec542ba1eb6e03a84c54edefae1881:/src/common/filectrlcmn.cpp diff --git a/src/common/filectrlcmn.cpp b/src/common/filectrlcmn.cpp new file mode 100644 index 0000000000..d6b4adb044 --- /dev/null +++ b/src/common/filectrlcmn.cpp @@ -0,0 +1,93 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/common/filectrlcmn.cpp +// Purpose: Implementation for wxFileCtrlBase and other common functions used by +// platform-specific wxFileCtrl's +// Author: Diaa M. Sami +// Created: 2007-07-07 +// RCS-ID: $Id$ +// Copyright: (c) Diaa M. Sami +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#if wxUSE_FILECTRL + +#include "wx/filectrl.h" + +#ifndef WX_PRECOMP +# include "wx/debug.h" +#endif + +const wxChar wxFileCtrlNameStr[] = wxT( "wxfilectrl" ); + +DEFINE_EVENT_TYPE( wxEVT_FILECTRL_SELECTIONCHANGED ); +DEFINE_EVENT_TYPE( wxEVT_FILECTRL_FILEACTIVATED ); +DEFINE_EVENT_TYPE( wxEVT_FILECTRL_FOLDERCHANGED ); + +IMPLEMENT_DYNAMIC_CLASS( wxFileCtrlEvent, wxCommandEvent ) + +// some helper functions + +void GenerateFolderChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd ) +{ + wxFileCtrlEvent event( wxEVT_FILECTRL_FOLDERCHANGED, wnd, wnd->GetId() ); + + event.SetDirectory( fileCtrl->GetDirectory() ); + + wnd->GetEventHandler()->ProcessEvent( event ); +} + +void GenerateSelectionChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd) +{ + wxFileCtrlEvent event( wxEVT_FILECTRL_SELECTIONCHANGED, wnd, wnd->GetId() ); + event.SetDirectory( fileCtrl->GetDirectory() ); + + wxArrayString filenames; + fileCtrl->GetFilenames( filenames ); + event.SetFiles( filenames ); + + wnd->GetEventHandler()->ProcessEvent( event ); +} + +void GenerateFileActivatedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd, const wxString filename ) +{ + wxFileCtrlEvent event( wxEVT_FILECTRL_FILEACTIVATED, wnd, wnd->GetId() ); + event.SetDirectory( fileCtrl->GetDirectory() ); + + wxArrayString filenames; + + if ( filename.empty() ) + { + fileCtrl->GetFilenames( filenames ); + } + else + { + filenames.Add( filename ); + } + + event.SetFiles( filenames ); + + wnd->GetEventHandler()->ProcessEvent( event ); +} + +/////////////////////////////////////////////////////////////////////////////// +// wxFileCtrlEvent implementation +/////////////////////////////////////////////////////////////////////////////// + +wxString wxFileCtrlEvent::GetFile() const +{ + wxASSERT_MSG( !wxDynamicCast( GetEventObject(), wxFileCtrl )->HasMultipleFileSelection(), + wxT( "Please use GetFiles() to get all files instead of this function" ) ); + + if ( files.Count() == 0 ) + return wxEmptyString; + else + return files[0]; +} + +#endif // wxUSE_FILECTRL