try and fail to have the app be activated without setting the activation policy
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
IoI_xD 2026-03-08 18:30:37 -07:00
commit c20da369e8
2 changed files with 889 additions and 865 deletions

View file

@ -21,19 +21,26 @@
#import <CoreGraphics/CoreGraphics.h> #import <CoreGraphics/CoreGraphics.h>
#endif #endif
// Note: implements NSApplicationDelegate
@interface MilskoCocoaApplicationDelegate : NSObject <NSApplicationDelegate> {
NSApplication *appl;
}
- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)appl;
@end
// Note: implements NSWindowDelegate // Note: implements NSWindowDelegate
@interface MilskoCocoaWindowDelegate : NSObject { @interface MilskoCocoaWindowDelegate : NSObject {
NSWindow* w; NSWindow *w;
} }
- (MilskoCocoaWindowDelegate*)initWithWin:(NSWindow*)win; - (MilskoCocoaWindowDelegate *)initWithWin:(NSWindow *)win;
@end @end
@interface MilskoFakePointer : NSView { @interface MilskoFakePointer : NSView {
void* ptr; void *ptr;
} }
- (void)setPointer:(void*)ptr; - (void)setPointer:(void *)ptr;
- (void*)pointer; - (void *)pointer;
@end @end
@ -41,24 +48,24 @@
MwBool valid; MwBool valid;
int width; int width;
int height; int height;
unsigned char* buf; unsigned char *buf;
NSImage* image; NSImage *image;
NSBitmapImageRep* rep; NSBitmapImageRep *rep;
} }
+ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height; + (MilskoCocoaPixmap *)newWithWidth:(int)width height:(int)height;
- (void)updateWithData:(unsigned char*)data; - (void)updateWithData:(unsigned char *)data;
- (void)destroy; - (void)destroy;
/* using @property to create instance variables fucks up 10.4 gcc for some /* using @property to create instance variables fucks up 10.4 gcc for some
* reason? */ * reason? */
- (NSImage*)image; - (NSImage *)image;
@end @end
@interface MilskoCocoaView : NSView { @interface MilskoCocoaView : NSView {
NSBitmapImageRep* rep; NSBitmapImageRep *rep;
NSGraphicsContext* context; NSGraphicsContext *context;
MwBool valid; MwBool valid;
CGColorSpaceRef space; CGColorSpaceRef space;
CGDataProviderRef provider; CGDataProviderRef provider;
@ -66,48 +73,48 @@
float height; float height;
} }
- (NSGraphicsContext*)context; - (NSGraphicsContext *)context;
- (void)destroy; - (void)destroy;
- (NSBitmapImageRep*)getRep; - (NSBitmapImageRep *)getRep;
@end @end
@interface MilskoCocoa : NSObject { @interface MilskoCocoa : NSObject {
NSApplication* application; NSApplication *application;
MwBool _forceRender; MwBool _forceRender;
NSWindow* window; NSWindow *window;
NSRect rect; NSRect rect;
MilskoCocoaView* view; MilskoCocoaView *view;
MwLL parent; MwLL parent;
MilskoFakePointer* handle; MilskoFakePointer *handle;
unsigned int strHash; unsigned int strHash;
NSEvent* lastEvent; NSEvent *lastEvent;
} }
+ (MilskoCocoa*)newWithParent:(MwLL)parent + (MilskoCocoa *)newWithParent:(MwLL)parent
x:(int)x x:(int)x
y:(int)y y:(int)y
width:(int)width width:(int)width
height:(int)height height:(int)height
handle:(MwLL)handle; handle:(MwLL)handle;
- (void)polygonWithPoints:(MwPoint*)points - (void)polygonWithPoints:(MwPoint *)points
points_count:(int)points_count points_count:(int)points_count
color:(MwLLColor)color; color:(MwLLColor)color;
- (void)lineWithPoints:(MwPoint*)points color:(MwLLColor)color; - (void)lineWithPoints:(MwPoint *)points color:(MwLLColor)color;
- (void)getX:(int*)x Y:(int*)y W:(unsigned int*)w H:(unsigned int*)h; - (void)getX:(int *)x Y:(int *)y W:(unsigned int *)w H:(unsigned int *)h;
- (void)setX:(int)x Y:(int)y; - (void)setX:(int)x Y:(int)y;
- (void)setW:(int)w H:(int)h; - (void)setW:(int)w H:(int)h;
- (int)pending; - (int)pending;
- (void)eventProcess:(NSEvent*)ev; - (void)eventProcess:(NSEvent *)ev;
- (void)handleKeyEvent:(NSEvent*)ev; - (void)handleKeyEvent:(NSEvent *)ev;
- (void)handleMouseEvent:(NSEvent*)ev ll:(MwLL)ll; - (void)handleMouseEvent:(NSEvent *)ev ll:(MwLL)ll;
- (void)getNextEvent; - (void)getNextEvent;
- (void)setTitle:(const char*)title; - (void)setTitle:(const char *)title;
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect*)rect; - (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect *)rect;
- (void)setIcon:(MwLLPixmap)pixmap; - (void)setIcon:(MwLLPixmap)pixmap;
- (void)forceRender; - (void)forceRender;
- (void)setCursor:(MwCursor*)image mask:(MwCursor*)mask; - (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask;
- (void)detachWithPoint:(MwPoint*)point; - (void)detachWithPoint:(MwPoint *)point;
- (void)show:(int)show; - (void)show:(int)show;
- (void)makePopupWithParent:(MwLL)parent; - (void)makePopupWithParent:(MwLL)parent;
- (void)setSizeHintsWithMinX:(int)minx - (void)setSizeHintsWithMinX:(int)minx
@ -117,29 +124,29 @@
- (void)makeBorderless:(int)toggle; - (void)makeBorderless:(int)toggle;
- (void)focus; - (void)focus;
- (void)grabPointer:(int)toggle; - (void)grabPointer:(int)toggle;
- (void)setClipboard:(const char*)text; - (void)setClipboard:(const char *)text;
- (void)makeToolWindow; - (void)makeToolWindow;
- (void)getCursorCoord:(MwPoint*)point; - (void)getCursorCoord:(MwPoint *)point;
- (void)getScreenSize:(MwRect*)rect; - (void)getScreenSize:(MwRect *)rect;
- (void)destroy; - (void)destroy;
- (void)sendClipboardEvent; - (void)sendClipboardEvent;
- (NSWindow*)parentWindow; - (NSWindow *)parentWindow;
- (NSView*)getView; - (NSView *)getView;
- (NSWindow*)getWindow; - (NSWindow *)getWindow;
- (MilskoFakePointer*)getHandle; - (MilskoFakePointer *)getHandle;
@end @end
#define OBJC(x) x #define OBJC(x) x
#else #else
#define OBJC(x) void* #define OBJC(x) void *
#endif #endif
MWDECL int MwLLCocoaCallInit(void); MWDECL int MwLLCocoaCallInit(void);
struct _MwLLCocoa { struct _MwLLCocoa {
struct _MwLLCommon common; struct _MwLLCommon common;
OBJC(MilskoCocoa*) OBJC(MilskoCocoa *)
real; real;
}; };
@ -149,7 +156,7 @@ struct _MwLLCocoaColor {
struct _MwLLCocoaPixmap { struct _MwLLCocoaPixmap {
struct _MwLLCommonPixmap common; struct _MwLLCommonPixmap common;
OBJC(MilskoCocoaPixmap*) OBJC(MilskoCocoaPixmap *)
real; real;
}; };

View file

@ -1,3 +1,4 @@
#include "Mw/BaseTypes.h"
#include <Mw/Milsko.h> #include <Mw/Milsko.h>
#include <stdlib.h> #include <stdlib.h>
@ -7,20 +8,20 @@
#endif #endif
static NSRect rectFlip(NSRect originFrame) { static NSRect rectFlip(NSRect originFrame) {
NSScreen* zeroScreen = [[NSScreen screens] objectAtIndex:0]; NSScreen *zeroScreen = [[NSScreen screens] objectAtIndex:0];
double screenHeight = [zeroScreen frame].size.height; double screenHeight = [zeroScreen frame].size.height;
double originY = originFrame.origin.y; double originY = originFrame.origin.y;
double frameHeight = originFrame.size.height; double frameHeight = originFrame.size.height;
double destinationY = screenHeight - (originY + frameHeight); double destinationY = screenHeight - (originY + frameHeight);
NSRect destinationFrame = originFrame; NSRect destinationFrame = originFrame;
destinationFrame.origin.y = destinationY; destinationFrame.origin.y = destinationY;
if(destinationFrame.origin.x < 0) if (destinationFrame.origin.x < 0)
destinationFrame.origin.x = 0; destinationFrame.origin.x = 0;
if(destinationFrame.origin.y < 0) if (destinationFrame.origin.y < 0)
destinationFrame.origin.y = 0; destinationFrame.origin.y = 0;
if(destinationFrame.size.width < 0) if (destinationFrame.size.width < 0)
destinationFrame.size.width = 0; destinationFrame.size.width = 0;
if(destinationFrame.size.height < 0) if (destinationFrame.size.height < 0)
destinationFrame.size.height = 0; destinationFrame.size.height = 0;
return destinationFrame; return destinationFrame;
} }
@ -31,8 +32,8 @@ static NSPoint pointFlip(NSPoint point) {
@implementation MilskoCocoaPixmap @implementation MilskoCocoaPixmap
+ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height { + (MilskoCocoaPixmap *)newWithWidth:(int)width height:(int)height {
MilskoCocoaPixmap* p = [MilskoCocoaPixmap alloc]; MilskoCocoaPixmap *p = [MilskoCocoaPixmap alloc];
p->width = width; p->width = width;
p->height = height; p->height = height;
@ -59,7 +60,7 @@ static NSPoint pointFlip(NSPoint point) {
return p; return p;
} }
- (void)updateWithData:(unsigned char*)_data { - (void)updateWithData:(unsigned char *)_data {
memcpy(self->buf, _data, width * height * 4); memcpy(self->buf, _data, width * height * 4);
} }
- (void)destroy { - (void)destroy {
@ -68,32 +69,32 @@ static NSPoint pointFlip(NSPoint point) {
[self->image dealloc]; [self->image dealloc];
[self->rep dealloc]; [self->rep dealloc];
} }
- (NSImage*)image { - (NSImage *)image {
return self->image; return self->image;
} }
@end @end
@implementation MilskoCocoa @implementation MilskoCocoa
+ (MilskoCocoa*)newWithParent:(MwLL)parent + (MilskoCocoa *)newWithParent:(MwLL)parent
x:(int)x x:(int)x
y:(int)y y:(int)y
width:(int)width width:(int)width
height:(int)height height:(int)height
handle:(MwLL)r { handle:(MwLL)r {
MilskoCocoa* c = [MilskoCocoa alloc]; MilskoCocoa *c = [MilskoCocoa alloc];
[c retain]; [c retain];
if(x == MwDEFAULT) { if (x == MwDEFAULT) {
x = ([[NSScreen mainScreen] frame].size.width / 2.) - (width / 2.); x = ([[NSScreen mainScreen] frame].size.width / 2.) - (width / 2.);
} }
if(y == MwDEFAULT) { if (y == MwDEFAULT) {
y = ([[NSScreen mainScreen] frame].size.height / 2.) - (height / 2.); y = ([[NSScreen mainScreen] frame].size.height / 2.) - (height / 2.);
} }
c->application = [NSApplication sharedApplication]; c->application = [NSApplication sharedApplication];
c->rect = rectFlip(NSMakeRect(x, y, width, height)); c->rect = rectFlip(NSMakeRect(x, y, width, height));
if(parent == NULL) { if (parent == NULL) {
c->window = [[NSWindow alloc] c->window = [[NSWindow alloc]
initWithContentRect:c->rect initWithContentRect:c->rect
styleMask:(NSTitledWindowMask | NSClosableWindowMask | styleMask:(NSTitledWindowMask | NSClosableWindowMask |
@ -102,9 +103,10 @@ static NSPoint pointFlip(NSPoint point) {
defer:NO]; defer:NO];
} else { } else {
double offset = 0; double offset = 0;
NSWindow* parentWindow = parent->cocoa.real->window; NSWindow *parentWindow = parent->cocoa.real->window;
offset = offset =
[parentWindow frameRectForContentRect:[parentWindow frame]].size.height - [parentWindow frameRectForContentRect:[parentWindow frame]]
.size.height -
[parentWindow contentRectForFrameRect:[parentWindow frame]].size.height; [parentWindow contentRectForFrameRect:[parentWindow frame]].size.height;
c->rect.origin.x += [parentWindow frame].origin.x; c->rect.origin.x += [parentWindow frame].origin.x;
@ -116,14 +118,15 @@ static NSPoint pointFlip(NSPoint point) {
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]; defer:NO];
} }
[c->window setDelegate:[[MilskoCocoaWindowDelegate alloc] [c->window
setDelegate:(id<NSWindowDelegate>)[[MilskoCocoaWindowDelegate alloc]
initWithWin:c->window]]; initWithWin:c->window]];
[c->window makeKeyAndOrderFront:c->application]; [c->window makeKeyAndOrderFront:c->application];
[c->window retain]; [c->window retain];
if(parent != NULL) { if (parent != NULL) {
MilskoCocoa* p = parent->cocoa.real; MilskoCocoa *p = parent->cocoa.real;
[p->window addChildWindow:c->window ordered:NSWindowAbove]; [p->window addChildWindow:c->window ordered:NSWindowAbove];
[c->window setHasShadow:MwFALSE]; [c->window setHasShadow:MwFALSE];
} else { } else {
@ -131,6 +134,9 @@ static NSPoint pointFlip(NSPoint point) {
[c->window makeFirstResponder:c->view]; [c->window makeFirstResponder:c->view];
} }
[c->application setDelegate:[[MilskoCocoaApplicationDelegate alloc]
initWithAppl:c->application]];
c->view = [[MilskoCocoaView alloc] initWithFrame:c->rect]; c->view = [[MilskoCocoaView alloc] initWithFrame:c->rect];
[c->view retain]; [c->view retain];
c->handle = [[MilskoFakePointer alloc] initWithFrame:NSMakeRect(0, 0, 1, 1)]; c->handle = [[MilskoFakePointer alloc] initWithFrame:NSMakeRect(0, 0, 1, 1)];
@ -145,17 +151,20 @@ static NSPoint pointFlip(NSPoint point) {
c->_forceRender = MwTRUE; c->_forceRender = MwTRUE;
c->strHash = 0; c->strHash = 0;
[c->application finishLaunching];
return c; return c;
} }
- (void)polygonWithPoints:(MwPoint*)points - (void)polygonWithPoints:(MwPoint *)points
points_count:(int)points_count points_count:(int)points_count
color:(MwLLColor)color { color:(MwLLColor)color {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSGraphicsContext* ctx = [self->view context]; NSGraphicsContext *ctx = [self->view context];
if(ctx) { if (ctx) {
int i; int i;
NSBezierPath* path = [NSBezierPath bezierPath]; NSBezierPath *path = [NSBezierPath bezierPath];
NSColor* nscolor = [NSColor colorWithCalibratedRed:color->common.red / 255. NSColor *nscolor =
[NSColor colorWithCalibratedRed:color->common.red / 255.
green:color->common.green / 255. green:color->common.green / 255.
blue:color->common.blue / 255. blue:color->common.blue / 255.
alpha:1.0]; alpha:1.0];
@ -164,8 +173,8 @@ static NSPoint pointFlip(NSPoint point) {
[NSGraphicsContext setCurrentContext:ctx]; [NSGraphicsContext setCurrentContext:ctx];
[nscolor setFill]; [nscolor setFill];
for(i = 0; i < points_count; i++) { for (i = 0; i < points_count; i++) {
if(i == 0) { if (i == 0) {
[path moveToPoint:NSMakePoint(points[i].x, [path moveToPoint:NSMakePoint(points[i].x,
[self->window frame].size.height - [self->window frame].size.height -
points[i].y)]; points[i].y)];
@ -185,11 +194,11 @@ static NSPoint pointFlip(NSPoint point) {
} }
[pool release]; [pool release];
}; };
- (void)lineWithPoints:(MwPoint*)points color:(MwLLColor)color { - (void)lineWithPoints:(MwPoint *)points color:(MwLLColor)color {
(void)points; (void)points;
(void)color; (void)color;
}; };
- (void)getX:(int*)x Y:(int*)y W:(unsigned int*)w H:(unsigned int*)h { - (void)getX:(int *)x Y:(int *)y W:(unsigned int *)w H:(unsigned int *)h {
NSRect frame = rectFlip([self->window frame]); NSRect frame = rectFlip([self->window frame]);
frame = rectFlip(frame); frame = rectFlip(frame);
@ -207,14 +216,15 @@ static NSPoint pointFlip(NSPoint point) {
frame = rectFlip(frame); frame = rectFlip(frame);
if(parent) { if (parent) {
double offset = 0; double offset = 0;
NSWindow* parentWindow = parent->cocoa.real->window; NSWindow *parentWindow = parent->cocoa.real->window;
offset = offset =
[parentWindow frameRectForContentRect:[parentWindow frame]].size.height - [parentWindow frameRectForContentRect:[parentWindow frame]]
.size.height -
[parentWindow contentRectForFrameRect:[parentWindow frame]].size.height; [parentWindow contentRectForFrameRect:[parentWindow frame]].size.height;
if(x < [parentWindow frame].origin.x) { if (x < [parentWindow frame].origin.x) {
frame.origin.x += [parentWindow frame].origin.x; frame.origin.x += [parentWindow frame].origin.x;
} }
@ -224,6 +234,8 @@ static NSPoint pointFlip(NSPoint point) {
[self->view setFrameSize:frame.size]; [self->view setFrameSize:frame.size];
[self->window setFrame:frame display:YES animate:false]; [self->window setFrame:frame display:YES animate:false];
[self forceRender];
}; };
- (void)setW:(int)w H:(int)h { - (void)setW:(int)w H:(int)h {
NSRect frame = [self->window frame]; NSRect frame = [self->window frame];
@ -234,11 +246,12 @@ static NSPoint pointFlip(NSPoint point) {
[self->view setFrameSize:frame.size]; [self->view setFrameSize:frame.size];
[self->window setFrame:frame display:YES animate:false]; [self->window setFrame:frame display:YES animate:false];
[self forceRender];
}; };
- (int)pending { - (int)pending {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MwBool isPending = MwFALSE; MwBool isPending = MwFALSE;
if(_forceRender) { if (_forceRender) {
_forceRender = MwFALSE; _forceRender = MwFALSE;
[pool release]; [pool release];
return 1; return 1;
@ -255,13 +268,13 @@ static NSPoint pointFlip(NSPoint point) {
- (void)getNextEvent { - (void)getNextEvent {
while(true) { while (true) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSEvent* ev = [self->window nextEventMatchingMask:NSAnyEventMask NSEvent *ev = [self->window nextEventMatchingMask:NSAnyEventMask
untilDate:[NSDate distantPast] untilDate:[NSDate distantPast]
inMode:NSDefaultRunLoopMode inMode:NSDefaultRunLoopMode
dequeue:YES]; dequeue:YES];
if(!ev) { if (!ev) {
[pool release]; [pool release];
break; break;
} }
@ -272,26 +285,27 @@ static NSPoint pointFlip(NSPoint point) {
[self sendClipboardEvent]; [self sendClipboardEvent];
}; };
- (void)eventProcess:(NSEvent*)ev { - (void)eventProcess:(NSEvent *)ev {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow* win = [ev window]; NSWindow *win = [ev window];
MwLL h; MwLL h;
MwBool doSendEvent = MwTRUE; MwBool doSendEvent = MwTRUE;
if(!win) { if (!win) {
[pool release]; [pool release];
return; return;
} }
if([[[win contentView] subviews] count] == 0) { if ([[[win contentView] subviews] count] == 0) {
printf("no subviews on %p\n", win); printf("no subviews on %p\n", win);
[pool release]; [pool release];
return; return;
} else { } else {
h = [((MilskoFakePointer*)[[[win contentView] subviews] objectAtIndex:0]) pointer]; h = [((MilskoFakePointer *)[[[win contentView] subviews]
objectAtIndex:0]) pointer];
} }
switch([ev type]) { switch ([ev type]) {
case NSLeftMouseDown: case NSLeftMouseDown:
case NSRightMouseDown: case NSRightMouseDown:
case NSOtherMouseDown: case NSOtherMouseDown:
@ -329,18 +343,18 @@ static NSPoint pointFlip(NSPoint point) {
default: default:
break; break;
}; };
if(doSendEvent) { if (doSendEvent) {
[win sendEvent:ev]; [win sendEvent:ev];
} }
[pool release]; [pool release];
} }
- (void)handleMouseEvent:(NSEvent*)ev ll:(MwLL)ll { - (void)handleMouseEvent:(NSEvent *)ev ll:(MwLL)ll {
MwLLMouse mouse; MwLLMouse mouse;
MwBool isDown = MwTRUE; MwBool isDown = MwTRUE;
NSPoint mousePoint = pointFlip([ev locationInWindow]); NSPoint mousePoint = pointFlip([ev locationInWindow]);
switch([ev type]) { switch ([ev type]) {
case NSLeftMouseUp: case NSLeftMouseUp:
isDown = MwFALSE; isDown = MwFALSE;
case NSLeftMouseDown: case NSLeftMouseDown:
@ -362,14 +376,14 @@ static NSPoint pointFlip(NSPoint point) {
mouse.point.x = mousePoint.x; mouse.point.x = mousePoint.x;
mouse.point.y = mousePoint.y; mouse.point.y = mousePoint.y;
if(isDown) { if (isDown) {
MwLLDispatch(ll, down, &mouse); MwLLDispatch(ll, down, &mouse);
} else { } else {
MwLLDispatch(ll, up, &mouse); MwLLDispatch(ll, up, &mouse);
} }
} }
- (void)handleKeyEvent:(NSEvent*)ev { - (void)handleKeyEvent:(NSEvent *)ev {
int ch; int ch;
MwLL this = [self->handle pointer]; MwLL this = [self->handle pointer];
enum { enum {
@ -436,7 +450,7 @@ static NSPoint pointFlip(NSPoint point) {
case x: \ case x: \
ch = y; \ ch = y; \
break; break;
switch([ev keyCode]) { switch ([ev keyCode]) {
KEY_CASE(kVK_ANSI_A, 'a') KEY_CASE(kVK_ANSI_A, 'a')
KEY_CASE(kVK_ANSI_B, 'b') KEY_CASE(kVK_ANSI_B, 'b')
KEY_CASE(kVK_ANSI_C, 'c') KEY_CASE(kVK_ANSI_C, 'c')
@ -496,7 +510,7 @@ static NSPoint pointFlip(NSPoint point) {
KEY_CASE(kVK_RightArrow, MwLLKeyRight) KEY_CASE(kVK_RightArrow, MwLLKeyRight)
KEY_CASE(kVK_UpArrow, MwLLKeyUp) KEY_CASE(kVK_UpArrow, MwLLKeyUp)
} }
switch([ev type]) { switch ([ev type]) {
case NSKeyDown: case NSKeyDown:
MwLLDispatch(this, key, &ch); MwLLDispatch(this, key, &ch);
break; break;
@ -523,14 +537,12 @@ static NSPoint pointFlip(NSPoint point) {
size_t size = 0; size_t size = 0;
for(NSPasteboardItem* item in [pasteboard pasteboardItems]) { for(NSPasteboardItem* item in [pasteboard pasteboardItems]) {
for(NSString* it in items) { for(NSString* it in items) {
NSString* itemData = [item stringForType:(NSString*)it]; NSString* itemData = [item
if(itemData != NULL) { stringForType:(NSString*)it]; if(itemData != NULL) { if(strHash != 0 &&
if(strHash != 0 && strHash != [itemData hash]) { strHash != [itemData hash]) { char* text = malloc([itemData length]);
char* text = malloc([itemData length]); strncpy(text, [itemData UTF8String],
strncpy(text, [itemData UTF8String], [itemData length]); [itemData length]); MwLLDispatch(this, clipboard, text); printf("%s -> %p\n",
MwLLDispatch(this, clipboard, text); text, this); free(text);
printf("%s -> %p\n", text, this);
free(text);
} }
strHash = [itemData hash]; strHash = [itemData hash];
} }
@ -541,22 +553,22 @@ static NSPoint pointFlip(NSPoint point) {
[pool release];*/ [pool release];*/
} }
- (void)setTitle:(const char*)title { - (void)setTitle:(const char *)title {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self->window [self->window
setTitleWithRepresentedFilename:[NSString stringWithUTF8String:title]]; setTitleWithRepresentedFilename:[NSString stringWithUTF8String:title]];
[pool release]; [pool release];
}; };
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect*)_rect { - (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect *)_rect {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MilskoCocoaPixmap* p = pixmap->cocoa.real; MilskoCocoaPixmap *p = pixmap->cocoa.real;
NSGraphicsContext* ctx = [self->view context]; NSGraphicsContext *ctx = [self->view context];
if(ctx) { if (ctx) {
[NSGraphicsContext saveGraphicsState]; [NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:ctx]; [NSGraphicsContext setCurrentContext:ctx];
[[p image] drawInRect:NSMakeRect(_rect->x, _rect->y, _rect->width, [[p image]
_rect->height) drawInRect:NSMakeRect(_rect->x, _rect->y, _rect->width, _rect->height)
fromRect:NSZeroRect fromRect:NSZeroRect
operation:NSCompositeSourceOver operation:NSCompositeSourceOver
fraction:1.0]; fraction:1.0];
@ -571,13 +583,22 @@ static NSPoint pointFlip(NSPoint point) {
(void)pixmap; (void)pixmap;
}; };
- (void)forceRender { - (void)forceRender {
_forceRender = MwTRUE; NSEvent *event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
location:NSMakePoint(0, 0)
modifierFlags:0
timestamp:0
windowNumber:0
context:nil
subtype:0
data1:0
data2:0];
[NSApp postEvent:event atStart:YES];
}; };
- (void)setCursor:(MwCursor*)image mask:(MwCursor*)mask { - (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask {
(void)image; (void)image;
(void)mask; (void)mask;
}; };
- (void)detachWithPoint:(MwPoint*)point { - (void)detachWithPoint:(MwPoint *)point {
(void)point; (void)point;
}; };
- (void)show:(int)show { - (void)show:(int)show {
@ -597,7 +618,7 @@ static NSPoint pointFlip(NSPoint point) {
}; };
- (void)makeBorderless:(int)toggle { - (void)makeBorderless:(int)toggle {
MwU32 mask = [self->window styleMask]; MwU32 mask = [self->window styleMask];
if(toggle) { if (toggle) {
mask ^= NSBorderlessWindowMask; mask ^= NSBorderlessWindowMask;
mask |= NSTitledWindowMask; mask |= NSTitledWindowMask;
} else { } else {
@ -617,33 +638,33 @@ static NSPoint pointFlip(NSPoint point) {
/* MacOS didn't have a "pointer grab" function /* MacOS didn't have a "pointer grab" function
* until 10.13.2 so I need to do this manually */ * until 10.13.2 so I need to do this manually */
}; };
- (void)setClipboard:(const char*)text { - (void)setClipboard:(const char *)text {
(void)text; (void)text;
// TODO: find out how to do this while supporting 10.4 // TODO: find out how to do this while supporting 10.4
// NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; // NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
// NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; // NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
// [pasteboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeString] owner:nil]; // [pasteboard declareTypes:[NSArray arrayWithObjects:NSPasteboardTypeString]
// [pasteboard setString:[NSString stringWithUTF8String:text] forType:NSPasteboardTypeString]; // owner:nil]; [pasteboard setString:[NSString stringWithUTF8String:text]
// [pool release]; // forType:NSPasteboardTypeString]; [pool release];
}; };
- (void)getClipboard { - (void)getClipboard {
}; };
- (void)makeToolWindow { - (void)makeToolWindow {
}; };
- (void)getCursorCoord:(MwPoint*)point { - (void)getCursorCoord:(MwPoint *)point {
NSPoint p = [NSEvent mouseLocation]; NSPoint p = [NSEvent mouseLocation];
point->x = p.x; point->x = p.x;
point->y = p.y; point->y = p.y;
}; };
- (void)getScreenSize:(MwRect*)_rect { - (void)getScreenSize:(MwRect *)_rect {
NSScreen* screen = [self->window screen]; NSScreen *screen = [self->window screen];
_rect->x = [screen frame].origin.x; _rect->x = [screen frame].origin.x;
_rect->y = [screen frame].origin.y; _rect->y = [screen frame].origin.y;
_rect->width = [screen frame].size.width; _rect->width = [screen frame].size.width;
_rect->height = [screen frame].size.height; _rect->height = [screen frame].size.height;
}; };
- (void)destroy { - (void)destroy {
if(self->lastEvent) { if (self->lastEvent) {
[self->lastEvent release]; [self->lastEvent release];
[self->lastEvent dealloc]; [self->lastEvent dealloc];
} }
@ -653,21 +674,21 @@ static NSPoint pointFlip(NSPoint point) {
[self->window dealloc]; [self->window dealloc];
} }
- (NSWindow*)parentWindow { - (NSWindow *)parentWindow {
NSWindow* topmostWindow = self->window; NSWindow *topmostWindow = self->window;
while([topmostWindow parentWindow]) while ([topmostWindow parentWindow])
topmostWindow = [topmostWindow parentWindow]; topmostWindow = [topmostWindow parentWindow];
return topmostWindow; return topmostWindow;
} }
- (NSView*)getView { - (NSView *)getView {
return view; return view;
} }
- (NSWindow*)getWindow { - (NSWindow *)getWindow {
return window; return window;
} }
- (MilskoFakePointer*)getHandle { - (MilskoFakePointer *)getHandle {
return handle; return handle;
} }
@end @end
@ -679,7 +700,7 @@ static NSPoint pointFlip(NSPoint point) {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
self->space = CGColorSpaceCreateDeviceRGB(); self->space = CGColorSpaceCreateDeviceRGB();
if(width == 0 || height == 0) { if (width == 0 || height == 0) {
self->rep = NULL; self->rep = NULL;
self->context = NULL; self->context = NULL;
} else { } else {
@ -706,19 +727,19 @@ static NSPoint pointFlip(NSPoint point) {
return self; return self;
} }
- (NSGraphicsContext*)context { - (NSGraphicsContext *)context {
return self->context; return self->context;
} }
- (NSBitmapImageRep*)getRep { - (NSBitmapImageRep *)getRep {
return self->rep; return self->rep;
} }
- (void)drawRect:(NSRect)dirtyRect { - (void)drawRect:(NSRect)dirtyRect {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSSize sz = [self->rep size]; NSSize sz = [self->rep size];
[super drawRect:dirtyRect]; [super drawRect:dirtyRect];
if(!self->rep) { if (!self->rep) {
[pool release]; [pool release];
return; return;
} }
@ -749,12 +770,22 @@ static NSPoint pointFlip(NSPoint point) {
@end @end
@implementation MilskoCocoaApplicationDelegate
- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)_appl {
self->appl = _appl;
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[self->appl activateIgnoringOtherApps:MwTRUE];
}
@end
@implementation MilskoCocoaWindowDelegate @implementation MilskoCocoaWindowDelegate
- (NSSize)windowWillResize:(NSWindow*)win toSize:(NSSize)frameSize; - (NSSize)windowWillResize:(NSWindow *)win toSize:(NSSize)frameSize;
{ {
if([[[win contentView] subviews] count] >= 1) { if ([[[win contentView] subviews] count] >= 1) {
MilskoFakePointer* ptr = [[[win contentView] subviews] objectAtIndex:0]; MilskoFakePointer *ptr = [[[win contentView] subviews] objectAtIndex:0];
MwLL h = [ptr pointer]; MwLL h = [ptr pointer];
// MwLLDispatch(h, resize, NULL); // MwLLDispatch(h, resize, NULL);
@ -763,12 +794,12 @@ static NSPoint pointFlip(NSPoint point) {
return frameSize; return frameSize;
} }
- (void)windowDidResize:(NSNotification*)notification { - (void)windowDidResize:(NSNotification *)notification {
(void)notification; (void)notification;
} }
// This will close/terminate the application when the main window is closed. // This will close/terminate the application when the main window is closed.
- (void)windowWillClose:(NSNotification*)notification { - (void)windowWillClose:(NSNotification *)notification {
(void)notification; (void)notification;
// MilskoCocoa *window = notification.object; // MilskoCocoa *window = notification.object;
// MwLL handle = [window getHandle].pointer; // MwLL handle = [window getHandle].pointer;
@ -776,7 +807,7 @@ static NSPoint pointFlip(NSPoint point) {
[NSApp terminate:nil]; [NSApp terminate:nil];
} }
- (MilskoCocoaWindowDelegate*)initWithWin:(NSWindow*)win { - (MilskoCocoaWindowDelegate *)initWithWin:(NSWindow *)win {
self->w = win; self->w = win;
return self; return self;
} }
@ -784,11 +815,11 @@ static NSPoint pointFlip(NSPoint point) {
@end @end
@implementation MilskoFakePointer @implementation MilskoFakePointer
- (void)setPointer:(void*)pointer { - (void)setPointer:(void *)pointer {
[self setFrame:*(NSRect*)&pointer]; [self setFrame:*(NSRect *)&pointer];
self->ptr = pointer; self->ptr = pointer;
}; };
- (void*)pointer { - (void *)pointer {
return self->ptr; return self->ptr;
}; };
@ -812,7 +843,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
MwLLCreateCommon(r); MwLLCreateCommon(r);
MilskoCocoa* o = [MilskoCocoa newWithParent:parent MilskoCocoa *o = [MilskoCocoa newWithParent:parent
x:x x:x
y:y y:y
width:width width:width
@ -824,7 +855,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
} }
static void MwLLDestroyImpl(MwLL handle) { static void MwLLDestroyImpl(MwLL handle) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h destroy]; [h destroy];
@ -833,22 +864,18 @@ static void MwLLDestroyImpl(MwLL handle) {
free(handle); free(handle);
} }
static void MwLLBeginDrawImpl(MwLL handle) { static void MwLLBeginDrawImpl(MwLL handle) { (void)handle; }
(void)handle;
}
static void MwLLEndDrawImpl(MwLL handle) { static void MwLLEndDrawImpl(MwLL handle) { (void)handle; }
(void)handle;
}
static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, static void MwLLPolygonImpl(MwLL handle, MwPoint *points, int points_count,
MwLLColor color) { MwLLColor color) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h polygonWithPoints:points points_count:points_count color:color]; [h polygonWithPoints:points points_count:points_count color:color];
} }
static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) { static void MwLLLineImpl(MwLL handle, MwPoint *points, MwLLColor color) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h lineWithPoints:points color:color]; [h lineWithPoints:points color:color];
} }
@ -866,29 +893,27 @@ static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
c->common.blue = b; c->common.blue = b;
} }
static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, static void MwLLGetXYWHImpl(MwLL handle, int *x, int *y, unsigned int *w,
unsigned int* height) { unsigned int *height) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h getX:x Y:y W:w H:height]; [h getX:x Y:y W:w H:height];
} }
static void MwLLSetXYImpl(MwLL handle, int x, int y) { static void MwLLSetXYImpl(MwLL handle, int x, int y) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h setX:x Y:y]; [h setX:x Y:y];
} }
static void MwLLSetWHImpl(MwLL handle, int w, int height) { static void MwLLSetWHImpl(MwLL handle, int w, int height) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h setW:w H:height]; [h setW:w H:height];
} }
static void MwLLFreeColorImpl(MwLLColor color) { static void MwLLFreeColorImpl(MwLLColor color) { free(color); }
free(color);
}
static int MwLLPendingImpl(MwLL handle) { static int MwLLPendingImpl(MwLL handle) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
if([h pending]) { if ([h pending]) {
MwLLDispatch(handle, draw, NULL); MwLLDispatch(handle, draw, NULL);
return 1; return 1;
}; };
@ -896,16 +921,16 @@ static int MwLLPendingImpl(MwLL handle) {
} }
static void MwLLNextEventImpl(MwLL handle) { static void MwLLNextEventImpl(MwLL handle) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h getNextEvent]; [h getNextEvent];
} }
static void MwLLSetTitleImpl(MwLL handle, const char* title) { static void MwLLSetTitleImpl(MwLL handle, const char *title) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h setTitle:title]; [h setTitle:title];
} }
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char *data,
int width, int height) { int width, int height) {
(void)handle; (void)handle;
@ -925,110 +950,102 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data,
} }
static void MwLLPixmapUpdateImpl(MwLLPixmap pixmap) { static void MwLLPixmapUpdateImpl(MwLLPixmap pixmap) {
MilskoCocoaPixmap* p = pixmap->cocoa.real; MilskoCocoaPixmap *p = pixmap->cocoa.real;
[p updateWithData:pixmap->common.raw]; [p updateWithData:pixmap->common.raw];
} }
static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
MilskoCocoaPixmap* p = pixmap->cocoa.real; MilskoCocoaPixmap *p = pixmap->cocoa.real;
[p destroy]; [p destroy];
[p dealloc]; [p dealloc];
free(pixmap); free(pixmap);
} }
static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { static void MwLLDrawPixmapImpl(MwLL handle, MwRect *rect, MwLLPixmap pixmap) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h drawPixmap:pixmap rect:rect]; [h drawPixmap:pixmap rect:rect];
MwLLForceRender(handle); MwLLForceRender(handle);
} }
static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) { static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h setIcon:pixmap]; [h setIcon:pixmap];
} }
static void MwLLForceRenderImpl(MwLL handle) { static void MwLLForceRenderImpl(MwLL handle) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h forceRender]; [h forceRender];
} }
static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) { static void MwLLSetCursorImpl(MwLL handle, MwCursor *image, MwCursor *mask) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h setCursor:image mask:mask]; [h setCursor:image mask:mask];
} }
static void MwLLDetachImpl(MwLL handle, MwPoint* point) { static void MwLLDetachImpl(MwLL handle, MwPoint *point) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h detachWithPoint:point]; [h detachWithPoint:point];
} }
static void MwLLShowImpl(MwLL handle, int show) { static void MwLLShowImpl(MwLL handle, int show) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h show:show]; [h show:show];
} }
static void MwLLMakePopupImpl(MwLL handle, MwLL parent) { static void MwLLMakePopupImpl(MwLL handle, MwLL parent) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h makePopupWithParent:parent]; [h makePopupWithParent:parent];
} }
static void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx, static void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx,
int maxy) { int maxy) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h setSizeHintsWithMinX:minx MinY:miny MaxX:maxx MaxY:maxy]; [h setSizeHintsWithMinX:minx MinY:miny MaxX:maxx MaxY:maxy];
} }
static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) { static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h makeBorderless:toggle]; [h makeBorderless:toggle];
} }
static void MwLLFocusImpl(MwLL handle) { static void MwLLFocusImpl(MwLL handle) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h focus]; [h focus];
} }
static void MwLLGrabPointerImpl(MwLL handle, int toggle) { static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h grabPointer:toggle]; [h grabPointer:toggle];
} }
static void MwLLSetClipboardImpl(MwLL handle, const char* text) { static void MwLLSetClipboardImpl(MwLL handle, const char *text) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h setClipboard:text]; [h setClipboard:text];
} }
static void MwLLGetClipboardImpl(MwLL handle) { static void MwLLGetClipboardImpl(MwLL handle) { (void)handle; }
(void)handle;
}
static void MwLLMakeToolWindowImpl(MwLL handle) { static void MwLLMakeToolWindowImpl(MwLL handle) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h makeToolWindow]; [h makeToolWindow];
} }
static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) { static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint *point) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h getCursorCoord:point]; [h getCursorCoord:point];
} }
static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) { static void MwLLGetScreenSizeImpl(MwLL handle, MwRect *rect) {
MilskoCocoa* h = handle->cocoa.real; MilskoCocoa *h = handle->cocoa.real;
[h getScreenSize:rect]; [h getScreenSize:rect];
} }
static void MwLLBeginStateChangeImpl(MwLL handle) { static void MwLLBeginStateChangeImpl(MwLL handle) { MwLLShow(handle, 0); }
MwLLShow(handle, 0);
}
static void MwLLEndStateChangeImpl(MwLL handle) { static void MwLLEndStateChangeImpl(MwLL handle) { MwLLShow(handle, 1); }
MwLLShow(handle, 1);
}
static int MwLLCocoaCallInitImpl(void) { static int MwLLCocoaCallInitImpl(void) { return 0; }
return 0;
}
#include "call.c" #include "call.c"
CALL(Cocoa); CALL(Cocoa);