Migrated the Mac OS X Table implementation. Untested due to VM issues.

This commit is contained in:
Pietro Gagliardi 2015-02-18 23:04:14 -05:00
parent 8ec518dfe8
commit 1d091637d8
4 changed files with 11 additions and 8 deletions

View File

@ -5,7 +5,7 @@
#define toNSInteger(x) ((NSInteger) (x)) #define toNSInteger(x) ((NSInteger) (x))
id toImageListImage(void *pixels, intptr_t width, intptr_t height, intptr_t stride) id toTableImage(void *pixels, intptr_t width, intptr_t height, intptr_t stride)
{ {
NSBitmapImageRep *bitmap; NSBitmapImageRep *bitmap;
NSImage *image; NSImage *image;
@ -26,5 +26,6 @@ id toImageListImage(void *pixels, intptr_t width, intptr_t height, intptr_t stri
memcpy((void *) [bitmap bitmapData], pixels, [bitmap bytesPerPlane]); memcpy((void *) [bitmap bitmapData], pixels, [bitmap bytesPerPlane]);
image = [[NSImage alloc] initWithSize:NSMakeSize((CGFloat) width, (CGFloat) height)]; image = [[NSImage alloc] initWithSize:NSMakeSize((CGFloat) width, (CGFloat) height)];
[image addRepresentation:bitmap]; [image addRepresentation:bitmap];
// TODO release bitmap?
return (id) image; return (id) image;
} }

View File

@ -146,8 +146,8 @@ extern void areaEndTextFieldEditing(id, id);
/* common_darwin.m */ /* common_darwin.m */
extern void disableAutocorrect(id); extern void disableAutocorrect(id);
/* imagerep_darwin.m */ /* image_darwin.m */
extern id toImageListImage(void *, intptr_t, intptr_t, intptr_t); extern id toTableImage(void *, intptr_t, intptr_t, intptr_t);
/* dialog_darwin.m */ /* dialog_darwin.m */
extern void openFile(id, void *); extern void openFile(id, void *);

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"unsafe" "unsafe"
"image"
) )
// #include "objc_darwin.h" // #include "objc_darwin.h"
@ -16,7 +17,6 @@ type table struct {
*scroller *scroller
images []C.id
selected *event selected *event
} }
@ -35,7 +35,7 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
coltype := C.colTypeText coltype := C.colTypeText
editable := false editable := false
switch { switch {
case ty.Field(i).Type == reflect.TypeOf(ImageIndex(0)): case ty.Field(i).Type == reflect.TypeOf((*image.RGBA)(nil)):
coltype = C.colTypeImage coltype = C.colTypeImage
case ty.Field(i).Type.Kind() == reflect.Bool: case ty.Field(i).Type.Kind() == reflect.Bool:
coltype = C.colTypeCheckbox coltype = C.colTypeCheckbox
@ -88,10 +88,11 @@ func goTableDataSource_getValue(data unsafe.Pointer, row C.intptr_t, col C.intpt
d := reflect.Indirect(reflect.ValueOf(t.data)) d := reflect.Indirect(reflect.ValueOf(t.data))
datum := d.Index(int(row)).Field(int(col)) datum := d.Index(int(row)).Field(int(col))
switch { switch {
case datum.Type() == reflect.TypeOf(ImageIndex(0)): case datum.Type() == reflect.TypeOf((*image.RGBA)(nil)):
*outtype = C.colTypeImage *outtype = C.colTypeImage
d := datum.Interface().(ImageIndex) d := datum.Interface().(*image.RGBA)
return unsafe.Pointer(t.images[d]) img := C.toTableImage(unsafe.Pointer(pixelData(img)), C.intptr_t(d.Rect.Dx()), C.intptr_t(d.Rect.Dy()), C.intptr_t(d.Stride))
return unsafe.Pointer(img)
case datum.Kind() == reflect.Bool: case datum.Kind() == reflect.Bool:
*outtype = C.colTypeCheckbox *outtype = C.colTypeCheckbox
if datum.Bool() == true { if datum.Bool() == true {

View File

@ -42,6 +42,7 @@
ret = goTableDataSource_getValue(self->gotable, (intptr_t) row, colnum, &type); ret = goTableDataSource_getValue(self->gotable, (intptr_t) row, colnum, &type);
switch (type) { switch (type) {
case colTypeImage: case colTypeImage:
// TODO free the returned image when done somehow
return (id) ret; return (id) ret;
case colTypeCheckbox: case colTypeCheckbox:
if (ret == NULL) if (ret == NULL)