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"
60 // If compiled under Windows, this macro can cause problems
65 #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW
67 static char * icon1_xpm
[] = {
68 /* width height ncolors chars_per_pixel */
96 static char * icon2_xpm
[] = {
97 /* width height ncolors chars_per_pixel */
125 static char * icon3_xpm
[] = {
126 /* width height ncolors chars_per_pixel */
151 static char * icon4_xpm
[] = {
178 static char * icon5_xpm
[] = {
205 static char *icon6_xpm
[] = {
235 static char * icon7_xpm
[] = {
262 static char * icon8_xpm
[] = {
289 static const int ID_DIRCTRL
= 1000;
290 static const int ID_TEXTCTRL
= 1001;
291 static const int ID_OK
= 1002;
292 static const int ID_CANCEL
= 1003;
293 static const int ID_NEW
= 1004;
294 //static const int ID_CHECK = 1005;
297 static bool wxIsDriveAvailable(const wxString dirName
)
300 UINT errorMode
= SetErrorMode(SEM_FAILCRITICALERRORS
| SEM_NOOPENFILEERRORBOX
);
304 // Check if this is a root directory and if so,
305 // whether the drive is avaiable.
306 if (dirName
.Len() == 3 && dirName
[(size_t)1] == wxT(':'))
308 wxString
dirNameLower(dirName
.Lower());
309 int currentDrive
= _getdrive();
310 int thisDrive
= (int) (dirNameLower
[(size_t)0] - 'a' + 1) ;
311 int err
= _chdrive( thisDrive
) ;
312 _chdrive( currentDrive
);
320 (void) SetErrorMode(errorMode
);
327 //-----------------------------------------------------------------------------
329 //-----------------------------------------------------------------------------
331 wxDirItemDataEx::wxDirItemDataEx(const wxString
& path
, const wxString
& name
,
336 /* Insert logic to detect hidden files here
337 * In UnixLand we just check whether the first char is a dot
338 * For FileNameFromPath read LastDirNameInThisPath ;-) */
339 // m_isHidden = (bool)(wxFileNameFromPath(*m_path)[0] == '.');
341 m_hasSubDirs
= HasSubDirs();
342 m_isExpanded
= FALSE
;
346 wxDirItemDataEx::~wxDirItemDataEx()
350 void wxDirItemDataEx::SetNewDirName( wxString path
)
353 m_name
= wxFileNameFromPath( path
);
356 bool wxDirItemDataEx::HasSubDirs()
358 if (m_path
.IsEmpty())
361 // On WIN32, must check if this volume is mounted or
362 // we get an error dialog for e.g. drive a:
364 if (!wxIsDriveAvailable(m_path
))
368 wxString search
= m_path
;
370 if (m_path
.Last() != wxFILE_SEP_PATH
)
372 search
+= wxString(wxFILE_SEP_PATH
);
377 wxString path
= wxFindFirstFile( search
, wxDIR
);
378 return (bool)(!path
.IsNull());
381 //-----------------------------------------------------------------------------
383 //-----------------------------------------------------------------------------
385 IMPLEMENT_DYNAMIC_CLASS(wxGenericDirCtrl
, wxControl
)
387 BEGIN_EVENT_TABLE(wxGenericDirCtrl
, wxControl
)
388 EVT_TREE_ITEM_EXPANDING (-1, wxGenericDirCtrl::OnExpandItem
)
389 EVT_TREE_ITEM_COLLAPSED (-1, wxGenericDirCtrl::OnCollapseItem
)
390 EVT_TREE_BEGIN_LABEL_EDIT (-1, wxGenericDirCtrl::OnBeginEditItem
)
391 EVT_TREE_END_LABEL_EDIT (-1, wxGenericDirCtrl::OnEndEditItem
)
392 EVT_SIZE (wxGenericDirCtrl::OnSize
)
395 wxGenericDirCtrl::wxGenericDirCtrl(void)
400 bool wxGenericDirCtrl::Create(wxWindow
*parent
,
406 const wxString
& filter
,
408 const wxString
& name
)
410 if (!wxControl::Create(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
413 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
417 long treeStyle
= wxTR_HAS_BUTTONS
;
418 if ((style
& wxDIRCTRL_3D_INTERNAL
) == 0)
419 treeStyle
|= wxNO_BORDER
;
421 long filterStyle
= 0;
422 if ((style
& wxDIRCTRL_3D_INTERNAL
) == 0)
423 filterStyle
|= wxNO_BORDER
;
425 m_treeCtrl
= new wxTreeCtrl(this, wxID_TREECTRL
, pos
, size
, treeStyle
);
427 if (!filter
.IsEmpty() && (style
& wxDIRCTRL_SHOW_FILTERS
))
428 m_filterListCtrl
= new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL
, wxDefaultPosition
, wxDefaultSize
, filterStyle
);
433 SetFilterIndex(defaultFilter
);
435 if (m_filterListCtrl
)
436 m_filterListCtrl
->FillFilterList(filter
, defaultFilter
);
438 m_imageList
= new wxImageList(16, 16, TRUE
);
439 #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW
440 m_imageList
->Add(wxIcon(icon1_xpm
));
441 m_imageList
->Add(wxIcon(icon2_xpm
));
442 m_imageList
->Add(wxIcon(icon3_xpm
));
443 m_imageList
->Add(wxIcon(icon4_xpm
));
444 m_imageList
->Add(wxIcon(icon5_xpm
));
445 m_imageList
->Add(wxIcon(icon6_xpm
));
446 m_imageList
->Add(wxIcon(icon7_xpm
));
447 m_imageList
->Add(wxIcon(icon8_xpm
));
448 #elif defined(__WXMSW__)
449 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CLOSED_FOLDER"), wxBITMAP_TYPE_ICO_RESOURCE
));
450 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_OPEN_FOLDER"), wxBITMAP_TYPE_ICO_RESOURCE
));
451 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FILE"), wxBITMAP_TYPE_ICO_RESOURCE
));
452 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_COMPUTER"), wxBITMAP_TYPE_ICO_RESOURCE
));
453 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_DRIVE"), wxBITMAP_TYPE_ICO_RESOURCE
));
454 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CDROM"), wxBITMAP_TYPE_ICO_RESOURCE
));
455 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FLOPPY"), wxBITMAP_TYPE_ICO_RESOURCE
));
456 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_REMOVEABLE"), wxBITMAP_TYPE_ICO_RESOURCE
));
458 #error "Sorry, we don't have icons available for this platforms."
460 m_treeCtrl
->SetImageList(m_imageList
);
462 m_showHidden
= FALSE
;
463 wxDirItemDataEx
* rootData
= new wxDirItemDataEx(wxT(""), wxT(""), TRUE
);
468 rootName
= _("Computer");
470 rootName
= _("Sections");
473 m_rootId
= m_treeCtrl
->AddRoot( rootName
, 3, -1, rootData
);
474 m_treeCtrl
->SetItemHasChildren(m_rootId
);
475 m_treeCtrl
->Expand(m_rootId
); // automatically expand first level
477 // Expand and select the default path
478 if (!m_defaultPath
.IsEmpty())
479 ExpandPath(m_defaultPath
);
486 wxGenericDirCtrl::~wxGenericDirCtrl()
488 m_treeCtrl
->SetImageList(NULL
);
492 void wxGenericDirCtrl::Init()
494 m_showHidden
= FALSE
;
497 m_currentFilterStr
= wxEmptyString
; // Default: any file
499 m_filterListCtrl
= NULL
;
502 void wxGenericDirCtrl::AddSection(const wxString
& path
, const wxString
& name
, int imageId
)
504 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,name
,TRUE
);
507 // Windows: sections are displayed as drives
508 wxTreeItemId id
= m_treeCtrl
->AppendItem( m_rootId
, name
, imageId
, -1, dir_item
);
510 // Unix: sections are displayed as folders
511 wxTreeItemId id
= m_treeCtrl
->AppendItem( m_rootId
, name
, 0, -1, dir_item
);
512 m_treeCtrl
->SetItemImage( id
, 1, wxTreeItemIcon_Expanded
);
514 // TODO: other operating systems.
516 m_treeCtrl
->SetItemHasChildren(id
);
519 void wxGenericDirCtrl::SetupSections()
524 wxChar driveBuffer
[256];
525 size_t n
= (size_t) GetLogicalDriveStrings(255, driveBuffer
);
530 path
.Printf(wxT("%c:\\"), driveBuffer
[i
]);
531 name
.Printf(wxT("(%c:)"), driveBuffer
[i
]);
534 int driveType
= ::GetDriveType(path
);
537 case DRIVE_REMOVABLE
:
538 if (path
== wxT("a:\\") || path
== wxT("b:\\"))
539 imageId
= 6; // Floppy
557 AddSection(path
, name
, imageId
);
559 while (driveBuffer
[i
] != wxT('\0'))
562 if (driveBuffer
[i
] == wxT('\0'))
569 /* If we can switch to the drive, it exists. */
570 for( drive
= 1; drive
<= 26; drive
++ )
573 path
.Printf(wxT("%c:\\"), (char) (drive
+ 'a' - 1));
574 name
.Printf(wxT("(%c:)"), (char) (drive
+ 'a' - 1));
576 if (wxIsDriveAvailable(path
))
579 AddSection(path
, name
);
585 AddSection(wxT("/"), _("The Computer"), 0);
586 AddSection(wxGetHomeDir(), _("My Home"), 0 );
587 AddSection(wxT("/mnt"), _("Mounted Devices"), 0 );
588 AddSection(wxT("/usr/local"), _("User Local"), 0 );
589 AddSection(wxT("/usr"), _("User"), 0 );
590 AddSection(wxT("/var"), _("Variables"), 0 );
591 AddSection(wxT("/etc"), _("Etcetera"), 0 );
592 AddSection(wxT("/tmp"), _("Temporary"), 0 );
596 void wxGenericDirCtrl::OnBeginEditItem(wxTreeEvent
&event
)
598 // don't rename the main entry "Sections"
599 if (event
.GetItem() == m_rootId
)
605 // don't rename the individual sections
606 if (m_treeCtrl
->GetParent( event
.GetItem() ) == m_rootId
)
613 void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent
&event
)
615 if ((event
.GetLabel().IsEmpty()) ||
616 (event
.GetLabel() == _(".")) ||
617 (event
.GetLabel() == _("..")) ||
618 (event
.GetLabel().First( wxT("/") ) != wxNOT_FOUND
))
620 wxMessageDialog
dialog(this, _("Illegal directory name."), _("Error"), wxOK
| wxICON_ERROR
);
626 wxTreeItemId id
= event
.GetItem();
627 wxDirItemDataEx
*data
= (wxDirItemDataEx
*)m_treeCtrl
->GetItemData( id
);
630 wxString
new_name( wxPathOnly( data
->m_path
) );
631 new_name
+= wxString(wxFILE_SEP_PATH
);
632 new_name
+= event
.GetLabel();
636 if (wxFileExists(new_name
))
638 wxMessageDialog
dialog(this, _("File name exists already."), _("Error"), wxOK
| wxICON_ERROR
);
643 if (wxRenameFile(data
->m_path
,new_name
))
645 data
->SetNewDirName( new_name
);
649 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
655 void wxGenericDirCtrl::OnExpandItem(wxTreeEvent
&event
)
657 wxTreeItemId parentId
= event
.GetItem();
662 void wxGenericDirCtrl::OnCollapseItem(wxTreeEvent
&event
)
664 wxTreeItemId child
, parent
= event
.GetItem();
666 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(event
.GetItem());
667 if (!data
->m_isExpanded
)
670 data
->m_isExpanded
= FALSE
;
672 /* Workaround because DeleteChildren has disapeared (why?) and
673 * CollapseAndReset doesn't work as advertised (deletes parent too) */
674 child
= m_treeCtrl
->GetFirstChild(parent
, cookie
);
677 m_treeCtrl
->Delete(child
);
678 /* Not GetNextChild below, because the cookie mechanism can't
679 * handle disappearing children! */
680 child
= m_treeCtrl
->GetFirstChild(parent
, cookie
);
684 void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId
)
686 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(parentId
);
688 if (data
->m_isExpanded
)
691 data
->m_isExpanded
= TRUE
;
693 if (parentId
== m_rootId
)
701 wxString search
,path
,filename
;
703 wxString
dirName(data
->m_path
);
706 // Check if this is a root directory and if so,
707 // whether the drive is avaiable.
708 if (!wxIsDriveAvailable(dirName
))
710 data
->m_isExpanded
= FALSE
;
711 wxMessageBox(wxT("Sorry, this drive is not available."));
716 // This may take a longish time. Go to busy cursor
720 if (dirName
.Last() == ':')
721 dirName
+= wxString(wxFILE_SEP_PATH
);
725 wxArrayString filenames
;
728 wxString eachFilename
;
735 if (d
.GetFirst(& eachFilename
, wxEmptyString
, wxDIR_DIRS
))
739 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
741 dirs
.Add(eachFilename
);
744 while (d
.GetNext(& eachFilename
)) ;
749 // Now do the filenames -- but only if we're allowed to
750 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
758 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, wxDIR_FILES
))
762 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
764 filenames
.Add(eachFilename
);
767 while (d
.GetNext(& eachFilename
)) ;
773 // Add the sorted dirs
775 for (i
= 0; i
< dirs
.Count(); i
++)
777 wxString
eachFilename(dirs
[i
]);
779 if (path
.Last() != wxFILE_SEP_PATH
)
780 path
+= wxString(wxFILE_SEP_PATH
);
781 path
+= eachFilename
;
783 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,TRUE
);
784 wxTreeItemId id
= m_treeCtrl
->AppendItem( parentId
, eachFilename
, 0, -1, dir_item
);
785 m_treeCtrl
->SetItemImage( id
, 1, wxTreeItemIcon_Expanded
);
787 // Has this got any children? If so, make it expandable.
788 int options
= wxDIR_DEFAULT
;
789 if (GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) // If only showing dirs, then we specify dirs only here
791 options
= wxDIR_DIRS
;
799 // Have to test for wxDIR_DIRS separately in case m_currentFilterStr is non-empty and
800 // and filters out any directories
801 if (dir2
.GetFirst(& str
, m_currentFilterStr
, options
) || dir2
.GetFirst(& str
, wxEmptyString
, wxDIR_DIRS
))
803 m_treeCtrl
->SetItemHasChildren(id
);
808 // Add the sorted filenames
809 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
811 for (i
= 0; i
< filenames
.Count(); i
++)
813 wxString
eachFilename(filenames
[i
]);
815 if (path
.Last() != wxFILE_SEP_PATH
)
816 path
+= wxString(wxFILE_SEP_PATH
);
817 path
+= eachFilename
;
818 //path = dirName + wxString(wxT("/")) + eachFilename;
819 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,FALSE
);
820 (void)m_treeCtrl
->AppendItem( parentId
, eachFilename
, 2, -1, dir_item
);
825 // Find the child that matches the first part of 'path'.
826 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
827 // then the child for /usr is returned.
828 wxTreeItemId
wxGenericDirCtrl::FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
)
830 wxString
path2(path
);
832 // Make sure all separators are as per the current platform
833 path2
.Replace(wxT("\\"), wxString(wxFILE_SEP_PATH
));
834 path2
.Replace(wxT("/"), wxString(wxFILE_SEP_PATH
));
836 // Append a separator to foil bogus substring matching
837 path2
+= wxString(wxFILE_SEP_PATH
);
839 // In MSW, case is not significant
845 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(parentId
, cookie
);
848 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
850 if (data
&& data
->m_path
!= "")
852 wxString
childPath(data
->m_path
);
853 if (childPath
.Last() != wxFILE_SEP_PATH
)
854 childPath
+= wxString(wxFILE_SEP_PATH
);
856 // In MSW, case is not significant
858 childPath
.MakeLower();
861 if (childPath
.Len() <= path2
.Len())
863 wxString path3
= path2
.Mid(0, childPath
.Len());
864 if (childPath
== path3
)
866 if (path3
.Len() == path2
.Len())
875 childId
= m_treeCtrl
->GetNextChild(childId
, cookie
);
877 wxTreeItemId invalid
;
881 // Try to expand as much of the given path as possible,
882 // and select the given tree item.
883 bool wxGenericDirCtrl::ExpandPath(const wxString
& path
)
886 wxTreeItemId id
= FindChild(m_rootId
, path
, done
);
887 wxTreeItemId lastId
= id
; // The last non-zero id
888 while ((id
> 0) && !done
)
892 id
= FindChild(id
, path
, done
);
898 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(lastId
);
901 m_treeCtrl
->Expand(lastId
);
903 if ((GetWindowStyle() & wxDIRCTRL_SELECT_FIRST
) && data
->m_isDir
)
905 // Find the first file in this directory
907 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(lastId
, cookie
);
908 bool selectedChild
= FALSE
;
911 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
913 if (data
&& data
->m_path
!= "" && !data
->m_isDir
)
915 m_treeCtrl
->SelectItem(childId
);
916 m_treeCtrl
->EnsureVisible(childId
);
917 selectedChild
= TRUE
;
920 childId
= m_treeCtrl
->GetNextChild(lastId
, cookie
);
924 m_treeCtrl
->SelectItem(lastId
);
925 m_treeCtrl
->EnsureVisible(lastId
);
930 m_treeCtrl
->SelectItem(lastId
);
931 m_treeCtrl
->EnsureVisible(lastId
);
940 wxString
wxGenericDirCtrl::GetPath() const
942 wxTreeItemId id
= m_treeCtrl
->GetSelection();
945 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
949 return wxEmptyString
;
952 wxString
wxGenericDirCtrl::GetFilePath() const
954 wxTreeItemId id
= m_treeCtrl
->GetSelection();
957 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
959 return wxEmptyString
;
964 return wxEmptyString
;
967 void wxGenericDirCtrl::SetPath(const wxString
& path
)
969 m_defaultPath
= path
;
976 void wxGenericDirCtrl::FindChildFiles(wxTreeItemId id
, int dirFlags
, wxArrayString
& filenames
)
978 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
980 // This may take a longish time. Go to busy cursor
985 wxString search
,path
,filename
;
987 wxString
dirName(data
->m_path
);
990 if (dirName
.Last() == ':')
991 dirName
+= wxString(wxFILE_SEP_PATH
);
995 wxString eachFilename
;
1002 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, dirFlags
))
1006 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
1008 filenames
.Add(eachFilename
);
1011 while (d
.GetNext(& eachFilename
)) ;
1017 void wxGenericDirCtrl::SetFilterIndex(int n
)
1019 m_currentFilter
= n
;
1022 if (ExtractWildcard(m_filter
, n
, f
, d
))
1023 m_currentFilterStr
= f
;
1025 m_currentFilterStr
= wxT("*.*");
1028 void wxGenericDirCtrl::SetFilter(const wxString
& filter
)
1033 if (ExtractWildcard(m_filter
, m_currentFilter
, f
, d
))
1034 m_currentFilterStr
= f
;
1036 m_currentFilterStr
= wxT("*.*");
1039 // Extract description and actual filter from overall filter string
1040 bool wxGenericDirCtrl::ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
)
1042 wxArrayString filters
, descriptions
;
1043 int count
= ParseFilter(filterStr
, filters
, descriptions
);
1044 if (count
> 0 && n
< count
)
1046 filter
= filters
[n
];
1047 description
= descriptions
[n
];
1054 // Parses the global filter, returning the number of filters.
1055 // Returns 0 if none or if there's a problem.
1056 // filterStr is in the form:
1058 // "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
1060 int wxGenericDirCtrl::ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
)
1062 wxString
str(filterStr
);
1064 wxString description
, filter
;
1066 bool finished
= FALSE
;
1069 pos
= str
.Find(wxT('|'));
1071 return 0; // Problem
1072 description
= str
.Left(pos
);
1073 str
= str
.Mid(pos
+1);
1074 pos
= str
.Find(wxT('|'));
1082 filter
= str
.Left(pos
);
1083 str
= str
.Mid(pos
+1);
1085 descriptions
.Add(description
);
1086 filters
.Add(filter
);
1090 return filters
.Count();
1093 void wxGenericDirCtrl::DoResize()
1095 wxSize sz
= GetClientSize();
1096 int verticalSpacing
= 3;
1100 if (m_filterListCtrl
)
1102 filterSz
= m_filterListCtrl
->GetSize();
1103 sz
.y
-= (filterSz
.y
+ verticalSpacing
);
1105 m_treeCtrl
->SetSize(0, 0, sz
.x
, sz
.y
);
1106 if (m_filterListCtrl
)
1108 m_filterListCtrl
->SetSize(0, sz
.y
+ verticalSpacing
, sz
.x
, filterSz
.y
);
1109 // Don't know why, but this needs refreshing after a resize (wxMSW)
1110 m_filterListCtrl
->Refresh();
1116 void wxGenericDirCtrl::OnSize(wxSizeEvent
&event
)
1121 //-----------------------------------------------------------------------------
1122 // wxDirFilterListCtrl
1123 //-----------------------------------------------------------------------------
1125 IMPLEMENT_CLASS(wxDirFilterListCtrl
, wxChoice
)
1127 BEGIN_EVENT_TABLE(wxDirFilterListCtrl
, wxChoice
)
1128 EVT_CHOICE(-1, wxDirFilterListCtrl::OnSelFilter
)
1131 bool wxDirFilterListCtrl::Create(wxGenericDirCtrl
* parent
, const wxWindowID id
,
1137 return wxChoice::Create(parent
, id
, pos
, size
, 0, NULL
, style
);
1140 void wxDirFilterListCtrl::Init()
1145 void wxDirFilterListCtrl::OnSelFilter(wxCommandEvent
& event
)
1147 int sel
= GetSelection();
1149 wxString currentPath
= m_dirCtrl
->GetPath();
1151 m_dirCtrl
->SetFilterIndex(sel
);
1153 // If the filter has changed, the view is out of date, so
1154 // collapse the tree.
1155 m_dirCtrl
->GetTreeCtrl()->Collapse(m_dirCtrl
->GetRootId());
1156 m_dirCtrl
->GetTreeCtrl()->Expand(m_dirCtrl
->GetRootId());
1158 // Try to restore the selection, or at least the directory
1159 m_dirCtrl
->ExpandPath(currentPath
);
1162 void wxDirFilterListCtrl::FillFilterList(const wxString
& filter
, int defaultFilter
)
1165 wxArrayString descriptions
, filters
;
1166 size_t n
= (size_t) m_dirCtrl
->ParseFilter(filter
, filters
, descriptions
);
1168 if (n
> 0 && defaultFilter
< (int) n
)
1171 for (i
= 0; i
< n
; i
++)
1172 Append(descriptions
[i
]);
1173 SetSelection(defaultFilter
);
1177 // wxGenericDirDialog implementation
1178 // This should be moved into dirdlgg.cpp eventually
1180 BEGIN_EVENT_TABLE(wxGenericDirDialog
, wxDialog
)
1181 EVT_BUTTON(wxID_OK
, wxGenericDirDialog::OnOK
)
1182 EVT_CLOSE(wxGenericDirDialog::OnCloseWindow
)
1185 wxGenericDirDialog::wxGenericDirDialog(wxWindow
* parent
, const wxString
& title
,
1186 const wxString
& defaultPath
, long style
, const wxPoint
& pos
, const wxSize
& sz
, const wxString
& name
):
1187 wxDialog(parent
, ID_DIRCTRL
, title
, pos
, sz
, style
, name
)
1189 wxBusyCursor cursor
;
1191 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
1194 m_dirCtrl
= new wxGenericDirCtrl(this, ID_DIRCTRL
,
1195 defaultPath
, wxPoint(5, 5),
1196 wxSize(300, 200), wxDIRCTRL_DIR_ONLY
|wxSUNKEN_BORDER
);
1198 topsizer
->Add( m_dirCtrl
, 1, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
1200 // 2) TODO: text control for entering path?
1204 topsizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
1208 wxSizer
* buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
1209 wxButton
* okButton
= new wxButton(this, wxID_OK
, _("OK"));
1210 buttonsizer
->Add( okButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1211 wxButton
* cancelButton
= new wxButton(this, wxID_CANCEL
, _("Cancel"));
1212 buttonsizer
->Add( cancelButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1214 /* TODO: new directory button
1215 wxButton* newButton = new wxButton( this, ID_NEW, _("New...") );
1216 buttonsizer->Add( newButton, 0, wxLEFT|wxRIGHT, 10 );
1218 topsizer
->Add( buttonsizer
, 0, wxALL
| wxCENTER
, 10 );
1220 okButton
->SetDefault();
1221 m_dirCtrl
->SetFocus();
1223 SetAutoLayout( TRUE
);
1224 SetSizer( topsizer
);
1226 topsizer
->SetSizeHints( this );
1227 topsizer
->Fit( this );
1232 void wxGenericDirDialog::OnCloseWindow(wxCloseEvent
& event
)
1234 EndModal(wxID_CANCEL
);
1237 void wxGenericDirDialog::OnOK(wxCommandEvent
& event
)
1242 void wxGenericDirDialog::SetPath(const wxString
& path
)
1244 m_dirCtrl
->SetPath(path
);
1247 wxString
wxGenericDirDialog::GetPath(void) const
1249 return m_dirCtrl
->GetPath();