]> git.saurik.com Git - wxWidgets.git/blame - src/common/filectrlcmn.cpp
Workaround for #15404: wxRichTextCtrl: caret does not disappear when focus is lost...
[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
0cf3e587
VZ
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
23318a53 25const char wxFileCtrlNameStr[] = "wxfilectrl";
0cf3e587 26
9b11752c
VZ
27wxDEFINE_EVENT( wxEVT_FILECTRL_SELECTIONCHANGED, wxFileCtrlEvent );
28wxDEFINE_EVENT( wxEVT_FILECTRL_FILEACTIVATED, wxFileCtrlEvent );
29wxDEFINE_EVENT( wxEVT_FILECTRL_FOLDERCHANGED, wxFileCtrlEvent );
6305f044 30wxDEFINE_EVENT( wxEVT_FILECTRL_FILTERCHANGED, wxFileCtrlEvent );
0cf3e587
VZ
31
32IMPLEMENT_DYNAMIC_CLASS( wxFileCtrlEvent, wxCommandEvent )
33
34// some helper functions
35
6305f044
VZ
36void 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
0cf3e587
VZ
45void 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
54void 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
66void 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
91wxString 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
260020e3
PC
96 wxString string;
97 if (m_files.Count() != 0)
98 string = m_files[0];
99 return string;
0cf3e587
VZ
100}
101
102#endif // wxUSE_FILECTRL