2000-07-23 15:10:27 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dirctrlg.h
|
|
|
|
// Purpose: wxGenericDirCtrl class
|
|
|
|
// Builds on wxDirCtrl class written by Robert Roebling for the
|
|
|
|
// wxFile application, modified by Harm van der Heijden.
|
|
|
|
// Further modified for Windows.
|
2002-01-06 18:10:56 -05:00
|
|
|
// Author: Robert Roebling, Harm van der Heijden, Julian Smart et al
|
2000-07-23 15:10:27 -04:00
|
|
|
// Modified by:
|
|
|
|
// Created: 21/3/2000
|
|
|
|
// RCS-ID: $Id$
|
2002-01-06 18:10:56 -05:00
|
|
|
// Copyright: (c) Robert Roebling, Harm van der Heijden, Julian Smart
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
2000-07-23 15:10:27 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_DIRCTRL_H_
|
|
|
|
#define _WX_DIRCTRL_H_
|
|
|
|
|
2004-06-17 15:50:20 -04:00
|
|
|
#if wxUSE_DIRDLG || wxUSE_FILEDLG
|
|
|
|
#include "wx/imaglist.h"
|
|
|
|
#endif
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#if wxUSE_DIRDLG
|
|
|
|
|
2000-07-23 15:10:27 -04:00
|
|
|
#include "wx/treectrl.h"
|
2002-01-06 18:10:56 -05:00
|
|
|
#include "wx/dialog.h"
|
2000-07-25 14:47:48 -04:00
|
|
|
#include "wx/dirdlg.h"
|
|
|
|
#include "wx/choice.h"
|
2000-07-23 15:10:27 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// classes
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxImageList;
|
|
|
|
class WXDLLIMPEXP_FWD_BASE wxHashTable;
|
2002-01-06 18:10:56 -05:00
|
|
|
|
2000-07-23 15:10:27 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Extra styles for wxGenericDirCtrl
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2002-01-06 18:10:56 -05:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
// Only allow directory viewing/selection, no files
|
|
|
|
wxDIRCTRL_DIR_ONLY = 0x0010,
|
|
|
|
// When setting the default path, select the first file in the directory
|
|
|
|
wxDIRCTRL_SELECT_FIRST = 0x0020,
|
2007-05-23 20:14:59 -04:00
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
|
|
|
// Unused, for compatibility only
|
2002-01-06 18:10:56 -05:00
|
|
|
wxDIRCTRL_SHOW_FILTERS = 0x0040,
|
2007-05-23 20:14:59 -04:00
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
2002-01-06 18:10:56 -05:00
|
|
|
// Use 3D borders on internal controls
|
2002-04-08 07:15:16 -04:00
|
|
|
wxDIRCTRL_3D_INTERNAL = 0x0080,
|
|
|
|
// Editable labels
|
2002-04-10 05:35:36 -04:00
|
|
|
wxDIRCTRL_EDIT_LABELS = 0x0100
|
2002-01-06 18:10:56 -05:00
|
|
|
};
|
2000-07-23 15:10:27 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxDirItemData
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxDirItemData : public wxTreeItemData
|
2000-07-23 15:10:27 -04:00
|
|
|
{
|
|
|
|
public:
|
2002-01-06 18:10:56 -05:00
|
|
|
wxDirItemData(const wxString& path, const wxString& name, bool isDir);
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxDirItemData(){}
|
2002-01-06 18:10:56 -05:00
|
|
|
void SetNewDirName(const wxString& path);
|
|
|
|
|
|
|
|
bool HasSubDirs() const;
|
|
|
|
bool HasFiles(const wxString& spec = wxEmptyString) const;
|
|
|
|
|
|
|
|
wxString m_path, m_name;
|
|
|
|
bool m_isHidden;
|
|
|
|
bool m_isExpanded;
|
|
|
|
bool m_isDir;
|
2000-07-23 15:10:27 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxDirCtrl
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxDirFilterListCtrl;
|
2000-07-23 15:10:27 -04:00
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxGenericDirCtrl: public wxControl
|
2000-07-23 15:10:27 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxGenericDirCtrl();
|
2004-06-17 12:22:36 -04:00
|
|
|
wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = wxID_ANY,
|
2000-07-23 15:10:27 -04:00
|
|
|
const wxString &dir = wxDirDialogDefaultFolderStr,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
2007-11-13 09:27:26 -05:00
|
|
|
long style = wxDIRCTRL_3D_INTERNAL,
|
2000-07-23 15:10:27 -04:00
|
|
|
const wxString& filter = wxEmptyString,
|
|
|
|
int defaultFilter = 0,
|
|
|
|
const wxString& name = wxTreeCtrlNameStr )
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
Create(parent, id, dir, pos, size, style, filter, defaultFilter, name);
|
|
|
|
}
|
2004-06-17 12:22:36 -04:00
|
|
|
|
|
|
|
bool Create(wxWindow *parent, const wxWindowID id = wxID_ANY,
|
2000-07-23 15:10:27 -04:00
|
|
|
const wxString &dir = wxDirDialogDefaultFolderStr,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
2007-11-13 09:27:26 -05:00
|
|
|
long style = wxDIRCTRL_3D_INTERNAL,
|
2000-07-23 15:10:27 -04:00
|
|
|
const wxString& filter = wxEmptyString,
|
|
|
|
int defaultFilter = 0,
|
|
|
|
const wxString& name = wxTreeCtrlNameStr );
|
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual void Init();
|
2000-07-23 15:10:27 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual ~wxGenericDirCtrl();
|
2000-07-23 15:10:27 -04:00
|
|
|
|
|
|
|
void OnExpandItem(wxTreeEvent &event );
|
|
|
|
void OnCollapseItem(wxTreeEvent &event );
|
|
|
|
void OnBeginEditItem(wxTreeEvent &event );
|
|
|
|
void OnEndEditItem(wxTreeEvent &event );
|
|
|
|
void OnSize(wxSizeEvent &event );
|
|
|
|
|
|
|
|
// Try to expand as much of the given path as possible.
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual bool ExpandPath(const wxString& path);
|
2006-05-28 19:54:28 -04:00
|
|
|
// collapse the path
|
|
|
|
virtual bool CollapsePath(const wxString& path);
|
2000-07-23 15:10:27 -04:00
|
|
|
|
|
|
|
// Accessors
|
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual inline wxString GetDefaultPath() const { return m_defaultPath; }
|
|
|
|
virtual void SetDefaultPath(const wxString& path) { m_defaultPath = path; }
|
2000-07-23 15:10:27 -04:00
|
|
|
|
|
|
|
// Get dir or filename
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual wxString GetPath() const;
|
2004-06-17 12:22:36 -04:00
|
|
|
|
2000-07-23 15:10:27 -04:00
|
|
|
// Get selected filename path only (else empty string).
|
|
|
|
// I.e. don't count a directory as a selection
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual wxString GetFilePath() const;
|
|
|
|
virtual void SetPath(const wxString& path);
|
2004-06-17 12:22:36 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual void ShowHidden( bool show );
|
|
|
|
virtual bool GetShowHidden() { return m_showHidden; }
|
2000-07-23 15:10:27 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual wxString GetFilter() const { return m_filter; }
|
|
|
|
virtual void SetFilter(const wxString& filter);
|
2000-07-23 15:10:27 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual int GetFilterIndex() const { return m_currentFilter; }
|
|
|
|
virtual void SetFilterIndex(int n);
|
2000-07-23 15:10:27 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual wxTreeItemId GetRootId() { return m_rootId; }
|
2000-07-23 15:10:27 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
|
|
|
|
virtual wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
|
2000-07-23 15:10:27 -04:00
|
|
|
|
2002-01-09 13:00:39 -05:00
|
|
|
// Helper
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual void SetupSections();
|
2004-06-17 12:22:36 -04:00
|
|
|
|
2000-07-23 15:10:27 -04:00
|
|
|
// Find the child that matches the first part of 'path'.
|
|
|
|
// E.g. if a child path is "/usr" and 'path' is "/usr/include"
|
|
|
|
// then the child for /usr is returned.
|
2004-06-17 12:22:36 -04:00
|
|
|
// If the path string has been used (we're at the leaf), done is set to true
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
|
2004-06-17 12:22:36 -04:00
|
|
|
|
2000-07-23 15:10:27 -04:00
|
|
|
// Resize the components of the control
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual void DoResize();
|
2004-06-17 12:22:36 -04:00
|
|
|
|
2002-04-09 18:52:07 -04:00
|
|
|
// Collapse & expand the tree, thus re-creating it from scratch:
|
2002-12-04 09:11:26 -05:00
|
|
|
virtual void ReCreateTree();
|
2004-06-17 12:22:36 -04:00
|
|
|
|
2005-03-31 14:04:03 -05:00
|
|
|
// Collapse the entire tree
|
|
|
|
virtual void CollapseTree();
|
|
|
|
|
2007-11-17 10:12:13 -05:00
|
|
|
|
|
|
|
// overridden base class methods
|
|
|
|
virtual void SetFocus();
|
|
|
|
|
2000-07-23 15:10:27 -04:00
|
|
|
protected:
|
2005-03-31 14:04:03 -05:00
|
|
|
virtual void ExpandRoot();
|
2003-06-01 11:48:42 -04:00
|
|
|
virtual void ExpandDir(wxTreeItemId parentId);
|
|
|
|
virtual void CollapseDir(wxTreeItemId parentId);
|
|
|
|
virtual const wxTreeItemId AddSection(const wxString& path, const wxString& name, int imageId = 0);
|
|
|
|
virtual wxTreeItemId AppendItem (const wxTreeItemId & parent,
|
|
|
|
const wxString & text,
|
|
|
|
int image = -1, int selectedImage = -1,
|
|
|
|
wxTreeItemData * data = NULL);
|
2000-07-23 15:10:27 -04:00
|
|
|
//void FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames);
|
2004-11-03 18:01:57 -05:00
|
|
|
virtual wxTreeCtrl* CreateTreeCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long treeStyle);
|
2000-07-23 15:10:27 -04:00
|
|
|
|
|
|
|
// Extract description and actual filter from overall filter string
|
|
|
|
bool ExtractWildcard(const wxString& filterStr, int n, wxString& filter, wxString& description);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_showHidden;
|
|
|
|
wxTreeItemId m_rootId;
|
|
|
|
wxString m_defaultPath; // Starting path
|
|
|
|
long m_styleEx; // Extended style
|
|
|
|
wxString m_filter; // Wildcards in same format as per wxFileDialog
|
|
|
|
int m_currentFilter; // The current filter index
|
|
|
|
wxString m_currentFilterStr; // Current filter string
|
|
|
|
wxTreeCtrl* m_treeCtrl;
|
|
|
|
wxDirFilterListCtrl* m_filterListCtrl;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxGenericDirCtrl)
|
2003-01-02 18:38:11 -05:00
|
|
|
DECLARE_NO_COPY_CLASS(wxGenericDirCtrl)
|
2000-07-23 15:10:27 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxDirFilterListCtrl
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxDirFilterListCtrl: public wxChoice
|
2000-07-23 15:10:27 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxDirFilterListCtrl() { Init(); }
|
2004-06-17 12:22:36 -04:00
|
|
|
wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY,
|
2000-07-23 15:10:27 -04:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0)
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
Create(parent, id, pos, size, style);
|
|
|
|
}
|
2004-06-17 12:22:36 -04:00
|
|
|
|
|
|
|
bool Create(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY,
|
2000-07-23 15:10:27 -04:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0);
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxDirFilterListCtrl() {}
|
2000-07-23 15:10:27 -04:00
|
|
|
|
2002-01-06 18:10:56 -05:00
|
|
|
//// Operations
|
2000-07-23 15:10:27 -04:00
|
|
|
void FillFilterList(const wxString& filter, int defaultFilter);
|
|
|
|
|
2002-01-06 18:10:56 -05:00
|
|
|
//// Events
|
2000-07-23 15:10:27 -04:00
|
|
|
void OnSelFilter(wxCommandEvent& event);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxGenericDirCtrl* m_dirCtrl;
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
DECLARE_CLASS(wxDirFilterListCtrl)
|
2003-01-02 18:38:11 -05:00
|
|
|
DECLARE_NO_COPY_CLASS(wxDirFilterListCtrl)
|
2000-07-23 15:10:27 -04:00
|
|
|
};
|
|
|
|
|
2002-01-06 18:10:56 -05:00
|
|
|
#if !defined(__WXMSW__) && !defined(__WXMAC__) && !defined(__WXPM__)
|
|
|
|
#define wxDirCtrl wxGenericDirCtrl
|
|
|
|
#endif
|
2000-07-23 15:10:27 -04:00
|
|
|
|
2002-04-08 06:50:14 -04:00
|
|
|
// Symbols for accessing individual controls
|
|
|
|
#define wxID_TREECTRL 7000
|
|
|
|
#define wxID_FILTERLISTCTRL 7001
|
|
|
|
|
2004-06-17 15:50:20 -04:00
|
|
|
#endif // wxUSE_DIRDLG
|
|
|
|
|
2003-04-06 15:57:51 -04:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// wxFileIconsTable - use wxTheFileIconsTable which is created as necessary
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2004-06-17 15:50:20 -04:00
|
|
|
#if wxUSE_DIRDLG || wxUSE_FILEDLG
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxFileIconsTable
|
2003-04-06 15:57:51 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxFileIconsTable();
|
|
|
|
~wxFileIconsTable();
|
|
|
|
|
|
|
|
enum iconId_Type
|
|
|
|
{
|
|
|
|
folder,
|
|
|
|
folder_open,
|
|
|
|
computer,
|
|
|
|
drive,
|
|
|
|
cdrom,
|
|
|
|
floppy,
|
|
|
|
removeable,
|
|
|
|
file,
|
|
|
|
executable
|
|
|
|
};
|
|
|
|
|
|
|
|
int GetIconID(const wxString& extension, const wxString& mime = wxEmptyString);
|
|
|
|
wxImageList *GetSmallImageList();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void Create(); // create on first use
|
|
|
|
|
|
|
|
wxImageList *m_smallImageList;
|
|
|
|
wxHashTable *m_HashTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The global fileicons table
|
2008-03-26 11:06:00 -04:00
|
|
|
extern WXDLLIMPEXP_DATA_CORE(wxFileIconsTable *) wxTheFileIconsTable;
|
2003-04-06 15:57:51 -04:00
|
|
|
|
2004-06-17 15:50:20 -04:00
|
|
|
#endif // wxUSE_DIRDLG || wxUSE_FILEDLG
|
2001-06-26 16:59:19 -04:00
|
|
|
|
2000-07-23 15:10:27 -04:00
|
|
|
#endif
|
|
|
|
// _WX_DIRCTRLG_H_
|