]> git.saurik.com Git - wxWidgets.git/blame - src/common/filectrlcmn.cpp
Halfway reasonable implementation of wxFont for wxCocoa.
[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
26const wxChar wxFileCtrlNameStr[] = wxT( "wxfilectrl" );
27
b3adca1e
VZ
28DEFINE_EVENT_TYPE( wxEVT_FILECTRL_SELECTIONCHANGED )
29DEFINE_EVENT_TYPE( wxEVT_FILECTRL_FILEACTIVATED )
30DEFINE_EVENT_TYPE( wxEVT_FILECTRL_FOLDERCHANGED )
0cf3e587
VZ
31
32IMPLEMENT_DYNAMIC_CLASS( wxFileCtrlEvent, wxCommandEvent )
33
34// some helper functions
35
36void GenerateFolderChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd )
37{
38 wxFileCtrlEvent event( wxEVT_FILECTRL_FOLDERCHANGED, wnd, wnd->GetId() );
39
40 event.SetDirectory( fileCtrl->GetDirectory() );
41
42 wnd->GetEventHandler()->ProcessEvent( event );
43}
44
45void GenerateSelectionChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd)
46{
47 wxFileCtrlEvent event( wxEVT_FILECTRL_SELECTIONCHANGED, wnd, wnd->GetId() );
48 event.SetDirectory( fileCtrl->GetDirectory() );
49
50 wxArrayString filenames;
51 fileCtrl->GetFilenames( filenames );
52 event.SetFiles( filenames );
53
54 wnd->GetEventHandler()->ProcessEvent( event );
55}
56
57void GenerateFileActivatedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd, const wxString filename )
58{
59 wxFileCtrlEvent event( wxEVT_FILECTRL_FILEACTIVATED, wnd, wnd->GetId() );
60 event.SetDirectory( fileCtrl->GetDirectory() );
61
62 wxArrayString filenames;
63
64 if ( filename.empty() )
65 {
66 fileCtrl->GetFilenames( filenames );
67 }
68 else
69 {
70 filenames.Add( filename );
71 }
72
73 event.SetFiles( filenames );
74
75 wnd->GetEventHandler()->ProcessEvent( event );
76}
77
78///////////////////////////////////////////////////////////////////////////////
79// wxFileCtrlEvent implementation
80///////////////////////////////////////////////////////////////////////////////
81
82wxString wxFileCtrlEvent::GetFile() const
83{
84 wxASSERT_MSG( !wxDynamicCast( GetEventObject(), wxFileCtrl )->HasMultipleFileSelection(),
85 wxT( "Please use GetFiles() to get all files instead of this function" ) );
86
260020e3
PC
87 wxString string;
88 if (m_files.Count() != 0)
89 string = m_files[0];
90 return string;
0cf3e587
VZ
91}
92
93#endif // wxUSE_FILECTRL