1 /////////////////////////////////////////////////////////////////////////////
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dirctrlg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/dialog.h"
27 #include "wx/button.h"
28 #include "wx/layout.h"
29 #include "wx/msgdlg.h"
30 #include "wx/textdlg.h"
31 #include "wx/filefn.h"
32 #include "wx/cmndata.h"
33 #include "wx/gdicmn.h"
35 #include "wx/imaglist.h"
39 #include "wx/tokenzr.h"
41 #include "wx/settings.h"
44 #include "wx/statline.h"
47 #include "wx/generic/dirctrlg.h"
55 // If compiled under Windows, this macro can cause problems
60 #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW
62 static char * icon1_xpm
[] = {
63 /* width height ncolors chars_per_pixel */
91 static char * icon2_xpm
[] = {
92 /* width height ncolors chars_per_pixel */
120 static char * icon3_xpm
[] = {
121 /* width height ncolors chars_per_pixel */
146 static char * icon4_xpm
[] = {
173 static char * icon5_xpm
[] = {
200 static char *icon6_xpm
[] = {
230 static char * icon7_xpm
[] = {
257 static char * icon8_xpm
[] = {
284 static const int ID_DIRCTRL
= 1000;
285 static const int ID_TEXTCTRL
= 1001;
286 static const int ID_OK
= 1002;
287 static const int ID_CANCEL
= 1003;
288 static const int ID_NEW
= 1004;
289 //static const int ID_CHECK = 1005;
292 static bool wxIsDriveAvailable(const wxString dirName
)
295 UINT errorMode
= SetErrorMode(SEM_FAILCRITICALERRORS
| SEM_NOOPENFILEERRORBOX
);
299 // Check if this is a root directory and if so,
300 // whether the drive is avaiable.
301 if (dirName
.Len() == 3 && dirName
[1] == wxT(':'))
303 wxString
dirNameLower(dirName
.Lower());
304 int currentDrive
= _getdrive();
305 int thisDrive
= (int) (dirNameLower
[0] - 'a' + 1) ;
306 int err
= _chdrive( thisDrive
) ;
307 _chdrive( currentDrive
);
315 (void) SetErrorMode(errorMode
);
322 //-----------------------------------------------------------------------------
324 //-----------------------------------------------------------------------------
326 wxDirItemDataEx::wxDirItemDataEx(const wxString
& path
, const wxString
& name
,
331 /* Insert logic to detect hidden files here
332 * In UnixLand we just check whether the first char is a dot
333 * For FileNameFromPath read LastDirNameInThisPath ;-) */
334 // m_isHidden = (bool)(wxFileNameFromPath(*m_path)[0] == '.');
336 m_hasSubDirs
= HasSubDirs();
337 m_isExpanded
= FALSE
;
341 wxDirItemDataEx::~wxDirItemDataEx()
345 void wxDirItemDataEx::SetNewDirName( wxString path
)
348 m_name
= wxFileNameFromPath( path
);
351 bool wxDirItemDataEx::HasSubDirs()
353 if (m_path
.IsEmpty())
356 // On WIN32, must check if this volume is mounted or
357 // we get an error dialog for e.g. drive a:
359 if (!wxIsDriveAvailable(m_path
))
363 wxString search
= m_path
;
365 if (m_path
.Last() != wxFILE_SEP_PATH
)
367 search
+= wxString(wxFILE_SEP_PATH
);
372 wxString path
= wxFindFirstFile( search
, wxDIR
);
373 return (bool)(!path
.IsNull());
376 //-----------------------------------------------------------------------------
378 //-----------------------------------------------------------------------------
380 IMPLEMENT_DYNAMIC_CLASS(wxGenericDirCtrl
, wxControl
)
382 BEGIN_EVENT_TABLE(wxGenericDirCtrl
, wxControl
)
383 EVT_TREE_ITEM_EXPANDING (-1, wxGenericDirCtrl::OnExpandItem
)
384 EVT_TREE_ITEM_COLLAPSED (-1, wxGenericDirCtrl::OnCollapseItem
)
385 EVT_TREE_BEGIN_LABEL_EDIT (-1, wxGenericDirCtrl::OnBeginEditItem
)
386 EVT_TREE_END_LABEL_EDIT (-1, wxGenericDirCtrl::OnEndEditItem
)
387 EVT_SIZE (wxGenericDirCtrl::OnSize
)
390 wxGenericDirCtrl::wxGenericDirCtrl(void)
395 bool wxGenericDirCtrl::Create(wxWindow
*parent
,
401 const wxString
& filter
,
403 const wxString
& name
)
405 if (!wxControl::Create(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
408 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
412 long treeStyle
= wxTR_HAS_BUTTONS
;
413 if ((style
& wxDIRCTRL_3D_INTERNAL
) == 0)
414 treeStyle
|= wxNO_BORDER
;
416 long filterStyle
= 0;
417 if ((style
& wxDIRCTRL_3D_INTERNAL
) == 0)
418 filterStyle
|= wxNO_BORDER
;
420 m_treeCtrl
= new wxTreeCtrl(this, wxID_TREECTRL
, pos
, size
, treeStyle
);
422 if (!filter
.IsEmpty() && (style
& wxDIRCTRL_SHOW_FILTERS
))
423 m_filterListCtrl
= new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL
, wxDefaultPosition
, wxDefaultSize
, filterStyle
);
428 SetFilterIndex(defaultFilter
);
430 if (m_filterListCtrl
)
431 m_filterListCtrl
->FillFilterList(filter
, defaultFilter
);
433 m_imageList
= new wxImageList(16, 16, TRUE
);
434 #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW
435 m_imageList
->Add(wxIcon(icon1_xpm
));
436 m_imageList
->Add(wxIcon(icon2_xpm
));
437 m_imageList
->Add(wxIcon(icon3_xpm
));
438 m_imageList
->Add(wxIcon(icon4_xpm
));
439 m_imageList
->Add(wxIcon(icon5_xpm
));
440 m_imageList
->Add(wxIcon(icon6_xpm
));
441 m_imageList
->Add(wxIcon(icon7_xpm
));
442 m_imageList
->Add(wxIcon(icon8_xpm
));
443 #elif defined(__WXMSW__)
444 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CLOSED_FOLDER"), wxBITMAP_TYPE_RESOURCE
));
445 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_OPEN_FOLDER"), wxBITMAP_TYPE_RESOURCE
));
446 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FILE"), wxBITMAP_TYPE_RESOURCE
));
447 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_COMPUTER"), wxBITMAP_TYPE_RESOURCE
));
448 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_DRIVE"), wxBITMAP_TYPE_RESOURCE
));
449 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CDROM"), wxBITMAP_TYPE_RESOURCE
));
450 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FLOPPY"), wxBITMAP_TYPE_RESOURCE
));
451 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_REMOVEABLE"), wxBITMAP_TYPE_RESOURCE
));
453 #error "Sorry, we don't have icons available for this platforms."
455 m_treeCtrl
->SetImageList(m_imageList
);
457 m_showHidden
= FALSE
;
458 wxDirItemDataEx
* rootData
= new wxDirItemDataEx(wxT(""), wxT(""), TRUE
);
463 rootName
= _("Computer");
465 rootName
= _("Sections");
468 m_rootId
= m_treeCtrl
->AddRoot( rootName
, 3, -1, rootData
);
469 m_treeCtrl
->SetItemHasChildren(m_rootId
);
470 m_treeCtrl
->Expand(m_rootId
); // automatically expand first level
472 // Expand and select the default path
473 if (!m_defaultPath
.IsEmpty())
474 ExpandPath(m_defaultPath
);
481 wxGenericDirCtrl::~wxGenericDirCtrl()
483 m_treeCtrl
->SetImageList(NULL
);
487 void wxGenericDirCtrl::Init()
489 m_showHidden
= FALSE
;
492 m_currentFilterStr
= wxEmptyString
; // Default: any file
494 m_filterListCtrl
= NULL
;
497 void wxGenericDirCtrl::AddSection(const wxString
& path
, const wxString
& name
, int imageId
)
499 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,name
,TRUE
);
502 // Windows: sections are displayed as drives
503 wxTreeItemId id
= m_treeCtrl
->AppendItem( m_rootId
, name
, imageId
, -1, dir_item
);
505 // Unix: sections are displayed as folders
506 wxTreeItemId id
= m_treeCtrl
->AppendItem( m_rootId
, name
, 0, -1, dir_item
);
507 m_treeCtrl
->SetItemImage( id
, 1, wxTreeItemIcon_Expanded
);
509 // TODO: other operating systems.
511 m_treeCtrl
->SetItemHasChildren(id
);
514 void wxGenericDirCtrl::SetupSections()
519 wxChar driveBuffer
[256];
520 size_t n
= (size_t) GetLogicalDriveStrings(255, driveBuffer
);
525 path
.Printf(wxT("%c:\\"), driveBuffer
[i
]);
526 name
.Printf(wxT("(%c:)"), driveBuffer
[i
]);
529 int driveType
= ::GetDriveType(path
);
532 case DRIVE_REMOVABLE
:
533 if (path
== wxT("a:\\") || path
== wxT("b:\\"))
534 imageId
= 6; // Floppy
552 AddSection(path
, name
, imageId
);
554 while (driveBuffer
[i
] != wxT('\0'))
557 if (driveBuffer
[i
] == wxT('\0'))
564 /* If we can switch to the drive, it exists. */
565 for( drive
= 1; drive
<= 26; drive
++ )
568 path
.Printf(wxT("%c:\\"), (char) (drive
+ 'a' - 1));
569 name
.Printf(wxT("(%c:)"), (char) (drive
+ 'a' - 1));
571 if (wxIsDriveAvailable(path
))
574 AddSection(path
, name
);
580 AddSection(wxT("/"), _("The Computer"), 0);
581 AddSection(wxGetHomeDir(), _("My Home"), 0 );
582 AddSection(wxT("/mnt"), _("Mounted Devices"), 0 );
583 AddSection(wxT("/usr/local"), _("User Local"), 0 );
584 AddSection(wxT("/usr"), _("User"), 0 );
585 AddSection(wxT("/var"), _("Variables"), 0 );
586 AddSection(wxT("/etc"), _("Etcetera"), 0 );
587 AddSection(wxT("/tmp"), _("Temporary"), 0 );
591 void wxGenericDirCtrl::OnBeginEditItem(wxTreeEvent
&event
)
593 // don't rename the main entry "Sections"
594 if (event
.GetItem() == m_rootId
)
600 // don't rename the individual sections
601 if (m_treeCtrl
->GetParent( event
.GetItem() ) == m_rootId
)
608 void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent
&event
)
610 if ((event
.GetLabel().IsEmpty()) ||
611 (event
.GetLabel() == _(".")) ||
612 (event
.GetLabel() == _("..")) ||
613 (event
.GetLabel().First( wxT("/") ) != wxNOT_FOUND
))
615 wxMessageDialog
dialog(this, _("Illegal directory name."), _("Error"), wxOK
| wxICON_ERROR
);
621 wxTreeItemId id
= event
.GetItem();
622 wxDirItemDataEx
*data
= (wxDirItemDataEx
*)m_treeCtrl
->GetItemData( id
);
625 wxString
new_name( wxPathOnly( data
->m_path
) );
626 new_name
+= wxString(wxFILE_SEP_PATH
);
627 new_name
+= event
.GetLabel();
631 if (wxFileExists(new_name
))
633 wxMessageDialog
dialog(this, _("File name exists already."), _("Error"), wxOK
| wxICON_ERROR
);
638 if (wxRenameFile(data
->m_path
,new_name
))
640 data
->SetNewDirName( new_name
);
644 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
650 void wxGenericDirCtrl::OnExpandItem(wxTreeEvent
&event
)
652 wxTreeItemId parentId
= event
.GetItem();
657 void wxGenericDirCtrl::OnCollapseItem(wxTreeEvent
&event
)
659 wxTreeItemId child
, parent
= event
.GetItem();
661 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(event
.GetItem());
662 if (!data
->m_isExpanded
)
665 data
->m_isExpanded
= FALSE
;
667 /* Workaround because DeleteChildren has disapeared (why?) and
668 * CollapseAndReset doesn't work as advertised (deletes parent too) */
669 child
= m_treeCtrl
->GetFirstChild(parent
, cookie
);
672 m_treeCtrl
->Delete(child
);
673 /* Not GetNextChild below, because the cookie mechanism can't
674 * handle disappearing children! */
675 child
= m_treeCtrl
->GetFirstChild(parent
, cookie
);
679 void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId
)
681 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(parentId
);
683 if (data
->m_isExpanded
)
686 data
->m_isExpanded
= TRUE
;
688 if (parentId
== m_rootId
)
696 wxString search
,path
,filename
;
698 wxString
dirName(data
->m_path
);
701 // Check if this is a root directory and if so,
702 // whether the drive is avaiable.
703 if (!wxIsDriveAvailable(dirName
))
705 data
->m_isExpanded
= FALSE
;
706 wxMessageBox(wxT("Sorry, this drive is not available."));
711 // This may take a longish time. Go to busy cursor
715 if (dirName
.Last() == ':')
716 dirName
+= wxString(wxFILE_SEP_PATH
);
720 wxArrayString filenames
;
723 wxString eachFilename
;
729 if (d
.GetFirst(& eachFilename
, wxEmptyString
, wxDIR_DIRS
))
733 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
735 dirs
.Add(eachFilename
);
738 while (d
.GetNext(& eachFilename
)) ;
743 // Now do the filenames -- but only if we're allowed to
744 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
750 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, wxDIR_FILES
))
754 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
756 filenames
.Add(eachFilename
);
759 while (d
.GetNext(& eachFilename
)) ;
765 // Add the sorted dirs
767 for (i
= 0; i
< dirs
.Count(); i
++)
769 wxString
eachFilename(dirs
[i
]);
771 if (path
.Last() != wxFILE_SEP_PATH
)
772 path
+= wxString(wxFILE_SEP_PATH
);
773 path
+= eachFilename
;
775 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,TRUE
);
776 wxTreeItemId id
= m_treeCtrl
->AppendItem( parentId
, eachFilename
, 0, -1, dir_item
);
777 m_treeCtrl
->SetItemImage( id
, 1, wxTreeItemIcon_Expanded
);
779 // Has this got any children? If so, make it expandable.
780 int options
= wxDIR_DEFAULT
;
781 if (GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) // If only showing dirs, then we specify dirs only here
783 options
= wxDIR_DIRS
;
788 // Have to test for wxDIR_DIRS separately in case m_currentFilterStr is non-empty and
789 // and filters out any directories
790 if (dir2
.GetFirst(& str
, m_currentFilterStr
, options
) || dir2
.GetFirst(& str
, wxEmptyString
, wxDIR_DIRS
))
792 m_treeCtrl
->SetItemHasChildren(id
);
796 // Add the sorted filenames
797 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
799 for (i
= 0; i
< filenames
.Count(); i
++)
801 wxString
eachFilename(filenames
[i
]);
803 if (path
.Last() != wxFILE_SEP_PATH
)
804 path
+= wxString(wxFILE_SEP_PATH
);
805 path
+= eachFilename
;
806 //path = dirName + wxString(wxT("/")) + eachFilename;
807 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,FALSE
);
808 (void)m_treeCtrl
->AppendItem( parentId
, eachFilename
, 2, -1, dir_item
);
813 // Find the child that matches the first part of 'path'.
814 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
815 // then the child for /usr is returned.
816 wxTreeItemId
wxGenericDirCtrl::FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
)
818 wxString
path2(path
);
820 // Make sure all separators are as per the current platform
821 path2
.Replace(wxT("\\"), wxString(wxFILE_SEP_PATH
));
822 path2
.Replace(wxT("/"), wxString(wxFILE_SEP_PATH
));
824 // Append a separator to foil bogus substring matching
825 path2
+= wxString(wxFILE_SEP_PATH
);
827 // In MSW, case is not significant
833 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(parentId
, cookie
);
836 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
838 if (data
&& data
->m_path
!= "")
840 wxString
childPath(data
->m_path
);
841 if (childPath
.Last() != wxFILE_SEP_PATH
)
842 childPath
+= wxString(wxFILE_SEP_PATH
);
844 // In MSW, case is not significant
846 childPath
.MakeLower();
849 if (childPath
.Len() <= path2
.Len())
851 wxString path3
= path2
.Mid(0, childPath
.Len());
852 if (childPath
== path3
)
854 if (path3
.Len() == path2
.Len())
863 childId
= m_treeCtrl
->GetNextChild(childId
, cookie
);
865 wxTreeItemId invalid
;
869 // Try to expand as much of the given path as possible,
870 // and select the given tree item.
871 bool wxGenericDirCtrl::ExpandPath(const wxString
& path
)
874 wxTreeItemId id
= FindChild(m_rootId
, path
, done
);
875 wxTreeItemId lastId
= id
; // The last non-zero id
876 while ((id
> 0) && !done
)
880 id
= FindChild(id
, path
, done
);
886 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(lastId
);
889 m_treeCtrl
->Expand(lastId
);
891 if ((GetWindowStyle() & wxDIRCTRL_SELECT_FIRST
) && data
->m_isDir
)
893 // Find the first file in this directory
895 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(lastId
, cookie
);
896 bool selectedChild
= FALSE
;
899 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
901 if (data
&& data
->m_path
!= "" && !data
->m_isDir
)
903 m_treeCtrl
->SelectItem(childId
);
904 m_treeCtrl
->EnsureVisible(childId
);
905 selectedChild
= TRUE
;
908 childId
= m_treeCtrl
->GetNextChild(lastId
, cookie
);
912 m_treeCtrl
->SelectItem(lastId
);
913 m_treeCtrl
->EnsureVisible(lastId
);
918 m_treeCtrl
->SelectItem(lastId
);
919 m_treeCtrl
->EnsureVisible(lastId
);
928 wxString
wxGenericDirCtrl::GetPath() const
930 wxTreeItemId id
= m_treeCtrl
->GetSelection();
933 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
937 return wxEmptyString
;
940 wxString
wxGenericDirCtrl::GetFilePath() const
942 wxTreeItemId id
= m_treeCtrl
->GetSelection();
945 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
947 return wxEmptyString
;
952 return wxEmptyString
;
955 void wxGenericDirCtrl::SetPath(const wxString
& path
)
957 m_defaultPath
= path
;
964 void wxGenericDirCtrl::FindChildFiles(wxTreeItemId id
, int dirFlags
, wxArrayString
& filenames
)
966 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
968 // This may take a longish time. Go to busy cursor
973 wxString search
,path
,filename
;
975 wxString
dirName(data
->m_path
);
978 if (dirName
.Last() == ':')
979 dirName
+= wxString(wxFILE_SEP_PATH
);
983 wxString eachFilename
;
989 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, dirFlags
))
993 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
995 filenames
.Add(eachFilename
);
998 while (d
.GetNext(& eachFilename
)) ;
1004 void wxGenericDirCtrl::SetFilterIndex(int n
)
1006 m_currentFilter
= n
;
1009 if (ExtractWildcard(m_filter
, n
, f
, d
))
1010 m_currentFilterStr
= f
;
1012 m_currentFilterStr
= wxT("*.*");
1015 void wxGenericDirCtrl::SetFilter(const wxString
& filter
)
1020 if (ExtractWildcard(m_filter
, m_currentFilter
, f
, d
))
1021 m_currentFilterStr
= f
;
1023 m_currentFilterStr
= wxT("*.*");
1026 // Extract description and actual filter from overall filter string
1027 bool wxGenericDirCtrl::ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
)
1029 wxArrayString filters
, descriptions
;
1030 int count
= ParseFilter(filterStr
, filters
, descriptions
);
1031 if (count
> 0 && n
< count
)
1033 filter
= filters
[n
];
1034 description
= descriptions
[n
];
1041 // Parses the global filter, returning the number of filters.
1042 // Returns 0 if none or if there's a problem.
1043 // filterStr is in the form:
1045 // "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
1047 int wxGenericDirCtrl::ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
)
1049 wxString
str(filterStr
);
1051 wxString description
, filter
;
1053 bool finished
= FALSE
;
1056 pos
= str
.Find(wxT('|'));
1058 return 0; // Problem
1059 description
= str
.Left(pos
);
1060 str
= str
.Mid(pos
+1);
1061 pos
= str
.Find(wxT('|'));
1069 filter
= str
.Left(pos
);
1070 str
= str
.Mid(pos
+1);
1072 descriptions
.Add(description
);
1073 filters
.Add(filter
);
1077 return filters
.Count();
1080 void wxGenericDirCtrl::DoResize()
1082 wxSize sz
= GetClientSize();
1083 int verticalSpacing
= 3;
1087 if (m_filterListCtrl
)
1089 filterSz
= m_filterListCtrl
->GetSize();
1090 sz
.y
-= (filterSz
.y
+ verticalSpacing
);
1092 m_treeCtrl
->SetSize(0, 0, sz
.x
, sz
.y
);
1093 if (m_filterListCtrl
)
1095 m_filterListCtrl
->SetSize(0, sz
.y
+ verticalSpacing
, sz
.x
, filterSz
.y
);
1096 // Don't know why, but this needs refreshing after a resize (wxMSW)
1097 m_filterListCtrl
->Refresh();
1103 void wxGenericDirCtrl::OnSize(wxSizeEvent
&event
)
1108 //-----------------------------------------------------------------------------
1109 // wxDirFilterListCtrl
1110 //-----------------------------------------------------------------------------
1112 IMPLEMENT_CLASS(wxDirFilterListCtrl
, wxChoice
)
1114 BEGIN_EVENT_TABLE(wxDirFilterListCtrl
, wxChoice
)
1115 EVT_CHOICE(-1, wxDirFilterListCtrl::OnSelFilter
)
1118 bool wxDirFilterListCtrl::Create(wxGenericDirCtrl
* parent
, const wxWindowID id
,
1124 return wxChoice::Create(parent
, id
, pos
, size
, 0, NULL
, style
);
1127 void wxDirFilterListCtrl::Init()
1132 void wxDirFilterListCtrl::OnSelFilter(wxCommandEvent
& event
)
1134 int sel
= GetSelection();
1136 wxString currentPath
= m_dirCtrl
->GetPath();
1138 m_dirCtrl
->SetFilterIndex(sel
);
1140 // If the filter has changed, the view is out of date, so
1141 // collapse the tree.
1142 m_dirCtrl
->GetTreeCtrl()->Collapse(m_dirCtrl
->GetRootId());
1143 m_dirCtrl
->GetTreeCtrl()->Expand(m_dirCtrl
->GetRootId());
1145 // Try to restore the selection, or at least the directory
1146 m_dirCtrl
->ExpandPath(currentPath
);
1149 void wxDirFilterListCtrl::FillFilterList(const wxString
& filter
, int defaultFilter
)
1152 wxArrayString descriptions
, filters
;
1153 size_t n
= (size_t) m_dirCtrl
->ParseFilter(filter
, filters
, descriptions
);
1155 if (n
> 0 && defaultFilter
< (int) n
)
1158 for (i
= 0; i
< n
; i
++)
1159 Append(descriptions
[i
]);
1160 SetSelection(defaultFilter
);
1164 // wxGenericDirDialog implementation
1165 // This should be moved into dirdlgg.cpp eventually
1167 BEGIN_EVENT_TABLE(wxGenericDirDialog
, wxDialog
)
1168 EVT_BUTTON(wxID_OK
, wxGenericDirDialog::OnOK
)
1169 EVT_CLOSE(wxGenericDirDialog::OnCloseWindow
)
1172 wxGenericDirDialog::wxGenericDirDialog(wxWindow
* parent
, const wxString
& title
,
1173 const wxString
& defaultPath
, long style
, const wxPoint
& pos
, const wxSize
& sz
, const wxString
& name
):
1174 wxDialog(parent
, ID_DIRCTRL
, title
, pos
, sz
, style
, name
)
1176 wxBusyCursor cursor
;
1178 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
1181 m_dirCtrl
= new wxGenericDirCtrl(this, ID_DIRCTRL
,
1182 defaultPath
, wxPoint(5, 5),
1183 wxSize(300, 200), wxDIRCTRL_DIR_ONLY
);
1185 topsizer
->Add( m_dirCtrl
, 1, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
1187 // 2) TODO: text control for entering path?
1191 topsizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
1195 wxSizer
* buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
1196 wxButton
* okButton
= new wxButton(this, wxID_OK
, _("OK"));
1197 buttonsizer
->Add( okButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1198 wxButton
* cancelButton
= new wxButton(this, wxID_CANCEL
, _("Cancel"));
1199 buttonsizer
->Add( cancelButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1201 /* TODO: new directory button
1202 wxButton* newButton = new wxButton( this, ID_NEW, _("New...") );
1203 buttonsizer->Add( newButton, 0, wxLEFT|wxRIGHT, 10 );
1205 topsizer
->Add( buttonsizer
, 0, wxALL
| wxCENTER
, 10 );
1207 okButton
->SetDefault();
1208 m_dirCtrl
->SetFocus();
1210 SetAutoLayout( TRUE
);
1211 SetSizer( topsizer
);
1213 topsizer
->SetSizeHints( this );
1214 topsizer
->Fit( this );
1219 void wxGenericDirDialog::OnCloseWindow(wxCloseEvent
& event
)
1221 EndModal(wxID_CANCEL
);
1224 void wxGenericDirDialog::OnOK(wxCommandEvent
& event
)
1229 void wxGenericDirDialog::SetPath(const wxString
& path
)
1231 m_dirCtrl
->SetPath(path
);
1234 wxString
wxGenericDirDialog::GetPath(void) const
1236 return m_dirCtrl
->GetPath();