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"
56 // If compiled under Windows, this macro can cause problems
61 #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW
63 static char * icon1_xpm
[] = {
64 /* width height ncolors chars_per_pixel */
92 static char * icon2_xpm
[] = {
93 /* width height ncolors chars_per_pixel */
121 static char * icon3_xpm
[] = {
122 /* width height ncolors chars_per_pixel */
147 static char * icon4_xpm
[] = {
174 static char * icon5_xpm
[] = {
201 static char *icon6_xpm
[] = {
231 static char * icon7_xpm
[] = {
258 static char * icon8_xpm
[] = {
285 static const int ID_DIRCTRL
= 1000;
286 static const int ID_TEXTCTRL
= 1001;
287 static const int ID_OK
= 1002;
288 static const int ID_CANCEL
= 1003;
289 static const int ID_NEW
= 1004;
290 //static const int ID_CHECK = 1005;
293 static bool wxIsDriveAvailable(const wxString dirName
)
296 UINT errorMode
= SetErrorMode(SEM_FAILCRITICALERRORS
| SEM_NOOPENFILEERRORBOX
);
300 // Check if this is a root directory and if so,
301 // whether the drive is avaiable.
302 if (dirName
.Len() == 3 && dirName
[(size_t)1] == wxT(':'))
304 wxString
dirNameLower(dirName
.Lower());
305 int currentDrive
= _getdrive();
306 int thisDrive
= (int) (dirNameLower
[(size_t)0] - 'a' + 1) ;
307 int err
= _chdrive( thisDrive
) ;
308 _chdrive( currentDrive
);
316 (void) SetErrorMode(errorMode
);
323 //-----------------------------------------------------------------------------
325 //-----------------------------------------------------------------------------
327 wxDirItemDataEx::wxDirItemDataEx(const wxString
& path
, const wxString
& name
,
332 /* Insert logic to detect hidden files here
333 * In UnixLand we just check whether the first char is a dot
334 * For FileNameFromPath read LastDirNameInThisPath ;-) */
335 // m_isHidden = (bool)(wxFileNameFromPath(*m_path)[0] == '.');
337 m_hasSubDirs
= HasSubDirs();
338 m_isExpanded
= FALSE
;
342 wxDirItemDataEx::~wxDirItemDataEx()
346 void wxDirItemDataEx::SetNewDirName( wxString path
)
349 m_name
= wxFileNameFromPath( path
);
352 bool wxDirItemDataEx::HasSubDirs()
354 if (m_path
.IsEmpty())
357 // On WIN32, must check if this volume is mounted or
358 // we get an error dialog for e.g. drive a:
360 if (!wxIsDriveAvailable(m_path
))
364 wxString search
= m_path
;
366 if (m_path
.Last() != wxFILE_SEP_PATH
)
368 search
+= wxString(wxFILE_SEP_PATH
);
373 wxString path
= wxFindFirstFile( search
, wxDIR
);
374 return (bool)(!path
.IsNull());
377 //-----------------------------------------------------------------------------
379 //-----------------------------------------------------------------------------
381 IMPLEMENT_DYNAMIC_CLASS(wxGenericDirCtrl
, wxControl
)
383 BEGIN_EVENT_TABLE(wxGenericDirCtrl
, wxControl
)
384 EVT_TREE_ITEM_EXPANDING (-1, wxGenericDirCtrl::OnExpandItem
)
385 EVT_TREE_ITEM_COLLAPSED (-1, wxGenericDirCtrl::OnCollapseItem
)
386 EVT_TREE_BEGIN_LABEL_EDIT (-1, wxGenericDirCtrl::OnBeginEditItem
)
387 EVT_TREE_END_LABEL_EDIT (-1, wxGenericDirCtrl::OnEndEditItem
)
388 EVT_SIZE (wxGenericDirCtrl::OnSize
)
391 wxGenericDirCtrl::wxGenericDirCtrl(void)
396 bool wxGenericDirCtrl::Create(wxWindow
*parent
,
402 const wxString
& filter
,
404 const wxString
& name
)
406 if (!wxControl::Create(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
409 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
413 long treeStyle
= wxTR_HAS_BUTTONS
;
414 if ((style
& wxDIRCTRL_3D_INTERNAL
) == 0)
415 treeStyle
|= wxNO_BORDER
;
417 long filterStyle
= 0;
418 if ((style
& wxDIRCTRL_3D_INTERNAL
) == 0)
419 filterStyle
|= wxNO_BORDER
;
421 m_treeCtrl
= new wxTreeCtrl(this, wxID_TREECTRL
, pos
, size
, treeStyle
);
423 if (!filter
.IsEmpty() && (style
& wxDIRCTRL_SHOW_FILTERS
))
424 m_filterListCtrl
= new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL
, wxDefaultPosition
, wxDefaultSize
, filterStyle
);
429 SetFilterIndex(defaultFilter
);
431 if (m_filterListCtrl
)
432 m_filterListCtrl
->FillFilterList(filter
, defaultFilter
);
434 m_imageList
= new wxImageList(16, 16, TRUE
);
435 #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW
436 m_imageList
->Add(wxIcon(icon1_xpm
));
437 m_imageList
->Add(wxIcon(icon2_xpm
));
438 m_imageList
->Add(wxIcon(icon3_xpm
));
439 m_imageList
->Add(wxIcon(icon4_xpm
));
440 m_imageList
->Add(wxIcon(icon5_xpm
));
441 m_imageList
->Add(wxIcon(icon6_xpm
));
442 m_imageList
->Add(wxIcon(icon7_xpm
));
443 m_imageList
->Add(wxIcon(icon8_xpm
));
444 #elif defined(__WXMSW__)
445 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CLOSED_FOLDER"), wxBITMAP_TYPE_ICO_RESOURCE
));
446 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_OPEN_FOLDER"), wxBITMAP_TYPE_ICO_RESOURCE
));
447 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FILE"), wxBITMAP_TYPE_ICO_RESOURCE
));
448 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_COMPUTER"), wxBITMAP_TYPE_ICO_RESOURCE
));
449 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_DRIVE"), wxBITMAP_TYPE_ICO_RESOURCE
));
450 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CDROM"), wxBITMAP_TYPE_ICO_RESOURCE
));
451 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FLOPPY"), wxBITMAP_TYPE_ICO_RESOURCE
));
452 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_REMOVEABLE"), wxBITMAP_TYPE_ICO_RESOURCE
));
454 #error "Sorry, we don't have icons available for this platforms."
456 m_treeCtrl
->SetImageList(m_imageList
);
458 m_showHidden
= FALSE
;
459 wxDirItemDataEx
* rootData
= new wxDirItemDataEx(wxT(""), wxT(""), TRUE
);
464 rootName
= _("Computer");
466 rootName
= _("Sections");
469 m_rootId
= m_treeCtrl
->AddRoot( rootName
, 3, -1, rootData
);
470 m_treeCtrl
->SetItemHasChildren(m_rootId
);
471 m_treeCtrl
->Expand(m_rootId
); // automatically expand first level
473 // Expand and select the default path
474 if (!m_defaultPath
.IsEmpty())
475 ExpandPath(m_defaultPath
);
482 wxGenericDirCtrl::~wxGenericDirCtrl()
484 m_treeCtrl
->SetImageList(NULL
);
488 void wxGenericDirCtrl::Init()
490 m_showHidden
= FALSE
;
493 m_currentFilterStr
= wxEmptyString
; // Default: any file
495 m_filterListCtrl
= NULL
;
498 void wxGenericDirCtrl::AddSection(const wxString
& path
, const wxString
& name
, int imageId
)
500 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,name
,TRUE
);
503 // Windows: sections are displayed as drives
504 wxTreeItemId id
= m_treeCtrl
->AppendItem( m_rootId
, name
, imageId
, -1, dir_item
);
506 // Unix: sections are displayed as folders
507 wxTreeItemId id
= m_treeCtrl
->AppendItem( m_rootId
, name
, 0, -1, dir_item
);
508 m_treeCtrl
->SetItemImage( id
, 1, wxTreeItemIcon_Expanded
);
510 // TODO: other operating systems.
512 m_treeCtrl
->SetItemHasChildren(id
);
515 void wxGenericDirCtrl::SetupSections()
520 wxChar driveBuffer
[256];
521 size_t n
= (size_t) GetLogicalDriveStrings(255, driveBuffer
);
526 path
.Printf(wxT("%c:\\"), driveBuffer
[i
]);
527 name
.Printf(wxT("(%c:)"), driveBuffer
[i
]);
530 int driveType
= ::GetDriveType(path
);
533 case DRIVE_REMOVABLE
:
534 if (path
== wxT("a:\\") || path
== wxT("b:\\"))
535 imageId
= 6; // Floppy
553 AddSection(path
, name
, imageId
);
555 while (driveBuffer
[i
] != wxT('\0'))
558 if (driveBuffer
[i
] == wxT('\0'))
565 /* If we can switch to the drive, it exists. */
566 for( drive
= 1; drive
<= 26; drive
++ )
569 path
.Printf(wxT("%c:\\"), (char) (drive
+ 'a' - 1));
570 name
.Printf(wxT("(%c:)"), (char) (drive
+ 'a' - 1));
572 if (wxIsDriveAvailable(path
))
575 AddSection(path
, name
);
581 AddSection(wxT("/"), _("The Computer"), 0);
582 AddSection(wxGetHomeDir(), _("My Home"), 0 );
583 AddSection(wxT("/mnt"), _("Mounted Devices"), 0 );
584 AddSection(wxT("/usr/local"), _("User Local"), 0 );
585 AddSection(wxT("/usr"), _("User"), 0 );
586 AddSection(wxT("/var"), _("Variables"), 0 );
587 AddSection(wxT("/etc"), _("Etcetera"), 0 );
588 AddSection(wxT("/tmp"), _("Temporary"), 0 );
592 void wxGenericDirCtrl::OnBeginEditItem(wxTreeEvent
&event
)
594 // don't rename the main entry "Sections"
595 if (event
.GetItem() == m_rootId
)
601 // don't rename the individual sections
602 if (m_treeCtrl
->GetParent( event
.GetItem() ) == m_rootId
)
609 void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent
&event
)
611 if ((event
.GetLabel().IsEmpty()) ||
612 (event
.GetLabel() == _(".")) ||
613 (event
.GetLabel() == _("..")) ||
614 (event
.GetLabel().First( wxT("/") ) != wxNOT_FOUND
))
616 wxMessageDialog
dialog(this, _("Illegal directory name."), _("Error"), wxOK
| wxICON_ERROR
);
622 wxTreeItemId id
= event
.GetItem();
623 wxDirItemDataEx
*data
= (wxDirItemDataEx
*)m_treeCtrl
->GetItemData( id
);
626 wxString
new_name( wxPathOnly( data
->m_path
) );
627 new_name
+= wxString(wxFILE_SEP_PATH
);
628 new_name
+= event
.GetLabel();
632 if (wxFileExists(new_name
))
634 wxMessageDialog
dialog(this, _("File name exists already."), _("Error"), wxOK
| wxICON_ERROR
);
639 if (wxRenameFile(data
->m_path
,new_name
))
641 data
->SetNewDirName( new_name
);
645 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
651 void wxGenericDirCtrl::OnExpandItem(wxTreeEvent
&event
)
653 wxTreeItemId parentId
= event
.GetItem();
658 void wxGenericDirCtrl::OnCollapseItem(wxTreeEvent
&event
)
660 wxTreeItemId child
, parent
= event
.GetItem();
662 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(event
.GetItem());
663 if (!data
->m_isExpanded
)
666 data
->m_isExpanded
= FALSE
;
668 /* Workaround because DeleteChildren has disapeared (why?) and
669 * CollapseAndReset doesn't work as advertised (deletes parent too) */
670 child
= m_treeCtrl
->GetFirstChild(parent
, cookie
);
673 m_treeCtrl
->Delete(child
);
674 /* Not GetNextChild below, because the cookie mechanism can't
675 * handle disappearing children! */
676 child
= m_treeCtrl
->GetFirstChild(parent
, cookie
);
680 void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId
)
682 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(parentId
);
684 if (data
->m_isExpanded
)
687 data
->m_isExpanded
= TRUE
;
689 if (parentId
== m_rootId
)
697 wxString search
,path
,filename
;
699 wxString
dirName(data
->m_path
);
702 // Check if this is a root directory and if so,
703 // whether the drive is avaiable.
704 if (!wxIsDriveAvailable(dirName
))
706 data
->m_isExpanded
= FALSE
;
707 wxMessageBox(wxT("Sorry, this drive is not available."));
712 // This may take a longish time. Go to busy cursor
716 if (dirName
.Last() == ':')
717 dirName
+= wxString(wxFILE_SEP_PATH
);
721 wxArrayString filenames
;
724 wxString eachFilename
;
731 if (d
.GetFirst(& eachFilename
, wxEmptyString
, wxDIR_DIRS
))
735 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
737 dirs
.Add(eachFilename
);
740 while (d
.GetNext(& eachFilename
)) ;
745 // Now do the filenames -- but only if we're allowed to
746 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
754 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, wxDIR_FILES
))
758 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
760 filenames
.Add(eachFilename
);
763 while (d
.GetNext(& eachFilename
)) ;
769 // Add the sorted dirs
771 for (i
= 0; i
< dirs
.Count(); i
++)
773 wxString
eachFilename(dirs
[i
]);
775 if (path
.Last() != wxFILE_SEP_PATH
)
776 path
+= wxString(wxFILE_SEP_PATH
);
777 path
+= eachFilename
;
779 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,TRUE
);
780 wxTreeItemId id
= m_treeCtrl
->AppendItem( parentId
, eachFilename
, 0, -1, dir_item
);
781 m_treeCtrl
->SetItemImage( id
, 1, wxTreeItemIcon_Expanded
);
783 // Has this got any children? If so, make it expandable.
784 int options
= wxDIR_DEFAULT
;
785 if (GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) // If only showing dirs, then we specify dirs only here
787 options
= wxDIR_DIRS
;
795 // Have to test for wxDIR_DIRS separately in case m_currentFilterStr is non-empty and
796 // and filters out any directories
797 if (dir2
.GetFirst(& str
, m_currentFilterStr
, options
) || dir2
.GetFirst(& str
, wxEmptyString
, wxDIR_DIRS
))
799 m_treeCtrl
->SetItemHasChildren(id
);
804 // Add the sorted filenames
805 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
807 for (i
= 0; i
< filenames
.Count(); i
++)
809 wxString
eachFilename(filenames
[i
]);
811 if (path
.Last() != wxFILE_SEP_PATH
)
812 path
+= wxString(wxFILE_SEP_PATH
);
813 path
+= eachFilename
;
814 //path = dirName + wxString(wxT("/")) + eachFilename;
815 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,FALSE
);
816 (void)m_treeCtrl
->AppendItem( parentId
, eachFilename
, 2, -1, dir_item
);
821 // Find the child that matches the first part of 'path'.
822 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
823 // then the child for /usr is returned.
824 wxTreeItemId
wxGenericDirCtrl::FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
)
826 wxString
path2(path
);
828 // Make sure all separators are as per the current platform
829 path2
.Replace(wxT("\\"), wxString(wxFILE_SEP_PATH
));
830 path2
.Replace(wxT("/"), wxString(wxFILE_SEP_PATH
));
832 // Append a separator to foil bogus substring matching
833 path2
+= wxString(wxFILE_SEP_PATH
);
835 // In MSW, case is not significant
841 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(parentId
, cookie
);
844 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
846 if (data
&& data
->m_path
!= "")
848 wxString
childPath(data
->m_path
);
849 if (childPath
.Last() != wxFILE_SEP_PATH
)
850 childPath
+= wxString(wxFILE_SEP_PATH
);
852 // In MSW, case is not significant
854 childPath
.MakeLower();
857 if (childPath
.Len() <= path2
.Len())
859 wxString path3
= path2
.Mid(0, childPath
.Len());
860 if (childPath
== path3
)
862 if (path3
.Len() == path2
.Len())
871 childId
= m_treeCtrl
->GetNextChild(childId
, cookie
);
873 wxTreeItemId invalid
;
877 // Try to expand as much of the given path as possible,
878 // and select the given tree item.
879 bool wxGenericDirCtrl::ExpandPath(const wxString
& path
)
882 wxTreeItemId id
= FindChild(m_rootId
, path
, done
);
883 wxTreeItemId lastId
= id
; // The last non-zero id
884 while ((id
> 0) && !done
)
888 id
= FindChild(id
, path
, done
);
894 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(lastId
);
897 m_treeCtrl
->Expand(lastId
);
899 if ((GetWindowStyle() & wxDIRCTRL_SELECT_FIRST
) && data
->m_isDir
)
901 // Find the first file in this directory
903 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(lastId
, cookie
);
904 bool selectedChild
= FALSE
;
907 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
909 if (data
&& data
->m_path
!= "" && !data
->m_isDir
)
911 m_treeCtrl
->SelectItem(childId
);
912 m_treeCtrl
->EnsureVisible(childId
);
913 selectedChild
= TRUE
;
916 childId
= m_treeCtrl
->GetNextChild(lastId
, cookie
);
920 m_treeCtrl
->SelectItem(lastId
);
921 m_treeCtrl
->EnsureVisible(lastId
);
926 m_treeCtrl
->SelectItem(lastId
);
927 m_treeCtrl
->EnsureVisible(lastId
);
936 wxString
wxGenericDirCtrl::GetPath() const
938 wxTreeItemId id
= m_treeCtrl
->GetSelection();
941 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
945 return wxEmptyString
;
948 wxString
wxGenericDirCtrl::GetFilePath() const
950 wxTreeItemId id
= m_treeCtrl
->GetSelection();
953 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
955 return wxEmptyString
;
960 return wxEmptyString
;
963 void wxGenericDirCtrl::SetPath(const wxString
& path
)
965 m_defaultPath
= path
;
972 void wxGenericDirCtrl::FindChildFiles(wxTreeItemId id
, int dirFlags
, wxArrayString
& filenames
)
974 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
976 // This may take a longish time. Go to busy cursor
981 wxString search
,path
,filename
;
983 wxString
dirName(data
->m_path
);
986 if (dirName
.Last() == ':')
987 dirName
+= wxString(wxFILE_SEP_PATH
);
991 wxString eachFilename
;
998 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, dirFlags
))
1002 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
1004 filenames
.Add(eachFilename
);
1007 while (d
.GetNext(& eachFilename
)) ;
1013 void wxGenericDirCtrl::SetFilterIndex(int n
)
1015 m_currentFilter
= n
;
1018 if (ExtractWildcard(m_filter
, n
, f
, d
))
1019 m_currentFilterStr
= f
;
1021 m_currentFilterStr
= wxT("*.*");
1024 void wxGenericDirCtrl::SetFilter(const wxString
& filter
)
1029 if (ExtractWildcard(m_filter
, m_currentFilter
, f
, d
))
1030 m_currentFilterStr
= f
;
1032 m_currentFilterStr
= wxT("*.*");
1035 // Extract description and actual filter from overall filter string
1036 bool wxGenericDirCtrl::ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
)
1038 wxArrayString filters
, descriptions
;
1039 int count
= ParseFilter(filterStr
, filters
, descriptions
);
1040 if (count
> 0 && n
< count
)
1042 filter
= filters
[n
];
1043 description
= descriptions
[n
];
1050 // Parses the global filter, returning the number of filters.
1051 // Returns 0 if none or if there's a problem.
1052 // filterStr is in the form:
1054 // "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
1056 int wxGenericDirCtrl::ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
)
1058 wxString
str(filterStr
);
1060 wxString description
, filter
;
1062 bool finished
= FALSE
;
1065 pos
= str
.Find(wxT('|'));
1067 return 0; // Problem
1068 description
= str
.Left(pos
);
1069 str
= str
.Mid(pos
+1);
1070 pos
= str
.Find(wxT('|'));
1078 filter
= str
.Left(pos
);
1079 str
= str
.Mid(pos
+1);
1081 descriptions
.Add(description
);
1082 filters
.Add(filter
);
1086 return filters
.Count();
1089 void wxGenericDirCtrl::DoResize()
1091 wxSize sz
= GetClientSize();
1092 int verticalSpacing
= 3;
1096 if (m_filterListCtrl
)
1098 filterSz
= m_filterListCtrl
->GetSize();
1099 sz
.y
-= (filterSz
.y
+ verticalSpacing
);
1101 m_treeCtrl
->SetSize(0, 0, sz
.x
, sz
.y
);
1102 if (m_filterListCtrl
)
1104 m_filterListCtrl
->SetSize(0, sz
.y
+ verticalSpacing
, sz
.x
, filterSz
.y
);
1105 // Don't know why, but this needs refreshing after a resize (wxMSW)
1106 m_filterListCtrl
->Refresh();
1112 void wxGenericDirCtrl::OnSize(wxSizeEvent
&event
)
1117 //-----------------------------------------------------------------------------
1118 // wxDirFilterListCtrl
1119 //-----------------------------------------------------------------------------
1121 IMPLEMENT_CLASS(wxDirFilterListCtrl
, wxChoice
)
1123 BEGIN_EVENT_TABLE(wxDirFilterListCtrl
, wxChoice
)
1124 EVT_CHOICE(-1, wxDirFilterListCtrl::OnSelFilter
)
1127 bool wxDirFilterListCtrl::Create(wxGenericDirCtrl
* parent
, const wxWindowID id
,
1133 return wxChoice::Create(parent
, id
, pos
, size
, 0, NULL
, style
);
1136 void wxDirFilterListCtrl::Init()
1141 void wxDirFilterListCtrl::OnSelFilter(wxCommandEvent
& event
)
1143 int sel
= GetSelection();
1145 wxString currentPath
= m_dirCtrl
->GetPath();
1147 m_dirCtrl
->SetFilterIndex(sel
);
1149 // If the filter has changed, the view is out of date, so
1150 // collapse the tree.
1151 m_dirCtrl
->GetTreeCtrl()->Collapse(m_dirCtrl
->GetRootId());
1152 m_dirCtrl
->GetTreeCtrl()->Expand(m_dirCtrl
->GetRootId());
1154 // Try to restore the selection, or at least the directory
1155 m_dirCtrl
->ExpandPath(currentPath
);
1158 void wxDirFilterListCtrl::FillFilterList(const wxString
& filter
, int defaultFilter
)
1161 wxArrayString descriptions
, filters
;
1162 size_t n
= (size_t) m_dirCtrl
->ParseFilter(filter
, filters
, descriptions
);
1164 if (n
> 0 && defaultFilter
< (int) n
)
1167 for (i
= 0; i
< n
; i
++)
1168 Append(descriptions
[i
]);
1169 SetSelection(defaultFilter
);
1173 // wxGenericDirDialog implementation
1174 // This should be moved into dirdlgg.cpp eventually
1176 BEGIN_EVENT_TABLE(wxGenericDirDialog
, wxDialog
)
1177 EVT_BUTTON(wxID_OK
, wxGenericDirDialog::OnOK
)
1178 EVT_CLOSE(wxGenericDirDialog::OnCloseWindow
)
1181 wxGenericDirDialog::wxGenericDirDialog(wxWindow
* parent
, const wxString
& title
,
1182 const wxString
& defaultPath
, long style
, const wxPoint
& pos
, const wxSize
& sz
, const wxString
& name
):
1183 wxDialog(parent
, ID_DIRCTRL
, title
, pos
, sz
, style
, name
)
1185 wxBusyCursor cursor
;
1187 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
1190 m_dirCtrl
= new wxGenericDirCtrl(this, ID_DIRCTRL
,
1191 defaultPath
, wxPoint(5, 5),
1192 wxSize(300, 200), wxDIRCTRL_DIR_ONLY
|wxSUNKEN_BORDER
);
1194 topsizer
->Add( m_dirCtrl
, 1, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
1196 // 2) TODO: text control for entering path?
1200 topsizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
1204 wxSizer
* buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
1205 wxButton
* okButton
= new wxButton(this, wxID_OK
, _("OK"));
1206 buttonsizer
->Add( okButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1207 wxButton
* cancelButton
= new wxButton(this, wxID_CANCEL
, _("Cancel"));
1208 buttonsizer
->Add( cancelButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1210 /* TODO: new directory button
1211 wxButton* newButton = new wxButton( this, ID_NEW, _("New...") );
1212 buttonsizer->Add( newButton, 0, wxLEFT|wxRIGHT, 10 );
1214 topsizer
->Add( buttonsizer
, 0, wxALL
| wxCENTER
, 10 );
1216 okButton
->SetDefault();
1217 m_dirCtrl
->SetFocus();
1219 SetAutoLayout( TRUE
);
1220 SetSizer( topsizer
);
1222 topsizer
->SetSizeHints( this );
1223 topsizer
->Fit( this );
1228 void wxGenericDirDialog::OnCloseWindow(wxCloseEvent
& event
)
1230 EndModal(wxID_CANCEL
);
1233 void wxGenericDirDialog::OnOK(wxCommandEvent
& event
)
1238 void wxGenericDirDialog::SetPath(const wxString
& path
)
1240 m_dirCtrl
->SetPath(path
);
1243 wxString
wxGenericDirDialog::GetPath(void) const
1245 return m_dirCtrl
->GetPath();