From dabd1377ce769598bda630dfad548be055e2a89b Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 10 Apr 2002 09:35:36 +0000 Subject: [PATCH] Added a wxDD_NEW_DIR_BUTTON style for wxDirDialog (currently, works for the generic implementation only). Renamed wxDIRCTRL_EDITABLE to wxDIRCTRL_EDIT_LABELS. Removed reported memory leaks from dynload.cpp using wxModule -- this may cause problems if other modules want to use wxPluginLibrary. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15074 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/dirctrl.tex | 2 +- docs/latex/wx/dirdlg.tex | 13 +++++++++++ include/wx/defs.h | 6 +++++ include/wx/dirdlg.h | 2 +- include/wx/dynload.h | 9 +++++--- include/wx/generic/dirctrlg.h | 2 +- include/wx/generic/dirdlgg.h | 2 +- src/common/dynload.cpp | 42 ++++++++++++++++++++++++----------- src/generic/dirctrlg.cpp | 4 +--- src/generic/dirdlgg.cpp | 28 ++++++++++++++++++----- 10 files changed, 81 insertions(+), 29 deletions(-) diff --git a/docs/latex/wx/dirctrl.tex b/docs/latex/wx/dirctrl.tex index 42d6726c83..7dafe11105 100644 --- a/docs/latex/wx/dirctrl.tex +++ b/docs/latex/wx/dirctrl.tex @@ -24,7 +24,7 @@ hierarchy, and optionally, a \helpref{wxChoice}{wxchoice} window containing a li \twocolitem{\indexit{wxDIRCTRL\_3D\_INTERNAL}}{Use 3D borders for internal controls.} \twocolitem{\indexit{wxDIRCTRL\_SELECT\_FIRST}}{When setting the default path, select the first file in the directory.} \twocolitem{\indexit{wxDIRCTRL\_SHOW\_FILTERS}}{Show the drop-down filter list.} -\twocolitem{\indexit{wxDIRCTRL\_EDITABLE}}{Allow the folder and file items to be editable.} +\twocolitem{\indexit{wxDIRCTRL\_EDIT\_LABELS}}{Allow the folder and file labels to be editable.} \end{twocollist} See also \helpref{Generic window styles}{windowstyles}. diff --git a/docs/latex/wx/dirdlg.tex b/docs/latex/wx/dirdlg.tex index 975062f23e..3662942693 100644 --- a/docs/latex/wx/dirdlg.tex +++ b/docs/latex/wx/dirdlg.tex @@ -12,6 +12,19 @@ This class represents the directory chooser dialog. \wxheading{Include files} + + +\wxheading{Window styles} + +\twocolwidtha{5cm} +\begin{twocollist} +\twocolitem{\indexit{wxDD\_NEW\_DIR\_BUTTON}}{Add "Create new directory" button and allow +directory names to be editable. Available only on platforms that use the generic +dialog chooser: GTK+, Motif, X11, MGL. For other platforms, use the wxGenericDirDialog +implementation explicitly if you wish to use this style.} +\end{twocollist} + +See also \helpref{Generic window styles}{windowstyles}. \wxheading{See also} diff --git a/include/wx/defs.h b/include/wx/defs.h index be319e0322..e22378d3d6 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -1159,6 +1159,12 @@ enum wxBorder // be modal. No progress will then be made at all. #define wxPD_REMAINING_TIME 0x0040 +/* + * wxDirDialog styles + */ + +#define wxDD_NEW_DIR_BUTTON 0x0080 + /* * extended dialog specifiers. these values are stored in a different * flag and thus do not overlap with other style flags. note that these diff --git a/include/wx/dirdlg.h b/include/wx/dirdlg.h index 5b0dacfef8..bb9a22f36d 100644 --- a/include/wx/dirdlg.h +++ b/include/wx/dirdlg.h @@ -41,7 +41,7 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxDirSelectorPromptStr; WXDLLEXPORT wxString wxDirSelector(const wxString& message = wxDirSelectorPromptStr, const wxString& defaultPath = wxEmptyString, - long style = 0, + long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxDD_NEW_DIR_BUTTON, const wxPoint& pos = wxDefaultPosition, wxWindow *parent = NULL); diff --git a/include/wx/dynload.h b/include/wx/dynload.h index a2d2763def..4cfd2b5de8 100644 --- a/include/wx/dynload.h +++ b/include/wx/dynload.h @@ -184,7 +184,7 @@ class WXDLLEXPORT wxPluginLibrary : public wxDynamicLibrary { public: - static wxDLImports ms_classes; // Static hash of all imported classes. + static wxDLImports* ms_classes; // Static hash of all imported classes. wxPluginLibrary( const wxString &libname, int flags = wxDL_DEFAULT ); ~wxPluginLibrary(); @@ -269,10 +269,13 @@ public: return m_entry->GetSymbol( symbol, success ); } + static void CreateManifest() { ms_manifest = new wxDLManifest(wxKEY_STRING); } + static void ClearManifest() { delete ms_manifest; ms_manifest = NULL; } + private: - static wxDLManifest ms_manifest; // Static hash of loaded libs. - wxPluginLibrary *m_entry; // Cache our entry in the manifest. + static wxDLManifest* ms_manifest; // Static hash of loaded libs. + wxPluginLibrary* m_entry; // Cache our entry in the manifest. // We could allow this class to be copied if we really // wanted to, but not without modification. diff --git a/include/wx/generic/dirctrlg.h b/include/wx/generic/dirctrlg.h index 23ca798c5a..ec2b098c29 100644 --- a/include/wx/generic/dirctrlg.h +++ b/include/wx/generic/dirctrlg.h @@ -47,7 +47,7 @@ enum // Use 3D borders on internal controls wxDIRCTRL_3D_INTERNAL = 0x0080, // Editable labels - wxDIRCTRL_EDITABLE = 0x0100 + wxDIRCTRL_EDIT_LABELS = 0x0100 }; //----------------------------------------------------------------------------- diff --git a/include/wx/generic/dirdlgg.h b/include/wx/generic/dirdlgg.h index d0b21b34f7..4996965dd3 100644 --- a/include/wx/generic/dirdlgg.h +++ b/include/wx/generic/dirdlgg.h @@ -38,7 +38,7 @@ public: wxGenericDirDialog(): wxDialog() {} wxGenericDirDialog(wxWindow* parent, const wxString& title, const wxString& defaultPath = wxEmptyString, - long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER, + long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxDD_NEW_DIR_BUTTON, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxSize(450, 550), const wxString& name = _T("dialog")); diff --git a/src/common/dynload.cpp b/src/common/dynload.cpp index b127ecf5d2..4d94741e29 100644 --- a/src/common/dynload.cpp +++ b/src/common/dynload.cpp @@ -38,6 +38,7 @@ #include "wx/filename.h" // for SplitPath() #include "wx/dynload.h" +#include "wx/module.h" #if defined(__DARWIN__) /* Porting notes: @@ -280,7 +281,22 @@ void *wxDynamicLibrary::GetSymbol(const wxString &name, bool *success) const // --------------------------------------------------------------------------- -wxDLImports wxPluginLibrary::ms_classes(wxKEY_STRING); +wxDLImports* wxPluginLibrary::ms_classes = NULL; + +class wxPluginLibraryModule : public wxModule +{ +public: + wxPluginLibraryModule() {} + bool OnInit() { wxPluginLibrary::ms_classes = new wxDLImports(wxKEY_STRING); return TRUE; } + void OnExit() { delete wxPluginLibrary::ms_classes; wxPluginLibrary::ms_classes = NULL; + wxPluginManager::ClearManifest(); } + +private: + DECLARE_DYNAMIC_CLASS(wxPluginLibraryModule ) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxPluginLibraryModule, wxModule) + wxPluginLibrary::wxPluginLibrary(const wxString &libname, int flags) : m_linkcount(1) @@ -347,8 +363,8 @@ void wxPluginLibrary::UpdateClassInfo() // Hash all the class names into a local table too so // we can quickly find the entry they correspond to. - if( ms_classes.Get(info->m_className) == 0 ) - ms_classes.Put(info->m_className, (wxObject *) this); + if( ms_classes->Get(info->m_className) == 0 ) + ms_classes->Put(info->m_className, (wxObject *) this); } } @@ -368,7 +384,7 @@ void wxPluginLibrary::RestoreClassInfo() for(info = m_after; info != m_before; info = info->m_next) { wxClassInfo::sm_classTable->Delete(info->m_className); - ms_classes.Delete(info->m_className); + ms_classes->Delete(info->m_className); } if( wxClassInfo::sm_first == m_after ) @@ -457,7 +473,7 @@ void wxPluginLibrary::UnregisterModules() // wxPluginLibrary // --------------------------------------------------------------------------- -wxDLManifest wxPluginManager::ms_manifest(wxKEY_STRING); +wxDLManifest* wxPluginManager::ms_manifest = NULL; // ------------------------ // Static accessors @@ -470,7 +486,7 @@ wxPluginLibrary *wxPluginManager::LoadLibrary(const wxString &libname, int flags if( !(flags & wxDL_VERBATIM) ) realname += wxDynamicLibrary::GetDllExt(); - wxPluginLibrary *entry = (wxPluginLibrary*) ms_manifest.Get(realname); + wxPluginLibrary *entry = (wxPluginLibrary*) ms_manifest->Get(realname); if( entry != 0 ) { @@ -482,7 +498,7 @@ wxPluginLibrary *wxPluginManager::LoadLibrary(const wxString &libname, int flags if( entry->IsLoaded() ) { - ms_manifest.Put(realname, (wxObject*) entry); + ms_manifest->Put(realname, (wxObject*) entry); } else { @@ -496,10 +512,10 @@ wxPluginLibrary *wxPluginManager::LoadLibrary(const wxString &libname, int flags bool wxPluginManager::UnloadLibrary(const wxString &libname) { - wxPluginLibrary *entry = (wxPluginLibrary*) ms_manifest.Get(libname); + wxPluginLibrary *entry = (wxPluginLibrary*) ms_manifest->Get(libname); if( !entry ) - entry = (wxPluginLibrary*) ms_manifest.Get(libname + wxDynamicLibrary::GetDllExt()); + entry = (wxPluginLibrary*) ms_manifest->Get(libname + wxDynamicLibrary::GetDllExt()); if( entry ) return entry->UnrefLib(); @@ -512,9 +528,9 @@ bool wxPluginManager::UnloadLibrary(const wxString &libname) wxPluginLibrary *wxPluginManager::GetObjectFromHandle(wxDllType handle) { wxNode *node; - ms_manifest.BeginFind(); + ms_manifest->BeginFind(); - for(node = ms_manifest.Next(); node; node = ms_manifest.Next()) + for(node = ms_manifest->Next(); node; node = ms_manifest->Next()) if( ((wxPluginLibrary*)node->GetData())->GetLibHandle() == handle ) return (wxPluginLibrary*)node->GetData(); @@ -535,11 +551,11 @@ bool wxPluginManager::Load(const wxString &libname, int flags) void wxPluginManager::Unload() { wxNode *node; - ms_manifest.BeginFind(); + ms_manifest->BeginFind(); // It's either this or store the name of the lib just to do this. - for(node = ms_manifest.Next(); node; node = ms_manifest.Next()) + for(node = ms_manifest->Next(); node; node = ms_manifest->Next()) if( (wxPluginLibrary*)node->GetData() == m_entry ) break; diff --git a/src/generic/dirctrlg.cpp b/src/generic/dirctrlg.cpp index 94e2f41024..38c948fc2c 100644 --- a/src/generic/dirctrlg.cpp +++ b/src/generic/dirctrlg.cpp @@ -504,10 +504,8 @@ bool wxGenericDirCtrl::Create(wxWindow *parent, long treeStyle = wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT; -#ifdef __WXMSW__ - if (style & wxDIRCTRL_EDITABLE) + if (style & wxDIRCTRL_EDIT_LABELS) treeStyle |= wxTR_EDIT_LABELS; -#endif if ((style & wxDIRCTRL_3D_INTERNAL) == 0) treeStyle |= wxNO_BORDER; diff --git a/src/generic/dirdlgg.cpp b/src/generic/dirdlgg.cpp index 94349e3c35..d74c7aadc0 100644 --- a/src/generic/dirdlgg.cpp +++ b/src/generic/dirdlgg.cpp @@ -93,14 +93,19 @@ wxGenericDirDialog::wxGenericDirDialog(wxWindow* parent, const wxString& title, // I'm not convinced we need a New button, and we tend to get annoying // accidental-editing with label editing enabled. - wxBitmapButton* newButton = - new wxBitmapButton(this, ID_NEW, - wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_CMN_DIALOG)); - buttonsizer->Add( newButton, 0, wxRIGHT, 10 ); + if (style & wxDD_NEW_DIR_BUTTON) + { + wxBitmapButton* newButton = + new wxBitmapButton(this, ID_NEW, + wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_CMN_DIALOG)); + buttonsizer->Add( newButton, 0, wxRIGHT, 10 ); +#if wxUSE_TOOLTIPS + newButton->SetToolTip(_("Create new directory")); +#endif + } #if wxUSE_TOOLTIPS homeButton->SetToolTip(_("Go to home directory")); - newButton->SetToolTip(_("Create new directory")); #endif topsizer->Add( buttonsizer, 0, wxTOP | wxALIGN_RIGHT, 10 ); @@ -108,10 +113,21 @@ wxGenericDirDialog::wxGenericDirDialog(wxWindow* parent, const wxString& title, // 1) dir ctrl m_dirCtrl = NULL; // this is neccessary, event handler called from // wxGenericDirCtrl would crash otherwise! + long dirStyle = wxDIRCTRL_DIR_ONLY|wxSUNKEN_BORDER; + +#ifdef __WXMSW__ + if (style & wxDD_NEW_DIR_BUTTON) + { + // Only under Windows do we need the wxTR_EDIT_LABEL tree control style + // before we can call EditLabel (required for "New directory") + dirStyle |= wxDIRCTRL_EDIT_LABELS; + } +#endif + m_dirCtrl = new wxGenericDirCtrl(this, ID_DIRCTRL, m_path, wxPoint(5, 5), wxSize(300, 200), - wxDIRCTRL_DIR_ONLY|wxDIRCTRL_EDITABLE|wxSUNKEN_BORDER); + dirStyle); topsizer->Add( m_dirCtrl, 1, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 ); -- 2.45.2