diff --git a/include/wx/dcmirror.h b/include/wx/dcmirror.h index 4bbd27e777..44747c1582 100644 --- a/include/wx/dcmirror.h +++ b/include/wx/dcmirror.h @@ -13,6 +13,8 @@ #include "wx/dc.h" +#include "wx/scopedarray.h" + // ---------------------------------------------------------------------------- // wxMirrorDC allows to write the same code for horz/vertical layout // ---------------------------------------------------------------------------- @@ -224,25 +226,21 @@ protected: virtual void DoDrawLines(int n, const wxPoint points[], wxCoord xoffset, wxCoord yoffset) wxOVERRIDE { - wxPoint* points_alloc = Mirror(n, points); + wxScopedArray points_alloc(Mirror(n, points)); m_dc.DoDrawLines(n, points, GetX(xoffset, yoffset), GetY(xoffset, yoffset)); - - delete[] points_alloc; } virtual void DoDrawPolygon(int n, const wxPoint points[], wxCoord xoffset, wxCoord yoffset, wxPolygonFillMode fillStyle = wxODDEVEN_RULE) wxOVERRIDE { - wxPoint* points_alloc = Mirror(n, points); + wxScopedArray points_alloc(Mirror(n, points)); m_dc.DoDrawPolygon(n, points, GetX(xoffset, yoffset), GetY(xoffset, yoffset), fillStyle); - - delete[] points_alloc; } virtual void DoSetDeviceClippingRegion(const wxRegion& WXUNUSED(region)) wxOVERRIDE diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index 4e656015e8..30eb2b857b 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -26,6 +26,7 @@ #include "wx/dcscreen.h" #include "wx/dcprint.h" #include "wx/prntbase.h" +#include "wx/scopedarray.h" #include "wx/scopeguard.h" #include "wx/stack.h" @@ -694,7 +695,7 @@ wxDCImpl::DoStretchBlit(wxCoord xdest, wxCoord ydest, void wxDCImpl::DrawLines(const wxPointList *list, wxCoord xoffset, wxCoord yoffset) { int n = list->GetCount(); - wxPoint *points = new wxPoint[n]; + wxScopedArray points(n); int i = 0; for ( wxPointList::compatibility_iterator node = list->GetFirst(); node; node = node->GetNext(), i++ ) @@ -704,9 +705,7 @@ void wxDCImpl::DrawLines(const wxPointList *list, wxCoord xoffset, wxCoord yoffs points[i].y = point->y; } - DoDrawLines(n, points, xoffset, yoffset); - - delete [] points; + DoDrawLines(n, points.get(), xoffset, yoffset); } void wxDCImpl::DrawPolygon(const wxPointList *list, @@ -714,7 +713,7 @@ void wxDCImpl::DrawPolygon(const wxPointList *list, wxPolygonFillMode fillStyle) { int n = list->GetCount(); - wxPoint *points = new wxPoint[n]; + wxScopedArray points(n); int i = 0; for ( wxPointList::compatibility_iterator node = list->GetFirst(); node; node = node->GetNext(), i++ ) @@ -724,9 +723,7 @@ void wxDCImpl::DrawPolygon(const wxPointList *list, points[i].y = point->y; } - DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); - - delete [] points; + DoDrawPolygon(n, points.get(), xoffset, yoffset, fillStyle); } void @@ -743,14 +740,13 @@ wxDCImpl::DoDrawPolyPolygon(int n, } int i, j, lastOfs; - wxPoint* pts; for (i = j = lastOfs = 0; i < n; i++) { lastOfs = j; j += count[i]; } - pts = new wxPoint[j+n-1]; + wxScopedArray pts(j+n-1); for (i = 0; i < j; i++) pts[i] = points[i]; for (i = 2; i <= n; i++) @@ -761,15 +757,14 @@ wxDCImpl::DoDrawPolyPolygon(int n, { wxDCPenChanger setTransp(*m_owner, *wxTRANSPARENT_PEN); - DoDrawPolygon(j, pts, xoffset, yoffset, fillStyle); + DoDrawPolygon(j, pts.get(), xoffset, yoffset, fillStyle); } for (i = j = 0; i < n; i++) { - DoDrawLines(count[i], pts+j, xoffset, yoffset); + DoDrawLines(count[i], pts.get()+j, xoffset, yoffset); j += count[i]; } - delete[] pts; } #if wxUSE_SPLINES diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index 8c77b37d19..f0980a4cfc 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -25,6 +25,7 @@ #endif #include "wx/display.h" +#include "wx/scopedarray.h" //----------------------------------------------------------------------------- // Local functions @@ -833,7 +834,7 @@ void wxGCDCImpl::DoDrawLines(int n, const wxPoint points[], int maxX = minX; int maxY = minY; - wxPoint2DDouble* pointsD = new wxPoint2DDouble[n]; + wxScopedArray pointsD(n); for( int i = 0; i < n; ++i) { wxPoint p = points[i]; @@ -846,8 +847,7 @@ void wxGCDCImpl::DoDrawLines(int n, const wxPoint points[], else if (p.y > maxY) maxY = p.y; } - m_graphicContext->StrokeLines( n , pointsD); - delete[] pointsD; + m_graphicContext->StrokeLines( n , pointsD.get()); CalcBoundingBox(minX + xoffset, minY + yoffset, maxX + xoffset, maxY + yoffset); @@ -915,7 +915,7 @@ void wxGCDCImpl::DoDrawPolygon( int n, const wxPoint points[], int maxX = minX; int maxY = minY; - wxPoint2DDouble* pointsD = new wxPoint2DDouble[n+(closeIt?1:0)]; + wxScopedArray pointsD(n+(closeIt?1:0)); for( int i = 0; i < n; ++i) { wxPoint p = points[i]; @@ -930,8 +930,7 @@ void wxGCDCImpl::DoDrawPolygon( int n, const wxPoint points[], if ( closeIt ) pointsD[n] = pointsD[0]; - m_graphicContext->DrawLines( n+(closeIt?1:0) , pointsD, fillStyle); - delete[] pointsD; + m_graphicContext->DrawLines( n+(closeIt?1:0) , pointsD.get(), fillStyle); CalcBoundingBox(minX + xoffset, minY + yoffset, maxX + xoffset, maxY + yoffset); diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index b8a9869d47..bb65558b45 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -21,6 +21,7 @@ #endif #include "wx/fontutil.h" +#include "wx/scopedarray.h" #include "wx/gtk/private.h" #include "wx/gtk/private/object.h" @@ -723,12 +724,12 @@ void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other const GdkPoint* gpts = reinterpret_cast(points); - GdkPoint* gpts_alloc = NULL; + wxScopedArray gpts_alloc; if (doScale) { - gpts_alloc = new GdkPoint[n]; - gpts = gpts_alloc; + gpts_alloc.reset(new GdkPoint[n]); + gpts = gpts_alloc.get(); } for (int i = 0; i < n; i++) @@ -743,8 +744,6 @@ void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset if (m_gdkwindow) gdk_draw_lines(m_gdkwindow, m_penGC, const_cast(gpts), n); - - delete[] gpts_alloc; } void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], @@ -761,12 +760,12 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], // GdkPoint and wxPoint have the same memory layout, so we can cast one to the other const GdkPoint* gdkpoints = reinterpret_cast(points); - GdkPoint* gdkpoints_alloc = NULL; + wxScopedArray gdkpoints_alloc; if (doScale) { - gdkpoints_alloc = new GdkPoint[n]; - gdkpoints = gdkpoints_alloc; + gdkpoints_alloc.reset(new GdkPoint[n]); + gdkpoints = gdkpoints_alloc.get(); } int i; @@ -810,8 +809,6 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], } } - - delete[] gdkpoints_alloc; } void wxWindowDCImpl::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) @@ -1010,11 +1007,11 @@ ScaleMask(GdkPixmap* mask, int x, int y, int w, int h, int dst_w, int dst_h, dou // convert black and white pixbuf back to a mono pixmap const unsigned out_rowstride = (dst_w + 7) / 8; const size_t data_size = out_rowstride * size_t(dst_h); - char* data = new char[data_size]; - char* out = data; + wxScopedArray data(data_size); + char* out = data.get(); const guchar* row = gdk_pixbuf_get_pixels(pixbuf); const int rowstride = gdk_pixbuf_get_rowstride(pixbuf); - memset(data, 0, data_size); + memset(data.get(), 0, data_size); for (int j = 0; j < dst_h; j++, row += rowstride, out += out_rowstride) { const guchar* in = row; @@ -1023,9 +1020,7 @@ ScaleMask(GdkPixmap* mask, int x, int y, int w, int h, int dst_w, int dst_h, dou out[i >> 3] |= 1 << (i & 7); } g_object_unref(pixbuf); - GdkPixmap* pixmap = gdk_bitmap_create_from_data(mask, data, dst_w, dst_h); - delete[] data; - return pixmap; + return gdk_bitmap_create_from_data(mask, data.get(), dst_w, dst_h); } // Make a new mask from part of a mask and a clip region. @@ -1632,13 +1627,12 @@ void wxWindowDCImpl::SetPen( const wxPen &pen ) if (req_dash && req_nb_dash) { - wxDash* real_req_dash = new wxDash[req_nb_dash]; + wxScopedArray real_req_dash(req_nb_dash); if (real_req_dash) { for (int i = 0; i < req_nb_dash; i++) real_req_dash[i] = req_dash[i] * width; - gdk_gc_set_dashes( m_penGC, 0, real_req_dash, req_nb_dash ); - delete[] real_req_dash; + gdk_gc_set_dashes( m_penGC, 0, real_req_dash.get(), req_nb_dash ); } else { diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index c949ae93ba..2031206ef9 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -21,6 +21,7 @@ #endif #include "wx/fontutil.h" +#include "wx/scopedarray.h" #include "wx/gtk1/win_gtk.h" #include "wx/gtk1/dcclient.h" @@ -651,7 +652,7 @@ void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset if (n <= 0) return; - GdkPoint * const gpts = new GdkPoint[n]; + wxScopedArray gpts(n); if ( !gpts ) { wxFAIL_MSG( wxT("Cannot allocate PolyLine") ); @@ -669,9 +670,7 @@ void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset gpts[i].y = YLOG2DEV(y); } - gdk_draw_lines( m_window, m_penGC, gpts, n); - - delete[] gpts; + gdk_draw_lines( m_window, m_penGC, gpts.get(), n); } void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], wxCoord xoffset, wxCoord yoffset, wxPolygonFillMode WXUNUSED(fillStyle) ) @@ -680,7 +679,7 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], wxCoord xoffs if (n <= 0) return; - GdkPoint * const gpts = new GdkPoint[n]; + wxScopedArray gpts(n); for (int i = 0 ; i < n ; i++) { @@ -695,7 +694,7 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], wxCoord xoffs if (m_brush.GetStyle() == wxBRUSHSTYLE_SOLID) { - gdk_draw_polygon( m_window, m_brushGC, TRUE, gpts, n ); + gdk_draw_polygon( m_window, m_brushGC, TRUE, gpts.get(), n ); } else if (m_brush.GetStyle() != wxBRUSHSTYLE_TRANSPARENT) { @@ -704,19 +703,19 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], wxCoord xoffs gdk_gc_set_ts_origin( m_textGC, m_deviceOriginX % m_brush.GetStipple()->GetWidth(), m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); - gdk_draw_polygon( m_window, m_textGC, TRUE, gpts, n ); + gdk_draw_polygon( m_window, m_textGC, TRUE, gpts.get(), n ); gdk_gc_set_ts_origin( m_textGC, 0, 0 ); } else if (IS_15_PIX_HATCH(m_brush.GetStyle())) { gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 15, m_deviceOriginY % 15 ); - gdk_draw_polygon( m_window, m_brushGC, TRUE, gpts, n ); + gdk_draw_polygon( m_window, m_brushGC, TRUE, gpts.get(), n ); gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); } else if (IS_16_PIX_HATCH(m_brush.GetStyle())) { gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % 16, m_deviceOriginY % 16 ); - gdk_draw_polygon( m_window, m_brushGC, TRUE, gpts, n ); + gdk_draw_polygon( m_window, m_brushGC, TRUE, gpts.get(), n ); gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); } else if (m_brush.GetStyle() == wxBRUSHSTYLE_STIPPLE) @@ -724,22 +723,20 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], wxCoord xoffs gdk_gc_set_ts_origin( m_brushGC, m_deviceOriginX % m_brush.GetStipple()->GetWidth(), m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); - gdk_draw_polygon( m_window, m_brushGC, TRUE, gpts, n ); + gdk_draw_polygon( m_window, m_brushGC, TRUE, gpts.get(), n ); gdk_gc_set_ts_origin( m_brushGC, 0, 0 ); } else { - gdk_draw_polygon( m_window, m_brushGC, TRUE, gpts, n ); + gdk_draw_polygon( m_window, m_brushGC, TRUE, gpts.get(), n ); } } if (m_pen.GetStyle() != wxPENSTYLE_TRANSPARENT) { - gdk_draw_polygon( m_window, m_penGC, FALSE, gpts, n ); + gdk_draw_polygon( m_window, m_penGC, FALSE, gpts.get(), n ); } - - delete[] gpts; } void wxWindowDCImpl::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) @@ -1728,13 +1725,12 @@ void wxWindowDCImpl::SetPen( const wxPen &pen ) if (req_dash && req_nb_dash) { - wxGTKDash *real_req_dash = new wxGTKDash[req_nb_dash]; + wxScopedArray real_req_dash(req_nb_dash); if (real_req_dash) { for (int i = 0; i < req_nb_dash; i++) real_req_dash[i] = req_dash[i] * width; - gdk_gc_set_dashes( m_penGC, 0, real_req_dash, req_nb_dash ); - delete[] real_req_dash; + gdk_gc_set_dashes( m_penGC, 0, real_req_dash.get(), req_nb_dash ); } else { diff --git a/src/motif/dcclient.cpp b/src/motif/dcclient.cpp index 1cee3077fb..001f382075 100644 --- a/src/motif/dcclient.cpp +++ b/src/motif/dcclient.cpp @@ -48,6 +48,8 @@ #include "wx/dcclient.h" #endif +#include "wx/scopedarray.h" + #ifdef __VMS__ #pragma message disable nosimpint #endif @@ -438,7 +440,7 @@ void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset if (m_autoSetting) SetPen (m_pen); - XPoint *xpoints = new XPoint[n]; + wxScopedArray xpoints(n); int i; for (i = 0; i < n; i++) @@ -446,7 +448,7 @@ void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset xpoints[i].x = (short)XLOG2DEV (points[i].x + xoffset); xpoints[i].y = (short)YLOG2DEV (points[i].y + yoffset); } - XDrawLines ((Display*) m_display, (Pixmap) m_pixmap, (GC) m_gc, xpoints, n, 0); + XDrawLines ((Display*) m_display, (Pixmap) m_pixmap, (GC) m_gc, xpoints.get(), n, 0); if (m_window && m_window->GetBackingPixmap()) { @@ -455,9 +457,8 @@ void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset xpoints[i].x = (short)XLOG2DEV_2 (points[i].x + xoffset); xpoints[i].y = (short)YLOG2DEV_2 (points[i].y + yoffset); } - XDrawLines ((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(),(GC) m_gcBacking, xpoints, n, 0); + XDrawLines ((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(),(GC) m_gcBacking, xpoints.get(), n, 0); } - delete[]xpoints; } } @@ -466,8 +467,8 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], { wxCHECK_RET( IsOk(), "invalid dc" ); - XPoint *xpoints1 = new XPoint[n + 1]; - XPoint *xpoints2 = new XPoint[n + 1]; + wxScopedArray xpoints1(n + 1); + wxScopedArray xpoints2(n + 1); int i; for (i = 0; i < n; i++) { @@ -488,13 +489,13 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], { SetBrush (m_brush); XSetFillRule ((Display*) m_display, (GC) m_gc, fillStyle == wxODDEVEN_RULE ? EvenOddRule : WindingRule); - XFillPolygon ((Display*) m_display, (Pixmap) m_pixmap, (GC) m_gc, xpoints1, n, Complex, 0); + XFillPolygon ((Display*) m_display, (Pixmap) m_pixmap, (GC) m_gc, xpoints1.get(), n, Complex, 0); XSetFillRule ((Display*) m_display, (GC) m_gc, EvenOddRule); // default mode if (m_window && m_window->GetBackingPixmap()) { XSetFillRule ((Display*) m_display,(GC) m_gcBacking, fillStyle == wxODDEVEN_RULE ? EvenOddRule : WindingRule); - XFillPolygon ((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(),(GC) m_gcBacking, xpoints2, n, Complex, 0); + XFillPolygon ((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(),(GC) m_gcBacking, xpoints2.get(), n, Complex, 0); XSetFillRule ((Display*) m_display,(GC) m_gcBacking, EvenOddRule); // default mode } } @@ -503,14 +504,11 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], { if (m_autoSetting) SetPen (m_pen); - XDrawLines ((Display*) m_display, (Pixmap) m_pixmap, (GC) m_gc, xpoints1, n + 1, 0); + XDrawLines ((Display*) m_display, (Pixmap) m_pixmap, (GC) m_gc, xpoints1.get(), n + 1, 0); if (m_window && m_window->GetBackingPixmap()) - XDrawLines ((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(),(GC) m_gcBacking, xpoints2, n + 1, 0); + XDrawLines ((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(),(GC) m_gcBacking, xpoints2.get(), n + 1, 0); } - - delete[]xpoints1; - delete[]xpoints2; } void wxWindowDCImpl::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 1c54f14a0e..c950b2b90b 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -37,6 +37,8 @@ #endif #include "wx/msw/dc.h" + +#include "wx/scopedarray.h" #include "wx/sysopt.h" #ifdef wxHAS_RAW_BITMAP @@ -621,11 +623,11 @@ void wxMSWDCImpl::SetClippingHrgn(WXHRGN hrgn, bool doRtlOffset) if ( GetLayoutDirection() == wxLayout_RightToLeft ) { DWORD bufLen = ::GetRegionData(hrgn, 0, NULL); // Get the storage size - char* pDataBuf = new char[bufLen]; // Buffer for the region data - if ( ::GetRegionData(hrgn, bufLen, reinterpret_cast(pDataBuf)) != bufLen ) + wxScopedArray pDataBuf(bufLen); + RGNDATA* const rgndata = reinterpret_cast(pDataBuf.get()); + if ( ::GetRegionData(hrgn, bufLen, rgndata) != bufLen ) { wxLogLastError("GetRegionData"); - delete[] pDataBuf; return; } int dcw, dch; @@ -644,8 +646,7 @@ void wxMSWDCImpl::SetClippingHrgn(WXHRGN hrgn, bool doRtlOffset) // shoulde be adjusted. tr.eDx = doRtlOffset ? dcw : dcw-1; // max X tr.eDy = 0; - hRgnRTL = ::ExtCreateRegion(&tr, bufLen, reinterpret_cast(pDataBuf)); - delete[] pDataBuf; + hRgnRTL = ::ExtCreateRegion(&tr, bufLen, rgndata); if ( !hRgnRTL ) { wxLogLastError("ExtCreateRegion"); @@ -1022,7 +1023,7 @@ void wxMSWDCImpl::DoDrawPolygon(int n, // Do things less efficiently if we have offsets if (xoffset != 0 || yoffset != 0) { - POINT *cpoints = new POINT[n]; + wxScopedArray cpoints(n); int i; for (i = 0; i < n; i++) { @@ -1032,9 +1033,8 @@ void wxMSWDCImpl::DoDrawPolygon(int n, CalcBoundingBox(cpoints[i].x, cpoints[i].y); } int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); - (void)Polygon(GetHdc(), cpoints, n); + (void)Polygon(GetHdc(), cpoints.get(), n); SetPolyFillMode(GetHdc(),prev); - delete[] cpoints; } else { @@ -1064,7 +1064,7 @@ wxMSWDCImpl::DoDrawPolyPolygon(int n, // Do things less efficiently if we have offsets if (xoffset != 0 || yoffset != 0) { - POINT *cpoints = new POINT[cnt]; + wxScopedArray cpoints(cnt); for (i = 0; i < cnt; i++) { cpoints[i].x = (int)(points[i].x + xoffset); @@ -1073,9 +1073,8 @@ wxMSWDCImpl::DoDrawPolyPolygon(int n, CalcBoundingBox(cpoints[i].x, cpoints[i].y); } int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); - (void)PolyPolygon(GetHdc(), cpoints, count, n); + (void)PolyPolygon(GetHdc(), cpoints.get(), count, n); SetPolyFillMode(GetHdc(),prev); - delete[] cpoints; } else { @@ -1093,7 +1092,7 @@ void wxMSWDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset, wx // Do things less efficiently if we have offsets if (xoffset != 0 || yoffset != 0) { - POINT *cpoints = new POINT[n]; + wxScopedArray cpoints(n); int i; for (i = 0; i < n; i++) { @@ -1102,8 +1101,7 @@ void wxMSWDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset, wx CalcBoundingBox(cpoints[i].x, cpoints[i].y); } - (void)Polyline(GetHdc(), cpoints, n); - delete[] cpoints; + (void)Polyline(GetHdc(), cpoints.get(), n); } else { @@ -1218,7 +1216,7 @@ void wxMSWDCImpl::DoDrawSpline(const wxPointList *points) wxCHECK_RET( n_points >= 2 , "incomplete list of spline points?" ); const size_t n_bezier_points = n_points * 3 + 1; - POINT *lppt = new POINT[n_bezier_points]; + wxScopedArray lppt(n_bezier_points); size_t bezier_pos = 0; wxCoord x1, y1, x2, y2, cx1, cy1; @@ -1279,9 +1277,7 @@ void wxMSWDCImpl::DoDrawSpline(const wxPointList *points) lppt[ bezier_pos ] = lppt[ bezier_pos-1 ]; bezier_pos++; - ::PolyBezier( GetHdc(), lppt, bezier_pos ); - - delete []lppt; + ::PolyBezier( GetHdc(), lppt.get(), bezier_pos ); } #endif // wxUSE_SPLINES diff --git a/src/x11/dcclient.cpp b/src/x11/dcclient.cpp index 5464eb16db..140f5c6a6e 100644 --- a/src/x11/dcclient.cpp +++ b/src/x11/dcclient.cpp @@ -22,6 +22,7 @@ #endif #include "wx/fontutil.h" +#include "wx/scopedarray.h" #include "wx/vector.h" #include "wx/x11/private.h" @@ -642,7 +643,7 @@ void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset if (m_pen.GetStyle() == wxPENSTYLE_TRANSPARENT) return; if (n <= 0) return; - XPoint *xpoints = new XPoint[n]; + wxScopedArray xpoints(n); for (int i = 0; i < n; i++) { xpoints[i].x = XLOG2DEV (points[i].x + xoffset); @@ -650,9 +651,7 @@ void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset ); } - XDrawLines( (Display*) m_display, (Window) m_x11window, (GC) m_penGC, xpoints, n, 0 ); - - delete[] xpoints; + XDrawLines( (Display*) m_display, (Window) m_x11window, (GC) m_penGC, xpoints.get(), n, 0 ); } void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], @@ -663,7 +662,7 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], if (n <= 0) return; - XPoint *xpoints = new XPoint[n + 1]; + wxScopedArray xpoints(n + 1); int i; for (i = 0; i < n; i++) { @@ -685,7 +684,7 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); XFillPolygon( (Display*) m_display, (Window) m_x11window, - (GC) m_textGC, xpoints, n, Complex, 0); + (GC) m_textGC, xpoints.get(), n, Complex, 0); XSetTSOrigin( (Display*) m_display, (GC) m_textGC, 0, 0 ); } else @@ -695,7 +694,7 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], m_deviceOriginX % 15, m_deviceOriginY % 15 ); XFillPolygon( (Display*) m_display, (Window) m_x11window, - (GC) m_brushGC, xpoints, n, Complex, 0); + (GC) m_brushGC, xpoints.get(), n, Complex, 0); XSetTSOrigin( (Display*) m_display, (GC) m_brushGC, 0, 0 ); } else @@ -705,7 +704,7 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], m_deviceOriginX % 16, m_deviceOriginY % 16 ); XFillPolygon( (Display*) m_display, (Window) m_x11window, - (GC) m_brushGC, xpoints, n, Complex, 0); + (GC) m_brushGC, xpoints.get(), n, Complex, 0); XSetTSOrigin( (Display*) m_display, (GC) m_brushGC, 0, 0 ); } else @@ -716,14 +715,14 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], m_deviceOriginY % m_brush.GetStipple()->GetHeight() ); XFillPolygon( (Display*) m_display, (Window) m_x11window, - (GC) m_brushGC, xpoints, n, Complex, 0); + (GC) m_brushGC, xpoints.get(), n, Complex, 0); XSetTSOrigin( (Display*) m_display, (GC) m_brushGC, 0, 0 ); } else { XFillPolygon( (Display*) m_display, (Window) m_x11window, - (GC) m_brushGC, xpoints, n, Complex, 0); + (GC) m_brushGC, xpoints.get(), n, Complex, 0); } } @@ -733,11 +732,9 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[], xpoints[i].x = xpoints[0].x; xpoints[i].y = xpoints[0].y; - XDrawLines( (Display*) m_display, (Window) m_x11window, (GC) m_penGC, xpoints, n + 1, 0); + XDrawLines( (Display*) m_display, (Window) m_x11window, (GC) m_penGC, xpoints.get(), n + 1, 0); } } - - delete[] xpoints; } void wxWindowDCImpl::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord height )