From 62d9ae07ade0857e838e5e10502a34501f88fd04 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 17 Feb 2015 17:13:40 -0500 Subject: [PATCH] Beginning the integration of the new Windows Table, which starts with removing ImageList. Darwin code will still be kept pending the use of its code. Windows code will be kept until I confirm nothing is used. --- imagelist.go | 29 ---------------- imagelist_darwin.go | 38 --------------------- imagelist_unix.go | 78 -------------------------------------------- imagelist_windows.go | 45 ------------------------- 4 files changed, 190 deletions(-) delete mode 100644 imagelist.go delete mode 100644 imagelist_darwin.go delete mode 100644 imagelist_unix.go delete mode 100644 imagelist_windows.go diff --git a/imagelist.go b/imagelist.go deleted file mode 100644 index 6b34b28..0000000 --- a/imagelist.go +++ /dev/null @@ -1,29 +0,0 @@ -// 16 august 2014 - -package ui - -import ( - "image" -) - -// ImageList is a list of images that can be used in the rows of a Table or Tree. -// ImageList maintains a copy of each image added. -// Images in an ImageList will be automatically scaled to the needed size. -type ImageList interface { - // Append inserts an image into the ImageList. - Append(i *image.RGBA) - - // Len returns the number of images in the ImageList. - Len() ImageIndex - - imageListApply -} - -// NewImageList creates a new ImageList. -// The ImageList is initially empty. -func NewImageList() ImageList { - return newImageList() -} - -// ImageIndex is a special type used to denote an entry in a Table or Tree's ImageList. -type ImageIndex int diff --git a/imagelist_darwin.go b/imagelist_darwin.go deleted file mode 100644 index add9584..0000000 --- a/imagelist_darwin.go +++ /dev/null @@ -1,38 +0,0 @@ -// 16 august 2014 - -package ui - -import ( - "image" - "unsafe" -) - -// #include "objc_darwin.h" -import "C" - -type imagelist struct { - list []C.id -} - -func newImageList() ImageList { - return new(imagelist) -} - -func (i *imagelist) Append(img *image.RGBA) { - id := C.toImageListImage( - unsafe.Pointer(pixelData(img)), C.intptr_t(img.Rect.Dx()), C.intptr_t(img.Rect.Dy()), C.intptr_t(img.Stride)) - i.list = append(i.list, id) -} - -func (i *imagelist) Len() ImageIndex { - return ImageIndex(len(i.list)) -} - -type imageListApply interface { - apply(*[]C.id) -} - -func (i *imagelist) apply(out *[]C.id) { - *out = make([]C.id, len(i.list)) - copy(*out, i.list) -} diff --git a/imagelist_unix.go b/imagelist_unix.go deleted file mode 100644 index 1729705..0000000 --- a/imagelist_unix.go +++ /dev/null @@ -1,78 +0,0 @@ -// +build !windows,!darwin - -// 16 august 2014 - -package ui - -import ( - "fmt" - "image" - "unsafe" -) - -// #include "gtk_unix.h" -import "C" - -type imagelist struct { - list []*C.GdkPixbuf -} - -func newImageList() ImageList { - return new(imagelist) -} - -// this is what GtkFileChooserWidget uses -// technically it uses max(width from that, height from that) if the call below fails and 16x16 otherwise, but we won't worry about that here (yet?) -const scaleTo = C.GTK_ICON_SIZE_MENU - -func (i *imagelist) Append(img *image.RGBA) { - var width, height C.gint - - surface := C.cairo_image_surface_create(C.CAIRO_FORMAT_ARGB32, - C.int(img.Rect.Dx()), - C.int(img.Rect.Dy())) - if status := C.cairo_surface_status(surface); status != C.CAIRO_STATUS_SUCCESS { - panic(fmt.Errorf("cairo_create_image_surface() failed in ImageList.Append(): %s\n", - C.GoString(C.cairo_status_to_string(status)))) - } - C.cairo_surface_flush(surface) - toARGB(img, uintptr(unsafe.Pointer(C.cairo_image_surface_get_data(surface))), - int(C.cairo_image_surface_get_stride(surface)), false) // not NRGBA - C.cairo_surface_mark_dirty(surface) - basepixbuf := C.gdk_pixbuf_get_from_surface(surface, 0, 0, C.gint(img.Rect.Dx()), C.gint(img.Rect.Dy())) - if basepixbuf == nil { - panic(fmt.Errorf("gdk_pixbuf_get_from_surface() failed in ImageList.Append() (no reason available)")) - } - - if C.gtk_icon_size_lookup(scaleTo, &width, &height) == C.FALSE { - panic(fmt.Errorf("gtk_icon_size_lookup() failed in ImageList.Append() (no reason available)")) - } - if int(width) == img.Rect.Dx() && int(height) == img.Rect.Dy() { - // just add the base pixbuf; we're good - i.list = append(i.list, basepixbuf) - C.cairo_surface_destroy(surface) - return - } - // else scale - pixbuf := C.gdk_pixbuf_scale_simple(basepixbuf, C.int(width), C.int(height), C.GDK_INTERP_NEAREST) - if pixbuf == nil { - panic(fmt.Errorf("gdk_pixbuf_scale_simple() failed in ImageList.Append() (no reason available)")) - } - - i.list = append(i.list, pixbuf) - C.g_object_unref(C.gpointer(unsafe.Pointer(basepixbuf))) - C.cairo_surface_destroy(surface) -} - -func (i *imagelist) Len() ImageIndex { - return ImageIndex(len(i.list)) -} - -type imageListApply interface { - apply(*[]*C.GdkPixbuf) -} - -func (i *imagelist) apply(out *[]*C.GdkPixbuf) { - *out = make([]*C.GdkPixbuf, len(i.list)) - copy(*out, i.list) -} diff --git a/imagelist_windows.go b/imagelist_windows.go deleted file mode 100644 index 087bbda..0000000 --- a/imagelist_windows.go +++ /dev/null @@ -1,45 +0,0 @@ -// 16 august 2014 - -package ui - -import ( - "image" - "unsafe" -) - -// #include "winapi_windows.h" -import "C" - -type imagelist struct { - list []C.HBITMAP - width []int - height []int -} - -func newImageList() ImageList { - return new(imagelist) -} - -func (i *imagelist) Append(img *image.RGBA) { - i.list = append(i.list, C.unscaledBitmap(unsafe.Pointer(img), C.intptr_t(img.Rect.Dx()), C.intptr_t(img.Rect.Dy()))) - i.width = append(i.width, img.Rect.Dx()) - i.height = append(i.height, img.Rect.Dy()) -} - -func (i *imagelist) Len() ImageIndex { - return ImageIndex(len(i.list)) -} - -type imageListApply interface { - apply(C.HWND, C.UINT) -} - -func (i *imagelist) apply(hwnd C.HWND, uMsg C.UINT) { - width := C.GetSystemMetrics(C.SM_CXSMICON) - height := C.GetSystemMetrics(C.SM_CYSMICON) - il := C.newImageList(width, height) - for index := range i.list { - C.addImage(il, hwnd, i.list[index], C.int(i.width[index]), C.int(i.height[index]), width, height) - } - C.SendMessageW(hwnd, uMsg, 0, C.LPARAM(uintptr(unsafe.Pointer(il)))) -}