mac: most window functions now implemented (save for makeToolWindow)
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
This commit is contained in:
parent
9eda46d981
commit
65afd85439
2 changed files with 135 additions and 48 deletions
|
|
@ -28,11 +28,15 @@
|
||||||
- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)appl;
|
- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)appl;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface MilskoCocoaWindow : NSWindow {
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
// Note: implements NSWindowDelegate
|
// Note: implements NSWindowDelegate
|
||||||
@interface MilskoCocoaWindowDelegate : NSObject {
|
@interface MilskoCocoaWindowDelegate : NSObject {
|
||||||
NSWindow *w;
|
MilskoCocoaWindow *w;
|
||||||
}
|
}
|
||||||
- (MilskoCocoaWindowDelegate *)initWithWin:(NSWindow *)win;
|
- (MilskoCocoaWindowDelegate *)initWithWin:(MilskoCocoaWindow *)win;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface MilskoFakePointer : NSView {
|
@interface MilskoFakePointer : NSView {
|
||||||
|
|
@ -82,13 +86,16 @@
|
||||||
@interface MilskoCocoa : NSObject {
|
@interface MilskoCocoa : NSObject {
|
||||||
NSApplication *application;
|
NSApplication *application;
|
||||||
MwBool _forceRender;
|
MwBool _forceRender;
|
||||||
NSWindow *window;
|
MilskoCocoaWindow *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;
|
||||||
|
|
||||||
|
MilskoCocoaPixmap *cursorPixmap;
|
||||||
|
NSCursor *cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (MilskoCocoa *)newWithParent:(MwLL)parent
|
+ (MilskoCocoa *)newWithParent:(MwLL)parent
|
||||||
|
|
@ -131,9 +138,9 @@
|
||||||
- (void)destroy;
|
- (void)destroy;
|
||||||
- (void)sendClipboardEvent;
|
- (void)sendClipboardEvent;
|
||||||
|
|
||||||
- (NSWindow *)parentWindow;
|
- (MilskoCocoaWindow *)parentWindow;
|
||||||
- (NSView *)getView;
|
- (NSView *)getView;
|
||||||
- (NSWindow *)getWindow;
|
- (MilskoCocoaWindow *)getWindow;
|
||||||
- (MilskoFakePointer *)getHandle;
|
- (MilskoFakePointer *)getHandle;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include "Mw/BaseTypes.h"
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
|
|
@ -93,41 +94,43 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
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 = [[MilskoCocoaWindow alloc]
|
||||||
initWithContentRect:c->rect
|
initWithContentRect:c->rect
|
||||||
styleMask:(NSTitledWindowMask | NSClosableWindowMask |
|
styleMask:(NSTitledWindowMask |
|
||||||
NSMiniaturizableWindowMask | NSResizableWindowMask)
|
NSTexturedBackgroundWindowMask |
|
||||||
|
NSClosableWindowMask | NSMiniaturizableWindowMask |
|
||||||
|
NSResizableWindowMask)
|
||||||
backing:NSBackingStoreBuffered
|
backing:NSBackingStoreBuffered
|
||||||
defer:NO];
|
defer:NO];
|
||||||
} else {
|
} else {
|
||||||
double offset = 0;
|
double offset = 0;
|
||||||
NSWindow* parentWindow = parent->cocoa.real->window;
|
MilskoCocoaWindow *parentWindow = parent->cocoa.real->window;
|
||||||
offset =
|
offset =
|
||||||
[parentWindow frameRectForContentRect:[parentWindow frame]].size.height -
|
[parentWindow frameRectForContentRect:[parentWindow frame]]
|
||||||
[parentWindow contentRectForFrameRect:[parentWindow frame]].size.height;
|
.size.height -
|
||||||
|
[parentWindow contentRectForFrameRect:[parentWindow frame]].size.height;
|
||||||
|
|
||||||
c->rect.origin.x += [parentWindow frame].origin.x;
|
c->rect.origin.x += [parentWindow frame].origin.x;
|
||||||
c->rect.origin.y -= [parentWindow frame].origin.y - offset;
|
c->rect.origin.y -= [parentWindow frame].origin.y - offset;
|
||||||
c->rect.origin.y -= offset;
|
c->rect.origin.y -= offset;
|
||||||
|
|
||||||
c->window = [[NSWindow alloc] initWithContentRect:c->rect
|
c->window =
|
||||||
styleMask:NSBorderlessWindowMask
|
[[MilskoCocoaWindow alloc] initWithContentRect:c->rect
|
||||||
backing:NSBackingStoreBuffered
|
styleMask:NSBorderlessWindowMask
|
||||||
defer:NO];
|
backing:NSBackingStoreBuffered
|
||||||
|
defer:NO];
|
||||||
}
|
}
|
||||||
[c->window
|
[c->window
|
||||||
setDelegate:[[MilskoCocoaWindowDelegate alloc]
|
setDelegate:[[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;
|
||||||
double offset = 0;
|
double offset = 0;
|
||||||
offset =
|
offset = [p->window frameRectForContentRect:[p->window frame]].size.height -
|
||||||
[p->window frameRectForContentRect:[p->window frame]].size.height -
|
[p->window contentRectForFrameRect:[p->window frame]].size.height;
|
||||||
[p->window contentRectForFrameRect:[p->window frame]].size.height;
|
|
||||||
[p->window addChildWindow:c->window ordered:NSWindowAbove];
|
[p->window addChildWindow:c->window ordered:NSWindowAbove];
|
||||||
[c->window setHasShadow:MwFALSE];
|
[c->window setHasShadow:MwFALSE];
|
||||||
[c->window setParentWindow:p->window];
|
[c->window setParentWindow:p->window];
|
||||||
|
|
@ -139,10 +142,11 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
[c->application setActivationPolicy:NSApplicationActivationPolicyRegular];
|
[c->application setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||||
[c->application activateIgnoringOtherApps:true];
|
[c->application activateIgnoringOtherApps:true];
|
||||||
[c->window makeFirstResponder:c->view];
|
[c->window makeFirstResponder:c->view];
|
||||||
|
[c->window makeKeyAndOrderFront:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
[c->application setDelegate:[[MilskoCocoaApplicationDelegate alloc]
|
[c->application setDelegate:[[MilskoCocoaApplicationDelegate alloc]
|
||||||
initWithAppl:c->application]];
|
initWithAppl:c->application]];
|
||||||
|
[c->application retain];
|
||||||
|
|
||||||
c->view = [[MilskoCocoaView alloc] initWithFrame:c->rect];
|
c->view = [[MilskoCocoaView alloc] initWithFrame:c->rect];
|
||||||
[c->view retain];
|
[c->view retain];
|
||||||
|
|
@ -158,6 +162,8 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
c->_forceRender = MwTRUE;
|
c->_forceRender = MwTRUE;
|
||||||
c->strHash = 0;
|
c->strHash = 0;
|
||||||
|
|
||||||
|
c->cursorPixmap = NULL;
|
||||||
|
|
||||||
[c->application finishLaunching];
|
[c->application finishLaunching];
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
|
|
@ -209,7 +215,7 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
NSRect frame = rectFlip([self->window frame]);
|
NSRect frame = rectFlip([self->window frame]);
|
||||||
frame = rectFlip(frame);
|
frame = rectFlip(frame);
|
||||||
|
|
||||||
if(parent) {
|
if (parent) {
|
||||||
frame.origin.x -= [parent->cocoa.real->window frame].origin.x;
|
frame.origin.x -= [parent->cocoa.real->window frame].origin.x;
|
||||||
frame.origin.y += [parent->cocoa.real->window frame].origin.y;
|
frame.origin.y += [parent->cocoa.real->window frame].origin.y;
|
||||||
}
|
}
|
||||||
|
|
@ -228,17 +234,18 @@ 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;
|
MilskoCocoaWindow *parentWindow = parent->cocoa.real->window;
|
||||||
offset =
|
offset =
|
||||||
[parentWindow frameRectForContentRect:[parentWindow frame]].size.height -
|
[parentWindow frameRectForContentRect:[parentWindow frame]]
|
||||||
[parentWindow contentRectForFrameRect:[parentWindow frame]].size.height;
|
.size.height -
|
||||||
|
[parentWindow contentRectForFrameRect:[parentWindow frame]].size.height;
|
||||||
|
|
||||||
frame.origin.x += [parentWindow frame].origin.x;
|
frame.origin.x += [parentWindow frame].origin.x;
|
||||||
frame.origin.y -= [parentWindow frame].origin.y - offset;
|
frame.origin.y -= [parentWindow frame].origin.y - offset;
|
||||||
frame.origin.y -= offset;
|
frame.origin.y -= offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self->view setFrameSize:frame.size];
|
[self->view setFrameSize:frame.size];
|
||||||
|
|
||||||
|
|
@ -336,9 +343,11 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
}
|
}
|
||||||
case NSMouseEntered:
|
case NSMouseEntered:
|
||||||
MwLLDispatch(h, focus_in, NULL);
|
MwLLDispatch(h, focus_in, NULL);
|
||||||
|
[self->cursor push];
|
||||||
break;
|
break;
|
||||||
case NSMouseExited:
|
case NSMouseExited:
|
||||||
MwLLDispatch(h, focus_out, NULL);
|
MwLLDispatch(h, focus_out, NULL);
|
||||||
|
[self->cursor pop];
|
||||||
break;
|
break;
|
||||||
case NSKeyDown:
|
case NSKeyDown:
|
||||||
case NSKeyUp: {
|
case NSKeyUp: {
|
||||||
|
|
@ -346,10 +355,12 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
doSendEvent = MwFALSE;
|
doSendEvent = MwFALSE;
|
||||||
}
|
}
|
||||||
case NSCursorUpdate:
|
case NSCursorUpdate:
|
||||||
|
[self->cursor set];
|
||||||
break;
|
break;
|
||||||
case NSScrollWheel:
|
case NSScrollWheel:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
doSendEvent = MwFALSE;
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
if (doSendEvent) {
|
if (doSendEvent) {
|
||||||
|
|
@ -589,7 +600,7 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
[pool release];
|
[pool release];
|
||||||
};
|
};
|
||||||
- (void)setIcon:(MwLLPixmap)pixmap {
|
- (void)setIcon:(MwLLPixmap)pixmap {
|
||||||
(void)pixmap;
|
[self->application setApplicationIconImage:[pixmap->cocoa.real image]];
|
||||||
};
|
};
|
||||||
- (void)forceRender {
|
- (void)forceRender {
|
||||||
self->_forceRender = MwTRUE;
|
self->_forceRender = MwTRUE;
|
||||||
|
|
@ -607,11 +618,63 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
// [pool release];
|
// [pool release];
|
||||||
};
|
};
|
||||||
- (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask {
|
- (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask {
|
||||||
(void)image;
|
int y, x, ys, xs;
|
||||||
(void)mask;
|
unsigned char *di = malloc(image->width * image->height * 4);
|
||||||
|
memset(di, 0, image->width * image->height * 4);
|
||||||
|
|
||||||
|
if (self->cursorPixmap) {
|
||||||
|
[self->cursorPixmap destroy];
|
||||||
|
}
|
||||||
|
self->cursorPixmap =
|
||||||
|
[MilskoCocoaPixmap newWithWidth:image->width height:image->height];
|
||||||
|
|
||||||
|
xs = -mask->x + image->x;
|
||||||
|
ys = MwCursorDataHeight + mask->y;
|
||||||
|
ys = MwCursorDataHeight + image->y - ys;
|
||||||
|
|
||||||
|
for (y = 0; y < mask->height; y++) {
|
||||||
|
unsigned int d = mask->data[y];
|
||||||
|
for (x = mask->width - 1; x >= 0; x--) {
|
||||||
|
int px = 0;
|
||||||
|
int idx = ((y * mask->width) + x) * 4;
|
||||||
|
|
||||||
|
if (d & 1) {
|
||||||
|
di[idx + 3] = 255;
|
||||||
|
};
|
||||||
|
d = d >> 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (y = 0; y < image->height; y++) {
|
||||||
|
unsigned int d = image->data[y];
|
||||||
|
for (x = image->width - 1; x >= 0; x--) {
|
||||||
|
int px = 0;
|
||||||
|
int idx = ((y * image->width) + x) * 4;
|
||||||
|
|
||||||
|
if (d & 1) {
|
||||||
|
px = 255;
|
||||||
|
};
|
||||||
|
|
||||||
|
di[idx] = px;
|
||||||
|
di[idx + 1] = px;
|
||||||
|
di[idx + 2] = px;
|
||||||
|
d = d >> 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[self->cursorPixmap updateWithData:di];
|
||||||
|
|
||||||
|
self->cursor = [[NSCursor alloc]
|
||||||
|
initWithImage:[self->cursorPixmap image]
|
||||||
|
hotSpot:NSMakePoint(image->x, image->y + image->height)];
|
||||||
|
[self->cursor retain];
|
||||||
|
|
||||||
|
[self->cursor pop];
|
||||||
|
[self->cursor push];
|
||||||
|
|
||||||
|
free(di);
|
||||||
};
|
};
|
||||||
- (void)detachWithPoint:(MwPoint *)point {
|
- (void)detachWithPoint:(MwPoint *)point {
|
||||||
(void)point;
|
[self->window setParentWindow:NULL];
|
||||||
};
|
};
|
||||||
- (void)show:(int)show {
|
- (void)show:(int)show {
|
||||||
(void)show;
|
(void)show;
|
||||||
|
|
@ -623,10 +686,8 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
MinY:(int)miny
|
MinY:(int)miny
|
||||||
MaxX:(int)maxx
|
MaxX:(int)maxx
|
||||||
MaxY:(int)maxy {
|
MaxY:(int)maxy {
|
||||||
(void)minx;
|
[self->window setMinSize:NSMakeSize(minx, miny)];
|
||||||
(void)miny;
|
[self->window setMaxSize:NSMakeSize(maxx, maxy)];
|
||||||
(void)maxx;
|
|
||||||
(void)maxy;
|
|
||||||
};
|
};
|
||||||
- (void)makeBorderless:(int)toggle {
|
- (void)makeBorderless:(int)toggle {
|
||||||
MwU32 mask = [self->window styleMask];
|
MwU32 mask = [self->window styleMask];
|
||||||
|
|
@ -659,8 +720,6 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
// owner:nil]; [pasteboard setString:[NSString stringWithUTF8String:text]
|
// owner:nil]; [pasteboard setString:[NSString stringWithUTF8String:text]
|
||||||
// forType:NSPasteboardTypeString]; [pool release];
|
// forType:NSPasteboardTypeString]; [pool release];
|
||||||
};
|
};
|
||||||
- (void)getClipboard {
|
|
||||||
};
|
|
||||||
- (void)makeToolWindow {
|
- (void)makeToolWindow {
|
||||||
};
|
};
|
||||||
- (void)getCursorCoord:(MwPoint *)point {
|
- (void)getCursorCoord:(MwPoint *)point {
|
||||||
|
|
@ -703,6 +762,7 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
- (MilskoFakePointer *)getHandle {
|
- (MilskoFakePointer *)getHandle {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MilskoCocoaView
|
@implementation MilskoCocoaView
|
||||||
|
|
@ -787,8 +847,15 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
self->appl = _appl;
|
self->appl = _appl;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
- (void)applicationDidBecomeActive:(NSNotification *)notification {
|
||||||
|
printf("test\n");
|
||||||
|
}
|
||||||
|
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
|
||||||
|
// printf("test\n");
|
||||||
|
// [self->appl activateIgnoringOtherApps:MwTRUE];
|
||||||
|
}
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
|
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
|
||||||
[self->appl activateIgnoringOtherApps:MwTRUE];
|
// [self->appl activateIgnoringOtherApps:MwTRUE];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
@ -806,6 +873,10 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
return frameSize;
|
return frameSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)windowDidBecomeMain:(NSNotification *)notification {
|
||||||
|
printf("waow\n");
|
||||||
|
}
|
||||||
|
|
||||||
- (void)windowDidResize:(NSNotification *)notification {
|
- (void)windowDidResize:(NSNotification *)notification {
|
||||||
(void)notification;
|
(void)notification;
|
||||||
}
|
}
|
||||||
|
|
@ -842,8 +913,17 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
|
|
||||||
- (void)destroy {
|
- (void)destroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation MilskoCocoaWindow
|
||||||
|
- (BOOL)canBecomeKeyWindow {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
- (BOOL)canBecomeMainWindow {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||||
MwLL r;
|
MwLL r;
|
||||||
(void)x;
|
(void)x;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue