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
;
730 if (d
.GetFirst(& eachFilename
, wxEmptyString
, wxDIR_DIRS
))
734 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
736 dirs
.Add(eachFilename
);
739 while (d
.GetNext(& eachFilename
)) ;
744 // Now do the filenames -- but only if we're allowed to
745 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
753 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, wxDIR_FILES
))
757 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
759 filenames
.Add(eachFilename
);
762 while (d
.GetNext(& eachFilename
)) ;
768 // Add the sorted dirs
770 for (i
= 0; i
< dirs
.Count(); i
++)
772 wxString
eachFilename(dirs
[i
]);
774 if (path
.Last() != wxFILE_SEP_PATH
)
775 path
+= wxString(wxFILE_SEP_PATH
);
776 path
+= eachFilename
;
778 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,TRUE
);
779 wxTreeItemId id
= m_treeCtrl
->AppendItem( parentId
, eachFilename
, 0, -1, dir_item
);
780 m_treeCtrl
->SetItemImage( id
, 1, wxTreeItemIcon_Expanded
);
782 // Has this got any children? If so, make it expandable.
783 int options
= wxDIR_DEFAULT
;
784 if (GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) // If only showing dirs, then we specify dirs only here
786 options
= wxDIR_DIRS
;
794 // Have to test for wxDIR_DIRS separately in case m_currentFilterStr is non-empty and
795 // and filters out any directories
796 if (dir2
.GetFirst(& str
, m_currentFilterStr
, options
) || dir2
.GetFirst(& str
, wxEmptyString
, wxDIR_DIRS
))
798 m_treeCtrl
->SetItemHasChildren(id
);
803 // Add the sorted filenames
804 if ((GetWindowStyle() & wxDIRCTRL_DIR_ONLY
) == 0)
806 for (i
= 0; i
< filenames
.Count(); i
++)
808 wxString
eachFilename(filenames
[i
]);
810 if (path
.Last() != wxFILE_SEP_PATH
)
811 path
+= wxString(wxFILE_SEP_PATH
);
812 path
+= eachFilename
;
813 //path = dirName + wxString(wxT("/")) + eachFilename;
814 wxDirItemDataEx
*dir_item
= new wxDirItemDataEx(path
,eachFilename
,FALSE
);
815 (void)m_treeCtrl
->AppendItem( parentId
, eachFilename
, 2, -1, dir_item
);
820 // Find the child that matches the first part of 'path'.
821 // E.g. if a child path is "/usr" and 'path' is "/usr/include"
822 // then the child for /usr is returned.
823 wxTreeItemId
wxGenericDirCtrl::FindChild(wxTreeItemId parentId
, const wxString
& path
, bool& done
)
825 wxString
path2(path
);
827 // Make sure all separators are as per the current platform
828 path2
.Replace(wxT("\\"), wxString(wxFILE_SEP_PATH
));
829 path2
.Replace(wxT("/"), wxString(wxFILE_SEP_PATH
));
831 // Append a separator to foil bogus substring matching
832 path2
+= wxString(wxFILE_SEP_PATH
);
834 // In MSW, case is not significant
840 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(parentId
, cookie
);
843 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
845 if (data
&& data
->m_path
!= "")
847 wxString
childPath(data
->m_path
);
848 if (childPath
.Last() != wxFILE_SEP_PATH
)
849 childPath
+= wxString(wxFILE_SEP_PATH
);
851 // In MSW, case is not significant
853 childPath
.MakeLower();
856 if (childPath
.Len() <= path2
.Len())
858 wxString path3
= path2
.Mid(0, childPath
.Len());
859 if (childPath
== path3
)
861 if (path3
.Len() == path2
.Len())
870 childId
= m_treeCtrl
->GetNextChild(childId
, cookie
);
872 wxTreeItemId invalid
;
876 // Try to expand as much of the given path as possible,
877 // and select the given tree item.
878 bool wxGenericDirCtrl::ExpandPath(const wxString
& path
)
881 wxTreeItemId id
= FindChild(m_rootId
, path
, done
);
882 wxTreeItemId lastId
= id
; // The last non-zero id
883 while ((id
> 0) && !done
)
887 id
= FindChild(id
, path
, done
);
893 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(lastId
);
896 m_treeCtrl
->Expand(lastId
);
898 if ((GetWindowStyle() & wxDIRCTRL_SELECT_FIRST
) && data
->m_isDir
)
900 // Find the first file in this directory
902 wxTreeItemId childId
= m_treeCtrl
->GetFirstChild(lastId
, cookie
);
903 bool selectedChild
= FALSE
;
906 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(childId
);
908 if (data
&& data
->m_path
!= "" && !data
->m_isDir
)
910 m_treeCtrl
->SelectItem(childId
);
911 m_treeCtrl
->EnsureVisible(childId
);
912 selectedChild
= TRUE
;
915 childId
= m_treeCtrl
->GetNextChild(lastId
, cookie
);
919 m_treeCtrl
->SelectItem(lastId
);
920 m_treeCtrl
->EnsureVisible(lastId
);
925 m_treeCtrl
->SelectItem(lastId
);
926 m_treeCtrl
->EnsureVisible(lastId
);
935 wxString
wxGenericDirCtrl::GetPath() const
937 wxTreeItemId id
= m_treeCtrl
->GetSelection();
940 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
944 return wxEmptyString
;
947 wxString
wxGenericDirCtrl::GetFilePath() const
949 wxTreeItemId id
= m_treeCtrl
->GetSelection();
952 wxDirItemDataEx
* data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
954 return wxEmptyString
;
959 return wxEmptyString
;
962 void wxGenericDirCtrl::SetPath(const wxString
& path
)
964 m_defaultPath
= path
;
971 void wxGenericDirCtrl::FindChildFiles(wxTreeItemId id
, int dirFlags
, wxArrayString
& filenames
)
973 wxDirItemDataEx
*data
= (wxDirItemDataEx
*) m_treeCtrl
->GetItemData(id
);
975 // This may take a longish time. Go to busy cursor
980 wxString search
,path
,filename
;
982 wxString
dirName(data
->m_path
);
985 if (dirName
.Last() == ':')
986 dirName
+= wxString(wxFILE_SEP_PATH
);
990 wxString eachFilename
;
997 if (d
.GetFirst(& eachFilename
, m_currentFilterStr
, dirFlags
))
1001 if ((eachFilename
!= wxT(".")) && (eachFilename
!= wxT("..")))
1003 filenames
.Add(eachFilename
);
1006 while (d
.GetNext(& eachFilename
)) ;
1012 void wxGenericDirCtrl::SetFilterIndex(int n
)
1014 m_currentFilter
= n
;
1017 if (ExtractWildcard(m_filter
, n
, f
, d
))
1018 m_currentFilterStr
= f
;
1020 m_currentFilterStr
= wxT("*.*");
1023 void wxGenericDirCtrl::SetFilter(const wxString
& filter
)
1028 if (ExtractWildcard(m_filter
, m_currentFilter
, f
, d
))
1029 m_currentFilterStr
= f
;
1031 m_currentFilterStr
= wxT("*.*");
1034 // Extract description and actual filter from overall filter string
1035 bool wxGenericDirCtrl::ExtractWildcard(const wxString
& filterStr
, int n
, wxString
& filter
, wxString
& description
)
1037 wxArrayString filters
, descriptions
;
1038 int count
= ParseFilter(filterStr
, filters
, descriptions
);
1039 if (count
> 0 && n
< count
)
1041 filter
= filters
[n
];
1042 description
= descriptions
[n
];
1049 // Parses the global filter, returning the number of filters.
1050 // Returns 0 if none or if there's a problem.
1051 // filterStr is in the form:
1053 // "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
1055 int wxGenericDirCtrl::ParseFilter(const wxString
& filterStr
, wxArrayString
& filters
, wxArrayString
& descriptions
)
1057 wxString
str(filterStr
);
1059 wxString description
, filter
;
1061 bool finished
= FALSE
;
1064 pos
= str
.Find(wxT('|'));
1066 return 0; // Problem
1067 description
= str
.Left(pos
);
1068 str
= str
.Mid(pos
+1);
1069 pos
= str
.Find(wxT('|'));
1077 filter
= str
.Left(pos
);
1078 str
= str
.Mid(pos
+1);
1080 descriptions
.Add(description
);
1081 filters
.Add(filter
);
1085 return filters
.Count();
1088 void wxGenericDirCtrl::DoResize()
1090 wxSize sz
= GetClientSize();
1091 int verticalSpacing
= 3;
1095 if (m_filterListCtrl
)
1097 filterSz
= m_filterListCtrl
->GetSize();
1098 sz
.y
-= (filterSz
.y
+ verticalSpacing
);
1100 m_treeCtrl
->SetSize(0, 0, sz
.x
, sz
.y
);
1101 if (m_filterListCtrl
)
1103 m_filterListCtrl
->SetSize(0, sz
.y
+ verticalSpacing
, sz
.x
, filterSz
.y
);
1104 // Don't know why, but this needs refreshing after a resize (wxMSW)
1105 m_filterListCtrl
->Refresh();
1111 void wxGenericDirCtrl::OnSize(wxSizeEvent
&event
)
1116 //-----------------------------------------------------------------------------
1117 // wxDirFilterListCtrl
1118 //-----------------------------------------------------------------------------
1120 IMPLEMENT_CLASS(wxDirFilterListCtrl
, wxChoice
)
1122 BEGIN_EVENT_TABLE(wxDirFilterListCtrl
, wxChoice
)
1123 EVT_CHOICE(-1, wxDirFilterListCtrl::OnSelFilter
)
1126 bool wxDirFilterListCtrl::Create(wxGenericDirCtrl
* parent
, const wxWindowID id
,
1132 return wxChoice::Create(parent
, id
, pos
, size
, 0, NULL
, style
);
1135 void wxDirFilterListCtrl::Init()
1140 void wxDirFilterListCtrl::OnSelFilter(wxCommandEvent
& event
)
1142 int sel
= GetSelection();
1144 wxString currentPath
= m_dirCtrl
->GetPath();
1146 m_dirCtrl
->SetFilterIndex(sel
);
1148 // If the filter has changed, the view is out of date, so
1149 // collapse the tree.
1150 m_dirCtrl
->GetTreeCtrl()->Collapse(m_dirCtrl
->GetRootId());
1151 m_dirCtrl
->GetTreeCtrl()->Expand(m_dirCtrl
->GetRootId());
1153 // Try to restore the selection, or at least the directory
1154 m_dirCtrl
->ExpandPath(currentPath
);
1157 void wxDirFilterListCtrl::FillFilterList(const wxString
& filter
, int defaultFilter
)
1160 wxArrayString descriptions
, filters
;
1161 size_t n
= (size_t) m_dirCtrl
->ParseFilter(filter
, filters
, descriptions
);
1163 if (n
> 0 && defaultFilter
< (int) n
)
1166 for (i
= 0; i
< n
; i
++)
1167 Append(descriptions
[i
]);
1168 SetSelection(defaultFilter
);
1172 // wxGenericDirDialog implementation
1173 // This should be moved into dirdlgg.cpp eventually
1175 BEGIN_EVENT_TABLE(wxGenericDirDialog
, wxDialog
)
1176 EVT_BUTTON(wxID_OK
, wxGenericDirDialog::OnOK
)
1177 EVT_CLOSE(wxGenericDirDialog::OnCloseWindow
)
1180 wxGenericDirDialog::wxGenericDirDialog(wxWindow
* parent
, const wxString
& title
,
1181 const wxString
& defaultPath
, long style
, const wxPoint
& pos
, const wxSize
& sz
, const wxString
& name
):
1182 wxDialog(parent
, ID_DIRCTRL
, title
, pos
, sz
, style
, name
)
1184 wxBusyCursor cursor
;
1186 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
1189 m_dirCtrl
= new wxGenericDirCtrl(this, ID_DIRCTRL
,
1190 defaultPath
, wxPoint(5, 5),
1191 wxSize(300, 200), wxDIRCTRL_DIR_ONLY
|wxSUNKEN_BORDER
);
1193 topsizer
->Add( m_dirCtrl
, 1, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
1195 // 2) TODO: text control for entering path?
1199 topsizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
1203 wxSizer
* buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
1204 wxButton
* okButton
= new wxButton(this, wxID_OK
, _("OK"));
1205 buttonsizer
->Add( okButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1206 wxButton
* cancelButton
= new wxButton(this, wxID_CANCEL
, _("Cancel"));
1207 buttonsizer
->Add( cancelButton
, 0, wxLEFT
|wxRIGHT
, 10 );
1209 /* TODO: new directory button
1210 wxButton* newButton = new wxButton( this, ID_NEW, _("New...") );
1211 buttonsizer->Add( newButton, 0, wxLEFT|wxRIGHT, 10 );
1213 topsizer
->Add( buttonsizer
, 0, wxALL
| wxCENTER
, 10 );
1215 okButton
->SetDefault();
1216 m_dirCtrl
->SetFocus();
1218 SetAutoLayout( TRUE
);
1219 SetSizer( topsizer
);
1221 topsizer
->SetSizeHints( this );
1222 topsizer
->Fit( this );
1227 void wxGenericDirDialog::OnCloseWindow(wxCloseEvent
& event
)
1229 EndModal(wxID_CANCEL
);
1232 void wxGenericDirDialog::OnOK(wxCommandEvent
& event
)
1237 void wxGenericDirDialog::SetPath(const wxString
& path
)
1239 m_dirCtrl
->SetPath(path
);
1242 wxString
wxGenericDirDialog::GetPath(void) const
1244 return m_dirCtrl
->GetPath();