diff --git a/docs/changes.txt b/docs/changes.txt index fe91400fc3..fc5e453a7d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -9,6 +9,10 @@ Note: This file contains the list of changes since wxWidgets 3.x, please see 3.1.0: (released 2014-xx-xx) ---------------------------- +All: + +- Add wxScopedArray ctor taking the number of elements to allocate. + All (GUI): - XRC handler for wxAuiToolBar added (Kinaou Hervé). diff --git a/include/wx/scopedarray.h b/include/wx/scopedarray.h index e6246a235e..c857093e7c 100644 --- a/include/wx/scopedarray.h +++ b/include/wx/scopedarray.h @@ -25,6 +25,7 @@ public: typedef T element_type; wxEXPLICIT wxScopedArray(T * array = NULL) : m_array(array) { } + wxEXPLICIT wxScopedArray(size_t count) : m_array(new T[count]) { } ~wxScopedArray() { delete [] m_array; } diff --git a/interface/wx/scopedarray.h b/interface/wx/scopedarray.h index bc2d4af69a..59e8baf9cb 100644 --- a/interface/wx/scopedarray.h +++ b/interface/wx/scopedarray.h @@ -129,6 +129,16 @@ public: */ explicit wxScopedArray(T * array = NULL); + /** + Constructor allocating a new array of the specified size. + + @param count + The number of elements to allocate. + + @since 3.1.0 + */ + explicit wxScopedArray(size_t count); + /// Destructor destroy the array. ~wxScopedArray(); diff --git a/src/common/docview.cpp b/src/common/docview.cpp index b646d9efe2..cfba011bfd 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -1810,7 +1810,7 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates, int noTemplates, bool sort) { wxArrayString strings; - wxScopedArray data(new wxDocTemplate *[noTemplates]); + wxScopedArray data(noTemplates); int i; int n = 0; @@ -1888,7 +1888,7 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates, int noTemplates, bool sort) { wxArrayString strings; - wxScopedArray data(new wxDocTemplate *[noTemplates]); + wxScopedArray data(noTemplates); int i; int n = 0; diff --git a/src/common/translation.cpp b/src/common/translation.cpp index 455fb315d0..f43638a1f5 100644 --- a/src/common/translation.cpp +++ b/src/common/translation.cpp @@ -138,7 +138,7 @@ wxString GetPreferredUILanguage(const wxArrayString& available) NULL, &bufferSize) ) { - wxScopedArray langs(new WCHAR[bufferSize]); + wxScopedArray langs(bufferSize); if ( (*s_pfnGetUserPreferredUILanguages)(MUI_LANGUAGE_NAME, &numLangs, langs.get(), diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index c1c9c9c99b..887bce0a10 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -626,7 +626,7 @@ bool wxClipboard::AddData( wxDataObject *data ) // get formats from wxDataObjects const size_t count = data->GetFormatCount(); - wxDataFormatArray formats(new wxDataFormat[count]); + wxDataFormatArray formats(count); data->GetAllFormats(formats.get()); // always provide TIMESTAMP as a target, see comments in selection_handler @@ -690,7 +690,7 @@ bool wxClipboard::GetData( wxDataObject& data ) // get all supported formats from wxDataObjects: notice that we are setting // the object data, so we need them in "Set" direction const size_t count = data.GetFormatCount(wxDataObject::Set); - wxDataFormatArray formats(new wxDataFormat[count]); + wxDataFormatArray formats(count); data.GetAllFormats(formats.get(), wxDataObject::Set); for ( size_t i = 0; i < count; i++ ) diff --git a/src/motif/clipbrd.cpp b/src/motif/clipbrd.cpp index 4664139db9..5012aff26f 100644 --- a/src/motif/clipbrd.cpp +++ b/src/motif/clipbrd.cpp @@ -264,7 +264,7 @@ void wxClipboardCallback( Widget xwidget, long* data_id, wxCharBuffer buffer(size); size_t count = dobj->GetFormatCount( wxDataObject::Get ); - wxDataFormatScopedArray dfarr( new wxDataFormat[count] ); + wxDataFormatScopedArray dfarr(count); dobj->GetAllFormats( dfarr.get(), wxDataObject::Get ); if( !dobj->GetDataHere( dfarr[*priv], buffer.data() ) ) @@ -300,7 +300,7 @@ bool wxClipboard::AddData( wxDataObject *data ) return false; size_t count = data->GetFormatCount( wxDataObject::Get ); - wxDataFormatScopedArray dfarr( new wxDataFormat[count] ); + wxDataFormatScopedArray dfarr(count); data->GetAllFormats( dfarr.get(), wxDataObject::Get ); for( size_t i = 0; i < count; ++i ) @@ -413,7 +413,7 @@ bool wxClipboard::GetData( wxDataObject& data ) int count; unsigned long max_name_length; size_t dfcount = data.GetFormatCount( wxDataObject::Set ); - wxDataFormatScopedArray dfarr( new wxDataFormat[dfcount] ); + wxDataFormatScopedArray dfarr(dfcount); data.GetAllFormats( dfarr.get(), wxDataObject::Set ); if( XmClipboardInquireCount( xdisplay, xwindow, &count, &max_name_length ) diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 5834da9b26..185a52ca13 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -860,7 +860,7 @@ size_t wxMenu::CopyAccels(wxAcceleratorEntry *accels) const wxAcceleratorTable *wxMenu::CreateAccelTable() const { const size_t count = m_accels.size(); - wxScopedArray accels(new wxAcceleratorEntry[count]); + wxScopedArray accels(count); CopyAccels(accels.get()); return new wxAcceleratorTable(count, accels.get()); diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index 2055a0a0de..097a576311 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -894,7 +894,7 @@ STDMETHODIMP wxIDataObject::EnumFormatEtc(DWORD dwDir, nFormatCount = wx_truncate_cast(ULONG, ourFormatCount + sysFormatCount); // fill format array with formats ... - wxScopedArray formats(new wxDataFormat[nFormatCount]); + wxScopedArray formats(nFormatCount); // ... from content data (supported formats) m_pDataObject->GetAllFormats(formats.get(), dir); diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index c292bb77de..a45adb5418 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -931,7 +931,7 @@ bool wxToolBar::Realize() // Next add the buttons and separators // ----------------------------------- - wxScopedArray buttons(new TBBUTTON[nTools]); + wxScopedArray buttons(nTools); // this array will hold the indices of all controls in the toolbar wxArrayInt controlIds;