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