-#pragma once
-
-#include "IListCtrl.h"
-#include <commctrl.h>
-#include <atlimage.h>
-
-class IListCtrlImpl : public IListCtrl
-{
-public:
- IListCtrlImpl(HWND hwndListCtrl) : m_hwndListCtrl(hwndListCtrl)
- {
- }
-
- int GetColumnCount() const
- {
- return Header_GetItemCount(ListView_GetHeader(m_hwndListCtrl));
- }
-
- int GetRowCount() const
- {
- return ListView_GetItemCount(m_hwndListCtrl);
- }
-
- String GetColumnName(int col) const
- {
- LVCOLUMN lvc;
- TCHAR columnName[256]; // Assuming max col header will never be > 256
- lvc.mask = LVCF_TEXT;
- lvc.pszText = &columnName[0];
- lvc.cchTextMax = sizeof(columnName) / sizeof(TCHAR);
- ListView_GetColumn(m_hwndListCtrl, col, &lvc);
- return lvc.pszText;
- }
-
- String GetItemText(int row, int col) const
- {
- TCHAR text[512]; // Assuming max col header will never be > 512
- ListView_GetItemText(m_hwndListCtrl, row, col, text, sizeof(text)/sizeof(text[0]));
- return text;
- }
-
- void *GetItemData(int row) const
- {
+#pragma once\r
+\r
+#include "IListCtrl.h"\r
+#include <commctrl.h>\r
+#include <atlimage.h>\r
+\r
+class IListCtrlImpl : public IListCtrl\r
+{\r
+public:\r
+ IListCtrlImpl(HWND hwndListCtrl) : m_hwndListCtrl(hwndListCtrl)\r
+ {\r
+ }\r
+\r
+ int GetColumnCount() const\r
+ {\r
+ return Header_GetItemCount(ListView_GetHeader(m_hwndListCtrl));\r
+ }\r
+\r
+ int GetRowCount() const\r
+ {\r
+ return ListView_GetItemCount(m_hwndListCtrl);\r
+ }\r
+\r
+ String GetColumnName(int col) const\r
+ {\r
+ LVCOLUMN lvc;\r
+ TCHAR columnName[256]; // Assuming max col header will never be > 256\r
+ lvc.mask = LVCF_TEXT;\r
+ lvc.pszText = &columnName[0];\r
+ lvc.cchTextMax = sizeof(columnName) / sizeof(TCHAR);\r
+ ListView_GetColumn(m_hwndListCtrl, col, &lvc);\r
+ return lvc.pszText;\r
+ }\r
+\r
+ String GetItemText(int row, int col) const\r
+ {\r
+ TCHAR text[512]; // Assuming max col header will never be > 512\r
+ ListView_GetItemText(m_hwndListCtrl, row, col, text, sizeof(text)/sizeof(text[0]));\r
+ return text;\r
+ }\r
+\r
+ void *GetItemData(int row) const\r
+ {\r
LVITEM lvi = {0};\r
lvi.iItem = row;\r
lvi.mask = LVIF_PARAM;\r
::SendMessage(m_hwndListCtrl, LVM_GETITEM, 0, (LPARAM)&lvi);\r
return (void *)lvi.lParam;\r
- }
-
- int GetBackColor(int row) const
- {
- NMLVCUSTOMDRAW nmlvcd = {0};
- nmlvcd.nmcd.hdr.code = NM_CUSTOMDRAW;
- nmlvcd.nmcd.hdr.idFrom = GetDlgCtrlID(m_hwndListCtrl);
- nmlvcd.nmcd.hdr.hwndFrom = m_hwndListCtrl;
- nmlvcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT | CDDS_SUBITEM;
- nmlvcd.nmcd.dwItemSpec = row;
- SendMessage(GetParent(m_hwndListCtrl), WM_NOTIFY, (WPARAM)m_hwndListCtrl, (LPARAM)&nmlvcd);
- return nmlvcd.clrTextBk;
- }
-
- bool IsSelectedItem(int sel) const
- {
- return !!ListView_GetItemState(m_hwndListCtrl, sel, LVIS_SELECTED);
- }
-
- int GetNextItem(int sel, bool selected = false, bool reverse = false) const
- {
- return ListView_GetNextItem(m_hwndListCtrl, sel, (selected ? LVNI_SELECTED : 0) | (reverse ? LVNI_ABOVE : 0));
- }
-
- int GetNextSelectedItem(int sel, bool reverse = false) const
- {
- return ListView_GetNextItem(m_hwndListCtrl, sel, LVNI_SELECTED | (reverse ? LVNI_ABOVE : 0));
- }
-
- unsigned GetSelectedCount() const
- {
- return ListView_GetSelectedCount(m_hwndListCtrl);
- }
-
- int GetIndent(int row) const
- {
- LVITEM item = {0};
- item.mask = LVIF_INDENT;
- item.iItem = row;
- ListView_GetItem(m_hwndListCtrl, &item);
- return item.iIndent;
- }
-
- int GetIconIndex(int row) const
- {
- LVITEM item = {0};
- item.mask = LVIF_IMAGE;
- item.iItem = row;
- ListView_GetItem(m_hwndListCtrl, &item);
- return item.iImage;
- }
-
- int GetIconCount() const
- {
- HIMAGELIST hImageList = ListView_GetImageList(m_hwndListCtrl, LVSIL_SMALL);
- return ImageList_GetImageCount(hImageList);
- }
-
- std::string GetIconPNGData(int iconIndex) const
- {
- HIMAGELIST hImageList = ListView_GetImageList(m_hwndListCtrl, LVSIL_SMALL);
- IMAGEINFO imageInfo;
- std::string ret;
- if (ImageList_GetImageInfo(hImageList, iconIndex, &imageInfo))
- {
- HDC hdcMem = CreateCompatibleDC(NULL);
- BITMAPINFO bmpinfo = { 0 };
- bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- int w = imageInfo.rcImage.right - imageInfo.rcImage.left;
- int h = imageInfo.rcImage.bottom - imageInfo.rcImage.top;
- bmpinfo.bmiHeader.biWidth = w;
- bmpinfo.bmiHeader.biHeight = h;
- bmpinfo.bmiHeader.biPlanes = 1;
- bmpinfo.bmiHeader.biBitCount = 32;
- bmpinfo.bmiHeader.biCompression = BI_RGB;
- HBITMAP hbmpImage = CreateDIBSection(NULL, &bmpinfo, DIB_RGB_COLORS, NULL, NULL, NULL);
- HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcMem, hbmpImage);
- ImageList_Draw(hImageList, iconIndex, hdcMem, 0, 0, ILD_TRANSPARENT);
- CImage image;
- image.Attach(hbmpImage);
- image.SetHasAlphaChannel(true);
- IStream *pStream = NULL;
- if (SUCCEEDED(CreateStreamOnHGlobal(NULL, TRUE, &pStream)))
- {
- image.Save(pStream, Gdiplus::ImageFormatPNG);
- STATSTG stat;
- if (SUCCEEDED(pStream->Stat(&stat, STATFLAG_NONAME)))
- {
- LARGE_INTEGER li = {0};
- ret.resize(stat.cbSize.LowPart, 0);
- pStream->Seek(li, STREAM_SEEK_SET, NULL);
- pStream->Read(&ret[0], stat.cbSize.LowPart, NULL);
- }
- pStream->Release();
- }
- SelectObject(hdcMem, hbmpOld);
- DeleteObject(hdcMem);
- DeleteObject(hbmpImage);
- }
- return ret;
- }
-\r
-protected:
- HWND m_hwndListCtrl;
-};
+ }\r
+\r
+ int GetBackColor(int row) const\r
+ {\r
+ NMLVCUSTOMDRAW nmlvcd = {0};\r
+ nmlvcd.nmcd.hdr.code = NM_CUSTOMDRAW;\r
+ nmlvcd.nmcd.hdr.idFrom = GetDlgCtrlID(m_hwndListCtrl);\r
+ nmlvcd.nmcd.hdr.hwndFrom = m_hwndListCtrl;\r
+ nmlvcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT | CDDS_SUBITEM;\r
+ nmlvcd.nmcd.dwItemSpec = row;\r
+ SendMessage(GetParent(m_hwndListCtrl), WM_NOTIFY, (WPARAM)m_hwndListCtrl, (LPARAM)&nmlvcd);\r
+ return nmlvcd.clrTextBk;\r
+ }\r
+\r
+ bool IsSelectedItem(int sel) const\r
+ {\r
+ return !!ListView_GetItemState(m_hwndListCtrl, sel, LVIS_SELECTED);\r
+ }\r
+\r
+ int GetNextItem(int sel, bool selected = false, bool reverse = false) const\r
+ {\r
+ return ListView_GetNextItem(m_hwndListCtrl, sel, (selected ? LVNI_SELECTED : 0) | (reverse ? LVNI_ABOVE : 0)); \r
+ }\r
+\r
+ int GetNextSelectedItem(int sel, bool reverse = false) const\r
+ {\r
+ return ListView_GetNextItem(m_hwndListCtrl, sel, LVNI_SELECTED | (reverse ? LVNI_ABOVE : 0)); \r
+ }\r
+\r
+ unsigned GetSelectedCount() const\r
+ {\r
+ return ListView_GetSelectedCount(m_hwndListCtrl);\r
+ }\r
+\r
+ int GetIndent(int row) const\r
+ {\r
+ LVITEM item = {0};\r
+ item.mask = LVIF_INDENT;\r
+ item.iItem = row;\r
+ ListView_GetItem(m_hwndListCtrl, &item);\r
+ return item.iIndent;\r
+ }\r
+\r
+ int GetIconIndex(int row) const\r
+ {\r
+ LVITEM item = {0};\r
+ item.mask = LVIF_IMAGE;\r
+ item.iItem = row;\r
+ ListView_GetItem(m_hwndListCtrl, &item);\r
+ return item.iImage;\r
+ }\r
+\r
+ int GetIconCount() const\r
+ {\r
+ HIMAGELIST hImageList = ListView_GetImageList(m_hwndListCtrl, LVSIL_SMALL);\r
+ return ImageList_GetImageCount(hImageList);\r
+ }\r
+\r
+ std::string GetIconPNGData(int iconIndex) const\r
+ {\r
+ HIMAGELIST hImageList = ListView_GetImageList(m_hwndListCtrl, LVSIL_SMALL);\r
+ IMAGEINFO imageInfo;\r
+ std::string ret;\r
+ if (ImageList_GetImageInfo(hImageList, iconIndex, &imageInfo))\r
+ {\r
+ HDC hdcMem = CreateCompatibleDC(NULL);\r
+ BITMAPINFO bmpinfo = { 0 };\r
+ bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);\r
+ int w = imageInfo.rcImage.right - imageInfo.rcImage.left;\r
+ int h = imageInfo.rcImage.bottom - imageInfo.rcImage.top;\r
+ bmpinfo.bmiHeader.biWidth = w;\r
+ bmpinfo.bmiHeader.biHeight = h;\r
+ bmpinfo.bmiHeader.biPlanes = 1;\r
+ bmpinfo.bmiHeader.biBitCount = 32;\r
+ bmpinfo.bmiHeader.biCompression = BI_RGB;\r
+ HBITMAP hbmpImage = CreateDIBSection(NULL, &bmpinfo, DIB_RGB_COLORS, NULL, NULL, NULL);\r
+ HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcMem, hbmpImage);\r
+ ImageList_Draw(hImageList, iconIndex, hdcMem, 0, 0, ILD_TRANSPARENT);\r
+ CImage image;\r
+ image.Attach(hbmpImage);\r
+ image.SetHasAlphaChannel(true);\r
+ IStream *pStream = NULL;\r
+ if (SUCCEEDED(CreateStreamOnHGlobal(NULL, TRUE, &pStream)))\r
+ {\r
+ image.Save(pStream, Gdiplus::ImageFormatPNG);\r
+ STATSTG stat;\r
+ if (SUCCEEDED(pStream->Stat(&stat, STATFLAG_NONAME)))\r
+ {\r
+ LARGE_INTEGER li = {0};\r
+ ret.resize(stat.cbSize.LowPart, 0);\r
+ pStream->Seek(li, STREAM_SEEK_SET, NULL);\r
+ pStream->Read(&ret[0], stat.cbSize.LowPart, NULL);\r
+ }\r
+ pStream->Release();\r
+ }\r
+ SelectObject(hdcMem, hbmpOld);\r
+ DeleteObject(hdcMem);\r
+ DeleteObject(hbmpImage);\r
+ }\r
+ return ret;\r
+ }\r
+\r
+protected:\r
+ HWND m_hwndListCtrl;\r
+};\r