From b9425707ea96e19af7617b6e1beefba6e90702e7 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 22 Mar 2021 16:19:26 +1100 Subject: Replace InitPixMap on Cocoa for drag & drop and XPM images in lists. --- cocoa/PlatCocoa.h | 3 ++- cocoa/PlatCocoa.mm | 13 ++++++++----- cocoa/ScintillaCocoa.mm | 21 ++++++++++----------- 3 files changed, 20 insertions(+), 17 deletions(-) (limited to 'cocoa') diff --git a/cocoa/PlatCocoa.h b/cocoa/PlatCocoa.h index d11b52336..83b724df9 100644 --- a/cocoa/PlatCocoa.h +++ b/cocoa/PlatCocoa.h @@ -82,6 +82,7 @@ public: void Init(SurfaceID sid, WindowID wid) override; void InitPixMap(int width, int height, Surface *surface_, WindowID wid) override; std::unique_ptr AllocatePixMap(int width, int height) override; + std::unique_ptr AllocatePixMapImplementation(int width, int height); CGContextRef GetContext() { return gc; } void SetMode(SurfaceMode mode) override; @@ -93,7 +94,7 @@ public: /** Returns a CGImageRef that represents the surface. Returns NULL if this is not possible. */ CGImageRef CreateImage(); - void CopyImageRectangle(Surface &surfaceSource, PRectangle srcRect, PRectangle dstRect); + void CopyImageRectangle(SurfaceImpl *source, PRectangle srcRect, PRectangle dstRect); int LogPixelsY() override; int PixelDivisions() override; diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index c9cca0ded..d509145d2 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -532,6 +532,10 @@ std::unique_ptr SurfaceImpl::AllocatePixMap(int width, int height) { return std::make_unique(this, width, height); } +std::unique_ptr SurfaceImpl::AllocatePixMapImplementation(int width, int height) { + return std::make_unique(this, width, height); +} + //-------------------------------------------------------------------------------------------------- void SurfaceImpl::SetMode(SurfaceMode mode_) { @@ -1387,9 +1391,8 @@ void SurfaceImpl::Stadium(PRectangle rc, FillStroke fillStroke, Ends ends) { CGContextSetLineWidth(gc, 1.0f); } -void SurfaceImpl::CopyImageRectangle(Surface &surfaceSource, PRectangle srcRect, PRectangle dstRect) { - SurfaceImpl &source = static_cast(surfaceSource); - CGImageRef image = source.CreateImage(); +void SurfaceImpl::CopyImageRectangle(SurfaceImpl *source, PRectangle srcRect, PRectangle dstRect) { + CGImageRef image = source->CreateImage(); CGRect src = PRectangleToCGRect(srcRect); CGRect dst = PRectangleToCGRect(dstRect); @@ -1999,8 +2002,8 @@ static NSImage *ImageFromXPM(XPM *pxpm) { const int width = pxpm->GetWidth(); const int height = pxpm->GetHeight(); PRectangle rcxpm(0, 0, width, height); - std::unique_ptr surfaceXPM(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); - surfaceXPM->InitPixMap(width, height, NULL, NULL); + std::unique_ptr surfaceBase(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); + std::unique_ptr surfaceXPM = surfaceBase->AllocatePixMap(width, height); SurfaceImpl *surfaceIXPM = static_cast(surfaceXPM.get()); CGContextClearRect(surfaceIXPM->GetContext(), CGRectMake(0, 0, width, height)); pxpm->Draw(surfaceXPM.get(), rcxpm); diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index 4a688bdff..4c3b50d28 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -1411,36 +1411,35 @@ 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; - sw.InitPixMap(static_cast(client.Width()), static_cast(client.Height()), NULL, NULL); + SurfaceImpl si; + si.SetMode(SurfaceMode(CodePage(), BidirectionalR2L())); + std::unique_ptr sw = si.AllocatePixMapImplementation(static_cast(client.Width()), static_cast(client.Height())); const bool lastHideSelection = view.hideSelection; view.hideSelection = true; PRectangle imageRect = rcSel; paintState = PaintState::painting; paintingAllText = true; - CGContextRef gcsw = sw.GetContext(); + CGContextRef gcsw = sw->GetContext(); CGContextTranslateCTM(gcsw, -client.left, -client.top); - Paint(&sw, client); + Paint(sw.get(), client); paintState = PaintState::notPainting; view.hideSelection = lastHideSelection; - SurfaceImpl pixmap; - pixmap.InitPixMap(static_cast(imageRect.Width()), static_cast(imageRect.Height()), NULL, NULL); - pixmap.SetMode(SurfaceMode(CodePage(), BidirectionalR2L())); - - CGContextRef gc = pixmap.GetContext(); + std::unique_ptr pixmap = si.AllocatePixMapImplementation(static_cast(imageRect.Width()), + static_cast(imageRect.Height())); + 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())); + pixmap->CopyImageRectangle(sw.get(), 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; - CGImageRef imagePixmap = pixmap.CreateImage(); + CGImageRef imagePixmap = pixmap->CreateImage(); if (imagePixmap) bitmap = [[NSBitmapImageRep alloc] initWithCGImage: imagePixmap]; CGImageRelease(imagePixmap); -- cgit v1.2.3