diff options
| author | Pietro Gagliardi <[email protected]> | 2014-08-16 17:37:21 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-08-16 17:37:21 -0400 |
| commit | d5f9c237b7e81e54e91241d49d2a8ad718bd397c (patch) | |
| tree | ee7d4c75c05b1b2144f83f7f07c1e20bcea6eab3 | |
| parent | 5d69bc2534cd3a90a2c93c564c2fcfc5accd5fad (diff) | |
Added image lists to Tables and added them to the Windows backend... mostly. There are a few kinks to work out...
| -rw-r--r-- | redo/imagelist_windows.c | 44 | ||||
| -rw-r--r-- | redo/imagelist_windows.go | 8 | ||||
| -rw-r--r-- | redo/table.go | 4 | ||||
| -rw-r--r-- | redo/table_windows.c | 2 | ||||
| -rw-r--r-- | redo/table_windows.go | 23 | ||||
| -rw-r--r-- | redo/winapi_windows.h | 3 | ||||
| -rw-r--r-- | redo/zz_test.go | 8 |
7 files changed, 65 insertions, 27 deletions
diff --git a/redo/imagelist_windows.c b/redo/imagelist_windows.c index 434190c..dcea7a1 100644 --- a/redo/imagelist_windows.c +++ b/redo/imagelist_windows.c @@ -36,10 +36,10 @@ HIMAGELIST newImageList(int width, int height) return il; } -void addImage(HIMAGELIST il, HBITMAP bitmap, int origwid, int oright, int width, int height) +void addImage(HIMAGELIST il, HWND hwnd, HBITMAP bitmap, int origwid, int oright, int width, int height) { BOOL wasScaled = FALSE; - HDC scaledDC, origDC; + HDC winDC, scaledDC, origDC; HBITMAP scaled; HBITMAP prevscaled, prevorig; @@ -49,33 +49,38 @@ void addImage(HIMAGELIST il, HBITMAP bitmap, int origwid, int oright, int width, goto noscale; } wasScaled = TRUE; - scaledDC = GetDC(NULL); + winDC = GetDC(hwnd); + if (winDC == NULL) + xpanic("error getting DC for window", GetLastError()); + origDC = CreateCompatibleDC(winDC); + if (winDC == NULL) + xpanic("error getting DC for original ImageList bitmap", GetLastError()); + prevorig = SelectObject(origDC, bitmap); + if (prevorig == NULL) + xpanic("error selecting original ImageList bitmap into DC", GetLastError()); + scaledDC = CreateCompatibleDC(origDC); if (scaledDC == NULL) - xpanic("error getting screen DC for scaled ImageList bitmap", GetLastError()); - scaled = CreateCompatibleBitmap(scaledDC, width, height); + xpanic("error getting DC for scaled ImageList bitmap", GetLastError()); + scaled = CreateCompatibleBitmap(origDC, width, height); if (scaled == NULL) xpanic("error creating scaled ImageList bitmap", GetLastError()); prevscaled = SelectObject(scaledDC, scaled); if (prevscaled == NULL) - xpanic("error selecting scaled ImageList bitmap into screen DC", GetLastError()); - origDC = GetDC(NULL); - if (origDC == NULL) - xpanic("error getting screen DC for original ImageList bitmap", GetLastError()); - prevorig = SelectObject(origDC, bitmap); - if (prevorig == NULL) - xpanic("error selecting original ImageList bitmap into screen DC", GetLastError()); + xpanic("error selecting scaled ImageList bitmap into DC", GetLastError()); if (StretchBlt(scaledDC, 0, 0, width, height, origDC, 0, 0, origwid, oright, SRCCOPY) == 0) xpanic("error scaling ImageList bitmap down", GetLastError()); if (SelectObject(origDC, prevorig) != bitmap) - xpanic("error selecting previous bitmap into original image's screen DC", GetLastError()); + xpanic("error selecting previous bitmap into original image's DC", GetLastError()); if (DeleteDC(origDC) == 0) - xpanic("error deleting original image's screen DC", GetLastError()); + xpanic("error deleting original image's DC", GetLastError()); if (SelectObject(scaledDC, prevscaled) != scaled) - xpanic("error selecting previous bitmap into scaled image's screen DC", GetLastError()); + xpanic("error selecting previous bitmap into scaled image's DC", GetLastError()); if (DeleteDC(scaledDC) == 0) - xpanic("error deleting scaled image's screen DC", GetLastError()); + xpanic("error deleting scaled image's DC", GetLastError()); + if (DeleteDC(winDC) == 0) + xpanic("error deleting window DC", GetLastError()); noscale: if ((*fv_ImageList_Add)(il, scaled, NULL) == -1) @@ -84,3 +89,10 @@ noscale: if (DeleteObject(scaled) == 0) xpanic("error deleting scaled bitmap", GetLastError()); } + +void applyImageList(HWND hwnd, UINT uMsg, WPARAM wParam, HIMAGELIST il) +{ + if (SendMessageW(hwnd, uMsg, wParam, (LPARAM) il) == (LRESULT) NULL) +;// xpanic("error setting image list", GetLastError()); + // TODO free old one here if any +} diff --git a/redo/imagelist_windows.go b/redo/imagelist_windows.go index 389c553..37924bd 100644 --- a/redo/imagelist_windows.go +++ b/redo/imagelist_windows.go @@ -31,15 +31,15 @@ func (i *imagelist) Len() ImageIndex { } type imageListApply interface { - apply() + apply(C.HWND, C.UINT, C.WPARAM) } -func (i *imagelist) apply() { +func (i *imagelist) apply(hwnd C.HWND, uMsg C.UINT, wParam C.WPARAM) { 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, i.list[index], C.int(i.width[index]), C.int(i.height[index]), width, height) + C.addImage(il, hwnd, i.list[index], C.int(i.width[index]), C.int(i.height[index]), width, height) } - // TODO do stuff + C.applyImageList(hwnd, uMsg, wParam, il) } diff --git a/redo/table.go b/redo/table.go index fab2eb8..314b8e7 100644 --- a/redo/table.go +++ b/redo/table.go @@ -27,6 +27,10 @@ type Table interface { // The returned value will contain an object of type pointer to slice of some structure; use a type assertion to get the properly typed object out. // Do not call this outside a Lock()..Unlock() or RLock()..RUnlock() pair. Data() interface{} + + // LoadImageList loads the given ImageList into the Table. + // This function copies; changes to the ImageList made later will not be reflected by the Table. + LoadImageList(ImageList) } type tablebase struct { diff --git a/redo/table_windows.c b/redo/table_windows.c index b25ebab..d5ca418 100644 --- a/redo/table_windows.c +++ b/redo/table_windows.c @@ -15,7 +15,7 @@ static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM case msgNOTIFY: switch (nmhdr->code) { case LVN_GETDISPINFO: - tableGetCellText((void *) data, fill->item.iItem, fill->item.iSubItem, &(fill->item.pszText)); + tableGetCell((void *) data, &(fill->item)); return 0; } return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam); diff --git a/redo/table_windows.go b/redo/table_windows.go index 93ff9c1..2f9155d 100644 --- a/redo/table_windows.go +++ b/redo/table_windows.go @@ -49,15 +49,28 @@ func (t *table) Unlock() { }() } -//export tableGetCellText -func tableGetCellText(data unsafe.Pointer, row C.int, col C.int, str *C.LPWSTR) { +func (t *table) LoadImageList(il ImageList) { + il.apply(t._hwnd, C.LVM_SETIMAGELIST, C.LVSIL_SMALL) +} + +//export tableGetCell +func tableGetCell(data unsafe.Pointer, item *C.LVITEMW) { t := (*table)(data) t.RLock() defer t.RUnlock() d := reflect.Indirect(reflect.ValueOf(t.data)) - datum := d.Index(int(row)).Field(int(col)) - s := fmt.Sprintf("%v", datum) - *str = toUTF16(s) + datum := d.Index(int(item.iItem)).Field(int(item.iSubItem)) + switch d := datum.Interface().(type) { + case ImageIndex: + item.mask |= C.LVIF_IMAGE + item.mask &^= C.LVIF_TEXT + item.iImage = C.int(d) + default: + item.mask |= C.LVIF_TEXT + item.mask &^= C.LVIF_IMAGE + s := fmt.Sprintf("%v", datum) + item.pszText = toUTF16(s) + } } // the column autoresize policy is simple: diff --git a/redo/winapi_windows.h b/redo/winapi_windows.h index c6a2c63..589fbec 100644 --- a/redo/winapi_windows.h +++ b/redo/winapi_windows.h @@ -117,6 +117,7 @@ extern HWND newArea(void *); // imagelist_windows.c extern HBITMAP unscaledBitmap(void *, intptr_t, intptr_t); extern HIMAGELIST newImageList(int, int); -extern void addImage(HIMAGELIST, HBITMAP, int, int, int, int); +extern void addImage(HIMAGELIST, HWND, HBITMAP, int, int, int, int); +extern void applyImageList(HWND, UINT, WPARAM, HIMAGELIST); #endif diff --git a/redo/zz_test.go b/redo/zz_test.go index 8a2d023..ef7da84 100644 --- a/redo/zz_test.go +++ b/redo/zz_test.go @@ -34,6 +34,7 @@ type testwin struct { w Window icons []icon il ImageList + icontbl Table group2 Group group Group grid Grid @@ -74,6 +75,13 @@ func (tw *testwin) make(done chan struct{}) { return true }) tw.icons, tw.il = readIcons() + tw.icontbl = NewTable(reflect.TypeOf(icon{})) + tw.icontbl.Lock() + idq := tw.icontbl.Data().(*[]icon) + *idq = tw.icons + tw.icontbl.Unlock() + tw.icontbl.LoadImageList(tw.il) + tw.t.Append("Image List Table", tw.icontbl) tw.group2 = NewGroup("Group", NewButton("Button in Group")) tw.t.Append("Filled Group", tw.group2) tw.group = NewGroup("Group", NewVerticalStack(NewCheckbox("Checkbox in Group"))) |
