]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/listctrl.cpp
::GetFileAttributes takes Unicode in Unicode build, don't use fn_str() (Borland Unico...
[wxWidgets.git] / src / msw / listctrl.cpp
index 14aa00809e656ade36d7d035715289e6ec754b0f..1102ccc5e3f303550296ef081b9cdfeb74c3a15d 100644 (file)
@@ -2409,18 +2409,27 @@ static void HandleSubItemPrepaint(LPNMLVCUSTOMDRAW pLVCD, HFONT hfont)
     it.cchTextMax = WXSIZEOF(text);
     ListView_GetItem(hwndList, &it);
 
-    if ( it.iImage != -1 )
+    HIMAGELIST himl = ListView_GetImageList(hwndList, LVSIL_SMALL);
+    if ( himl && ImageList_GetImageCount(himl) )
     {
-        HIMAGELIST himl = ListView_GetImageList(hwndList, LVSIL_SMALL);
-
-        ImageList_Draw(himl, it.iImage, hdc, rc.left, rc.top,
-                       nmcd.uItemState & CDIS_SELECTED ? ILD_SELECTED
-                                                       : ILD_TRANSPARENT);
+        if ( it.iImage != -1 )
+        {
+            ImageList_Draw(himl, it.iImage, hdc, rc.left, rc.top,
+                           nmcd.uItemState & CDIS_SELECTED ? ILD_SELECTED
+                                                           : ILD_TRANSPARENT);
+        }
 
-        int wImage, hImage;
-        ImageList_GetIconSize(himl, &wImage, &hImage);
+        // notice that even if this item doesn't have any image, the list
+        // control still leaves space for the image in the first column if the
+        // image list is not empty (presumably so that items with and without
+        // images align?)
+        if ( it.iImage != -1 || it.iSubItem == 0 )
+        {
+            int wImage, hImage;
+            ImageList_GetIconSize(himl, &wImage, &hImage);
 
-        rc.left += wImage + 2;
+            rc.left += wImage + 2;
+        }
     }
 
     ::SetBkMode(hdc, TRANSPARENT);
@@ -2449,7 +2458,8 @@ static void HandleItemPaint(LPNMLVCUSTOMDRAW pLVCD, HFONT hfont)
 {
     NMCUSTOMDRAW& nmcd = pLVCD->nmcd; // just a shortcut
 
-    HWND hwndList = nmcd.hdr.hwndFrom;
+    const HWND hwndList = nmcd.hdr.hwndFrom;
+    const int item = nmcd.dwItemSpec;
 
     // unfortunately we can't trust CDIS_SELECTED, it is often set even when
     // the item is not at all selected for some reason (comctl32 6), but we
@@ -2465,13 +2475,23 @@ static void HandleItemPaint(LPNMLVCUSTOMDRAW pLVCD, HFONT hfont)
             break;
         }
 
-        if ( (DWORD)i == nmcd.dwItemSpec )
+        if ( i == item )
         {
             nmcd.uItemState |= CDIS_SELECTED;
             break;
         }
     }
 
+    // same thing for CDIS_FOCUS (except simpler as there is only one of them)
+    if ( ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED) == item )
+    {
+        nmcd.uItemState |= CDIS_FOCUS;
+    }
+    else
+    {
+        nmcd.uItemState &= ~CDIS_FOCUS;
+    }
+
     if ( nmcd.uItemState & CDIS_SELECTED )
     {
         int syscolFg, syscolBg;
@@ -2524,12 +2544,12 @@ static WXLPARAM HandleItemPrepaint(wxListCtrl *listctrl,
 
 
     // set the colours to use for text drawing
-    pLVCD->clrText = wxColourToRGB(attr->HasTextColour()
-                                    ? attr->GetTextColour()
-                                    : listctrl->GetTextColour());
-    pLVCD->clrTextBk = wxColourToRGB(attr->HasBackgroundColour()
-                                        ? attr->GetBackgroundColour()
-                                        : listctrl->GetBackgroundColour());
+    pLVCD->clrText = attr->HasTextColour()
+                     ? wxColourToRGB(attr->GetTextColour())
+                     : wxColourToRGB(listctrl->GetTextColour());
+    pLVCD->clrTextBk = attr->HasBackgroundColour()
+                       ? wxColourToRGB(attr->GetBackgroundColour())
+                       : wxColourToRGB(listctrl->GetBackgroundColour());
 
     // select the font if non default one is specified
     if ( attr->HasFont() )