ultimatepp/uppsrc/CtrlCore/CocoMM.h
cxl 37cc1d5212 CtrlCore: Developing Cocoa
git-svn-id: svn://ultimatepp.org/upp/trunk@12082 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2018-07-17 14:08:28 +00:00

80 lines
1.4 KiB
Objective-C

#ifndef _CtrlCore_CocoMM_h_
#define _CtrlCore_CocoMM_h_
#ifdef flagCOCOA
#define Point NS_Point
#define Rect NS_Rect
#define Size NS_Size
#include <AppKit/AppKit.h>
#undef Point
#undef Rect
#undef Size
#include "CtrlCore.h"
namespace Upp {
template <class T>
struct CFRef {
T ptr;
T operator~() { return ptr; }
operator T() { return ptr; }
T operator->() { return ptr; }
T Detach() { T h = ptr; ptr = NULL; return h; }
CFRef(T p) { ptr = p; }
~CFRef() { if(ptr) CFRelease(ptr); }
};
struct AutoreleasePool {
NSAutoreleasePool *pool;
AutoreleasePool() {
pool = [[NSAutoreleasePool alloc] init];
}
~AutoreleasePool() {
[pool release];
}
};
WString ToWString(CFStringRef s);
String ToString(CFStringRef s);
#define cgHandle (CGContextRef)handle
struct RectCG {
int x, y, cx, cy;
operator CGRect() const { return CGRectMake(x, y, cx, cy); }
RectCG(int x, int y, int cx, int cy) : x(x), y(y), cx(cx), cy(cy) {}
RectCG();
};
}
@interface CocoView : NSView <NSWindowDelegate>
{
@public
Upp::Ctrl *ctrl;
}
@end
struct Upp::MMCtrl {
static void SyncRect(CocoView *view);
};
struct Upp::CocoTop {
NSWindow *window = NULL;
CocoView *view = NULL;
};
void SyncRect(CocoView *view);
inline Upp::Rect MakeRect(const CGRect& r) {
return Upp::RectC(r.origin.x, r.origin.y, r.size.width, r.size.height);
}
#endif
#endif