Merge pull request 'fix/backColors' (#494) from fix/backColors into release/v9.1.0

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/desktop-apps/pulls/494
This commit is contained in:
Oleg Korshul
2025-10-13 13:34:08 +00:00
5 changed files with 380 additions and 273 deletions

View File

@ -42,7 +42,7 @@
#import "ASCTabView.h"
#import "NSCefView.h"
@interface ASCCommonViewController : NSViewController
@interface ASCCommonViewController : NSViewController <NSTabViewDelegate>
- (BOOL)shouldTerminateApplication;
- (BOOL)shouldCloseMainWindow;
@ -53,4 +53,3 @@
- (void)openEULA;
- (void)openPreferences;
@end

View File

@ -59,5 +59,7 @@
- (instancetype)duplicate;
- (void)shake;
- (NSImage *)imageRepresentation;
- (NSImage *)windowScreenshot;
- (nullable NSView *)subviewOfClassName:(NSString * _Nonnull)className;
@end

View File

@ -265,4 +265,58 @@ static NSString * const kASCUuidPropertyKey = @"ascUuidPropertyKey";
return image;
}
- (nullable NSImage *)windowScreenshot {
if (self.window) {
NSRect viewFrameInWindow = [self convertRect:self.bounds toView:nil];
NSRect windowFrame = [self.window convertRectToScreen:viewFrameInWindow];
CGFloat screenHeight = NSScreen.mainScreen.frame.size.height;
CGImageRef cgImage = CGWindowListCreateImage
(
CGRectMake
(
windowFrame.origin.x,
screenHeight - windowFrame.origin.y - windowFrame.size.height,
windowFrame.size.width,
windowFrame.size.height
),
kCGWindowListOptionIncludingWindow,
(CGWindowID)[self.window windowNumber],
kCGWindowImageBoundsIgnoreFraming | kCGWindowImageShouldBeOpaque
);
NSImage *snapshot = nil;
if (cgImage) {
snapshot = [[NSImage alloc] initWithCGImage:cgImage size:viewFrameInWindow.size];
CGImageRelease(cgImage);
}
return snapshot;
}
return nil;
}
- (nullable NSView *)subviewOfClassName:(NSString * _Nonnull)className {
Class cls = NSClassFromString(className);
if (!cls) {
return nil;
}
for (NSView *subview in self.subviews) {
if ([subview isKindOfClass:cls]) {
return subview;
}
NSView *found = [subview subviewOfClassName:className];
if (found) {
return found;
}
}
return nil;
}
@end

View File

@ -56,7 +56,11 @@
self = [super initWithFrame:frame];
if (self) {
CALayer *viewLayer = [CALayer layer];
[viewLayer setBackgroundColor:CGColorCreateGenericRGB(1.0, 1.0, 1.0, 1.0)]; //RGB plus Alpha Channel
CGColorRef backColor = CGColorCreateGenericRGB(1.0, 1.0, 1.0, 1.0); //RGB plus Alpha Channel
[viewLayer setBackgroundColor:backColor];
CGColorRelease(backColor);
[self setWantsLayer:YES]; // view's backing store is using a Core Animation Layer
[self setLayer:viewLayer];
@ -108,9 +112,14 @@
}
- (void)setBackgroundColor:(NSColor *)color {
CGFloat red, green, blue, alpha;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
CGColorRef backColor = CGColorCreateGenericRGB(red, green, blue, 1.0); //RGB plus Alpha Channel
[self.layer setBackgroundColor:backColor];
CGColorRelease(backColor);
if (m_pCefView) {
CGFloat red, green, blue, alpha;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
return m_pCefView->SetBackgroundCefColor(255 * red, 255 * green, 255 * blue);
}
}