]> git.saurik.com Git - wxWidgets.git/blame - src/generic/dirctrlg.cpp
exposing common used button impl class
[wxWidgets.git] / src / generic / dirctrlg.cpp
CommitLineData
51a58d8b 1/////////////////////////////////////////////////////////////////////////////
7fc65a03 2// Name: src/generic/dirctrlg.cpp
51a58d8b
JS
3// Purpose: wxGenericDirCtrl
4// Author: Harm van der Heijden, Robert Roebling, Julian Smart
5// Modified by:
6// Created: 12/12/98
7// RCS-ID: $Id$
8// Copyright: (c) Harm van der Heijden, Robert Roebling and Julian Smart
65571936 9// Licence: wxWindows licence
51a58d8b
JS
10/////////////////////////////////////////////////////////////////////////////
11
51a58d8b
JS
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
32d4c30a 16 #pragma hdrstop
51a58d8b
JS
17#endif
18
13de0c8c 19#if wxUSE_DIRDLG || wxUSE_FILEDLG
51a58d8b 20
88a7a4e1
WS
21#include "wx/generic/dirctrlg.h"
22
32d4c30a
WS
23#ifndef WX_PRECOMP
24 #include "wx/hash.h"
88a7a4e1 25 #include "wx/intl.h"
e4db172a 26 #include "wx/log.h"
de6185e2 27 #include "wx/utils.h"
f1e01716 28 #include "wx/button.h"
923d28da 29 #include "wx/icon.h"
9eddec69 30 #include "wx/settings.h"
246c5004 31 #include "wx/msgdlg.h"
b36e08d0 32 #include "wx/choice.h"
fec9cc08 33 #include "wx/textctrl.h"
ed2fbeb8
WS
34 #include "wx/layout.h"
35 #include "wx/sizer.h"
949c9f74 36 #include "wx/textdlg.h"
dd05139a 37 #include "wx/gdicmn.h"
155ecd4c 38 #include "wx/image.h"
02761f6c 39 #include "wx/module.h"
32d4c30a
WS
40#endif
41
35c2aa4f 42#include "wx/filename.h"
51a58d8b 43#include "wx/filefn.h"
51a58d8b 44#include "wx/imaglist.h"
51a58d8b
JS
45#include "wx/tokenzr.h"
46#include "wx/dir.h"
06cc1fb9 47#include "wx/artprov.h"
06cc1fb9 48#include "wx/mimetype.h"
51a58d8b
JS
49
50#if wxUSE_STATLINE
51 #include "wx/statline.h"
52#endif
53
76a5e5d2 54#if defined(__WXMAC__)
33ddeaba 55 #include "wx/osx/private.h" // includes mac headers
76a5e5d2
SC
56#endif
57
bb5a9514 58#ifdef __WINDOWS__
2736b3ce 59#include <windows.h>
7acf6a92 60#include "wx/msw/winundef.h"
006b7af2 61#include "wx/volume.h"
7328394a 62
c9ecda60
VS
63// FIXME - Mingw32 1.0 has both _getdrive() and _chdrive(). For now, let's assume
64// older releases don't, but it should be verified and the checks modified
65// accordingly.
b4da152e 66#if !defined(__GNUWIN32__) || (defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
1c193821 67#if !defined(__WXWINCE__)
32d4c30a 68 #include <direct.h>
1c193821 69#endif
32d4c30a
WS
70 #include <stdlib.h>
71 #include <ctype.h>
51a58d8b
JS
72#endif
73
bb5a9514 74#endif // __WINDOWS__
7328394a 75
1c53456f 76#if defined(__OS2__) || defined(__DOS__)
ed2fbeb8
WS
77 #ifdef __OS2__
78 #define INCL_BASE
79 #include <os2.h>
80 #ifndef __EMX__
81 #include <direct.h>
82 #endif
83 #include <stdlib.h>
84 #include <ctype.h>
1c53456f 85 #endif
0d853c54 86#endif // __OS2__
ec1b28a3 87
f4ac0693 88#if defined(__WXMAC__)
e1f31102 89// #include "MoreFilesX.h"
bedaf53e
SC
90#endif
91
267a7108 92#ifdef __BORLANDC__
32d4c30a 93 #include "dos.h"
267a7108
JS
94#endif
95
f36e602b 96extern WXDLLEXPORT_DATA(const char) wxFileSelectorDefaultWildcardStr[];
a3e70e1f 97
51a58d8b
JS
98// If compiled under Windows, this macro can cause problems
99#ifdef GetFirstChild
100#undef GetFirstChild
101#endif
102
207ddcc9
VZ
103bool wxIsDriveAvailable(const wxString& dirName);
104
84605707
VZ
105// ----------------------------------------------------------------------------
106// events
107// ----------------------------------------------------------------------------
108
109wxDEFINE_EVENT( wxEVT_COMMAND_DIRCTRL_CHANGED, wxTreeEvent );
110
06cc1fb9 111// ----------------------------------------------------------------------------
0d853c54 112// wxGetAvailableDrives, for WINDOWS, DOS, OS2, MAC, UNIX (returns "/")
06cc1fb9 113// ----------------------------------------------------------------------------
51a58d8b 114
06cc1fb9
JS
115size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayInt &icon_ids)
116{
35c2aa4f 117#ifdef wxHAS_FILESYSTEM_VOLUMES
51a58d8b 118
4676948b
JS
119#ifdef __WXWINCE__
120 // No logical drives; return "\"
121 paths.Add(wxT("\\"));
122 names.Add(wxT("\\"));
1ab36908 123 icon_ids.Add(wxFileIconsTable::computer);
006b7af2
VZ
124#elif defined(__WIN32__) && wxUSE_FSVOLUME
125 // TODO: this code (using wxFSVolumeBase) should be used for all platforms
126 // but unfortunately wxFSVolumeBase is not implemented everywhere
127 const wxArrayString as = wxFSVolumeBase::GetVolumes();
0026e0f2 128
006b7af2
VZ
129 for (size_t i = 0; i < as.GetCount(); i++)
130 {
131 wxString path = as[i];
132 wxFSVolume vol(path);
999836aa 133 int imageId;
006b7af2 134 switch (vol.GetKind())
06cc1fb9 135 {
006b7af2
VZ
136 case wxFS_VOL_FLOPPY:
137 if ( (path == wxT("a:\\")) || (path == wxT("b:\\")) )
06cc1fb9
JS
138 imageId = wxFileIconsTable::floppy;
139 else
140 imageId = wxFileIconsTable::removeable;
141 break;
006b7af2
VZ
142 case wxFS_VOL_DVDROM:
143 case wxFS_VOL_CDROM:
06cc1fb9
JS
144 imageId = wxFileIconsTable::cdrom;
145 break;
006b7af2
VZ
146 case wxFS_VOL_NETWORK:
147 if (path[0] == wxT('\\'))
148 continue; // skip "\\computer\folder"
149 imageId = wxFileIconsTable::drive;
150 break;
151 case wxFS_VOL_DISK:
152 case wxFS_VOL_OTHER:
06cc1fb9
JS
153 default:
154 imageId = wxFileIconsTable::drive;
155 break;
156 }
06cc1fb9 157 paths.Add(path);
006b7af2 158 names.Add(vol.GetDisplayName());
06cc1fb9 159 icon_ids.Add(imageId);
06cc1fb9 160 }
0d853c54
SN
161#elif defined(__OS2__)
162 APIRET rc;
163 ULONG ulDriveNum = 0;
164 ULONG ulDriveMap = 0;
165 rc = ::DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap);
ca65c044
WS
166 if ( rc == 0)
167 {
0d853c54
SN
168 size_t i = 0;
169 while (i < 26)
170 {
ca65c044
WS
171 if (ulDriveMap & ( 1 << i ))
172 {
35c2aa4f
VZ
173 const wxString path = wxFileName::GetVolumeString(
174 'A' + i, wxPATH_GET_SEPARATOR);
175 const wxString name = wxFileName::GetVolumeString(
176 'A' + i, wxPATH_NO_SEPARATOR);
ca65c044 177
be283c77
SN
178 // Note: If _filesys is unsupported by some compilers,
179 // we can always replace it by DosQueryFSAttach
180 char filesysname[20];
7fc65a03
WS
181#ifdef __WATCOMC__
182 ULONG cbBuffer = sizeof(filesysname);
183 PFSQBUFFER2 pfsqBuffer = (PFSQBUFFER2)filesysname;
184 APIRET rc = ::DosQueryFSAttach(name.fn_str(),0,FSAIL_QUERYNAME,pfsqBuffer,&cbBuffer);
185 if (rc != NO_ERROR)
186 {
187 filesysname[0] = '\0';
188 }
189#else
be283c77 190 _filesys(name.fn_str(), filesysname, sizeof(filesysname));
7fc65a03 191#endif
be283c77 192 /* FAT, LAN, HPFS, CDFS, NFS */
ca65c044
WS
193 int imageId;
194 if (path == wxT("A:\\") || path == wxT("B:\\"))
195 imageId = wxFileIconsTable::floppy;
be283c77
SN
196 else if (!strcmp(filesysname, "CDFS"))
197 imageId = wxFileIconsTable::cdrom;
198 else if (!strcmp(filesysname, "LAN") ||
199 !strcmp(filesysname, "NFS"))
200 imageId = wxFileIconsTable::drive;
ca65c044
WS
201 else
202 imageId = wxFileIconsTable::drive;
203 paths.Add(path);
204 names.Add(name);
205 icon_ids.Add(imageId);
206 }
0d853c54 207 i ++;
ca65c044
WS
208 }
209 }
0d853c54 210#else // !__WIN32__, !__OS2__
06cc1fb9 211 /* If we can switch to the drive, it exists. */
35c2aa4f 212 for ( char drive = 'A'; drive <= 'Z'; drive++ )
06cc1fb9 213 {
35c2aa4f
VZ
214 const wxString
215 path = wxFileName::GetVolumeString(drive, wxPATH_GET_SEPARATOR);
51a58d8b 216
06cc1fb9
JS
217 if (wxIsDriveAvailable(path))
218 {
219 paths.Add(path);
35c2aa4f
VZ
220 names.Add(wxFileName::GetVolumeString(drive, wxPATH_NO_SEPARATOR));
221 icon_ids.Add(drive <= 2 ? wxFileIconsTable::floppy
222 : wxFileIconsTable::drive);
06cc1fb9
JS
223 }
224 }
225#endif // __WIN32__/!__WIN32__
226
96f04e1d 227#elif defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON
06cc1fb9 228
a2b77260
SC
229 ItemCount volumeIndex = 1;
230 OSErr err = noErr ;
44d60c0b 231
a2b77260
SC
232 while( noErr == err )
233 {
234 HFSUniStr255 volumeName ;
235 FSRef fsRef ;
236 FSVolumeInfo volumeInfo ;
44d60c0b
WS
237 err = FSGetVolumeInfo(0, volumeIndex, NULL, kFSVolInfoFlags , &volumeInfo , &volumeName, &fsRef);
238 if( noErr == err )
239 {
240 wxString path = wxMacFSRefToPath( &fsRef ) ;
a2b77260 241 wxString name = wxMacHFSUniStrToString( &volumeName ) ;
44d60c0b 242
a2b77260 243 if ( (volumeInfo.flags & kFSVolFlagSoftwareLockedMask) || (volumeInfo.flags & kFSVolFlagHardwareLockedMask) )
06cc1fb9 244 {
a2b77260 245 icon_ids.Add(wxFileIconsTable::cdrom);
06cc1fb9 246 }
a2b77260
SC
247 else
248 {
249 icon_ids.Add(wxFileIconsTable::drive);
06cc1fb9 250 }
a2b77260 251 // todo other removable
44d60c0b 252
06cc1fb9
JS
253 paths.Add(path);
254 names.Add(name);
a2b77260 255 volumeIndex++ ;
44d60c0b 256 }
06cc1fb9 257 }
06cc1fb9 258
bd362275 259#elif defined(__UNIX__)
06cc1fb9
JS
260 paths.Add(wxT("/"));
261 names.Add(wxT("/"));
262 icon_ids.Add(wxFileIconsTable::computer);
263#else
264 #error "Unsupported platform in wxGenericDirCtrl!"
265#endif
e9890600
WS
266 wxASSERT_MSG( (paths.GetCount() == names.GetCount()), wxT("The number of paths and their human readable names should be equal in number."));
267 wxASSERT_MSG( (paths.GetCount() == icon_ids.GetCount()), wxT("Wrong number of icons for available drives."));
06cc1fb9
JS
268 return paths.GetCount();
269}
51a58d8b 270
06cc1fb9
JS
271// ----------------------------------------------------------------------------
272// wxIsDriveAvailable
273// ----------------------------------------------------------------------------
748fcded 274
748fcded 275#if defined(__DOS__)
db5333a5 276
37fd1c97 277bool wxIsDriveAvailable(const wxString& dirName)
db5333a5 278{
0e1f8ea4 279 // FIXME: this method leads to hang up under Watcom for some reason
127eab18
WS
280#ifdef __WATCOMC__
281 wxUnusedVar(dirName);
282#else
b36e08d0 283 if ( dirName.length() == 3 && dirName[1u] == wxT(':') )
db5333a5
VS
284 {
285 wxString dirNameLower(dirName.Lower());
ca65c044 286 // VS: always return true for removable media, since Win95 doesn't
db5333a5
VS
287 // like it when MS-DOS app accesses empty floppy drive
288 return (dirNameLower[0u] == wxT('a') ||
289 dirNameLower[0u] == wxT('b') ||
da865fdd 290 wxDirExists(dirNameLower));
db5333a5
VS
291 }
292 else
6157794c 293#endif
ca65c044 294 return true;
db5333a5
VS
295}
296
0d853c54 297#elif defined(__WINDOWS__) || defined(__OS2__)
db5333a5 298
0c0d1521 299int setdrive(int WXUNUSED_IN_WINCE(drive))
33ac7e6f 300{
4676948b
JS
301#ifdef __WXWINCE__
302 return 0;
303#elif defined(__GNUWIN32__) && \
c9ecda60
VS
304 (defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
305 return _chdrive(drive);
306#else
ca65c044 307 wxChar newdrive[4];
33ac7e6f 308
ca65c044
WS
309 if (drive < 1 || drive > 31)
310 return -1;
311 newdrive[0] = (wxChar)(wxT('A') + drive - 1);
312 newdrive[1] = wxT(':');
0d853c54 313#ifdef __OS2__
ca65c044
WS
314 newdrive[2] = wxT('\\');
315 newdrive[3] = wxT('\0');
0d853c54 316#else
ca65c044 317 newdrive[2] = wxT('\0');
0d853c54 318#endif
bb5a9514 319#if defined(__WINDOWS__)
ca65c044 320 if (::SetCurrentDirectory(newdrive))
50c76ce1
DW
321#else
322 // VA doesn't know what LPSTR is and has its own set
ca65c044 323 if (!DosSetCurrentDir((PSZ)newdrive))
50c76ce1 324#endif
ca65c044
WS
325 return 0;
326 else
327 return -1;
c9ecda60 328#endif // !GNUWIN32
33ac7e6f
KB
329}
330
0c0d1521 331bool wxIsDriveAvailable(const wxString& WXUNUSED_IN_WINCE(dirName))
ad9cd15c 332{
4676948b 333#ifdef __WXWINCE__
ca65c044 334 return false;
4676948b 335#else
ad9cd15c 336#ifdef __WIN32__
33fed835 337 UINT errorMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
ad9cd15c 338#endif
ca65c044 339 bool success = true;
ad9cd15c
JS
340
341 // Check if this is a root directory and if so,
2d4e4f80 342 // whether the drive is available.
b36e08d0 343 if (dirName.length() == 3 && dirName[(size_t)1] == wxT(':'))
ad9cd15c 344 {
33fed835 345 wxString dirNameLower(dirName.Lower());
b4da152e 346#if defined(__GNUWIN32__) && !(defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
da865fdd 347 success = wxDirExists(dirNameLower);
7328394a 348#else
0d853c54
SN
349 #if defined(__OS2__)
350 // Avoid changing to drive since no media may be inserted.
351 if (dirNameLower[(size_t)0] == 'a' || dirNameLower[(size_t)0] == 'b')
352 return success;
353 #endif
ad9cd15c 354 int currentDrive = _getdrive();
33fed835 355 int thisDrive = (int) (dirNameLower[(size_t)0] - 'a' + 1) ;
33ac7e6f
KB
356 int err = setdrive( thisDrive ) ;
357 setdrive( currentDrive );
ad9cd15c
JS
358
359 if (err == -1)
360 {
ca65c044 361 success = false;
ad9cd15c 362 }
7328394a 363#endif
ad9cd15c
JS
364 }
365#ifdef __WIN32__
33fed835 366 (void) SetErrorMode(errorMode);
ad9cd15c
JS
367#endif
368
33fed835 369 return success;
4676948b 370#endif
ad9cd15c 371}
0d853c54 372#endif // __WINDOWS__ || __OS2__
ad9cd15c 373
13de0c8c
WS
374#endif // wxUSE_DIRDLG || wxUSE_FILEDLG
375
376
377
378#if wxUSE_DIRDLG
b600ed13 379
57e26a09
JS
380// Function which is called by quick sort. We want to override the default wxArrayString behaviour,
381// and sort regardless of case.
a2a03d78 382static int wxCMPFUNC_CONV wxDirCtrlStringCompareFunction(const wxString& strFirst, const wxString& strSecond)
57e26a09 383{
a2a03d78 384 return strFirst.CmpNoCase(strSecond);
57e26a09
JS
385}
386
51a58d8b 387//-----------------------------------------------------------------------------
748fcded 388// wxDirItemData
51a58d8b
JS
389//-----------------------------------------------------------------------------
390
748fcded
VS
391wxDirItemData::wxDirItemData(const wxString& path, const wxString& name,
392 bool isDir)
51a58d8b
JS
393{
394 m_path = path;
395 m_name = name;
396 /* Insert logic to detect hidden files here
397 * In UnixLand we just check whether the first char is a dot
398 * For FileNameFromPath read LastDirNameInThisPath ;-) */
399 // m_isHidden = (bool)(wxFileNameFromPath(*m_path)[0] == '.');
ca65c044
WS
400 m_isHidden = false;
401 m_isExpanded = false;
51a58d8b
JS
402 m_isDir = isDir;
403}
404
748fcded 405void wxDirItemData::SetNewDirName(const wxString& path)
51a58d8b
JS
406{
407 m_path = path;
748fcded
VS
408 m_name = wxFileNameFromPath(path);
409}
410
411bool wxDirItemData::HasSubDirs() const
412{
44d60c0b 413 if (m_path.empty())
ca65c044 414 return false;
748fcded
VS
415
416 wxDir dir;
417 {
418 wxLogNull nolog;
419 if ( !dir.Open(m_path) )
ca65c044 420 return false;
748fcded
VS
421 }
422
423 return dir.HasSubDirs();
424}
425
574c939e 426bool wxDirItemData::HasFiles(const wxString& WXUNUSED(spec)) const
748fcded 427{
44d60c0b 428 if (m_path.empty())
ca65c044 429 return false;
748fcded
VS
430
431 wxDir dir;
432 {
433 wxLogNull nolog;
434 if ( !dir.Open(m_path) )
ca65c044 435 return false;
748fcded
VS
436 }
437
438 return dir.HasFiles();
51a58d8b
JS
439}
440
51a58d8b
JS
441//-----------------------------------------------------------------------------
442// wxGenericDirCtrl
443//-----------------------------------------------------------------------------
444
51a58d8b 445BEGIN_EVENT_TABLE(wxGenericDirCtrl, wxControl)
6b707fc3
JS
446 EVT_TREE_ITEM_EXPANDING (wxID_TREECTRL, wxGenericDirCtrl::OnExpandItem)
447 EVT_TREE_ITEM_COLLAPSED (wxID_TREECTRL, wxGenericDirCtrl::OnCollapseItem)
448 EVT_TREE_BEGIN_LABEL_EDIT (wxID_TREECTRL, wxGenericDirCtrl::OnBeginEditItem)
449 EVT_TREE_END_LABEL_EDIT (wxID_TREECTRL, wxGenericDirCtrl::OnEndEditItem)
84605707 450 EVT_TREE_SEL_CHANGED (wxID_TREECTRL, wxGenericDirCtrl::OnTreeSelChange)
51a58d8b
JS
451 EVT_SIZE (wxGenericDirCtrl::OnSize)
452END_EVENT_TABLE()
453
454wxGenericDirCtrl::wxGenericDirCtrl(void)
455{
456 Init();
457}
458
c06dde42
JS
459void wxGenericDirCtrl::ExpandRoot()
460{
461 ExpandDir(m_rootId); // automatically expand first level
462
463 // Expand and select the default path
464 if (!m_defaultPath.empty())
465 {
466 ExpandPath(m_defaultPath);
467 }
468#ifdef __UNIX__
469 else
470 {
471 // On Unix, there's only one node under the (hidden) root node. It
472 // represents the / path, so the user would always have to expand it;
473 // let's do it ourselves
474 ExpandPath( wxT("/") );
475 }
476#endif
477}
478
51a58d8b 479bool wxGenericDirCtrl::Create(wxWindow *parent,
c1ec7ee8 480 const wxWindowID treeid,
748fcded
VS
481 const wxString& dir,
482 const wxPoint& pos,
483 const wxSize& size,
484 long style,
485 const wxString& filter,
486 int defaultFilter,
487 const wxString& name)
51a58d8b 488{
c1ec7ee8 489 if (!wxControl::Create(parent, treeid, pos, size, style, wxDefaultValidator, name))
ca65c044 490 return false;
51a58d8b 491
db5333a5 492 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
e1957703 493 SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
51a58d8b
JS
494
495 Init();
496
3bd8a405
JS
497 long treeStyle = wxTR_HAS_BUTTONS;
498
499 // On Windows CE, if you hide the root, you get a crash when
500 // attempting to access data for children of the root item.
501#ifndef __WXWINCE__
502 treeStyle |= wxTR_HIDE_ROOT;
503#endif
2997ca30 504
82c1f2a3
RR
505#ifdef __WXGTK20__
506 treeStyle |= wxTR_NO_LINES;
507#endif
fd775aae 508
dabd1377 509 if (style & wxDIRCTRL_EDIT_LABELS)
fd775aae
JS
510 treeStyle |= wxTR_EDIT_LABELS;
511
80f624ec
VZ
512 if (style & wxDIRCTRL_MULTIPLE)
513 treeStyle |= wxTR_MULTIPLE;
514
51a58d8b
JS
515 if ((style & wxDIRCTRL_3D_INTERNAL) == 0)
516 treeStyle |= wxNO_BORDER;
517
a78955e3 518 m_treeCtrl = CreateTreeCtrl(this, wxID_TREECTRL,
c47addef 519 wxPoint(0,0), GetClientSize(), treeStyle);
51a58d8b 520
d0bc78e2
VZ
521 if (!filter.empty())
522 m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL);
51a58d8b
JS
523
524 m_defaultPath = dir;
525 m_filter = filter;
526
dd0138d9 527 if (m_filter.empty())
d0bc78e2 528 m_filter = wxFileSelectorDefaultWildcardStr;
dd0138d9 529
51a58d8b
JS
530 SetFilterIndex(defaultFilter);
531
532 if (m_filterListCtrl)
533 m_filterListCtrl->FillFilterList(filter, defaultFilter);
534
06cc1fb9 535 m_treeCtrl->SetImageList(wxTheFileIconsTable->GetSmallImageList());
51a58d8b 536
ca65c044
WS
537 m_showHidden = false;
538 wxDirItemData* rootData = new wxDirItemData(wxEmptyString, wxEmptyString, true);
51a58d8b
JS
539
540 wxString rootName;
541
0d853c54 542#if defined(__WINDOWS__) || defined(__OS2__) || defined(__DOS__)
51a58d8b
JS
543 rootName = _("Computer");
544#else
545 rootName = _("Sections");
546#endif
547
548 m_rootId = m_treeCtrl->AddRoot( rootName, 3, -1, rootData);
549 m_treeCtrl->SetItemHasChildren(m_rootId);
2997ca30 550
c06dde42 551 ExpandRoot();
51a58d8b 552
4a89f0e9 553 SetInitialSize(size);
51a58d8b
JS
554 DoResize();
555
ca65c044 556 return true;
51a58d8b
JS
557}
558
559wxGenericDirCtrl::~wxGenericDirCtrl()
560{
51a58d8b
JS
561}
562
563void wxGenericDirCtrl::Init()
564{
ca65c044 565 m_showHidden = false;
51a58d8b
JS
566 m_currentFilter = 0;
567 m_currentFilterStr = wxEmptyString; // Default: any file
568 m_treeCtrl = NULL;
569 m_filterListCtrl = NULL;
570}
571
c1ec7ee8 572wxTreeCtrl* wxGenericDirCtrl::CreateTreeCtrl(wxWindow *parent, wxWindowID treeid, const wxPoint& pos, const wxSize& size, long treeStyle)
a78955e3 573{
c1ec7ee8 574 return new wxTreeCtrl(parent, treeid, pos, size, treeStyle);
a78955e3
VS
575}
576
42dcacf0
RR
577void wxGenericDirCtrl::ShowHidden( bool show )
578{
9092371c
VZ
579 if ( m_showHidden == show )
580 return;
581
42dcacf0 582 m_showHidden = show;
574c939e 583
80f624ec
VZ
584 if ( HasFlag(wxDIRCTRL_MULTIPLE) )
585 {
586 wxArrayString paths;
587 GetPaths(paths);
588 ReCreateTree();
589 for ( unsigned n = 0; n < paths.size(); n++ )
590 {
591 ExpandPath(paths[n]);
592 }
593 }
594 else
595 {
596 wxString path = GetPath();
597 ReCreateTree();
598 SetPath(path);
599 }
42dcacf0
RR
600}
601
22328fa4
JS
602const wxTreeItemId
603wxGenericDirCtrl::AddSection(const wxString& path, const wxString& name, int imageId)
51a58d8b 604{
ca65c044 605 wxDirItemData *dir_item = new wxDirItemData(path,name,true);
51a58d8b 606
c1ec7ee8 607 wxTreeItemId treeid = AppendItem( m_rootId, name, imageId, -1, dir_item);
4f5c180e 608
c1ec7ee8 609 m_treeCtrl->SetItemHasChildren(treeid);
22328fa4 610
c1ec7ee8 611 return treeid;
06cc1fb9 612}
51a58d8b 613
06cc1fb9
JS
614void wxGenericDirCtrl::SetupSections()
615{
616 wxArrayString paths, names;
617 wxArrayInt icons;
2d4e4f80 618
06cc1fb9 619 size_t n, count = wxGetAvailableDrives(paths, names, icons);
4f5c180e 620
82c1f2a3
RR
621#ifdef __WXGTK20__
622 wxString home = wxGetHomeDir();
623 AddSection( home, _("Home directory"), 1);
624 home += wxT("/Desktop");
625 AddSection( home, _("Desktop"), 1);
626#endif
627
06cc1fb9 628 for (n = 0; n < count; n++)
06cc1fb9 629 AddSection(paths[n], names[n], icons[n]);
51a58d8b
JS
630}
631
905e0905
VZ
632void wxGenericDirCtrl::SetFocus()
633{
634 // we don't need focus ourselves, give it to the tree so that the user
635 // could navigate it
d095f867
RR
636 if (m_treeCtrl)
637 m_treeCtrl->SetFocus();
905e0905
VZ
638}
639
51a58d8b
JS
640void wxGenericDirCtrl::OnBeginEditItem(wxTreeEvent &event)
641{
642 // don't rename the main entry "Sections"
643 if (event.GetItem() == m_rootId)
644 {
645 event.Veto();
646 return;
647 }
648
649 // don't rename the individual sections
99006e44 650 if (m_treeCtrl->GetItemParent( event.GetItem() ) == m_rootId)
51a58d8b
JS
651 {
652 event.Veto();
653 return;
654 }
655}
656
657void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent &event)
658{
6e86472f
VZ
659 if (event.IsEditCancelled())
660 return;
661
44d60c0b 662 if ((event.GetLabel().empty()) ||
47b8afad
MR
663 (event.GetLabel() == wxT(".")) ||
664 (event.GetLabel() == wxT("..")) ||
06cc1fb9
JS
665 (event.GetLabel().Find(wxT('/')) != wxNOT_FOUND) ||
666 (event.GetLabel().Find(wxT('\\')) != wxNOT_FOUND) ||
667 (event.GetLabel().Find(wxT('|')) != wxNOT_FOUND))
51a58d8b
JS
668 {
669 wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR );
670 dialog.ShowModal();
671 event.Veto();
672 return;
673 }
674
c1ec7ee8 675 wxTreeItemId treeid = event.GetItem();
0d6f66f4 676 wxDirItemData *data = GetItemData( treeid );
51a58d8b
JS
677 wxASSERT( data );
678
679 wxString new_name( wxPathOnly( data->m_path ) );
ad9cd15c 680 new_name += wxString(wxFILE_SEP_PATH);
51a58d8b
JS
681 new_name += event.GetLabel();
682
683 wxLogNull log;
684
685 if (wxFileExists(new_name))
686 {
687 wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR );
688 dialog.ShowModal();
689 event.Veto();
690 }
691
692 if (wxRenameFile(data->m_path,new_name))
693 {
694 data->SetNewDirName( new_name );
695 }
696 else
697 {
698 wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
699 dialog.ShowModal();
700 event.Veto();
701 }
702}
703
84605707
VZ
704void wxGenericDirCtrl::OnTreeSelChange(wxTreeEvent &event)
705{
706 wxTreeEvent changedEvent(wxEVT_COMMAND_DIRCTRL_CHANGED, GetId());
707
708 changedEvent.SetItem(event.GetItem());
709 changedEvent.SetClientObject(m_treeCtrl->GetItemData(event.GetItem()));
710
711 GetEventHandler()->SafelyProcessEvent(changedEvent);
712 event.Skip();
713}
714
51a58d8b
JS
715void wxGenericDirCtrl::OnExpandItem(wxTreeEvent &event)
716{
717 wxTreeItemId parentId = event.GetItem();
718
748fcded
VS
719 // VS: this is needed because the event handler is called from wxTreeCtrl
720 // ctor when wxTR_HIDE_ROOT was specified
4ded51f2
CE
721
722 if (!m_rootId.IsOk())
748fcded
VS
723 m_rootId = m_treeCtrl->GetRootItem();
724
51a58d8b
JS
725 ExpandDir(parentId);
726}
727
728void wxGenericDirCtrl::OnCollapseItem(wxTreeEvent &event )
729{
08887820
VS
730 CollapseDir(event.GetItem());
731}
732
733void wxGenericDirCtrl::CollapseDir(wxTreeItemId parentId)
734{
735 wxTreeItemId child;
51a58d8b 736
0d6f66f4 737 wxDirItemData *data = GetItemData(parentId);
51a58d8b
JS
738 if (!data->m_isExpanded)
739 return;
740
ca65c044 741 data->m_isExpanded = false;
5b806097
JS
742
743 m_treeCtrl->Freeze();
c06dde42 744 if (parentId != m_treeCtrl->GetRootItem())
5b806097
JS
745 m_treeCtrl->CollapseAndReset(parentId);
746 m_treeCtrl->DeleteChildren(parentId);
747 m_treeCtrl->Thaw();
51a58d8b
JS
748}
749
ef57807f 750void wxGenericDirCtrl::PopulateNode(wxTreeItemId parentId)
51a58d8b 751{
0d6f66f4 752 wxDirItemData *data = GetItemData(parentId);
51a58d8b
JS
753
754 if (data->m_isExpanded)
755 return;
756
ca65c044 757 data->m_isExpanded = true;
51a58d8b 758
748fcded 759 if (parentId == m_treeCtrl->GetRootItem())
51a58d8b
JS
760 {
761 SetupSections();
762 return;
763 }
764
765 wxASSERT(data);
766
767 wxString search,path,filename;
768
769 wxString dirName(data->m_path);
770
3bd8a405 771#if (defined(__WINDOWS__) && !defined(__WXWINCE__)) || defined(__DOS__) || defined(__OS2__)
51a58d8b
JS
772 // Check if this is a root directory and if so,
773 // whether the drive is avaiable.
33fed835
MB
774 if (!wxIsDriveAvailable(dirName))
775 {
ca65c044 776 data->m_isExpanded = false;
7328394a
JS
777 //wxMessageBox(wxT("Sorry, this drive is not available."));
778 return;
33fed835 779 }
51a58d8b
JS
780#endif
781
782 // This may take a longish time. Go to busy cursor
783 wxBusyCursor busy;
784
0d853c54 785#if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)
51a58d8b
JS
786 if (dirName.Last() == ':')
787 dirName += wxString(wxFILE_SEP_PATH);
788#endif
789
790 wxArrayString dirs;
791 wxArrayString filenames;
792
793 wxDir d;
794 wxString eachFilename;
795
f9c165b1 796 wxLogNull log;
51a58d8b
JS
797 d.Open(dirName);
798
799 if (d.IsOpened())
800 {
42dcacf0
RR
801 int style = wxDIR_DIRS;
802 if (m_showHidden) style |= wxDIR_HIDDEN;
803 if (d.GetFirst(& eachFilename, wxEmptyString, style))
51a58d8b
JS
804 {
805 do
806 {
807 if ((eachFilename != wxT(".")) && (eachFilename != wxT("..")))
808 {
809 dirs.Add(eachFilename);
810 }
811 }
2b0a7c09 812 while (d.GetNext(&eachFilename));
51a58d8b
JS
813 }
814 }
222ed1d6 815 dirs.Sort(wxDirCtrlStringCompareFunction);
51a58d8b
JS
816
817 // Now do the filenames -- but only if we're allowed to
d9c98a9a 818 if (!HasFlag(wxDIRCTRL_DIR_ONLY))
51a58d8b
JS
819 {
820 d.Open(dirName);
ec1b28a3 821
51a58d8b
JS
822 if (d.IsOpened())
823 {
2b0a7c09
RN
824 int style = wxDIR_FILES;
825 if (m_showHidden) style |= wxDIR_HIDDEN;
3da4e4bd
JS
826 // Process each filter (ex: "JPEG Files (*.jpg;*.jpeg)|*.jpg;*.jpeg")
827 wxStringTokenizer strTok;
828 wxString curFilter;
829 strTok.SetString(m_currentFilterStr,wxT(";"));
830 while(strTok.HasMoreTokens())
51a58d8b 831 {
3da4e4bd 832 curFilter = strTok.GetNextToken();
f0e5a44d 833 if (d.GetFirst(& eachFilename, curFilter, style))
51a58d8b 834 {
3da4e4bd 835 do
51a58d8b 836 {
3da4e4bd
JS
837 if ((eachFilename != wxT(".")) && (eachFilename != wxT("..")))
838 {
839 filenames.Add(eachFilename);
840 }
51a58d8b 841 }
3da4e4bd 842 while (d.GetNext(& eachFilename));
51a58d8b 843 }
51a58d8b
JS
844 }
845 }
222ed1d6 846 filenames.Sort(wxDirCtrlStringCompareFunction);
51a58d8b
JS
847 }
848
c72fa1cd
VZ
849 // Now we really know whether we have any children so tell the tree control
850 // about it.
851 m_treeCtrl->SetItemHasChildren(parentId, !dirs.empty() || !filenames.empty());
852
51a58d8b
JS
853 // Add the sorted dirs
854 size_t i;
b4a980f4 855 for (i = 0; i < dirs.GetCount(); i++)
51a58d8b 856 {
4e115ed2 857 eachFilename = dirs[i];
51a58d8b 858 path = dirName;
083f7497 859 if (!wxEndsWithPathSeparator(path))
51a58d8b
JS
860 path += wxString(wxFILE_SEP_PATH);
861 path += eachFilename;
862
ca65c044 863 wxDirItemData *dir_item = new wxDirItemData(path,eachFilename,true);
c1ec7ee8 864 wxTreeItemId treeid = AppendItem( parentId, eachFilename,
06cc1fb9 865 wxFileIconsTable::folder, -1, dir_item);
c1ec7ee8 866 m_treeCtrl->SetItemImage( treeid, wxFileIconsTable::folder_open,
06cc1fb9 867 wxTreeItemIcon_Expanded );
ec1b28a3 868
d9c98a9a
VZ
869 // assume that it does have children by default as it can take a long
870 // time to really check for this (think remote drives...)
871 //
c72fa1cd 872 // and if we're wrong, we'll correct the icon later if
d9c98a9a 873 // the user really tries to open this item
c1ec7ee8 874 m_treeCtrl->SetItemHasChildren(treeid);
51a58d8b
JS
875 }
876
877 // Add the sorted filenames
d9c98a9a 878 if (!HasFlag(wxDIRCTRL_DIR_ONLY))
51a58d8b 879 {
b4a980f4 880 for (i = 0; i < filenames.GetCount(); i++)
51a58d8b 881 {
4e115ed2 882 eachFilename = filenames[i];
51a58d8b 883 path = dirName;
083f7497 884 if (!wxEndsWithPathSeparator(path))
51a58d8b
JS
885 path += wxString(wxFILE_SEP_PATH);
886 path += eachFilename;
887 //path = dirName + wxString(wxT("/")) + eachFilename;
ca65c044 888 wxDirItemData *dir_item = new wxDirItemData(path,eachFilename,false);
06cc1fb9
JS
889 int image_id = wxFileIconsTable::file;
890 if (eachFilename.Find(wxT('.')) != wxNOT_FOUND)
891 image_id = wxTheFileIconsTable->GetIconID(eachFilename.AfterLast(wxT('.')));
22328fa4 892 (void) AppendItem( parentId, eachFilename, image_id, -1, dir_item);
51a58d8b
JS
893 }
894 }
895}
896
ef57807f
VZ
897void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
898{
899 // ExpandDir() will not actually expand the tree node, just populate it
900 PopulateNode(parentId);
901}
902
08887820
VS
903void wxGenericDirCtrl::ReCreateTree()
904{
905 CollapseDir(m_treeCtrl->GetRootItem());
c06dde42
JS
906 ExpandRoot();
907}
908
909void wxGenericDirCtrl::CollapseTree()
910{
911 wxTreeItemIdValue cookie;
912 wxTreeItemId child = m_treeCtrl->GetFirstChild(m_rootId, cookie);
913 while (child.IsOk())
914 {
915 CollapseDir(child);
916 child = m_treeCtrl->GetNextChild(m_rootId, cookie);
917 }
08887820
VS
918}
919
51a58d8b
JS
920// Find the child that matches the first part of 'path'.
921// E.g. if a child path is "/usr" and 'path' is "/usr/include"
922// then the child for /usr is returned.
923wxTreeItemId wxGenericDirCtrl::FindChild(wxTreeItemId parentId, const wxString& path, bool& done)
924{
925 wxString path2(path);
ec1b28a3 926
51a58d8b
JS
927 // Make sure all separators are as per the current platform
928 path2.Replace(wxT("\\"), wxString(wxFILE_SEP_PATH));
929 path2.Replace(wxT("/"), wxString(wxFILE_SEP_PATH));
ec1b28a3 930
51a58d8b
JS
931 // Append a separator to foil bogus substring matching
932 path2 += wxString(wxFILE_SEP_PATH);
ec1b28a3
DW
933
934 // In MSW or PM, case is not significant
0d853c54 935#if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)
51a58d8b
JS
936 path2.MakeLower();
937#endif
ec1b28a3 938
2d75caaa 939 wxTreeItemIdValue cookie;
51a58d8b 940 wxTreeItemId childId = m_treeCtrl->GetFirstChild(parentId, cookie);
53ccf1c0 941 while (childId.IsOk())
51a58d8b 942 {
0d6f66f4 943 wxDirItemData* data = GetItemData(childId);
ec1b28a3 944
44d60c0b 945 if (data && !data->m_path.empty())
51a58d8b
JS
946 {
947 wxString childPath(data->m_path);
083f7497 948 if (!wxEndsWithPathSeparator(childPath))
51a58d8b 949 childPath += wxString(wxFILE_SEP_PATH);
ec1b28a3
DW
950
951 // In MSW and PM, case is not significant
0d853c54 952#if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)
51a58d8b
JS
953 childPath.MakeLower();
954#endif
ec1b28a3 955
b36e08d0 956 if (childPath.length() <= path2.length())
51a58d8b 957 {
b36e08d0 958 wxString path3 = path2.Mid(0, childPath.length());
51a58d8b
JS
959 if (childPath == path3)
960 {
b36e08d0 961 if (path3.length() == path2.length())
ca65c044 962 done = true;
51a58d8b 963 else
ca65c044 964 done = false;
51a58d8b
JS
965 return childId;
966 }
967 }
968 }
ec1b28a3 969
748fcded 970 childId = m_treeCtrl->GetNextChild(parentId, cookie);
51a58d8b 971 }
3fa4bd0e
VS
972 wxTreeItemId invalid;
973 return invalid;
51a58d8b
JS
974}
975
976// Try to expand as much of the given path as possible,
977// and select the given tree item.
978bool wxGenericDirCtrl::ExpandPath(const wxString& path)
979{
ca65c044 980 bool done = false;
c1ec7ee8
SC
981 wxTreeItemId treeid = FindChild(m_rootId, path, done);
982 wxTreeItemId lastId = treeid; // The last non-zero treeid
983 while (treeid.IsOk() && !done)
51a58d8b 984 {
c1ec7ee8 985 ExpandDir(treeid);
51a58d8b 986
c1ec7ee8
SC
987 treeid = FindChild(treeid, path, done);
988 if (treeid.IsOk())
989 lastId = treeid;
51a58d8b 990 }
4e115ed2
VZ
991 if (!lastId.IsOk())
992 return false;
993
0d6f66f4 994 wxDirItemData *data = GetItemData(lastId);
4e115ed2 995 if (data->m_isDir)
51a58d8b 996 {
4e115ed2
VZ
997 m_treeCtrl->Expand(lastId);
998 }
d9c98a9a 999 if (HasFlag(wxDIRCTRL_SELECT_FIRST) && data->m_isDir)
4e115ed2
VZ
1000 {
1001 // Find the first file in this directory
1002 wxTreeItemIdValue cookie;
1003 wxTreeItemId childId = m_treeCtrl->GetFirstChild(lastId, cookie);
1004 bool selectedChild = false;
1005 while (childId.IsOk())
51a58d8b 1006 {
0d6f66f4 1007 data = GetItemData(childId);
ec1b28a3 1008
4e115ed2 1009 if (data && data->m_path != wxEmptyString && !data->m_isDir)
51a58d8b 1010 {
4e115ed2
VZ
1011 m_treeCtrl->SelectItem(childId);
1012 m_treeCtrl->EnsureVisible(childId);
1013 selectedChild = true;
1014 break;
51a58d8b 1015 }
4e115ed2 1016 childId = m_treeCtrl->GetNextChild(lastId, cookie);
51a58d8b 1017 }
4e115ed2 1018 if (!selectedChild)
51a58d8b
JS
1019 {
1020 m_treeCtrl->SelectItem(lastId);
1021 m_treeCtrl->EnsureVisible(lastId);
1022 }
51a58d8b
JS
1023 }
1024 else
4e115ed2
VZ
1025 {
1026 m_treeCtrl->SelectItem(lastId);
1027 m_treeCtrl->EnsureVisible(lastId);
1028 }
1029
1030 return true;
51a58d8b
JS
1031}
1032
f395a825
VZ
1033
1034bool wxGenericDirCtrl::CollapsePath(const wxString& path)
1035{
1036 bool done = false;
c1ec7ee8
SC
1037 wxTreeItemId treeid = FindChild(m_rootId, path, done);
1038 wxTreeItemId lastId = treeid; // The last non-zero treeid
f395a825 1039
c1ec7ee8 1040 while ( treeid.IsOk() && !done )
f395a825 1041 {
c1ec7ee8 1042 CollapseDir(treeid);
f395a825 1043
c1ec7ee8 1044 treeid = FindChild(treeid, path, done);
f395a825 1045
c1ec7ee8
SC
1046 if ( treeid.IsOk() )
1047 lastId = treeid;
f395a825
VZ
1048 }
1049
1050 if ( !lastId.IsOk() )
1051 return false;
1052
1053 m_treeCtrl->SelectItem(lastId);
1054 m_treeCtrl->EnsureVisible(lastId);
1055
1056 return true;
1057}
1058
0d6f66f4
VZ
1059wxDirItemData* wxGenericDirCtrl::GetItemData(wxTreeItemId itemId)
1060{
1061 return static_cast<wxDirItemData*>(m_treeCtrl->GetItemData(itemId));
1062}
1063
e3f084fd
VZ
1064wxString wxGenericDirCtrl::GetPath(wxTreeItemId itemId) const
1065{
1066 const wxDirItemData*
1067 data = static_cast<wxDirItemData*>(m_treeCtrl->GetItemData(itemId));
1068
1069 return data->m_path;
1070}
f395a825 1071
51a58d8b
JS
1072wxString wxGenericDirCtrl::GetPath() const
1073{
2dd62dc0
RR
1074 // Allow calling GetPath() in multiple selection from OnSelFilter
1075 if (m_treeCtrl->HasFlag(wxTR_MULTIPLE))
1076 {
1077 wxArrayTreeItemIds items;
1078 m_treeCtrl->GetSelections(items);
1079 if (items.size() > 0)
1080 {
1081 // return first string only
c1ec7ee8 1082 wxTreeItemId treeid = items[0];
e3f084fd 1083 return GetPath(treeid);
2dd62dc0 1084 }
ce00f59b 1085
2dd62dc0
RR
1086 return wxEmptyString;
1087 }
1088
c1ec7ee8
SC
1089 wxTreeItemId treeid = m_treeCtrl->GetSelection();
1090 if (treeid)
51a58d8b 1091 {
e3f084fd 1092 return GetPath(treeid);
51a58d8b
JS
1093 }
1094 else
1095 return wxEmptyString;
1096}
1097
80f624ec
VZ
1098void wxGenericDirCtrl::GetPaths(wxArrayString& paths) const
1099{
1100 paths.clear();
1101
1102 wxArrayTreeItemIds items;
1103 m_treeCtrl->GetSelections(items);
1104 for ( unsigned n = 0; n < items.size(); n++ )
1105 {
c1ec7ee8 1106 wxTreeItemId treeid = items[n];
e3f084fd 1107 paths.push_back(GetPath(treeid));
80f624ec
VZ
1108 }
1109}
1110
51a58d8b
JS
1111wxString wxGenericDirCtrl::GetFilePath() const
1112{
c1ec7ee8
SC
1113 wxTreeItemId treeid = m_treeCtrl->GetSelection();
1114 if (treeid)
51a58d8b 1115 {
c1ec7ee8 1116 wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(treeid);
51a58d8b
JS
1117 if (data->m_isDir)
1118 return wxEmptyString;
1119 else
1120 return data->m_path;
1121 }
1122 else
1123 return wxEmptyString;
1124}
1125
80f624ec
VZ
1126void wxGenericDirCtrl::GetFilePaths(wxArrayString& paths) const
1127{
1128 paths.clear();
1129
1130 wxArrayTreeItemIds items;
1131 m_treeCtrl->GetSelections(items);
1132 for ( unsigned n = 0; n < items.size(); n++ )
1133 {
c1ec7ee8
SC
1134 wxTreeItemId treeid = items[n];
1135 wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(treeid);
80f624ec
VZ
1136 if ( !data->m_isDir )
1137 paths.Add(data->m_path);
1138 }
1139}
1140
51a58d8b
JS
1141void wxGenericDirCtrl::SetPath(const wxString& path)
1142{
1143 m_defaultPath = path;
1144 if (m_rootId)
1145 ExpandPath(path);
1146}
1147
80f624ec
VZ
1148void wxGenericDirCtrl::SelectPath(const wxString& path, bool select)
1149{
1150 bool done = false;
c1ec7ee8
SC
1151 wxTreeItemId treeid = FindChild(m_rootId, path, done);
1152 wxTreeItemId lastId = treeid; // The last non-zero treeid
1153 while ( treeid.IsOk() && !done )
80f624ec 1154 {
c1ec7ee8
SC
1155 treeid = FindChild(treeid, path, done);
1156 if ( treeid.IsOk() )
1157 lastId = treeid;
80f624ec
VZ
1158 }
1159 if ( !lastId.IsOk() )
1160 return;
1161
1162 if ( done )
1163 {
c1ec7ee8 1164 m_treeCtrl->SelectItem(treeid, select);
80f624ec
VZ
1165 }
1166}
1167
1168void wxGenericDirCtrl::SelectPaths(const wxArrayString& paths)
1169{
1170 if ( HasFlag(wxDIRCTRL_MULTIPLE) )
1171 {
1172 UnselectAll();
1173 for ( unsigned n = 0; n < paths.size(); n++ )
1174 {
1175 SelectPath(paths[n]);
1176 }
1177 }
1178}
1179
1180void wxGenericDirCtrl::UnselectAll()
1181{
1182 m_treeCtrl->UnselectAll();
1183}
1184
51a58d8b
JS
1185// Not used
1186#if 0
c1ec7ee8 1187void wxGenericDirCtrl::FindChildFiles(wxTreeItemId treeid, int dirFlags, wxArrayString& filenames)
51a58d8b 1188{
c1ec7ee8 1189 wxDirItemData *data = (wxDirItemData *) m_treeCtrl->GetItemData(treeid);
51a58d8b
JS
1190
1191 // This may take a longish time. Go to busy cursor
1192 wxBusyCursor busy;
1193
1194 wxASSERT(data);
1195
1196 wxString search,path,filename;
1197
1198 wxString dirName(data->m_path);
1199
bb5a9514 1200#if defined(__WINDOWS__) || defined(__OS2__)
51a58d8b
JS
1201 if (dirName.Last() == ':')
1202 dirName += wxString(wxFILE_SEP_PATH);
1203#endif
1204
1205 wxDir d;
1206 wxString eachFilename;
1207
f9c165b1 1208 wxLogNull log;
51a58d8b
JS
1209 d.Open(dirName);
1210
1211 if (d.IsOpened())
1212 {
1213 if (d.GetFirst(& eachFilename, m_currentFilterStr, dirFlags))
1214 {
1215 do
1216 {
1217 if ((eachFilename != wxT(".")) && (eachFilename != wxT("..")))
1218 {
1219 filenames.Add(eachFilename);
1220 }
1221 }
1222 while (d.GetNext(& eachFilename)) ;
1223 }
1224 }
1225}
1226#endif
1227
1228void wxGenericDirCtrl::SetFilterIndex(int n)
1229{
1230 m_currentFilter = n;
1231
1232 wxString f, d;
1233 if (ExtractWildcard(m_filter, n, f, d))
1234 m_currentFilterStr = f;
1235 else
dd0138d9
RR
1236#ifdef __UNIX__
1237 m_currentFilterStr = wxT("*");
1238#else
51a58d8b 1239 m_currentFilterStr = wxT("*.*");
dd0138d9 1240#endif
51a58d8b
JS
1241}
1242
1243void wxGenericDirCtrl::SetFilter(const wxString& filter)
1244{
1245 m_filter = filter;
1246
d0bc78e2
VZ
1247 if (!filter.empty() && !m_filterListCtrl)
1248 m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL);
1249 else if (filter.empty() && m_filterListCtrl)
1250 {
1251 m_filterListCtrl->Destroy();
1252 m_filterListCtrl = NULL;
1253 }
1254
51a58d8b
JS
1255 wxString f, d;
1256 if (ExtractWildcard(m_filter, m_currentFilter, f, d))
1257 m_currentFilterStr = f;
1258 else
dd0138d9
RR
1259#ifdef __UNIX__
1260 m_currentFilterStr = wxT("*");
1261#else
51a58d8b 1262 m_currentFilterStr = wxT("*.*");
dd0138d9 1263#endif
d0bc78e2
VZ
1264 // current filter index is meaningless after filter change, set it to zero
1265 SetFilterIndex(0);
1266 if (m_filterListCtrl)
1267 m_filterListCtrl->FillFilterList(m_filter, 0);
51a58d8b
JS
1268}
1269
1270// Extract description and actual filter from overall filter string
1271bool wxGenericDirCtrl::ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description)
1272{
1273 wxArrayString filters, descriptions;
daf32463 1274 int count = wxParseCommonDialogsFilter(filterStr, descriptions, filters);
51a58d8b
JS
1275 if (count > 0 && n < count)
1276 {
1277 filter = filters[n];
1278 description = descriptions[n];
ca65c044 1279 return true;
51a58d8b 1280 }
5716a1ab 1281
ca65c044 1282 return false;
51a58d8b
JS
1283}
1284
51a58d8b
JS
1285
1286void wxGenericDirCtrl::DoResize()
1287{
1288 wxSize sz = GetClientSize();
1289 int verticalSpacing = 3;
1290 if (m_treeCtrl)
1291 {
1292 wxSize filterSz ;
1293 if (m_filterListCtrl)
1294 {
1295 filterSz = m_filterListCtrl->GetSize();
1296 sz.y -= (filterSz.y + verticalSpacing);
1297 }
1298 m_treeCtrl->SetSize(0, 0, sz.x, sz.y);
1299 if (m_filterListCtrl)
1300 {
1301 m_filterListCtrl->SetSize(0, sz.y + verticalSpacing, sz.x, filterSz.y);
1302 // Don't know why, but this needs refreshing after a resize (wxMSW)
1303 m_filterListCtrl->Refresh();
1304 }
1305 }
1306}
1307
1308
33ac7e6f 1309void wxGenericDirCtrl::OnSize(wxSizeEvent& WXUNUSED(event))
51a58d8b
JS
1310{
1311 DoResize();
1312}
1313
22328fa4 1314wxTreeItemId wxGenericDirCtrl::AppendItem (const wxTreeItemId & parent,
ca65c044
WS
1315 const wxString & text,
1316 int image, int selectedImage,
1317 wxTreeItemData * data)
22328fa4
JS
1318{
1319 wxTreeCtrl *treeCtrl = GetTreeCtrl ();
1320
1321 wxASSERT (treeCtrl);
1322
1323 if (treeCtrl)
1324 {
1325 return treeCtrl->AppendItem (parent, text, image, selectedImage, data);
1326 }
1327 else
1328 {
1329 return wxTreeItemId();
1330 }
1331}
1332
1333
51a58d8b
JS
1334//-----------------------------------------------------------------------------
1335// wxDirFilterListCtrl
1336//-----------------------------------------------------------------------------
1337
1338IMPLEMENT_CLASS(wxDirFilterListCtrl, wxChoice)
1339
1340BEGIN_EVENT_TABLE(wxDirFilterListCtrl, wxChoice)
ca65c044 1341 EVT_CHOICE(wxID_ANY, wxDirFilterListCtrl::OnSelFilter)
51a58d8b
JS
1342END_EVENT_TABLE()
1343
d0bc78e2 1344bool wxDirFilterListCtrl::Create(wxGenericDirCtrl* parent,
c1ec7ee8 1345 const wxWindowID treeid,
d0bc78e2
VZ
1346 const wxPoint& pos,
1347 const wxSize& size,
1348 long style)
51a58d8b
JS
1349{
1350 m_dirCtrl = parent;
d0bc78e2
VZ
1351
1352 // by default our border style is determined by the style of our parent
1353 if ( !(style & wxBORDER_MASK) )
1354 {
1355 style |= parent->HasFlag(wxDIRCTRL_3D_INTERNAL) ? wxBORDER_SUNKEN
1356 : wxBORDER_NONE;
1357 }
1358
c1ec7ee8 1359 return wxChoice::Create(parent, treeid, pos, size, 0, NULL, style);
51a58d8b
JS
1360}
1361
1362void wxDirFilterListCtrl::Init()
1363{
1364 m_dirCtrl = NULL;
1365}
1366
33ac7e6f 1367void wxDirFilterListCtrl::OnSelFilter(wxCommandEvent& WXUNUSED(event))
51a58d8b
JS
1368{
1369 int sel = GetSelection();
1370
9e48865c
SL
1371 if (m_dirCtrl->HasFlag(wxDIRCTRL_MULTIPLE))
1372 {
1373 wxArrayString paths;
1374 m_dirCtrl->GetPaths(paths);
1375
1376 m_dirCtrl->SetFilterIndex(sel);
ec1b28a3 1377
9e48865c
SL
1378 // If the filter has changed, the view is out of date, so
1379 // collapse the tree.
1380 m_dirCtrl->ReCreateTree();
1381
1382 // Expand and select the previously selected paths
1383 for (unsigned int i = 0; i < paths.GetCount(); i++)
1384 {
1385 m_dirCtrl->ExpandPath(paths.Item(i));
1386 }
1387 }
1388 else
1389 {
1390 wxString currentPath = m_dirCtrl->GetPath();
51a58d8b 1391
9e48865c
SL
1392 m_dirCtrl->SetFilterIndex(sel);
1393 m_dirCtrl->ReCreateTree();
51a58d8b 1394
9e48865c
SL
1395 // Try to restore the selection, or at least the directory
1396 m_dirCtrl->ExpandPath(currentPath);
1397 }
51a58d8b
JS
1398}
1399
1400void wxDirFilterListCtrl::FillFilterList(const wxString& filter, int defaultFilter)
1401{
1402 Clear();
1403 wxArrayString descriptions, filters;
866918a8 1404 size_t n = (size_t) wxParseCommonDialogsFilter(filter, descriptions, filters);
51a58d8b
JS
1405
1406 if (n > 0 && defaultFilter < (int) n)
1407 {
999836aa 1408 for (size_t i = 0; i < n; i++)
51a58d8b
JS
1409 Append(descriptions[i]);
1410 SetSelection(defaultFilter);
1411 }
1412}
13de0c8c 1413#endif // wxUSE_DIRDLG
51a58d8b 1414
13de0c8c 1415#if wxUSE_DIRDLG || wxUSE_FILEDLG
22328fa4 1416
06cc1fb9
JS
1417// ----------------------------------------------------------------------------
1418// wxFileIconsTable icons
1419// ----------------------------------------------------------------------------
1420
ff654490 1421#ifndef __WXGTK20__
13b22a67 1422/* Computer (c) Julian Smart */
a243da29 1423static const char* const file_icons_tbl_computer_xpm[] = {
13b22a67
JS
1424/* columns rows colors chars-per-pixel */
1425"16 16 42 1",
1426"r c #4E7FD0",
1427"$ c #7198D9",
1428"; c #DCE6F6",
1429"q c #FFFFFF",
1430"u c #4A7CCE",
1431"# c #779DDB",
1432"w c #95B2E3",
1433"y c #7FA2DD",
1434"f c #3263B4",
1435"= c #EAF0FA",
1436"< c #B1C7EB",
1437"% c #6992D7",
1438"9 c #D9E4F5",
1439"o c #9BB7E5",
1440"6 c #F7F9FD",
1441", c #BED0EE",
1442"3 c #F0F5FC",
1443"1 c #A8C0E8",
1444" c None",
1445"0 c #FDFEFF",
1446"4 c #C4D5F0",
1447"@ c #81A4DD",
1448"e c #4377CD",
1449"- c #E2EAF8",
1450"i c #9FB9E5",
1451"> c #CCDAF2",
1452"+ c #89A9DF",
1453"s c #5584D1",
1454"t c #5D89D3",
1455": c #D2DFF4",
1456"5 c #FAFCFE",
1457"2 c #F5F8FD",
1458"8 c #DFE8F7",
1459"& c #5E8AD4",
1460"X c #638ED5",
1461"a c #CEDCF2",
1462"p c #90AFE2",
1463"d c #2F5DA9",
1464"* c #5282D0",
1465"7 c #E5EDF9",
1466". c #A2BCE6",
1467"O c #8CACE0",
1468/* pixels */
1469" ",
1470" .XXXXXXXXXXX ",
1471" oXO++@#$%&*X ",
1472" oX=-;:>,<1%X ",
1473" oX23=-;:4,$X ",
1474" oX5633789:@X ",
1475" oX05623=78+X ",
1476" oXqq05623=OX ",
1477" oX,,,,,<<<$X ",
1478" wXXXXXXXXXXe ",
1479" XrtX%$$y@+O,, ",
1480" uyiiiiiiiii@< ",
1481" ouiiiiiiiiiip<a",
1482" rustX%$$y@+Ow,,",
1483" dfffffffffffffd",
1484" "
1485};
ff654490 1486#endif // !GTK+ 2
06cc1fb9 1487
06cc1fb9
JS
1488// ----------------------------------------------------------------------------
1489// wxFileIconsTable & friends
1490// ----------------------------------------------------------------------------
1491
1492// global instance of a wxFileIconsTable
d3b9f782 1493wxFileIconsTable* wxTheFileIconsTable = NULL;
06cc1fb9
JS
1494
1495// A module to allow icons table cleanup
1496
1497class wxFileIconsTableModule: public wxModule
1498{
1499DECLARE_DYNAMIC_CLASS(wxFileIconsTableModule)
1500public:
1501 wxFileIconsTableModule() {}
ca65c044 1502 bool OnInit() { wxTheFileIconsTable = new wxFileIconsTable; return true; }
06cc1fb9
JS
1503 void OnExit()
1504 {
5276b0a5 1505 wxDELETE(wxTheFileIconsTable);
06cc1fb9
JS
1506 }
1507};
1508
1509IMPLEMENT_DYNAMIC_CLASS(wxFileIconsTableModule, wxModule)
1510
1511class wxFileIconEntry : public wxObject
1512{
1513public:
c1ec7ee8 1514 wxFileIconEntry(int i) { iconid = i; }
06cc1fb9 1515
c1ec7ee8 1516 int iconid;
06cc1fb9
JS
1517};
1518
1519wxFileIconsTable::wxFileIconsTable()
1520{
1521 m_HashTable = NULL;
1522 m_smallImageList = NULL;
1523}
1524
1525wxFileIconsTable::~wxFileIconsTable()
1526{
222ed1d6
MB
1527 if (m_HashTable)
1528 {
1529 WX_CLEAR_HASH_TABLE(*m_HashTable);
1530 delete m_HashTable;
1531 }
06cc1fb9
JS
1532 if (m_smallImageList) delete m_smallImageList;
1533}
1534
1535// delayed initialization - wait until first use (wxArtProv not created yet)
1536void wxFileIconsTable::Create()
1537{
1538 wxCHECK_RET(!m_smallImageList && !m_HashTable, wxT("creating icons twice"));
06cc1fb9
JS
1539 m_HashTable = new wxHashTable(wxKEY_STRING);
1540 m_smallImageList = new wxImageList(16, 16);
1541
06cc1fb9 1542 // folder:
4b92a33f
VS
1543 m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_FOLDER,
1544 wxART_CMN_DIALOG,
1545 wxSize(16, 16)));
06cc1fb9 1546 // folder_open
82c1f2a3
RR
1547 m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_FOLDER_OPEN,
1548 wxART_CMN_DIALOG,
1549 wxSize(16, 16)));
06cc1fb9 1550 // computer
ff654490 1551#ifdef __WXGTK20__
82c1f2a3
RR
1552 // GTK24 uses this icon in the file open dialog
1553 m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_HARDDISK,
1554 wxART_CMN_DIALOG,
1555 wxSize(16, 16)));
1556#else
06cc1fb9 1557 m_smallImageList->Add(wxIcon(file_icons_tbl_computer_xpm));
82c1f2a3 1558#endif
06cc1fb9 1559 // drive
82c1f2a3
RR
1560 m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_HARDDISK,
1561 wxART_CMN_DIALOG,
1562 wxSize(16, 16)));
06cc1fb9 1563 // cdrom
82c1f2a3
RR
1564 m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_CDROM,
1565 wxART_CMN_DIALOG,
1566 wxSize(16, 16)));
06cc1fb9 1567 // floppy
82c1f2a3
RR
1568 m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_FLOPPY,
1569 wxART_CMN_DIALOG,
1570 wxSize(16, 16)));
06cc1fb9 1571 // removeable
82c1f2a3
RR
1572 m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_REMOVABLE,
1573 wxART_CMN_DIALOG,
1574 wxSize(16, 16)));
06cc1fb9 1575 // file
4b92a33f
VS
1576 m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_NORMAL_FILE,
1577 wxART_CMN_DIALOG,
1578 wxSize(16, 16)));
06cc1fb9 1579 // executable
9a83f860 1580 if (GetIconID(wxEmptyString, wxT("application/x-executable")) == file)
06cc1fb9 1581 {
4b92a33f
VS
1582 m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_EXECUTABLE_FILE,
1583 wxART_CMN_DIALOG,
1584 wxSize(16, 16)));
9a83f860
VZ
1585 delete m_HashTable->Get(wxT("exe"));
1586 m_HashTable->Delete(wxT("exe"));
1587 m_HashTable->Put(wxT("exe"), new wxFileIconEntry(executable));
06cc1fb9
JS
1588 }
1589 /* else put into list by GetIconID
1590 (KDE defines application/x-executable for *.exe and has nice icon)
1591 */
1592}
1593
1594wxImageList *wxFileIconsTable::GetSmallImageList()
1595{
1596 if (!m_smallImageList)
1597 Create();
1598
1599 return m_smallImageList;
1600}
1601
bb5a9514 1602#if wxUSE_MIMETYPE && wxUSE_IMAGE && (!defined(__WINDOWS__) || wxUSE_WXDIB)
06cc1fb9
JS
1603// VS: we don't need this function w/o wxMimeTypesManager because we'll only have
1604// one icon and we won't resize it
1605
1606static wxBitmap CreateAntialiasedBitmap(const wxImage& img)
1607{
1d529ef7 1608 const unsigned int size = 16;
ca65c044 1609
1d529ef7 1610 wxImage smallimg (size, size);
06cc1fb9
JS
1611 unsigned char *p1, *p2, *ps;
1612 unsigned char mr = img.GetMaskRed(),
1613 mg = img.GetMaskGreen(),
1614 mb = img.GetMaskBlue();
1615
1616 unsigned x, y;
1617 unsigned sr, sg, sb, smask;
1618
1d529ef7 1619 p1 = img.GetData(), p2 = img.GetData() + 3 * size*2, ps = smallimg.GetData();
06cc1fb9
JS
1620 smallimg.SetMaskColour(mr, mr, mr);
1621
1d529ef7 1622 for (y = 0; y < size; y++)
06cc1fb9 1623 {
1d529ef7 1624 for (x = 0; x < size; x++)
06cc1fb9
JS
1625 {
1626 sr = sg = sb = smask = 0;
1627 if (p1[0] != mr || p1[1] != mg || p1[2] != mb)
1628 sr += p1[0], sg += p1[1], sb += p1[2];
1629 else smask++;
1630 p1 += 3;
1631 if (p1[0] != mr || p1[1] != mg || p1[2] != mb)
1632 sr += p1[0], sg += p1[1], sb += p1[2];
1633 else smask++;
1634 p1 += 3;
1635 if (p2[0] != mr || p2[1] != mg || p2[2] != mb)
1636 sr += p2[0], sg += p2[1], sb += p2[2];
1637 else smask++;
1638 p2 += 3;
1639 if (p2[0] != mr || p2[1] != mg || p2[2] != mb)
1640 sr += p2[0], sg += p2[1], sb += p2[2];
1641 else smask++;
1642 p2 += 3;
1643
1644 if (smask > 2)
1645 ps[0] = ps[1] = ps[2] = mr;
1646 else
8253f2e0
WS
1647 {
1648 ps[0] = (unsigned char)(sr >> 2);
1649 ps[1] = (unsigned char)(sg >> 2);
1650 ps[2] = (unsigned char)(sb >> 2);
1651 }
06cc1fb9
JS
1652 ps += 3;
1653 }
1d529ef7 1654 p1 += size*2 * 3, p2 += size*2 * 3;
06cc1fb9 1655 }
ca65c044 1656
06cc1fb9
JS
1657 return wxBitmap(smallimg);
1658}
1659
b126fe3a
DS
1660// This function is currently not unused anymore
1661#if 0
06cc1fb9
JS
1662// finds empty borders and return non-empty area of image:
1663static wxImage CutEmptyBorders(const wxImage& img)
1664{
1665 unsigned char mr = img.GetMaskRed(),
1666 mg = img.GetMaskGreen(),
1667 mb = img.GetMaskBlue();
1668 unsigned char *dt = img.GetData(), *dttmp;
1669 unsigned w = img.GetWidth(), h = img.GetHeight();
1670
1671 unsigned top, bottom, left, right, i;
1672 bool empt;
1673
1674#define MK_DTTMP(x,y) dttmp = dt + ((x + y * w) * 3)
ca65c044 1675#define NOEMPTY_PIX(empt) if (dttmp[0] != mr || dttmp[1] != mg || dttmp[2] != mb) {empt = false; break;}
06cc1fb9 1676
ca65c044 1677 for (empt = true, top = 0; empt && top < h; top++)
06cc1fb9
JS
1678 {
1679 MK_DTTMP(0, top);
1680 for (i = 0; i < w; i++, dttmp+=3)
1681 NOEMPTY_PIX(empt)
1682 }
ca65c044 1683 for (empt = true, bottom = h-1; empt && bottom > top; bottom--)
06cc1fb9
JS
1684 {
1685 MK_DTTMP(0, bottom);
1686 for (i = 0; i < w; i++, dttmp+=3)
1687 NOEMPTY_PIX(empt)
1688 }
ca65c044 1689 for (empt = true, left = 0; empt && left < w; left++)
06cc1fb9
JS
1690 {
1691 MK_DTTMP(left, 0);
1692 for (i = 0; i < h; i++, dttmp+=3*w)
1693 NOEMPTY_PIX(empt)
1694 }
ca65c044 1695 for (empt = true, right = w-1; empt && right > left; right--)
06cc1fb9
JS
1696 {
1697 MK_DTTMP(right, 0);
1698 for (i = 0; i < h; i++, dttmp+=3*w)
1699 NOEMPTY_PIX(empt)
1700 }
1701 top--, left--, bottom++, right++;
1702
1703 return img.GetSubImage(wxRect(left, top, right - left + 1, bottom - top + 1));
1704}
b126fe3a
DS
1705#endif // #if 0
1706
06cc1fb9
JS
1707#endif // wxUSE_MIMETYPE
1708
1709int wxFileIconsTable::GetIconID(const wxString& extension, const wxString& mime)
1710{
1711 if (!m_smallImageList)
1712 Create();
1713
1714#if wxUSE_MIMETYPE
44d60c0b 1715 if (!extension.empty())
06cc1fb9
JS
1716 {
1717 wxFileIconEntry *entry = (wxFileIconEntry*) m_HashTable->Get(extension);
c1ec7ee8 1718 if (entry) return (entry -> iconid);
06cc1fb9
JS
1719 }
1720
44d60c0b 1721 wxFileType *ft = (mime.empty()) ?
06cc1fb9
JS
1722 wxTheMimeTypesManager -> GetFileTypeFromExtension(extension) :
1723 wxTheMimeTypesManager -> GetFileTypeFromMimeType(mime);
55d0aaa3
VZ
1724
1725 wxIconLocation iconLoc;
06cc1fb9 1726 wxIcon ic;
02dd0487 1727
55d0aaa3 1728 {
02dd0487
JS
1729 wxLogNull logNull;
1730 if ( ft && ft->GetIcon(&iconLoc) )
1731 {
8e5c6521 1732 ic = wxIcon( iconLoc );
02dd0487 1733 }
55d0aaa3 1734 }
ca65c044 1735
55d0aaa3
VZ
1736 delete ft;
1737
a1b806b9 1738 if ( !ic.IsOk() )
06cc1fb9
JS
1739 {
1740 int newid = file;
1741 m_HashTable->Put(extension, new wxFileIconEntry(newid));
1742 return newid;
1743 }
1744
3fc93ebd
JS
1745 wxBitmap bmp;
1746 bmp.CopyFromIcon(ic);
06cc1fb9 1747
a1b806b9 1748 if ( !bmp.IsOk() )
b6668c25
JS
1749 {
1750 int newid = file;
1751 m_HashTable->Put(extension, new wxFileIconEntry(newid));
1752 return newid;
1753 }
1754
1d529ef7 1755 const unsigned int size = 16;
ca65c044 1756
c1ec7ee8 1757 int treeid = m_smallImageList->GetImageCount();
1aa81b17 1758 if ((bmp.GetWidth() == (int) size) && (bmp.GetHeight() == (int) size))
1d529ef7 1759 {
3fc93ebd 1760 m_smallImageList->Add(bmp);
1d529ef7 1761 }
bb5a9514 1762#if wxUSE_IMAGE && (!defined(__WINDOWS__) || wxUSE_WXDIB)
06cc1fb9
JS
1763 else
1764 {
3fc93ebd
JS
1765 wxImage img = bmp.ConvertToImage();
1766
1d529ef7
RR
1767 if ((img.GetWidth() != size*2) || (img.GetHeight() != size*2))
1768// m_smallImageList->Add(CreateAntialiasedBitmap(CutEmptyBorders(img).Rescale(size*2, size*2)));
1769 m_smallImageList->Add(CreateAntialiasedBitmap(img.Rescale(size*2, size*2)));
06cc1fb9
JS
1770 else
1771 m_smallImageList->Add(CreateAntialiasedBitmap(img));
1772 }
1904aa72
DS
1773#endif // wxUSE_IMAGE
1774
c1ec7ee8
SC
1775 m_HashTable->Put(extension, new wxFileIconEntry(treeid));
1776 return treeid;
06cc1fb9
JS
1777
1778#else // !wxUSE_MIMETYPE
1779
79e162f5 1780 wxUnusedVar(mime);
06cc1fb9
JS
1781 if (extension == wxT("exe"))
1782 return executable;
1783 else
1784 return file;
1785#endif // wxUSE_MIMETYPE/!wxUSE_MIMETYPE
1786}
1787
13de0c8c 1788#endif // wxUSE_DIRDLG || wxUSE_FILEDLG