aboutsummaryrefslogtreecommitdiffhomepage
path: root/cocoa
diff options
context:
space:
mode:
authorNeil Hodgson <nyamatongwe@gmail.com>2023-02-24 10:43:05 +1100
committerNeil Hodgson <nyamatongwe@gmail.com>2023-02-24 10:43:05 +1100
commita00f308a11b90a0edb1bd9a71a78612e0463fe83 (patch)
treec97e63f5fb0c24833e81b7d634e0dc315d3ad822 /cocoa
parent778dc10b3ee2f621d8548b1d074429c44bd3ae62 (diff)
downloadscintilla-mirror-a00f308a11b90a0edb1bd9a71a78612e0463fe83.tar.gz
Replace deprecated graphicsPort API with current CGContext.
Diffstat (limited to 'cocoa')
-rw-r--r--cocoa/ScintillaCocoa.h2
-rw-r--r--cocoa/ScintillaCocoa.mm18
-rw-r--r--cocoa/ScintillaView.mm2
3 files changed, 19 insertions, 3 deletions
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h
index 63f4b106b..4c1f10a97 100644
--- a/cocoa/ScintillaCocoa.h
+++ b/cocoa/ScintillaCocoa.h
@@ -83,6 +83,8 @@ extern "C" NSString *ScintillaRecPboardType;
namespace Scintilla::Internal {
+CGContextRef CGContextCurrent();
+
/**
* Main scintilla class, implemented for macOS (Cocoa).
*/
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index 884a976d0..3d4a0f622 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -399,6 +399,20 @@ const CGFloat paddingHighlightY = 2;
@end
+//----------------- CGContextCurrent ---------------------------------------------------------------
+
+CGContextRef Scintilla::Internal::CGContextCurrent() {
+ if (@available(macOS 10.10, *)) {
+ return [NSGraphicsContext currentContext].CGContext;
+ } else {
+ // Use old deprecated API
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ return static_cast<CGContextRef>([NSGraphicsContext currentContext].graphicsPort);
+#pragma clang diagnostic pop
+ }
+}
+
//----------------- ScintillaCocoa -----------------------------------------------------------------
ScintillaCocoa::ScintillaCocoa(ScintillaView *sciView_, SCIContentView *viewContent, SCIMarginView *viewMargin) {
@@ -1132,7 +1146,7 @@ void ScintillaCocoa::CTPaint(void *gc, NSRect rc) {
- (void) drawRect: (NSRect) needsDisplayInRect {
if (sci) {
- CGContextRef context = (CGContextRef) [NSGraphicsContext currentContext].graphicsPort;
+ CGContextRef context = CGContextCurrent();
sci->CTPaint(context, needsDisplayInRect);
}
}
@@ -1873,7 +1887,7 @@ bool ScintillaCocoa::SyncPaint(void *gc, PRectangle rc) {
* Paint the margin into the SCIMarginView space.
*/
void ScintillaCocoa::PaintMargin(NSRect aRect) {
- CGContextRef gc = (CGContextRef) [NSGraphicsContext currentContext].graphicsPort;
+ CGContextRef gc = CGContextCurrent();
PRectangle rc = NSRectToPRectangle(aRect);
rcPaint = rc;
diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm
index ad074b496..6e113b523 100644
--- a/cocoa/ScintillaView.mm
+++ b/cocoa/ScintillaView.mm
@@ -373,7 +373,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) {
* Gets called by the runtime when the view needs repainting.
*/
- (void) drawRect: (NSRect) rect {
- CGContextRef context = (CGContextRef) [NSGraphicsContext currentContext].graphicsPort;
+ CGContextRef context = CGContextCurrent();
if (!mOwner.backend->Draw(rect, context)) {
dispatch_async(dispatch_get_main_queue(), ^ {