]> git.saurik.com Git - wxWidgets.git/blob - src/common/filectrlcmn.cpp
fix building with WXWIN_COMPATIBILITY_2_8 == 0
[wxWidgets.git] / src / common / filectrlcmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/filectrlcmn.cpp
3 // Purpose: Implementation for wxFileCtrlBase and other common functions used by
4 // platform-specific wxFileCtrl's
5 // Author: Diaa M. Sami
6 // Created: 2007-07-07
7 // Copyright: (c) Diaa M. Sami
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #if wxUSE_FILECTRL
18
19 #include "wx/filectrl.h"
20
21 #ifndef WX_PRECOMP
22 # include "wx/debug.h"
23 #endif
24
25 const char wxFileCtrlNameStr[] = "wxfilectrl";
26
27 wxDEFINE_EVENT( wxEVT_FILECTRL_SELECTIONCHANGED, wxFileCtrlEvent );
28 wxDEFINE_EVENT( wxEVT_FILECTRL_FILEACTIVATED, wxFileCtrlEvent );
29 wxDEFINE_EVENT( wxEVT_FILECTRL_FOLDERCHANGED, wxFileCtrlEvent );
30 wxDEFINE_EVENT( wxEVT_FILECTRL_FILTERCHANGED, wxFileCtrlEvent );
31
32 IMPLEMENT_DYNAMIC_CLASS( wxFileCtrlEvent, wxCommandEvent )
33
34 // some helper functions
35
36 void GenerateFilterChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd )
37 {
38 wxFileCtrlEvent event( wxEVT_FILECTRL_FILTERCHANGED, wnd, wnd->GetId() );
39
40 event.SetFilterIndex( fileCtrl->GetFilterIndex() );
41
42 wnd->GetEventHandler()->ProcessEvent( event );
43 }
44
45 void GenerateFolderChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd )
46 {
47 wxFileCtrlEvent event( wxEVT_FILECTRL_FOLDERCHANGED, wnd, wnd->GetId() );
48
49 event.SetDirectory( fileCtrl->GetDirectory() );
50
51 wnd->GetEventHandler()->ProcessEvent( event );
52 }
53
54 void GenerateSelectionChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd)
55 {
56 wxFileCtrlEvent event( wxEVT_FILECTRL_SELECTIONCHANGED, wnd, wnd->GetId() );
57 event.SetDirectory( fileCtrl->GetDirectory() );
58
59 wxArrayString filenames;
60 fileCtrl->GetFilenames( filenames );
61 event.SetFiles( filenames );
62
63 wnd->GetEventHandler()->ProcessEvent( event );
64 }
65
66 void GenerateFileActivatedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd, const wxString filename )
67 {
68 wxFileCtrlEvent event( wxEVT_FILECTRL_FILEACTIVATED, wnd, wnd->GetId() );
69 event.SetDirectory( fileCtrl->GetDirectory() );
70
71 wxArrayString filenames;
72
73 if ( filename.empty() )
74 {
75 fileCtrl->GetFilenames( filenames );
76 }
77 else
78 {
79 filenames.Add( filename );
80 }
81
82 event.SetFiles( filenames );
83
84 wnd->GetEventHandler()->ProcessEvent( event );
85 }
86
87 ///////////////////////////////////////////////////////////////////////////////
88 // wxFileCtrlEvent implementation
89 ///////////////////////////////////////////////////////////////////////////////
90
91 wxString wxFileCtrlEvent::GetFile() const
92 {
93 wxASSERT_MSG( !wxDynamicCast( GetEventObject(), wxFileCtrl )->HasMultipleFileSelection(),
94 wxT( "Please use GetFiles() to get all files instead of this function" ) );
95
96 wxString string;
97 if (m_files.Count() != 0)
98 string = m_files[0];
99 return string;
100 }
101
102 #endif // wxUSE_FILECTRL