X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d7a15103f7307a27c35a0c1cad095cda50d64aea..ea18eed94c637bee3343b929e09cae78a1b80928:/src/generic/dirdlgg.cpp?ds=sidebyside diff --git a/src/generic/dirdlgg.cpp b/src/generic/dirdlgg.cpp index b4b93e0035..49a60b6337 100644 --- a/src/generic/dirdlgg.cpp +++ b/src/generic/dirdlgg.cpp @@ -12,6 +12,13 @@ #pragma implementation "dirdlgg.h" #endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + #include "wx/defs.h" #include "wx/utils.h" #include "wx/dialog.h" @@ -27,6 +34,11 @@ #include "wx/generic/dirdlgg.h" +// If compiled under Windows, this macro can cause problems +#ifdef GetFirstChild +#undef GetFirstChild +#endif + /* XPM */ static char * icon1_xpm[] = { /* width height ncolors chars_per_pixel */ @@ -56,6 +68,34 @@ static char * icon1_xpm[] = { " ", " "}; +/* XPM */ +static char * icon2_xpm[] = { +/* width height ncolors chars_per_pixel */ +"16 16 6 1", +/* colors */ +" s None c None", +". c #000000", +"+ c #c0c0c0", +"@ c #808080", +"# c #ffff00", +"$ c #ffffff", +/* pixels */ +" ", +" @@@@@ ", +" @$$$$$@ ", +" @$#+#+#$@@@@@@ ", +" @$+#+#+$$$$$$@.", +" @$#+#+#+#+#+#@.", +"@@@@@@@@@@@@@#@.", +"@$$$$$$$$$$@@+@.", +"@$#+#+#+#+##.@@.", +" @$#+#+#+#+#+.@.", +" @$+#+#+#+#+#.@.", +" @$+#+#+#+##@..", +" @@@@@@@@@@@@@.", +" .............", +" ", +" "}; static const int ID_DIRCTRL = 1000; static const int ID_TEXTCTRL = 1001; @@ -68,6 +108,50 @@ static const int ID_NEW = 1004; // wxDirItemData //----------------------------------------------------------------------------- +class wxDirItemData : public wxTreeItemData +{ +public: + wxDirItemData(wxString& path, wxString& name); + ~wxDirItemData(); + bool HasSubDirs(); + wxString *m_path, *m_name; + bool m_isHidden; + bool m_hasSubDirs; +}; + +//----------------------------------------------------------------------------- +// wxDirCtrl +//----------------------------------------------------------------------------- + +class wxDirCtrl: public wxTreeCtrl +{ + DECLARE_DYNAMIC_CLASS(wxDirCtrl) + + public: + bool m_showHidden; + wxTreeItemId m_rootId; + + wxDirCtrl(void); + wxDirCtrl(wxWindow *parent, const wxWindowID id = -1, + const wxString &dir = "/", + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + const long style = wxTR_HAS_BUTTONS, + const wxString& name = "wxTreeCtrl" ); + void OnExpandItem(wxTreeEvent &event ); + void OnCollapseItem(wxTreeEvent &event ); + void ShowHidden( const bool yesno ); + DECLARE_EVENT_TABLE() + protected: + void CreateItems(const wxTreeItemId &parent); + void SetupSections(void); + wxArrayString m_paths, m_names; +}; + +//----------------------------------------------------------------------------- +// wxDirItemData +//----------------------------------------------------------------------------- + wxDirItemData::wxDirItemData(wxString& path, wxString& name) { m_path = new wxString(path); @@ -117,6 +201,7 @@ wxDirCtrl::wxDirCtrl(wxWindow *parent, const wxWindowID id, const wxString &WXUN { m_imageListNormal = new wxImageList(16, 16, TRUE); m_imageListNormal->Add(wxICON(icon1)); + m_imageListNormal->Add(wxICON(icon2)); SetImageList(m_imageListNormal); m_showHidden = FALSE; @@ -157,12 +242,12 @@ void wxDirCtrl::CreateItems(const wxTreeItemId &parent) for (unsigned int i=0; im_hasSubDirs) SetItemHasChildren(id); } } -void wxDirCtrl::OnExpandItem( const wxTreeEvent &event ) +void wxDirCtrl::OnExpandItem(wxTreeEvent &event ) { if (event.GetItem() == m_rootId) { @@ -195,10 +280,12 @@ void wxDirCtrl::OnExpandItem( const wxTreeEvent &event ) } CreateItems(event.GetItem()); wxEndBusyCursor(); + + SortChildren( event.GetItem() ); }; -void wxDirCtrl::OnCollapseItem( const wxTreeEvent &event ) +void wxDirCtrl::OnCollapseItem(wxTreeEvent &event ) { wxTreeItemId child, parent = event.GetItem(); long cookie; @@ -251,7 +338,7 @@ wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message, m_input = new wxTextCtrl( this, ID_TEXTCTRL, m_path, wxDefaultPosition ); // m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden") ); m_ok = new wxButton( this, ID_OK, _("OK") ); - m_cancel = new wxButton( this, ID_CANCEL, _("Cancel") ); + m_cancel = new wxButton( this, ID_CANCEL, _("Cancel"), wxDefaultPosition, wxSize(75,-1) ); m_new = new wxButton( this, ID_NEW, _("New...") ); // m_check->SetValue(TRUE); @@ -277,7 +364,7 @@ void wxDirDialog::doSize() m_input->GetSize(&w,&h2); h -= h2; m_ok->GetSize(&w, &h2); h -= h2; //m_check->GetSize(&w, &h2); h -= h2; - h -= 20; + h -= 30; wxLayoutConstraints *c = new wxLayoutConstraints; c->left.SameAs (this, wxLeft,5); @@ -303,14 +390,14 @@ void wxDirDialog::doSize() c = new wxLayoutConstraints; c->width.SameAs (m_cancel, wxWidth); c->height.AsIs (); - c->top.Below (m_input,5); - c->centreX.PercentOf (this, wxWidth, 25); + c->top.Below (m_input,10); + c->centreX.PercentOf (this, wxWidth, 20); m_ok->SetConstraints(c); c = new wxLayoutConstraints; c->width.SameAs (m_cancel, wxWidth); c->height.AsIs (); - c->top.Below (m_input,5); + c->top.Below (m_input,10); c->bottom.SameAs (this, wxBottom, 5); c->centreX.PercentOf (this, wxWidth, 50); m_new->SetConstraints(c); @@ -318,8 +405,8 @@ void wxDirDialog::doSize() c = new wxLayoutConstraints; c->width.AsIs (); c->height.AsIs (); - c->top.Below (m_input,5); - c->centreX.PercentOf (this, wxWidth, 75); + c->top.Below (m_input,10); + c->centreX.PercentOf (this, wxWidth, 80); m_cancel->SetConstraints(c); Layout(); @@ -339,7 +426,7 @@ void wxDirDialog::OnTreeSelected( wxTreeEvent &event ) m_input->SetValue( *(data->m_path) ); }; -void wxDirDialog::OnTreeKeyDown( wxKeyEvent &WXUNUSED(event) ) +void wxDirDialog::OnTreeKeyDown( wxTreeEvent &WXUNUSED(event) ) { wxDirItemData *data = (wxDirItemData*)m_dir->GetItemData(m_dir->GetSelection());