aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil Hodgson <nyamatongwe@gmail.com>2015-08-23 12:09:03 +1000
committerNeil Hodgson <nyamatongwe@gmail.com>2015-08-23 12:09:03 +1000
commitf8fccd41ed4b56e4916f199ea6f9f49b127d7d76 (patch)
treed084c28bcf2c670b16a384922ca103dc33d1ced8
parente6871279bd799686ae2d107076c59742623657c4 (diff)
downloadscintilla-mirror-f8fccd41ed4b56e4916f199ea6f9f49b127d7d76.tar.gz
In C++, new fails with an exception instead of returning NULL so remove handling
of NULL SurfaceImpl objects and replace heap with stack to simplify code.
-rw-r--r--cocoa/ScintillaCocoa.mm72
1 files changed, 29 insertions, 43 deletions
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index dd7afe120..e12f7a934 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -1407,54 +1407,40 @@ void ScintillaCocoa::StartDrag()
SCIContentView* content = ContentView();
// To get a bitmap of the text we're dragging, we just use Paint on a pixmap surface.
- SurfaceImpl *sw = new SurfaceImpl();
- SurfaceImpl *pixmap = NULL;
+ SurfaceImpl sw;
+ sw.InitPixMap(static_cast<int>(client.Width()), static_cast<int>(client.Height()), NULL, NULL);
- bool lastHideSelection = view.hideSelection;
+ const bool lastHideSelection = view.hideSelection;
view.hideSelection = true;
- if (sw)
- {
- pixmap = new SurfaceImpl();
- if (pixmap)
- {
- PRectangle imageRect = rcSel;
- paintState = painting;
- sw->InitPixMap(static_cast<int>(client.Width()), static_cast<int>(client.Height()), NULL, NULL);
- paintingAllText = true;
- CGContextRef gcsw = sw->GetContext();
- CGContextTranslateCTM(gcsw, -client.left, -client.top);
- Paint(sw, client);
- paintState = notPainting;
-
- pixmap->InitPixMap(static_cast<int>(imageRect.Width()), static_cast<int>(imageRect.Height()), NULL, NULL);
- pixmap->SetUnicodeMode(IsUnicodeMode());
- pixmap->SetDBCSMode(CodePage());
-
- CGContextRef gc = pixmap->GetContext();
- // To make Paint() work on a bitmap, we have to flip our coordinates and translate the origin
- CGContextTranslateCTM(gc, 0, imageRect.Height());
- CGContextScaleCTM(gc, 1.0, -1.0);
-
- pixmap->CopyImageRectangle(*sw, imageRect, PRectangle(0.0f, 0.0f, imageRect.Width(), imageRect.Height()));
- // XXX TODO: overwrite any part of the image that is not part of the
- // selection to make it transparent. right now we just use
- // the full rectangle which may include non-selected text.
- }
- sw->Release();
- delete sw;
- }
+ PRectangle imageRect = rcSel;
+ paintState = painting;
+ paintingAllText = true;
+ CGContextRef gcsw = sw.GetContext();
+ CGContextTranslateCTM(gcsw, -client.left, -client.top);
+ Paint(&sw, client);
+ paintState = notPainting;
view.hideSelection = lastHideSelection;
+ SurfaceImpl pixmap;
+ pixmap.InitPixMap(static_cast<int>(imageRect.Width()), static_cast<int>(imageRect.Height()), NULL, NULL);
+ pixmap.SetUnicodeMode(IsUnicodeMode());
+ pixmap.SetDBCSMode(CodePage());
+
+ CGContextRef gc = pixmap.GetContext();
+ // To make Paint() work on a bitmap, we have to flip our coordinates and translate the origin
+ CGContextTranslateCTM(gc, 0, imageRect.Height());
+ CGContextScaleCTM(gc, 1.0, -1.0);
+
+ pixmap.CopyImageRectangle(sw, imageRect, PRectangle(0.0f, 0.0f, imageRect.Width(), imageRect.Height()));
+ // XXX TODO: overwrite any part of the image that is not part of the
+ // selection to make it transparent. right now we just use
+ // the full rectangle which may include non-selected text.
+
NSBitmapImageRep* bitmap = NULL;
- if (pixmap)
- {
- CGImageRef imagePixmap = pixmap->GetImage();
- if (imagePixmap)
- bitmap = [[[NSBitmapImageRep alloc] initWithCGImage: imagePixmap] autorelease];
- CGImageRelease(imagePixmap);
- pixmap->Release();
- delete pixmap;
- }
+ CGImageRef imagePixmap = pixmap.GetImage();
+ if (imagePixmap)
+ bitmap = [[[NSBitmapImageRep alloc] initWithCGImage: imagePixmap] autorelease];
+ CGImageRelease(imagePixmap);
NSImage* image = [[[NSImage alloc] initWithSize: selectionRectangle.size] autorelease];
[image addRepresentation: bitmap];