2026-01-09 21:35:23 -07:00
|
|
|
/*!
|
|
|
|
|
* @file Mw/LowLevel/Cocoa.h
|
|
|
|
|
* @brief Work in progress Cocoa Backend
|
|
|
|
|
* @warning This is used internally.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef __MW_LOWLEVEL_COCOA_H__
|
|
|
|
|
#define __MW_LOWLEVEL_COCOA_H__
|
|
|
|
|
|
|
|
|
|
#include <Mw/LowLevel.h>
|
|
|
|
|
#include <Mw/MachDep.h>
|
|
|
|
|
#include <Mw/TypeDefs.h>
|
|
|
|
|
|
2026-01-14 13:47:49 -07:00
|
|
|
#ifdef __OBJC__
|
2026-01-14 17:13:12 -07:00
|
|
|
#import <AppKit/AppKit.h>
|
|
|
|
|
#import <Foundation/Foundation.h>
|
2026-03-03 23:24:28 -07:00
|
|
|
#import <Foundation/NSGeometry.h>
|
2026-01-14 17:13:12 -07:00
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
#import <CoreServices/CoreServices.h>
|
|
|
|
|
#else
|
|
|
|
|
#import <CoreGraphics/CoreGraphics.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2026-03-25 17:49:28 -07:00
|
|
|
@interface MilskoCocoaApplication : NSApplication {
|
|
|
|
|
MwBool doPending;
|
|
|
|
|
}
|
|
|
|
|
- (MwBool)pending;
|
|
|
|
|
@end
|
|
|
|
|
|
2026-03-08 18:30:37 -07:00
|
|
|
// Note: implements NSApplicationDelegate
|
2026-03-08 19:15:17 -07:00
|
|
|
@interface MilskoCocoaApplicationDelegate : NSObject {
|
2026-03-25 17:49:28 -07:00
|
|
|
MilskoCocoaApplication* appl;
|
2026-03-08 18:30:37 -07:00
|
|
|
}
|
2026-03-25 17:49:28 -07:00
|
|
|
- (MilskoCocoaApplicationDelegate*)initWithAppl:(MilskoCocoaApplication*)appl;
|
2026-03-08 18:30:37 -07:00
|
|
|
@end
|
|
|
|
|
|
2026-03-09 14:01:54 -07:00
|
|
|
@interface MilskoCocoaWindow : NSWindow {
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
2026-03-08 18:04:37 -07:00
|
|
|
// Note: implements NSWindowDelegate
|
|
|
|
|
@interface MilskoCocoaWindowDelegate : NSObject {
|
2026-03-24 04:26:26 +09:00
|
|
|
MilskoCocoaWindow* w;
|
2026-03-04 19:34:19 -07:00
|
|
|
}
|
2026-03-24 04:26:26 +09:00
|
|
|
- (MilskoCocoaWindowDelegate*)initWithWin:(MilskoCocoaWindow*)win;
|
2026-03-04 19:34:19 -07:00
|
|
|
@end
|
|
|
|
|
|
2026-03-09 16:19:12 -07:00
|
|
|
/*
|
|
|
|
|
So we want to associate each NSWindow with its corresponding MwLL handle. The
|
|
|
|
|
conventional way of doing this is through "associative pointers", however
|
|
|
|
|
this is a feature that Apple added in 10.6 (marketted back then as "Objective
|
|
|
|
|
C 2" iirc). For 10.4 compatibility, we have to do a bit of an ugly hack that
|
|
|
|
|
might seem like horrifically undefined behavior, but I've tested this on
|
|
|
|
|
both 10.4 and modern Mac OS and as long as we're careful there's no
|
|
|
|
|
problems: we override NSView, use NSView's "frame" property to store the
|
|
|
|
|
pointer, and then override functions appropriately so that this frame is never
|
|
|
|
|
actually used. This can then be attached to an NSWindow with addSubview and
|
|
|
|
|
retrieved appropriately.
|
|
|
|
|
*/
|
2026-03-04 19:34:19 -07:00
|
|
|
@interface MilskoFakePointer : NSView {
|
2026-03-24 04:26:26 +09:00
|
|
|
void* ptr;
|
2026-03-04 19:34:19 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 04:26:26 +09:00
|
|
|
- (void)setPointer:(void*)ptr;
|
|
|
|
|
- (void*)pointer;
|
2026-03-04 19:34:19 -07:00
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2026-01-14 13:47:49 -07:00
|
|
|
@interface MilskoCocoaPixmap : NSObject {
|
2026-03-24 04:26:26 +09:00
|
|
|
MwBool valid;
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
unsigned char* buf;
|
|
|
|
|
NSImage* image;
|
|
|
|
|
NSBitmapImageRep* rep;
|
2026-01-14 13:47:49 -07:00
|
|
|
}
|
2026-01-14 17:13:12 -07:00
|
|
|
|
2026-03-24 04:26:26 +09:00
|
|
|
+ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height;
|
|
|
|
|
- (void)updateWithData:(unsigned char*)data;
|
2026-01-14 13:47:49 -07:00
|
|
|
- (void)destroy;
|
2026-01-14 17:13:12 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
/* using @property to create instance variables fucks up 10.4 gcc for some
|
|
|
|
|
* reason? */
|
2026-03-24 04:26:26 +09:00
|
|
|
- (NSImage*)image;
|
2026-01-14 17:13:12 -07:00
|
|
|
|
2026-01-14 13:47:49 -07:00
|
|
|
@end
|
2026-01-14 17:13:12 -07:00
|
|
|
|
|
|
|
|
@interface MilskoCocoaView : NSView {
|
2026-03-25 17:49:28 -07:00
|
|
|
NSBitmapImageRep* rep;
|
|
|
|
|
NSGraphicsContext* context;
|
|
|
|
|
MwBool valid;
|
|
|
|
|
CGColorSpaceRef space;
|
|
|
|
|
CGDataProviderRef provider;
|
|
|
|
|
NSRect givenRect;
|
|
|
|
|
float x;
|
|
|
|
|
float y;
|
|
|
|
|
float width;
|
|
|
|
|
float height;
|
|
|
|
|
MwBool _child;
|
|
|
|
|
IBOutlet NSViewController* viewController;
|
2026-01-14 17:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-10 17:10:47 -07:00
|
|
|
- (void)initRepAndContextWithWidth:(float)w Height:(float)h;
|
2026-03-24 04:26:26 +09:00
|
|
|
- (NSGraphicsContext*)context;
|
2026-03-04 19:34:19 -07:00
|
|
|
- (void)destroy;
|
2026-03-24 04:26:26 +09:00
|
|
|
- (NSBitmapImageRep*)getRep;
|
2026-03-25 17:49:28 -07:00
|
|
|
- (void)setChild;
|
2026-03-04 19:34:19 -07:00
|
|
|
|
2026-01-14 17:13:12 -07:00
|
|
|
@end
|
|
|
|
|
|
2026-01-14 13:47:49 -07:00
|
|
|
@interface MilskoCocoa : NSObject {
|
2026-03-25 17:49:28 -07:00
|
|
|
MilskoCocoaApplication* application;
|
|
|
|
|
MwBool _forceRender;
|
|
|
|
|
MwBool _eventsPending;
|
|
|
|
|
MilskoCocoaWindow* window;
|
|
|
|
|
NSRect rect;
|
|
|
|
|
MilskoCocoaView* view;
|
|
|
|
|
MwLL parent;
|
|
|
|
|
MilskoFakePointer* handle;
|
|
|
|
|
unsigned int strHash;
|
|
|
|
|
NSEvent* lastEvent;
|
2026-03-24 04:26:26 +09:00
|
|
|
|
|
|
|
|
MilskoCocoaPixmap* cursorPixmap;
|
|
|
|
|
NSCursor* cursor;
|
|
|
|
|
NSModalSession modalSession;
|
|
|
|
|
|
|
|
|
|
MwBool pointerLocked;
|
|
|
|
|
MwBool mouseMoved;
|
2026-01-14 13:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 04:26:26 +09:00
|
|
|
+ (MilskoCocoa*)newWithParent:(MwLL)parent
|
|
|
|
|
x:(int)x
|
|
|
|
|
y:(int)y
|
|
|
|
|
width:(int)width
|
|
|
|
|
height:(int)height
|
|
|
|
|
handle:(MwLL)handle;
|
|
|
|
|
- (void)polygonWithPoints:(MwPoint*)points
|
|
|
|
|
points_count:(int)points_count
|
|
|
|
|
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;
|
2026-01-14 13:47:49 -07:00
|
|
|
- (void)setX:(int)x Y:(int)y;
|
|
|
|
|
- (void)setW:(int)w H:(int)h;
|
|
|
|
|
- (int)pending;
|
|
|
|
|
- (void)getNextEvent;
|
2026-03-24 04:26:26 +09:00
|
|
|
- (void)setTitle:(const char*)title;
|
|
|
|
|
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect*)rect;
|
2026-01-14 13:47:49 -07:00
|
|
|
- (void)setIcon:(MwLLPixmap)pixmap;
|
|
|
|
|
- (void)forceRender;
|
2026-03-24 04:26:26 +09:00
|
|
|
- (void)setCursor:(MwCursor*)image mask:(MwCursor*)mask;
|
|
|
|
|
- (void)detachWithPoint:(MwPoint*)point;
|
2026-01-14 13:47:49 -07:00
|
|
|
- (void)show:(int)show;
|
|
|
|
|
- (void)makePopupWithParent:(MwLL)parent;
|
|
|
|
|
- (void)setSizeHintsWithMinX:(int)minx
|
2026-03-24 04:26:26 +09:00
|
|
|
MinY:(int)miny
|
|
|
|
|
MaxX:(int)maxx
|
|
|
|
|
MaxY:(int)maxy;
|
2026-01-14 13:47:49 -07:00
|
|
|
- (void)makeBorderless:(int)toggle;
|
|
|
|
|
- (void)focus;
|
|
|
|
|
- (void)grabPointer:(int)toggle;
|
2026-03-24 04:26:26 +09:00
|
|
|
- (void)setClipboard:(const char*)text;
|
2026-01-14 13:47:49 -07:00
|
|
|
- (void)makeToolWindow;
|
2026-03-24 04:26:26 +09:00
|
|
|
- (void)getCursorCoord:(MwPoint*)point;
|
|
|
|
|
- (void)getScreenSize:(MwRect*)rect;
|
2026-01-14 13:47:49 -07:00
|
|
|
- (void)destroy;
|
2026-03-05 21:58:22 -07:00
|
|
|
- (void)sendClipboardEvent;
|
2026-03-04 19:34:19 -07:00
|
|
|
|
2026-03-10 17:10:47 -07:00
|
|
|
- (MwLL)getParent;
|
2026-03-24 04:26:26 +09:00
|
|
|
- (NSView*)getView;
|
|
|
|
|
- (MilskoCocoaWindow*)getWindow;
|
2026-03-25 17:49:28 -07:00
|
|
|
- (void)nudge;
|
|
|
|
|
|
|
|
|
|
- (void)pushCursor;
|
|
|
|
|
- (void)popCursor;
|
2026-03-10 17:10:47 -07:00
|
|
|
|
2026-03-24 04:26:26 +09:00
|
|
|
- (MilskoFakePointer*)getHandle;
|
|
|
|
|
+ (void)eventCanceller:(MilskoCocoa*)this;
|
2026-01-14 13:47:49 -07:00
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
#define OBJC(x) x
|
|
|
|
|
#else
|
2026-03-24 04:26:26 +09:00
|
|
|
#define OBJC(x) void*
|
2026-01-14 13:47:49 -07:00
|
|
|
#endif
|
|
|
|
|
|
2026-01-09 21:35:23 -07:00
|
|
|
MWDECL int MwLLCocoaCallInit(void);
|
|
|
|
|
|
|
|
|
|
struct _MwLLCocoa {
|
2026-03-24 04:26:26 +09:00
|
|
|
struct _MwLLCommon common;
|
|
|
|
|
OBJC(MilskoCocoa*)
|
|
|
|
|
real;
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _MwLLCocoaColor {
|
2026-03-24 04:26:26 +09:00
|
|
|
struct _MwLLCommonColor common;
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _MwLLCocoaPixmap {
|
2026-03-24 04:26:26 +09:00
|
|
|
struct _MwLLCommonPixmap common;
|
|
|
|
|
OBJC(MilskoCocoaPixmap*)
|
|
|
|
|
real;
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|