Fixed an obvious crash while retrieving source names and a visual bug when adding a new item and hovering over it right after

This commit is contained in:
HomeWorld 2013-02-05 22:04:28 +02:00
parent 43f56fce30
commit 2c219c7e7a

View File

@ -2137,16 +2137,19 @@ LRESULT CALLBACK OBS::OBSProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
case CDDS_ITEMPREPAINT: case CDDS_ITEMPREPAINT:
int state; int state, bkMode;
BOOL checkState; BOOL checkState;
RECT iconRect,textRect, itemRect; RECT iconRect,textRect, itemRect;
COLORREF oldTextColor; COLORREF oldTextColor;
// It seems there's a limitation to ListView's displayed max text length http://support.microsoft.com/default.aspx?scid=KB;EN-US;321104
// Read the comment below.
String itemText; String itemText;
HDC hdc = lplvcd->nmcd.hdc; HDC hdc = lplvcd->nmcd.hdc;
int itemId = lplvcd->nmcd.dwItemSpec; int itemId = lplvcd->nmcd.dwItemSpec;
// Not happy about this XElement *sources, *sourcesElement;
itemText = App->sceneElement->GetElement(TEXT("sources"))->GetElementByID(itemId)->GetName();
ListView_GetItemRect(nmh.hwndFrom,itemId, &itemRect, LVIR_BOUNDS); ListView_GetItemRect(nmh.hwndFrom,itemId, &itemRect, LVIR_BOUNDS);
ListView_GetItemRect(nmh.hwndFrom,itemId, &textRect, LVIR_LABEL); ListView_GetItemRect(nmh.hwndFrom,itemId, &textRect, LVIR_LABEL);
@ -2159,6 +2162,7 @@ LRESULT CALLBACK OBS::OBSProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
checkState = ListView_GetCheckState(nmh.hwndFrom, itemId); checkState = ListView_GetCheckState(nmh.hwndFrom, itemId);
oldTextColor = GetTextColor(hdc); oldTextColor = GetTextColor(hdc);
if(state&LVIS_SELECTED) if(state&LVIS_SELECTED)
{ {
FillRect(hdc, &itemRect, (HBRUSH)(COLOR_HIGHLIGHT + 1)); FillRect(hdc, &itemRect, (HBRUSH)(COLOR_HIGHLIGHT + 1));
@ -2177,8 +2181,31 @@ LRESULT CALLBACK OBS::OBSProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
CloseThemeData(hTheme); CloseThemeData(hTheme);
} }
if(itemText.IsValid()) // Not happy about this at all , wanted it to be generic (as a simple ListView_GetItemText should suffice if we knew max text length),
DrawText(hdc, itemText, slen(itemText), &textRect, DT_LEFT | DT_END_ELLIPSIS | DT_VCENTER | DT_SINGLELINE ); // but sending LVM_GETITEMTEXT msg to get the text length seems confusing (for me) by MSDN doc.
// We can use ListView_GetItemText with a MAX_PATH sized buffer instead of the following stuff (see the MSDN link above).
sources = App->sceneElement->GetElement(TEXT("sources"));
if(sources)
{
sourcesElement = sources->GetElementByID(itemId);
if(sourcesElement)
{
itemText = sourcesElement->GetName();
if(itemText.IsValid())
{
if(state&LVIS_SELECTED)
bkMode = SetBkMode(hdc, TRANSPARENT);
DrawText(hdc, itemText, slen(itemText), &textRect, DT_LEFT | DT_END_ELLIPSIS | DT_VCENTER | DT_SINGLELINE );
if(state&LVIS_SELECTED)
SetBkMode(hdc, bkMode);
}
}
}
SetTextColor(hdc, oldTextColor); SetTextColor(hdc, oldTextColor);
return CDRF_SKIPDEFAULT; return CDRF_SKIPDEFAULT;