Migrated everything else to Objective-C native; fixed a few things I missed along the way.

This commit is contained in:
Pietro Gagliardi 2014-05-15 19:55:16 -04:00
parent b73d4e9010
commit 9d8976abab
9 changed files with 31 additions and 22 deletions

View File

@ -40,7 +40,7 @@ func areaView_drawRect(self C.id, rect C.struct_xrect) {
// rectangles in Cocoa are origin/size, not point0/point1; if we don't watch for this, weird things will happen when scrolling
// TODO change names EVERYWHERE ELSE to match
cliprect := image.Rect(int(rect.x), int(rect.y), int(rect.x + rect.width), int(rect.y + rect.height))
max := C.objc_msgSend_stret_rect_noargs(self, _frame)
max := C.frame(self)
cliprect = image.Rect(0, 0, int(max.width), int(max.height)).Intersect(cliprect)
if cliprect.Empty() { // no intersection; nothing to paint
return
@ -97,7 +97,7 @@ func areaMouseEvent(self C.id, e C.id, click bool, up bool) {
xp := C.getTranslatedEventPoint(self, e)
me.Pos = image.Pt(int(xp.x), int(xp.y))
// for the most part, Cocoa won't geenerate an event outside the Area... except when dragging outside the Area, so check for this
max := C.objc_msgSend_stret_rect_noargs(self, _frame)
max := C.frame(self)
if !me.Pos.In(image.Rect(0, 0, int(max.width), int(max.height))) {
return
}
@ -112,7 +112,7 @@ func areaMouseEvent(self C.id, e C.id, click bool, up bool) {
me.Up = which
} else if click {
me.Down = which
me.Count = uint(C.objc_msgSend_intret_noargs(e, _clickCount))
me.Count = uint(C.clickCount(e))
} else {
which = 0 // reset for Held processing below
}
@ -136,7 +136,7 @@ func areaMouseEvent(self C.id, e C.id, click bool, up bool) {
}
repaint := s.handler.Mouse(me)
if repaint {
C.objc_msgSend_noargs(self, _display)
C.display(self)
}
}
@ -165,7 +165,7 @@ func sendKeyEvent(self C.id, e C.id, ke KeyEvent) bool {
s := getSysData(self)
handled, repaint := s.handler.Key(ke)
if repaint {
C.objc_msgSend_noargs(self, _display)
C.display(self)
}
return handled
}

View File

@ -4,5 +4,6 @@ extern id makeArea(void);
extern uintptr_t modifierFlags(id);
extern struct xpoint getTranslatedEventPoint(id, id);
extern intptr_t buttonNumber(id);
extern intptr_t clickCount(id);
extern uintptr_t pressedMouseButtons(void);
extern uintptr_t keyCode(id);

View File

@ -112,6 +112,11 @@ intptr_t buttonNumber(id e)
return fromNSInteger([toNSEvent(e) buttonNumber]);
}
intptr_t clickCount(id e)
{
return fromNSInteger([toNSEvent(e) clickCount]);
}
uintptr_t pressedMouseButtons(void)
{
return fromNSUInteger([NSEvent pressedMouseButtons]);

View File

@ -49,10 +49,10 @@ var (
func appDelegate_windowDidResize(win C.id) {
s := getSysData(win)
wincv := C.windowGetContentView(win) // we want the content view's size, not the window's
r := C.objc_msgSend_stret_rect_noargs(wincv, _frame)
r := C.frame(wincv)
// winheight is used here because (0,0) is the bottom-left corner, not the top-left corner
s.doResize(0, 0, int(r.width), int(r.height), int(r.height))
C.objc_msgSend_noargs(win, _display) // redraw everything; TODO only if resize() was called?
C.display(win) // redraw everything; TODO only if resize() was called?
}
//export appDelegate_buttonClicked

View File

@ -182,7 +182,7 @@ func newListboxScrollView(listbox C.id) C.id {
)
scrollview := newScrollView(listbox)
C.objc_msgSend_uint(scrollview, _setBorderType, _NSBezelBorder) // this is what Interface Builder gives the scroll view
C.giveScrollViewBezelBorder(scrollview) // this is what Interface Builder gives the scroll view
return scrollview
}

View File

@ -43,14 +43,11 @@ func toNSString(str string) C.id {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
return C.objc_msgSend_str(_NSString,
_stringWithUTF8String,
cstr)
return C.toNSString(cstr)
}
func fromNSString(str C.id) string {
cstr := C.objc_msgSend_noargs(str, _UTF8String)
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
return C.GoString(C.fromNSString(str))
}
// These consolidate the NSScrollView code (used by listbox_darwin.go and area_darwin.go) into a single place.
@ -66,15 +63,9 @@ var (
)
func newScrollView(content C.id) C.id {
scrollview := C.objc_msgSend_noargs(_NSScrollView, _alloc)
scrollview = initWithDummyFrame(scrollview)
C.objc_msgSend_bool(scrollview, _setHasHorizontalScroller, C.BOOL(C.YES))
C.objc_msgSend_bool(scrollview, _setHasVerticalScroller, C.BOOL(C.YES))
C.objc_msgSend_bool(scrollview, _setAutohidesScrollers, C.BOOL(C.YES))
C.objc_msgSend_id(scrollview, _setDocumentView, content)
return scrollview
return C.makeScrollView(content)
}
func getScrollViewContent(scrollview C.id) C.id {
return C.objc_msgSend_noargs(scrollview, _documentView)
return C.scrollViewContent(scrollview)
}

View File

@ -20,6 +20,18 @@ The format should be self-explanatory.
#include <stdint.h>
struct xrect; // TODO move that up here when finally getting rid of bleh_darwin.m
extern id toNSString(char *);
extern char *fromNSString(id);
extern void display(id);
extern struct xrect frame(id);
extern id makeScrollView(id);
extern void giveScrollViewBezelBorder(id);
extern id scrollViewContent(id);
// BEGIN OLD CODE
static inline id objc_msgSend_noargs(id obj, SEL sel)
{
return objc_msgSend(obj, sel);

View File

@ -91,7 +91,6 @@ var (
_deselectItemAtIndex = sel_getUid("deselectItemAtIndex:")
)
// because the only way to make a new NSControl/NSView is with a frame (it gets overridden later)
func initWithDummyFrame(self C.id) C.id {
return C.objc_msgSend_rect(self, _initWithFrame,
C.int64_t(0), C.int64_t(0), C.int64_t(100), C.int64_t(100))

View File

@ -14,6 +14,7 @@
#include <AppKit/NSProgressIndicator.h>
#include <AppKit/NSScrollView.h>
// because the only way to make a new NSControl/NSView is with a frame (it gets overridden later)
static NSRect dummyRect;// = NSMakeRect(0, 0, 100, 100);
#define to(T, x) ((T *) (x))