diff options
| -rw-r--r-- | cocoa/ScintillaCocoa.mm | 72 | 
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]; | 
