1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/dirctrlg.cpp
3 // Purpose: wxGenericDirCtrl
4 // Author: Harm van der Heijden, Robert Roebling, Julian Smart
8 // Copyright: (c) Harm van der Heijden, Robert Roebling and Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxUSE_DIRDLG || wxUSE_FILEDLG
21 #include "wx/generic/dirctrlg.h"
28 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
32 #include "wx/cmndata.h"
33 #include "wx/choice.h"
34 #include "wx/textctrl.h"
35 #include "wx/layout.h"
37 #include "wx/textdlg.h"
38 #include "wx/gdicmn.h"
40 #include "wx/module.h"
43 #include "wx/filename.h"
44 #include "wx/filefn.h"
45 #include "wx/imaglist.h"
46 #include "wx/tokenzr.h"
48 #include "wx/artprov.h"
49 #include "wx/mimetype.h"
52 #include "wx/statline.h"
55 #if defined(__WXMAC__)
56 #include "wx/osx/private.h" // includes mac headers
61 #include "wx/msw/winundef.h"
62 #include "wx/volume.h"
64 // FIXME - Mingw32 1.0 has both _getdrive() and _chdrive(). For now, let's assume
65 // older releases don't, but it should be verified and the checks modified
67 #if !defined(__GNUWIN32__) || (defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
68 #if !defined(__WXWINCE__)
77 #if defined(__OS2__) || defined(__DOS__)
89 #if defined(__WXMAC__)
90 // #include "MoreFilesX.h"
97 extern WXDLLEXPORT_DATA(const char) wxFileSelectorDefaultWildcardStr
[];
99 // If compiled under Windows, this macro can cause problems
104 bool wxIsDriveAvailable(const wxString
& dirName
);
106 // ----------------------------------------------------------------------------
107 // wxGetAvailableDrives, for WINDOWS, DOS, OS2, MAC, UNIX (returns "/")
108 // ----------------------------------------------------------------------------
110 size_t wxGetAvailableDrives(wxArrayString
&paths
, wxArrayString
&names
, wxArrayInt
&icon_ids
)
112 #ifdef wxHAS_FILESYSTEM_VOLUMES
115 // No logical drives; return "\"
116 paths
.Add(wxT("\\"));
117 names
.Add(wxT("\\"));
118 icon_ids
.Add(wxFileIconsTable::computer
);
119 #elif defined(__WIN32__) && wxUSE_FSVOLUME
120 // TODO: this code (using wxFSVolumeBase) should be used for all platforms
121 // but unfortunately wxFSVolumeBase is not implemented everywhere
122 const wxArrayString as
= wxFSVolumeBase::GetVolumes();
124 for (size_t i
= 0; i
< as
.GetCount(); i
++)
126 wxString path
= as
[i
];
127 wxFSVolume
vol(path
);
129 switch (vol
.GetKind())
131 case wxFS_VOL_FLOPPY
:
132 if ( (path
== wxT("a:\\")) || (path
== wxT("b:\\")) )
133 imageId
= wxFileIconsTable::floppy
;
135 imageId
= wxFileIconsTable::removeable
;
137 case wxFS_VOL_DVDROM
:
139 imageId
= wxFileIconsTable::cdrom
;
141 case wxFS_VOL_NETWORK
:
142 if (path
[0] == wxT('\\'))
143 continue; // skip "\\computer\folder"
144 imageId
= wxFileIconsTable::drive
;
149 imageId
= wxFileIconsTable::drive
;
153 names
.Add(vol
.GetDisplayName());
154 icon_ids
.Add(imageId
);
156 #elif defined(__OS2__)
158 ULONG ulDriveNum
= 0;
159 ULONG ulDriveMap
= 0;
160 rc
= ::DosQueryCurrentDisk(&ulDriveNum
, &ulDriveMap
);
166 if (ulDriveMap
& ( 1 << i
))
168 const wxString path
= wxFileName::GetVolumeString(
169 'A' + i
, wxPATH_GET_SEPARATOR
);
170 const wxString name
= wxFileName::GetVolumeString(
171 'A' + i
, wxPATH_NO_SEPARATOR
);
173 // Note: If _filesys is unsupported by some compilers,
174 // we can always replace it by DosQueryFSAttach
175 char filesysname
[20];
177 ULONG cbBuffer
= sizeof(filesysname
);
178 PFSQBUFFER2 pfsqBuffer
= (PFSQBUFFER2
)filesysname
;
179 APIRET rc
= ::DosQueryFSAttach(name
.fn_str(),0,FSAIL_QUERYNAME
,pfsqBuffer
,&cbBuffer
);
182 filesysname
[0] = '\0';
185 _filesys(name
.fn_str(), filesysname
, sizeof(filesysname
));
187 /* FAT, LAN, HPFS, CDFS, NFS */
189 if (path
== wxT("A:\\") || path
== wxT("B:\\"))
190 imageId
= wxFileIconsTable::floppy
;
191 else if (!strcmp(filesysname
, "CDFS"))
192 imageId
= wxFileIconsTable::cdrom
;
193 else if (!strcmp(filesysname
, "LAN") ||
194 !strcmp(filesysname
, "NFS"))
195 imageId
= wxFileIconsTable::drive
;
197 imageId
= wxFileIconsTable::drive
;
200 icon_ids
.Add(imageId
);
205 #else // !__WIN32__, !__OS2__
206 /* If we can switch to the drive, it exists. */
207 for ( char drive
= 'A'; drive
<= 'Z'; drive
++ )
210 path
= wxFileName::GetVolumeString(drive
, wxPATH_GET_SEPARATOR
);
212 if (wxIsDriveAvailable(path
))
215 names
.Add(wxFileName::GetVolumeString(drive
, wxPATH_NO_SEPARATOR
));
216 icon_ids
.Add(drive
<= 2 ? wxFileIconsTable::floppy
217 : wxFileIconsTable::drive
);
220 #endif // __WIN32__/!__WIN32__
222 #elif defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON
224 ItemCount volumeIndex
= 1;
227 while( noErr
== err
)
229 HFSUniStr255 volumeName
;
231 FSVolumeInfo volumeInfo
;
232 err
= FSGetVolumeInfo(0, volumeIndex
, NULL
, kFSVolInfoFlags
, &volumeInfo
, &volumeName
, &fsRef
);
235 wxString path
= wxMacFSRefToPath( &fsRef
) ;
236 wxString name
= wxMacHFSUniStrToString( &volumeName
) ;
238 if ( (volumeInfo
.flags
& kFSVolFlagSoftwareLockedMask
) || (volumeInfo
.flags
& kFSVolFlagHardwareLockedMask
) )
240 icon_ids
.Add(wxFileIconsTable::cdrom
);
244 icon_ids
.Add(wxFileIconsTable::drive
);
246 // todo other removable
254 #elif defined(__UNIX__) || defined(__WXPALMOS__)
257 icon_ids
.Add(wxFileIconsTable::computer
);
259 #error "Unsupported platform in wxGenericDirCtrl!"
261 wxASSERT_MSG( (paths
.GetCount() == names
.GetCount()), wxT("The number of paths and their human readable names should be equal in number."));
262 wxASSERT_MSG( (paths
.GetCount() == icon_ids
.GetCount()), wxT("Wrong number of icons for available drives."));
263 return paths
.GetCount();
266 // ----------------------------------------------------------------------------
267 // wxIsDriveAvailable
268 // ----------------------------------------------------------------------------
272 bool wxIsDriveAvailable(const wxString
& dirName
)
274 // FIXME_MGL - this method leads to hang up under Watcom for some reason
276 wxUnusedVar(dirName
);
278 if ( dirName
.length() == 3 && dirName
[1u] == wxT(':') )
280 wxString
dirNameLower(dirName
.Lower());
281 // VS: always return true for removable media, since Win95 doesn't
282 // like it when MS-DOS app accesses empty floppy drive
283 return (dirNameLower
[0u] == wxT('a') ||
284 dirNameLower
[0u] == wxT('b') ||
285 wxDirExists(dirNameLower
));
292 #elif defined(__WINDOWS__) || defined(__OS2__)
294 int setdrive(int WXUNUSED_IN_WINCE(drive
))
298 #elif defined(__GNUWIN32__) && \
299 (defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
300 return _chdrive(drive
);
304 if (drive
< 1 || drive
> 31)
306 newdrive
[0] = (wxChar
)(wxT('A') + drive
- 1);
307 newdrive
[1] = wxT(':');
309 newdrive
[2] = wxT('\\');
310 newdrive
[3] = wxT('\0');
312 newdrive
[2] = wxT('\0');
314 #if defined(__WXMSW__)
315 if (::SetCurrentDirectory(newdrive
))
317 // VA doesn't know what LPSTR is and has its own set
318 if (!DosSetCurrentDir((PSZ
)newdrive
))
326 bool wxIsDriveAvailable(const wxString
& WXUNUSED_IN_WINCE(dirName
))
332 UINT errorMode
= SetErrorMode(SEM_FAILCRITICALERRORS
| SEM_NOOPENFILEERRORBOX
);
336 // Check if this is a root directory and if so,
337 // whether the drive is available.
338 if (dirName
.length() == 3 && dirName
[(size_t)1] == wxT(':'))
340 wxString
dirNameLower(dirName
.Lower());
341 #if defined(__GNUWIN32__) && !(defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1)
342 success
= wxDirExists(dirNameLower
);
345 // Avoid changing to drive since no media may be inserted.
346 if (dirNameLower
[(size_t)0] == 'a' || dirNameLower
[(size_t)0] == 'b')
349 int currentDrive
= _getdrive();
350 int thisDrive
= (int) (dirNameLower
[(size_t)0] - 'a' + 1) ;
351 int err
= setdrive( thisDrive
) ;
352 setdrive( currentDrive
);
361 (void) SetErrorMode(errorMode
);
367 #endif // __WINDOWS__ || __OS2__
369 #endif // wxUSE_DIRDLG || wxUSE_FILEDLG
375 // Function which is called by quick sort. We want to override the default wxArrayString behaviour,
376 // and sort regardless of case.
377 static int wxCMPFUNC_CONV
wxDirCtrlStringCompareFunction(const wxString
& strFirst
, const wxString
& strSecond
)
379 return strFirst
.CmpNoCase(strSecond
);
382 //-----------------------------------------------------------------------------
384 //-----------------------------------------------------------------------------
386 wxDirItemData::wxDirItemData(const wxString
& path
, const wxString
& name
,
391 /* Insert logic to detect hidden files here
392 * In UnixLand we just check whether the first char is a dot
393 * For FileNameFromPath read LastDirNameInThisPath ;-) */
394 // m_isHidden = (bool)(wxFileNameFromPath(*m_path)[0] == '.');
396 m_isExpanded
= false;
400 void wxDirItemData::SetNewDirName(const wxString
& path
)
403 m_name
= wxFileNameFromPath(path
);
406 bool wxDirItemData::HasSubDirs() const
414 if ( !dir
.Open(m_path
) )
418 return dir
.HasSubDirs();
421 bool wxDirItemData::HasFiles(const wxString
& WXUNUSED(spec
)) const
429 if ( !dir
.Open(m_path
) )
433 return dir
.HasFiles();
436 //-----------------------------------------------------------------------------
438 //-----------------------------------------------------------------------------
441 #if wxUSE_EXTENDED_RTTI
442 WX_DEFINE_FLAGS( wxGenericDirCtrlStyle
)
444 wxBEGIN_FLAGS( wxGenericDirCtrlStyle
)
445 // new style border flags, we put them first to
446 // use them for streaming out
447 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
448 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
449 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
450 wxFLAGS_MEMBER(wxBORDER_RAISED
)
451 wxFLAGS_MEMBER(wxBORDER_STATIC
)
452 wxFLAGS_MEMBER(wxBORDER_NONE
)
454 // old style border flags
455 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
456 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
457 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
458 wxFLAGS_MEMBER(wxRAISED_BORDER
)
459 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
460 wxFLAGS_MEMBER(wxBORDER
)
462 // standard window styles
463 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
464 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
465 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
466 wxFLAGS_MEMBER(wxWANTS_CHARS
)
467 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
468 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
469 wxFLAGS_MEMBER(wxVSCROLL
)
470 wxFLAGS_MEMBER(wxHSCROLL
)
472 wxFLAGS_MEMBER(wxDIRCTRL_DIR_ONLY
)
473 wxFLAGS_MEMBER(wxDIRCTRL_3D_INTERNAL
)
474 wxFLAGS_MEMBER(wxDIRCTRL_SELECT_FIRST
)
475 wxFLAGS_MEMBER(wxDIRCTRL_MULTIPLE
)
477 wxEND_FLAGS( wxGenericDirCtrlStyle
)
479 IMPLEMENT_DYNAMIC_CLASS_XTI(wxGenericDirCtrl
, wxControl
,"wx/dirctrl.h")
481 wxBEGIN_PROPERTIES_TABLE(wxGenericDirCtrl
)
482 wxHIDE_PROPERTY( Children
)
483 wxPROPERTY( DefaultPath
, wxString
, SetDefaultPath
, GetDefaultPath
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
484 wxPROPERTY( Filter
, wxString
, SetFilter
, GetFilter
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
485 wxPROPERTY( DefaultFilter
, int , SetFilterIndex
, GetFilterIndex
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
486 wxPROPERTY_FLAGS( WindowStyle
, wxGenericDirCtrlStyle
, long, SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0, wxT("Helpstring"), wxT("group") )
487 wxEND_PROPERTIES_TABLE()
489 wxBEGIN_HANDLERS_TABLE(wxGenericDirCtrl
)
490 wxEND_HANDLERS_TABLE()
492 wxCONSTRUCTOR_8( wxGenericDirCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, DefaultPath
,
493 wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
, wxString
, Filter
, int , DefaultFilter
)
495 IMPLEMENT_DYNAMIC_CLASS(wxGenericDirCtrl
, wxControl
)
498 BEGIN_EVENT_TABLE(wxGenericDirCtrl
, wxControl
)
499 EVT_TREE_ITEM_EXPANDING (wxID_TREECTRL
, wxGenericDirCtrl::OnExpandItem
)
500 EVT_TREE_ITEM_COLLAPSED (wxID_TREECTRL
, wxGenericDirCtrl::OnCollapseItem
)
501 EVT_TREE_BEGIN_LABEL_EDIT (wxID_TREECTRL
, wxGenericDirCtrl::OnBeginEditItem
)
502 EVT_TREE_END_LABEL_EDIT (wxID_TREECTRL
, wxGenericDirCtrl::OnEndEditItem
)
503 EVT_SIZE (wxGenericDirCtrl::OnSize
)
506 wxGenericDirCtrl::wxGenericDirCtrl(void)
511 void wxGenericDirCtrl::ExpandRoot()
513 ExpandDir(m_rootId
); // automatically expand first level
515 // Expand and select the default path
516 if (!m_defaultPath
.empty())
518 ExpandPath(m_defaultPath
);
523 // On Unix, there's only one node under the (hidden) root node. It
524 // represents the / path, so the user would always have to expand it;
525 // let's do it ourselves
526 ExpandPath( wxT("/") );
531 bool wxGenericDirCtrl::Create(wxWindow
*parent
,
537 const wxString
& filter
,
539 const wxString
& name
)
541 if (!wxControl::Create(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
544 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
545 SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
549 long treeStyle
= wxTR_HAS_BUTTONS
;
551 // On Windows CE, if you hide the root, you get a crash when
552 // attempting to access data for children of the root item.
554 treeStyle
|= wxTR_HIDE_ROOT
;
558 treeStyle
|= wxTR_NO_LINES
;
561 if (style
& wxDIRCTRL_EDIT_LABELS
)
562 treeStyle
|= wxTR_EDIT_LABELS
;
564 if (style
& wxDIRCTRL_MULTIPLE
)
565 treeStyle
|= wxTR_MULTIPLE
;
567 if ((style
& wxDIRCTRL_3D_INTERNAL
) == 0)
568 treeStyle
|= wxNO_BORDER
;
570 m_treeCtrl
= CreateTreeCtrl(this, wxID_TREECTRL
,
571 wxPoint(0,0), GetClientSize(), treeStyle
);
574 m_filterListCtrl
= new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL
);
579 if (m_filter
.empty())
580 m_filter
= wxFileSelectorDefaultWildcardStr
;
582 SetFilterIndex(defaultFilter
);
584 if (m_filterListCtrl
)
585 m_filterListCtrl
->FillFilterList(filter
, defaultFilter
);
587 m_treeCtrl
->SetImageList(wxTheFileIconsTable
->GetSmallImageList());
589 m_showHidden
= false;
590 wxDirItemData
* rootData
= new wxDirItemData(wxEmptyString
, wxEmptyString
, true);
594 #if defined(__WINDOWS__) || defined(__OS2__) || defined(__DOS__)
595 rootName
= _("Computer");
597 rootName
= _("Sections");
600 m_rootId
= m_treeCtrl
->AddRoot( rootName
, 3, -1, rootData
);
601 m_treeCtrl
->SetItemHasChildren(m_rootId
);
605 SetInitialSize(size
);
611 wxGenericDirCtrl::~wxGenericDirCtrl()
615 void wxGenericDirCtrl::Init()
617 m_showHidden
= false;
619 m_currentFilterStr
= wxEmptyString
; // Default: any file
621 m_filterListCtrl
= NULL
;
624 wxTreeCtrl
* wxGenericDirCtrl::CreateTreeCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long treeStyle
)
626 return new wxTreeCtrl(parent
, id
, pos
, size
, treeStyle
);
629 void wxGenericDirCtrl::ShowHidden( bool show
)
631 if ( m_showHidden
== show
)
636 if ( HasFlag(wxDIRCTRL_MULTIPLE
) )
641 for ( unsigned n
= 0; n
< paths
.size(); n
++ )
643 ExpandPath(paths
[n
]);
648 wxString path
= GetPath();
655 wxGenericDirCtrl::AddSection(const wxString
& path
, const wxString
& name
, int imageId
)
657 wxDirItemData
*dir_item
= new wxDirItemData(path
,name
,true);
659 wxTreeItemId id
= AppendItem( m_rootId
, name
, imageId
, -1, dir_item
);
661 m_treeCtrl
->SetItemHasChildren(id
);
666 void wxGenericDirCtrl::SetupSections()
668 wxArrayString paths
, names
;
671 size_t n
, count
= wxGetAvailableDrives(paths
, names
, icons
);
674 wxString home
= wxGetHomeDir();
675 AddSection( home
, _("Home directory"), 1);
676 home
+= wxT("/Desktop");
677 AddSection( home
, _("Desktop"), 1);
680 for (n
= 0; n
< count
; n
++)
681 AddSection(paths
[n
], names
[n
], icons
[n
]);
684 void wxGenericDirCtrl::SetFocus()
686 // we don't need focus ourselves, give it to the tree so that the user
689 m_treeCtrl
->SetFocus();
692 void wxGenericDirCtrl::OnBeginEditItem(wxTreeEvent
&event
)
694 // don't rename the main entry "Sections"
695 if (event
.GetItem() == m_rootId
)
701 // don't rename the individual sections
702 if (m_treeCtrl
->GetItemParent( event
.GetItem() ) == m_rootId
)
709 void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent
&event
)
711 if (event
.IsEditCancelled())
714 if ((event
.GetLabel().empty()) ||
715 (event
.GetLabel() == wxT(".")) ||
716 (event
.GetLabel() == wxT("..")) ||
717 (event
.GetLabel().Find(wxT('/')) != wxNOT_FOUND
) ||
718 (event
.GetLabel().Find(wxT('\\')) != wxNOT_FOUND
) ||
719 (event
.GetLabel().Find(wxT('|')) != wxNOT_FOUND
))
721 wxMessageDialog
dialog(this, _("Illegal directory name."), _("Error"), wxOK
| wxICON_ERROR
);
727 wxTreeItemId id
= event
.GetItem();
728 wxDirItemData
*data
= (wxDirItemData
*)m_treeCtrl
->GetItemData( id
);
731 wxString
new_name( wxPathOnly( data
->m_path
) );
732 new_name
+= wxString(wxFILE_SEP_PATH
);
733 new_name
+= event
.GetLabel();
737 if (wxFileExists(new_name
))
739 wxMessageDialog
dialog(this, _("File name exists already."), _("Error"), wxOK
| wxICON_ERROR
);
744 if (wxRenameFile(data
->m_path
,new_name
))
746 data
->SetNewDirName( new_name
);
750 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
756 void wxGenericDirCtrl::OnExpandItem(wxTreeEvent
&event
)
758 wxTreeItemId parentId
= event
.GetItem();
760 // VS: this is needed because the event handler is called from wxTreeCtrl
761 // ctor when wxTR_HIDE_ROOT was specified
763 if (!m_rootId
.IsOk())
764 m_rootId
= m_treeCtrl
->GetRootItem();
769 void wxGenericDirCtrl::OnCollapseItem(wxTreeEvent
&event
)
771 CollapseDir(event
.GetItem());
774 void wxGenericDirCtrl::CollapseDir(wxTreeItemId parentId
)
778 wxDirItemData
*data
= (wxDirItemData
*) m_treeCtrl
->GetItemData(parentId
);
779 if (!data
->m_isExpanded
)
782 data
->m_isExpanded
= false;
784 m_treeCtrl
->Freeze();
785 if (parentId
!= m_treeCtrl
->GetRootItem())
786 m_treeCtrl
->CollapseAndReset(parentId
);
787 m_treeCtrl
->DeleteChildren(parentId
);
791 void wxGenericDirCtrl::PopulateNode(wxTreeItemId parentId
)
793 wxDirItemData
*data
= (wxDirItemData
*) m_treeCtrl
->GetItemData(parentId
);
795 if (data
->m_isExpanded
)
798 data
->m_isExpanded
= true;
800 if (parentId
== m_treeCtrl
->GetRootItem())
808 wxString search
,path
,filename
;
810 wxString
dirName(data
->m_path
);
812 #if (defined(__WINDOWS__) && !defined(__WXWINCE__)) || defined(__DOS__) || defined(__OS2__)
813 // Check if this is a root directory and if so,
814 // whether the drive is avaiable.
815 if (!wxIsDriveAvailable(dirName
))
817 data
->m_isExpanded
= false;
818 //wxMessageBox(wxT("Sorry, this drive is not available."));
823 // This may take a longish time. Go to busy cursor
826 #if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)
827 if (dirName
.Last() == ':')
828 dirName
+= wxString(wxFILE_SEP_PATH
);
832 wxArrayString filenames
;
835 wxString eachFilename
;
842 int style
= wxDIR_DIRS
;
843 if (m_showHidden
) style
|= wxDIR_HIDDEN
;
844 if (d
.GetFirst(& eachFilename
, wxEmptyString
, style
))
848 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
850 dirs
.Add(eachFilename
);
853 while (d
.GetNext(&eachFilename
));
856 dirs
.Sort(wxDirCtrlStringCompareFunction
);
858 // Now do the filenames -- but only if we're allowed to
859 if (!HasFlag(wxDIRCTRL_DIR_ONLY
))
865 int style
= wxDIR_FILES
;
866 if (m_showHidden
) style
|= wxDIR_HIDDEN
;
867 // Process each filter (ex: "JPEG Files (*.jpg;*.jpeg)|*.jpg;*.jpeg")
868 wxStringTokenizer strTok
;
870 strTok
.SetString(m_currentFilterStr
,wxT(";"));
871 while(strTok
.HasMoreTokens())
873 curFilter
= strTok
.GetNextToken();
874 if (d
.GetFirst(& eachFilename
, curFilter
, style
))
878 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
880 filenames
.Add(eachFilename
);
883 while (d
.GetNext(& eachFilename
));
887 filenames
.Sort(wxDirCtrlStringCompareFunction
);
890 // Now we really know whether we have any children so tell the tree control
892 m_treeCtrl
->SetItemHasChildren(parentId
, !dirs
.empty() || !filenames
.empty());
894 // Add the sorted dirs
896 for (i
= 0; i
< dirs
.GetCount(); i
++)
898 eachFilename
= dirs
[i
];
900 if (!wxEndsWithPathSeparator(path
))
901 path
+= wxString(wxFILE_SEP_PATH
);
902 path
+= eachFilename
;
904 wxDirItemData
*dir_item
= new wxDirItemData(path
,eachFilename
,true);
905 wxTreeItemId id
= AppendItem( parentId
, eachFilename
,
906 wxFileIconsTable::folder
, -1, dir_item
);
907 m_treeCtrl
->SetItemImage( id
, wxFileIconsTable::folder_open
,
908 wxTreeItemIcon_Expanded
);
910 // assume that it does have children by default as it can take a long
911 // time to really check for this (think remote drives...)
913 // and if we're wrong, we'll correct the icon later if
914 // the user really tries to open this item
915 m_treeCtrl
->SetItemHasChildren(id
);
918 // Add the sorted filenames
919 if (!HasFlag(wxDIRCTRL_DIR_ONLY
))
921 for (i
= 0; i
< filenames
.GetCount(); i
++)
923 eachFilename
= filenames
[i
];
925 if (!wxEndsWithPathSeparator(path
))
926 path
+= wxString(wxFILE_SEP_PATH
);
927 path
+= eachFilename
;
928 //path = dirName + wxString(wxT("/")) + eachFilename;
929 wxDirItemData
*dir_item
= new wxDirItemData(path
,eachFilename
,false);
930 int image_id
= wxFileIconsTable::file
;
931 if (eachFilename
.Find(wxT('.')) != wxNOT_FOUND
)
932 image_id
= wxTheFileIconsTable
->GetIconID(eachFilename
.AfterLast(wxT('.')));
933 (void) AppendItem( parentId
, eachFilename
, image_id
, -1, dir_item
);
938 void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId
)
940 // ExpandDir() will not actually expand the tree node, just populate it
941 PopulateNode(parentId
);
944 void wxGenericDirCtrl::ReCreateTree()
946 CollapseDir(m_treeCtrl
->GetRootItem());
950 void wxGenericDirCtrl::CollapseTree()
952 wxTreeItemIdValue cookie
;
953 wxTreeItemId child
= m_treeCtrl
->GetFirstChild(m_rootId
, cookie
);
957 child
= m_treeCtrl
->GetNextChild(m_rootId
, cookie
);
961 // Find the child that matches the first part of 'path'.
962 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
963 // then the child for /usr is returned.
964 wxTreeItemId
wxGenericDirCtrl::FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
)
966 wxString
path2(path
);
968 // Make sure all separators are as per the current platform
969 path2
.Replace(wxT("\\"), wxString(wxFILE_SEP_PATH
));
970 path2
.Replace(wxT("/"), wxString(wxFILE_SEP_PATH
));
972 // Append a separator to foil bogus substring matching
973 path2
+= wxString(wxFILE_SEP_PATH
);
975 // In MSW or PM, case is not significant
976 #if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)
980 wxTreeItemIdValue cookie
;
981 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(parentId
, cookie
);
982 while (childId
.IsOk())
984 wxDirItemData
* data
= (wxDirItemData
*) m_treeCtrl
->GetItemData(childId
);
986 if (data
&& !data
->m_path
.empty())
988 wxString
childPath(data
->m_path
);
989 if (!wxEndsWithPathSeparator(childPath
))
990 childPath
+= wxString(wxFILE_SEP_PATH
);
992 // In MSW and PM, case is not significant
993 #if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)
994 childPath
.MakeLower();
997 if (childPath
.length() <= path2
.length())
999 wxString path3
= path2
.Mid(0, childPath
.length());
1000 if (childPath
== path3
)
1002 if (path3
.length() == path2
.length())
1011 childId
= m_treeCtrl
->GetNextChild(parentId
, cookie
);
1013 wxTreeItemId invalid
;
1017 // Try to expand as much of the given path as possible,
1018 // and select the given tree item.
1019 bool wxGenericDirCtrl::ExpandPath(const wxString
& path
)
1022 wxTreeItemId id
= FindChild(m_rootId
, path
, done
);
1023 wxTreeItemId lastId
= id
; // The last non-zero id
1024 while (id
.IsOk() && !done
)
1028 id
= FindChild(id
, path
, done
);
1035 wxDirItemData
*data
= (wxDirItemData
*) m_treeCtrl
->GetItemData(lastId
);
1038 m_treeCtrl
->Expand(lastId
);
1040 if (HasFlag(wxDIRCTRL_SELECT_FIRST
) && data
->m_isDir
)
1042 // Find the first file in this directory
1043 wxTreeItemIdValue cookie
;
1044 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(lastId
, cookie
);
1045 bool selectedChild
= false;
1046 while (childId
.IsOk())
1048 data
= (wxDirItemData
*) m_treeCtrl
->GetItemData(childId
);
1050 if (data
&& data
->m_path
!= wxEmptyString
&& !data
->m_isDir
)
1052 m_treeCtrl
->SelectItem(childId
);
1053 m_treeCtrl
->EnsureVisible(childId
);
1054 selectedChild
= true;
1057 childId
= m_treeCtrl
->GetNextChild(lastId
, cookie
);
1061 m_treeCtrl
->SelectItem(lastId
);
1062 m_treeCtrl
->EnsureVisible(lastId
);
1067 m_treeCtrl
->SelectItem(lastId
);
1068 m_treeCtrl
->EnsureVisible(lastId
);
1075 bool wxGenericDirCtrl::CollapsePath(const wxString
& path
)
1078 wxTreeItemId id
= FindChild(m_rootId
, path
, done
);
1079 wxTreeItemId lastId
= id
; // The last non-zero id
1081 while ( id
.IsOk() && !done
)
1085 id
= FindChild(id
, path
, done
);
1091 if ( !lastId
.IsOk() )
1094 m_treeCtrl
->SelectItem(lastId
);
1095 m_treeCtrl
->EnsureVisible(lastId
);
1101 wxString
wxGenericDirCtrl::GetPath() const
1103 // Allow calling GetPath() in multiple selection from OnSelFilter
1104 if (m_treeCtrl
->HasFlag(wxTR_MULTIPLE
))
1106 wxArrayTreeItemIds items
;
1107 m_treeCtrl
->GetSelections(items
);
1108 if (items
.size() > 0)
1110 // return first string only
1111 wxTreeItemId id
= items
[0];
1112 wxDirItemData
* data
= (wxDirItemData
*) m_treeCtrl
->GetItemData(id
);
1113 return data
->m_path
;
1116 return wxEmptyString
;
1119 wxTreeItemId id
= m_treeCtrl
->GetSelection();
1122 wxDirItemData
* data
= (wxDirItemData
*) m_treeCtrl
->GetItemData(id
);
1123 return data
->m_path
;
1126 return wxEmptyString
;
1129 void wxGenericDirCtrl::GetPaths(wxArrayString
& paths
) const
1133 wxArrayTreeItemIds items
;
1134 m_treeCtrl
->GetSelections(items
);
1135 for ( unsigned n
= 0; n
< items
.size(); n
++ )
1137 wxTreeItemId id
= items
[n
];
1138 wxDirItemData
* data
= (wxDirItemData
*) m_treeCtrl
->GetItemData(id
);
1139 paths
.Add(data
->m_path
);
1143 wxString
wxGenericDirCtrl::GetFilePath() const
1145 wxTreeItemId id
= m_treeCtrl
->GetSelection();
1148 wxDirItemData
* data
= (wxDirItemData
*) m_treeCtrl
->GetItemData(id
);
1150 return wxEmptyString
;
1152 return data
->m_path
;
1155 return wxEmptyString
;
1158 void wxGenericDirCtrl::GetFilePaths(wxArrayString
& paths
) const
1162 wxArrayTreeItemIds items
;
1163 m_treeCtrl
->GetSelections(items
);
1164 for ( unsigned n
= 0; n
< items
.size(); n
++ )
1166 wxTreeItemId id
= items
[n
];
1167 wxDirItemData
* data
= (wxDirItemData
*) m_treeCtrl
->GetItemData(id
);
1168 if ( !data
->m_isDir
)
1169 paths
.Add(data
->m_path
);
1173 void wxGenericDirCtrl::SetPath(const wxString
& path
)
1175 m_defaultPath
= path
;
1180 void wxGenericDirCtrl::SelectPath(const wxString
& path
, bool select
)
1183 wxTreeItemId id
= FindChild(m_rootId
, path
, done
);
1184 wxTreeItemId lastId
= id
; // The last non-zero id
1185 while ( id
.IsOk() && !done
)
1187 id
= FindChild(id
, path
, done
);
1191 if ( !lastId
.IsOk() )
1196 m_treeCtrl
->SelectItem(id
, select
);
1200 void wxGenericDirCtrl::SelectPaths(const wxArrayString
& paths
)
1202 if ( HasFlag(wxDIRCTRL_MULTIPLE
) )
1205 for ( unsigned n
= 0; n
< paths
.size(); n
++ )
1207 SelectPath(paths
[n
]);
1212 void wxGenericDirCtrl::UnselectAll()
1214 m_treeCtrl
->UnselectAll();
1219 void wxGenericDirCtrl::FindChildFiles(wxTreeItemId id
, int dirFlags
, wxArrayString
& filenames
)
1221 wxDirItemData
*data
= (wxDirItemData
*) m_treeCtrl
->GetItemData(id
);
1223 // This may take a longish time. Go to busy cursor
1228 wxString search
,path
,filename
;
1230 wxString
dirName(data
->m_path
);
1232 #if defined(__WXMSW__) || defined(__OS2__)
1233 if (dirName
.Last() == ':')
1234 dirName
+= wxString(wxFILE_SEP_PATH
);
1238 wxString eachFilename
;
1245 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, dirFlags
))
1249 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
1251 filenames
.Add(eachFilename
);
1254 while (d
.GetNext(& eachFilename
)) ;
1260 void wxGenericDirCtrl::SetFilterIndex(int n
)
1262 m_currentFilter
= n
;
1265 if (ExtractWildcard(m_filter
, n
, f
, d
))
1266 m_currentFilterStr
= f
;
1269 m_currentFilterStr
= wxT("*");
1271 m_currentFilterStr
= wxT("*.*");
1275 void wxGenericDirCtrl::SetFilter(const wxString
& filter
)
1279 if (!filter
.empty() && !m_filterListCtrl
)
1280 m_filterListCtrl
= new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL
);
1281 else if (filter
.empty() && m_filterListCtrl
)
1283 m_filterListCtrl
->Destroy();
1284 m_filterListCtrl
= NULL
;
1288 if (ExtractWildcard(m_filter
, m_currentFilter
, f
, d
))
1289 m_currentFilterStr
= f
;
1292 m_currentFilterStr
= wxT("*");
1294 m_currentFilterStr
= wxT("*.*");
1296 // current filter index is meaningless after filter change, set it to zero
1298 if (m_filterListCtrl
)
1299 m_filterListCtrl
->FillFilterList(m_filter
, 0);
1302 // Extract description and actual filter from overall filter string
1303 bool wxGenericDirCtrl::ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
)
1305 wxArrayString filters
, descriptions
;
1306 int count
= wxParseCommonDialogsFilter(filterStr
, descriptions
, filters
);
1307 if (count
> 0 && n
< count
)
1309 filter
= filters
[n
];
1310 description
= descriptions
[n
];
1318 void wxGenericDirCtrl::DoResize()
1320 wxSize sz
= GetClientSize();
1321 int verticalSpacing
= 3;
1325 if (m_filterListCtrl
)
1327 filterSz
= m_filterListCtrl
->GetSize();
1328 sz
.y
-= (filterSz
.y
+ verticalSpacing
);
1330 m_treeCtrl
->SetSize(0, 0, sz
.x
, sz
.y
);
1331 if (m_filterListCtrl
)
1333 m_filterListCtrl
->SetSize(0, sz
.y
+ verticalSpacing
, sz
.x
, filterSz
.y
);
1334 // Don't know why, but this needs refreshing after a resize (wxMSW)
1335 m_filterListCtrl
->Refresh();
1341 void wxGenericDirCtrl::OnSize(wxSizeEvent
& WXUNUSED(event
))
1346 wxTreeItemId
wxGenericDirCtrl::AppendItem (const wxTreeItemId
& parent
,
1347 const wxString
& text
,
1348 int image
, int selectedImage
,
1349 wxTreeItemData
* data
)
1351 wxTreeCtrl
*treeCtrl
= GetTreeCtrl ();
1353 wxASSERT (treeCtrl
);
1357 return treeCtrl
->AppendItem (parent
, text
, image
, selectedImage
, data
);
1361 return wxTreeItemId();
1366 //-----------------------------------------------------------------------------
1367 // wxDirFilterListCtrl
1368 //-----------------------------------------------------------------------------
1370 IMPLEMENT_CLASS(wxDirFilterListCtrl
, wxChoice
)
1372 BEGIN_EVENT_TABLE(wxDirFilterListCtrl
, wxChoice
)
1373 EVT_CHOICE(wxID_ANY
, wxDirFilterListCtrl::OnSelFilter
)
1376 bool wxDirFilterListCtrl::Create(wxGenericDirCtrl
* parent
,
1377 const wxWindowID id
,
1384 // by default our border style is determined by the style of our parent
1385 if ( !(style
& wxBORDER_MASK
) )
1387 style
|= parent
->HasFlag(wxDIRCTRL_3D_INTERNAL
) ? wxBORDER_SUNKEN
1391 return wxChoice::Create(parent
, id
, pos
, size
, 0, NULL
, style
);
1394 void wxDirFilterListCtrl::Init()
1399 void wxDirFilterListCtrl::OnSelFilter(wxCommandEvent
& WXUNUSED(event
))
1401 int sel
= GetSelection();
1403 if (m_dirCtrl
->HasFlag(wxDIRCTRL_MULTIPLE
))
1405 wxArrayString paths
;
1406 m_dirCtrl
->GetPaths(paths
);
1408 m_dirCtrl
->SetFilterIndex(sel
);
1410 // If the filter has changed, the view is out of date, so
1411 // collapse the tree.
1412 m_dirCtrl
->ReCreateTree();
1414 // Expand and select the previously selected paths
1415 for (unsigned int i
= 0; i
< paths
.GetCount(); i
++)
1417 m_dirCtrl
->ExpandPath(paths
.Item(i
));
1422 wxString currentPath
= m_dirCtrl
->GetPath();
1424 m_dirCtrl
->SetFilterIndex(sel
);
1425 m_dirCtrl
->ReCreateTree();
1427 // Try to restore the selection, or at least the directory
1428 m_dirCtrl
->ExpandPath(currentPath
);
1432 void wxDirFilterListCtrl::FillFilterList(const wxString
& filter
, int defaultFilter
)
1435 wxArrayString descriptions
, filters
;
1436 size_t n
= (size_t) wxParseCommonDialogsFilter(filter
, descriptions
, filters
);
1438 if (n
> 0 && defaultFilter
< (int) n
)
1440 for (size_t i
= 0; i
< n
; i
++)
1441 Append(descriptions
[i
]);
1442 SetSelection(defaultFilter
);
1445 #endif // wxUSE_DIRDLG
1447 #if wxUSE_DIRDLG || wxUSE_FILEDLG
1449 // ----------------------------------------------------------------------------
1450 // wxFileIconsTable icons
1451 // ----------------------------------------------------------------------------
1454 /* Computer (c) Julian Smart */
1455 static const char* const file_icons_tbl_computer_xpm
[] = {
1456 /* columns rows colors chars-per-pixel */
1520 // ----------------------------------------------------------------------------
1521 // wxFileIconsTable & friends
1522 // ----------------------------------------------------------------------------
1524 // global instance of a wxFileIconsTable
1525 wxFileIconsTable
* wxTheFileIconsTable
= NULL
;
1527 // A module to allow icons table cleanup
1529 class wxFileIconsTableModule
: public wxModule
1531 DECLARE_DYNAMIC_CLASS(wxFileIconsTableModule
)
1533 wxFileIconsTableModule() {}
1534 bool OnInit() { wxTheFileIconsTable
= new wxFileIconsTable
; return true; }
1537 wxDELETE(wxTheFileIconsTable
);
1541 IMPLEMENT_DYNAMIC_CLASS(wxFileIconsTableModule
, wxModule
)
1543 class wxFileIconEntry
: public wxObject
1546 wxFileIconEntry(int i
) { id
= i
; }
1551 wxFileIconsTable::wxFileIconsTable()
1554 m_smallImageList
= NULL
;
1557 wxFileIconsTable::~wxFileIconsTable()
1561 WX_CLEAR_HASH_TABLE(*m_HashTable
);
1564 if (m_smallImageList
) delete m_smallImageList
;
1567 // delayed initialization - wait until first use (wxArtProv not created yet)
1568 void wxFileIconsTable::Create()
1570 wxCHECK_RET(!m_smallImageList
&& !m_HashTable
, wxT("creating icons twice"));
1571 m_HashTable
= new wxHashTable(wxKEY_STRING
);
1572 m_smallImageList
= new wxImageList(16, 16);
1575 m_smallImageList
->Add(wxArtProvider::GetBitmap(wxART_FOLDER
,
1579 m_smallImageList
->Add(wxArtProvider::GetBitmap(wxART_FOLDER_OPEN
,
1584 // GTK24 uses this icon in the file open dialog
1585 m_smallImageList
->Add(wxArtProvider::GetBitmap(wxART_HARDDISK
,
1589 m_smallImageList
->Add(wxIcon(file_icons_tbl_computer_xpm
));
1592 m_smallImageList
->Add(wxArtProvider::GetBitmap(wxART_HARDDISK
,
1596 m_smallImageList
->Add(wxArtProvider::GetBitmap(wxART_CDROM
,
1600 m_smallImageList
->Add(wxArtProvider::GetBitmap(wxART_FLOPPY
,
1604 m_smallImageList
->Add(wxArtProvider::GetBitmap(wxART_REMOVABLE
,
1608 m_smallImageList
->Add(wxArtProvider::GetBitmap(wxART_NORMAL_FILE
,
1612 if (GetIconID(wxEmptyString
, wxT("application/x-executable")) == file
)
1614 m_smallImageList
->Add(wxArtProvider::GetBitmap(wxART_EXECUTABLE_FILE
,
1617 delete m_HashTable
->Get(wxT("exe"));
1618 m_HashTable
->Delete(wxT("exe"));
1619 m_HashTable
->Put(wxT("exe"), new wxFileIconEntry(executable
));
1621 /* else put into list by GetIconID
1622 (KDE defines application/x-executable for *.exe and has nice icon)
1626 wxImageList
*wxFileIconsTable::GetSmallImageList()
1628 if (!m_smallImageList
)
1631 return m_smallImageList
;
1634 #if wxUSE_MIMETYPE && wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
1635 // VS: we don't need this function w/o wxMimeTypesManager because we'll only have
1636 // one icon and we won't resize it
1638 static wxBitmap
CreateAntialiasedBitmap(const wxImage
& img
)
1640 const unsigned int size
= 16;
1642 wxImage
smallimg (size
, size
);
1643 unsigned char *p1
, *p2
, *ps
;
1644 unsigned char mr
= img
.GetMaskRed(),
1645 mg
= img
.GetMaskGreen(),
1646 mb
= img
.GetMaskBlue();
1649 unsigned sr
, sg
, sb
, smask
;
1651 p1
= img
.GetData(), p2
= img
.GetData() + 3 * size
*2, ps
= smallimg
.GetData();
1652 smallimg
.SetMaskColour(mr
, mr
, mr
);
1654 for (y
= 0; y
< size
; y
++)
1656 for (x
= 0; x
< size
; x
++)
1658 sr
= sg
= sb
= smask
= 0;
1659 if (p1
[0] != mr
|| p1
[1] != mg
|| p1
[2] != mb
)
1660 sr
+= p1
[0], sg
+= p1
[1], sb
+= p1
[2];
1663 if (p1
[0] != mr
|| p1
[1] != mg
|| p1
[2] != mb
)
1664 sr
+= p1
[0], sg
+= p1
[1], sb
+= p1
[2];
1667 if (p2
[0] != mr
|| p2
[1] != mg
|| p2
[2] != mb
)
1668 sr
+= p2
[0], sg
+= p2
[1], sb
+= p2
[2];
1671 if (p2
[0] != mr
|| p2
[1] != mg
|| p2
[2] != mb
)
1672 sr
+= p2
[0], sg
+= p2
[1], sb
+= p2
[2];
1677 ps
[0] = ps
[1] = ps
[2] = mr
;
1680 ps
[0] = (unsigned char)(sr
>> 2);
1681 ps
[1] = (unsigned char)(sg
>> 2);
1682 ps
[2] = (unsigned char)(sb
>> 2);
1686 p1
+= size
*2 * 3, p2
+= size
*2 * 3;
1689 return wxBitmap(smallimg
);
1692 // This function is currently not unused anymore
1694 // finds empty borders and return non-empty area of image:
1695 static wxImage
CutEmptyBorders(const wxImage
& img
)
1697 unsigned char mr
= img
.GetMaskRed(),
1698 mg
= img
.GetMaskGreen(),
1699 mb
= img
.GetMaskBlue();
1700 unsigned char *dt
= img
.GetData(), *dttmp
;
1701 unsigned w
= img
.GetWidth(), h
= img
.GetHeight();
1703 unsigned top
, bottom
, left
, right
, i
;
1706 #define MK_DTTMP(x,y) dttmp = dt + ((x + y * w) * 3)
1707 #define NOEMPTY_PIX(empt) if (dttmp[0] != mr || dttmp[1] != mg || dttmp[2] != mb) {empt = false; break;}
1709 for (empt
= true, top
= 0; empt
&& top
< h
; top
++)
1712 for (i
= 0; i
< w
; i
++, dttmp
+=3)
1715 for (empt
= true, bottom
= h
-1; empt
&& bottom
> top
; bottom
--)
1717 MK_DTTMP(0, bottom
);
1718 for (i
= 0; i
< w
; i
++, dttmp
+=3)
1721 for (empt
= true, left
= 0; empt
&& left
< w
; left
++)
1724 for (i
= 0; i
< h
; i
++, dttmp
+=3*w
)
1727 for (empt
= true, right
= w
-1; empt
&& right
> left
; right
--)
1730 for (i
= 0; i
< h
; i
++, dttmp
+=3*w
)
1733 top
--, left
--, bottom
++, right
++;
1735 return img
.GetSubImage(wxRect(left
, top
, right
- left
+ 1, bottom
- top
+ 1));
1739 #endif // wxUSE_MIMETYPE
1741 int wxFileIconsTable::GetIconID(const wxString
& extension
, const wxString
& mime
)
1743 if (!m_smallImageList
)
1747 if (!extension
.empty())
1749 wxFileIconEntry
*entry
= (wxFileIconEntry
*) m_HashTable
->Get(extension
);
1750 if (entry
) return (entry
-> id
);
1753 wxFileType
*ft
= (mime
.empty()) ?
1754 wxTheMimeTypesManager
-> GetFileTypeFromExtension(extension
) :
1755 wxTheMimeTypesManager
-> GetFileTypeFromMimeType(mime
);
1757 wxIconLocation iconLoc
;
1762 if ( ft
&& ft
->GetIcon(&iconLoc
) )
1764 ic
= wxIcon( iconLoc
);
1773 m_HashTable
->Put(extension
, new wxFileIconEntry(newid
));
1778 bmp
.CopyFromIcon(ic
);
1783 m_HashTable
->Put(extension
, new wxFileIconEntry(newid
));
1787 const unsigned int size
= 16;
1789 int id
= m_smallImageList
->GetImageCount();
1790 if ((bmp
.GetWidth() == (int) size
) && (bmp
.GetHeight() == (int) size
))
1792 m_smallImageList
->Add(bmp
);
1794 #if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
1797 wxImage img
= bmp
.ConvertToImage();
1799 if ((img
.GetWidth() != size
*2) || (img
.GetHeight() != size
*2))
1800 // m_smallImageList->Add(CreateAntialiasedBitmap(CutEmptyBorders(img).Rescale(size*2, size*2)));
1801 m_smallImageList
->Add(CreateAntialiasedBitmap(img
.Rescale(size
*2, size
*2)));
1803 m_smallImageList
->Add(CreateAntialiasedBitmap(img
));
1805 #endif // wxUSE_IMAGE
1807 m_HashTable
->Put(extension
, new wxFileIconEntry(id
));
1810 #else // !wxUSE_MIMETYPE
1813 if (extension
== wxT("exe"))
1817 #endif // wxUSE_MIMETYPE/!wxUSE_MIMETYPE
1820 #endif // wxUSE_DIRDLG || wxUSE_FILEDLG