mac: support delayed creation of the view's context, for anything whose size starts at 0x0

This commit is contained in:
IoI_xD 2026-03-10 17:10:47 -07:00
commit d9ee157ee8
2 changed files with 43 additions and 26 deletions

View file

@ -89,6 +89,7 @@
float height;
}
- (void)initRepAndContextWithWidth:(float)w Height:(float)h;
- (NSGraphicsContext *)context;
- (void)destroy;
- (NSBitmapImageRep *)getRep;
@ -153,9 +154,10 @@
- (void)destroy;
- (void)sendClipboardEvent;
- (MilskoCocoaWindow *)parentWindow;
- (MwLL)getParent;
- (NSView *)getView;
- (MilskoCocoaWindow *)getWindow;
- (MilskoFakePointer *)getHandle;
+ (void)eventCanceller:(MilskoCocoa *)this;

View file

@ -773,11 +773,8 @@ static NSPoint pointFlip(NSPoint point) {
[self->window dealloc];
}
- (NSWindow *)parentWindow {
NSWindow *topmostWindow = self->window;
while ([topmostWindow parentWindow])
topmostWindow = [topmostWindow parentWindow];
return topmostWindow;
- (MwLL)getParent {
return self->parent;
}
- (NSView *)getView {
@ -804,24 +801,7 @@ static NSPoint pointFlip(NSPoint point) {
self->rep = NULL;
self->context = NULL;
} else {
self->rep =
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:width
pixelsHigh:height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:width * 4
bitsPerPixel:32];
assert(self->rep);
[self->rep retain];
self->context =
[NSGraphicsContext graphicsContextWithBitmapImageRep:self->rep];
assert(self->context);
[self->context retain];
[self initRepAndContextWithWidth:width Height:height];
}
return self;
@ -840,8 +820,15 @@ static NSPoint pointFlip(NSPoint point) {
NSSize sz = [self->rep size];
[super drawRect:dirtyRect];
if (!self->rep) {
[pool release];
return;
if (dirtyRect.size.width && dirtyRect.size.height) {
[self initRepAndContextWithWidth:dirtyRect.size.width
Height:dirtyRect.size.height];
self->width = dirtyRect.size.width;
self->height = dirtyRect.size.height;
} else {
[pool release];
return;
}
}
[self->rep drawInRect:NSMakeRect(0, 0, sz.width, sz.height)];
@ -850,6 +837,27 @@ static NSPoint pointFlip(NSPoint point) {
[pool release];
}
- (void)initRepAndContextWithWidth:(float)w Height:(float)h {
self->rep =
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:w
pixelsHigh:h
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:w * 4
bitsPerPixel:32];
assert(self->rep);
[self->rep retain];
self->context =
[NSGraphicsContext graphicsContextWithBitmapImageRep:self->rep];
assert(self->context);
[self->context retain];
}
- (void)destroy {
CGColorSpaceRelease(self->space);
[self->rep release];
@ -884,6 +892,7 @@ static NSPoint pointFlip(NSPoint point) {
return self;
}
- (void)applicationDidBecomeActive:(NSNotification *)notification {
[self->appl activateIgnoringOtherApps:true];
printf("test\n");
}
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
@ -910,6 +919,12 @@ static NSPoint pointFlip(NSPoint point) {
}
- (void)windowDidBecomeMain:(NSNotification *)notification {
if ([[[w contentView] subviews] count] != 0) {
MwLL h = [((MilskoFakePointer *)[[[w contentView] subviews]
objectAtIndex:0]) pointer];
MwLLDispatch(h, focus_in, NULL);
}
[self->w makeKeyAndOrderFront:nil];
}
- (void)windowDidResize:(NSNotification *)notification {