summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-02-18 23:04:14 -0500
committerPietro Gagliardi <[email protected]>2015-02-18 23:04:14 -0500
commit1d091637d8a958b648fe77dd1ce5a9760737dfc1 (patch)
tree10126d366e05ed7328b60fe9149d6ac79a2b5904
parent8ec518dfe8813feebf8a408113499ec54254927a (diff)
Migrated the Mac OS X Table implementation. Untested due to VM issues.
-rw-r--r--image_darwin.m (renamed from imagelist_darwin.m)3
-rw-r--r--objc_darwin.h4
-rw-r--r--table_darwin.go11
-rw-r--r--table_darwin.m1
4 files changed, 11 insertions, 8 deletions
diff --git a/imagelist_darwin.m b/image_darwin.m
index 7433b12..1b77e22 100644
--- a/imagelist_darwin.m
+++ b/image_darwin.m
@@ -5,7 +5,7 @@
#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;
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]);
image = [[NSImage alloc] initWithSize:NSMakeSize((CGFloat) width, (CGFloat) height)];
[image addRepresentation:bitmap];
+ // TODO release bitmap?
return (id) image;
}
diff --git a/objc_darwin.h b/objc_darwin.h
index e8b7752..388f43f 100644
--- a/objc_darwin.h
+++ b/objc_darwin.h
@@ -146,8 +146,8 @@ extern void areaEndTextFieldEditing(id, id);
/* common_darwin.m */
extern void disableAutocorrect(id);
-/* imagerep_darwin.m */
-extern id toImageListImage(void *, intptr_t, intptr_t, intptr_t);
+/* image_darwin.m */
+extern id toTableImage(void *, intptr_t, intptr_t, intptr_t);
/* dialog_darwin.m */
extern void openFile(id, void *);
diff --git a/table_darwin.go b/table_darwin.go
index 60a3614..23482fb 100644
--- a/table_darwin.go
+++ b/table_darwin.go
@@ -6,6 +6,7 @@ import (
"fmt"
"reflect"
"unsafe"
+ "image"
)
// #include "objc_darwin.h"
@@ -16,7 +17,6 @@ type table struct {
*scroller
- images []C.id
selected *event
}
@@ -35,7 +35,7 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
coltype := C.colTypeText
editable := false
switch {
- case ty.Field(i).Type == reflect.TypeOf(ImageIndex(0)):
+ case ty.Field(i).Type == reflect.TypeOf((*image.RGBA)(nil)):
coltype = C.colTypeImage
case ty.Field(i).Type.Kind() == reflect.Bool:
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))
datum := d.Index(int(row)).Field(int(col))
switch {
- case datum.Type() == reflect.TypeOf(ImageIndex(0)):
+ case datum.Type() == reflect.TypeOf((*image.RGBA)(nil)):
*outtype = C.colTypeImage
- d := datum.Interface().(ImageIndex)
- return unsafe.Pointer(t.images[d])
+ d := datum.Interface().(*image.RGBA)
+ 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:
*outtype = C.colTypeCheckbox
if datum.Bool() == true {
diff --git a/table_darwin.m b/table_darwin.m
index 5e7a9e6..f04aae8 100644
--- a/table_darwin.m
+++ b/table_darwin.m
@@ -42,6 +42,7 @@
ret = goTableDataSource_getValue(self->gotable, (intptr_t) row, colnum, &type);
switch (type) {
case colTypeImage:
+ // TODO free the returned image when done somehow
return (id) ret;
case colTypeCheckbox:
if (ret == NULL)