]> git.saurik.com Git - wxWidgets.git/blame - src/common/filectrlcmn.cpp
Merge of SOC2010_RTC_IMAGES branch.
[wxWidgets.git] / src / common / filectrlcmn.cpp
CommitLineData
0cf3e587
VZ
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
23318a53 26const char wxFileCtrlNameStr[] = "wxfilectrl";
0cf3e587 27
9b11752c
VZ
28wxDEFINE_EVENT( wxEVT_FILECTRL_SELECTIONCHANGED, wxFileCtrlEvent );
29wxDEFINE_EVENT( wxEVT_FILECTRL_FILEACTIVATED, wxFileCtrlEvent );
30wxDEFINE_EVENT( wxEVT_FILECTRL_FOLDERCHANGED, wxFileCtrlEvent );
6305f044 31wxDEFINE_EVENT( wxEVT_FILECTRL_FILTERCHANGED, wxFileCtrlEvent );
0cf3e587
VZ
32
33IMPLEMENT_DYNAMIC_CLASS( wxFileCtrlEvent, wxCommandEvent )
34
35// some helper functions
36
6305f044
VZ
37void 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
0cf3e587
VZ
46void 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
55void 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
67void 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
92wxString 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
260020e3
PC
97 wxString string;
98 if (m_files.Count() != 0)
99 string = m_files[0];
100 return string;
0cf3e587
VZ
101}
102
103#endif // wxUSE_FILECTRL