[Git][wxwidgets/wxwidgets][master] 13 commits: Improve disabled wxListCtrl in MSW dark mode

0 views
Skip to first unread message

Vadim Zeitlin (@_VZ_)

unread,
Dec 13, 2025, 5:12:25 PM (3 days ago) Dec 13
to wx-commi...@googlegroups.com

Vadim Zeitlin pushed to branch master at wxWidgets / wxWidgets

Commits:

  • ecfaa59a
    by Maarten Bent at 2025-11-30T01:15:30+01:00
    Improve disabled wxListCtrl in MSW dark mode
    
    Draw the background color outside the list-items area on all Windows version,
    both below and behind the items, and when the list is empty.
    
    Set the text foreground and background colors when custom drawing. So the disabled
    list will use the correct colors in list or icon view.
    
    Fixes #25990
    
  • d26f7a85
    by Maarten Bent at 2025-11-30T01:15:32+01:00
    Improve drawing wxListCtrl gird lines in dark mode
    
    The grid lines are erased when custom drawing the sub-items, so the grid lines need to be redrawn after drawing the item.
    OnPaint() is not called after every custom draw (e.g. just hovering over a row will cause a custom draw but no paint),
    so it has to be drawn in the custom paint handler.
    
    Add a common function for drawing grid lines and reuse it on OnPaint().
    
  • b2ada524
    by Maarten Bent at 2025-11-30T01:15:32+01:00
    Fix incorrect wxListCtrl::GetSubItemRect(n, 0)
    
    This was broken in bde6b7a8b8.
    When the list is scrolled the x-coordinate will be negative.
    So don't start counting from 0, but start from the original x coordinate of the full rectangle.
    
  • 92167838
    by Maarten Bent at 2025-11-30T13:47:51+01:00
    Correctly restore dark mode header in MSW wxListCtrl
    
    When removing custom header attributes, the default dark mode attributes need to be restored.
    
  • 907ab5f5
    by Maarten Bent at 2025-11-30T15:56:11+01:00
    Fix MSW wxListCtrl custom colours in light mode
    
    This was broken in 3842352b21.
    
  • 10bac0ff
    by Maarten Bent at 2025-11-30T16:00:10+01:00
    Improve drawing MSW wxListCtrl focus rect in dark mode
    
    Subtract 2px so the right border is visible.
    
  • 47891abe
    by Maarten Bent at 2025-11-30T16:10:35+01:00
    Draw hot tracking highlight in MSW wxListCtrl in dark mode
    
    When the mouse is over an item, change the colour of it.
    
    This only works when using Explorer theme, DarkMode_Explorer does not get custom draw calls to remove the colour.
    
    Fixes #26001
    
  • 96e7dcdd
    by Maarten Bent at 2025-11-30T20:42:45+01:00
    Fix highlighting first item in MSW wxListCtrl in dark mode
    
    The item was also highlighted when hovering over the header because ListView_HitTest
    returns true when hovering over the header.
    Replace ListView_HitTest by checking if the mouse pointer is in the item rectangle.
    
  • 41a7420f
    by Maarten Bent at 2025-11-30T21:15:20+01:00
    Slightly increase text padding in MSW wxListCtrl in dark mode
    
    Try to get it to look like light mode.
    See #26001
    
  • 99fb774c
    by Maarten Bent at 2025-12-03T00:32:54+01:00
    Better fix for MSW wxListCtrl focus rect visibility
    
    When erasing the background, draw outside the item rectangle.
    
  • 8dc41cf1
    by Maarten Bent at 2025-12-03T00:34:05+01:00
    Try to fix missing MSW wxListCtrl attribute colour in dark mode
    
    See #26001
    
  • b56c6bae
    by Maarten Bent at 2025-12-03T01:13:05+01:00
    Improve MSW wxListCtrl background attribute in dark mode
    
    It extends the full column, including the padding.
    To match light mode, there should be 1px between columns that do not have the attribute colour.
    The first (most left) column, and columns with checkboxes or images should still use the padding.
    
  • d6737d15
    by Vadim Zeitlin at 2025-12-13T22:43:07+01:00
    Merge branch 'wxlistctrl-msw-dark-disabled' of github.com:MaartenBent/wxWidgets
    
    Multiple improvements to wxListCtrl in MSW dark mode.
    
    See #25999.
    

1 changed file:

Changes:

  • src/msw/listctrl.cpp
    ... ... @@ -615,8 +615,9 @@ bool wxListCtrl::MSWGetDarkModeSupport(MSWDarkModeSupport& support) const
    615 615
         //  - "ItemsView" draws the selection and hover as expected, but uses light
    
    616 616
         //    mode scrollbars and also misaligned vertical separators.
    
    617 617
         //
    
    618
    -    // We currently use DarkMode_Explorer and override selection drawing.
    
    619
    -    support.themeName = L"DarkMode_Explorer";
    
    618
    +    // We currently use Explorer, in Report view we can override all drawing,
    
    619
    +    // the other views will still have the bluish hover colour.
    
    620
    +    support.themeName = L"Explorer";
    
    620 621
     
    
    621 622
         return true;
    
    622 623
     }
    
    ... ... @@ -707,6 +708,8 @@ bool wxListCtrl::SetHeaderAttr(const wxItemAttr& attr)
    707 708
     
    
    708 709
             delete m_headerCustomDraw;
    
    709 710
             m_headerCustomDraw = nullptr;
    
    711
    +
    
    712
    +        MSWInitHeader();
    
    710 713
         }
    
    711 714
         else // We do have custom attributes.
    
    712 715
         {
    
    ... ... @@ -1388,16 +1391,15 @@ bool wxListCtrl::GetSubItemRect(long item, long subItem, wxRect& rect, int code)
    1388 1391
         {
    
    1389 1392
             // Because the columns can be reordered, we need to sum the widths of
    
    1390 1393
             // all preceding columns to get the correct x position.
    
    1391
    -        rect.x = 0;
    
    1392 1394
             for ( auto col : GetColumnsOrder() )
    
    1393 1395
             {
    
    1394
    -            if ( col == 0 )
    
    1396
    +            if ( col == subItem )
    
    1395 1397
                     break;
    
    1396 1398
     
    
    1397 1399
                 rect.x += GetColumnWidth(col);
    
    1398 1400
             }
    
    1399 1401
     
    
    1400
    -        rect.width = GetColumnWidth(0);
    
    1402
    +        rect.width = GetColumnWidth(subItem);
    
    1401 1403
         }
    
    1402 1404
     
    
    1403 1405
         return true;
    
    ... ... @@ -3050,12 +3052,13 @@ RECT GetCustomDrawnItemRect(const NMCUSTOMDRAW& nmcd)
    3050 3052
     // These values try to replicate the native listctrl rendering as close as
    
    3051 3053
     // possible. Notice that they are not scaled with DPI because the native
    
    3052 3054
     // control doesn't do it either.
    
    3053
    -constexpr int PADDING_LEFT_SIDE = 1;
    
    3055
    +constexpr int PADDING_LEFT_SIDE = 3;
    
    3054 3056
     constexpr int PADDING_RIGHT_SIDE = 2;
    
    3055 3057
     constexpr int GAP_AFTER_CHECKBOX = 2;
    
    3056 3058
     constexpr int GAP_BEFORE_IMAGE = 2;
    
    3057 3059
     constexpr int GAP_BEFORE_CHECKBOX = 4;
    
    3058
    -constexpr int PADDING_FOR_TEXT = 1;
    
    3060
    +constexpr int PADDING_LEFT_FOR_TEXT = 2;
    
    3061
    +constexpr int PADDING_RIGHT_FOR_TEXT = 4;
    
    3059 3062
     
    
    3060 3063
     void
    
    3061 3064
     HandleSubItemPrepaint(wxListCtrl* listctrl,
    
    ... ... @@ -3084,6 +3087,9 @@ HandleSubItemPrepaint(wxListCtrl* listctrl,
    3084 3087
             return;
    
    3085 3088
         }
    
    3086 3089
     
    
    3090
    +    bool checkboxShown = false;
    
    3091
    +    bool imageShown = false;
    
    3092
    +
    
    3087 3093
         if ( !col && listctrl->HasCheckBoxes() )
    
    3088 3094
         {
    
    3089 3095
             const HIMAGELIST himl = ListView_GetImageList(hwndList, LVSIL_STATE);
    
    ... ... @@ -3123,6 +3129,7 @@ HandleSubItemPrepaint(wxListCtrl* listctrl,
    3123 3129
                     ILD_TRANSPARENT
    
    3124 3130
                 );
    
    3125 3131
     
    
    3132
    +            checkboxShown = true;
    
    3126 3133
                 rc.left += GAP_AFTER_CHECKBOX;
    
    3127 3134
     
    
    3128 3135
                 // move left edge for further drawing
    
    ... ... @@ -3191,6 +3198,7 @@ HandleSubItemPrepaint(wxListCtrl* listctrl,
    3191 3198
             // images align?)
    
    3192 3199
             if ( it.iImage != -1 )
    
    3193 3200
             {
    
    3201
    +            imageShown = true;
    
    3194 3202
                 rc.left += xOffset;
    
    3195 3203
             }
    
    3196 3204
         }
    
    ... ... @@ -3200,6 +3208,9 @@ HandleSubItemPrepaint(wxListCtrl* listctrl,
    3200 3208
     
    
    3201 3209
         // draw attribute background after drawing any images or checkboxes
    
    3202 3210
         RECT fillRect = rc;
    
    3211
    +    if ( !checkboxShown && !imageShown && listctrl->GetColumnOrder(col) != 0 )
    
    3212
    +        fillRect.left -= PADDING_LEFT_SIDE;
    
    3213
    +    fillRect.right += (PADDING_RIGHT_SIDE - 1);
    
    3203 3214
         ::FillRect(hdc, &fillRect, AutoHBRUSH(pLVCD->clrTextBk));
    
    3204 3215
     
    
    3205 3216
         ::SetBkMode(hdc, TRANSPARENT);
    
    ... ... @@ -3218,16 +3229,18 @@ HandleSubItemPrepaint(wxListCtrl* listctrl,
    3218 3229
             {
    
    3219 3230
                 case LVCFMT_LEFT:
    
    3220 3231
                     fmt |= DT_LEFT;
    
    3221
    -                rc.left += PADDING_FOR_TEXT;
    
    3232
    +                rc.left += PADDING_LEFT_FOR_TEXT;
    
    3222 3233
                     break;
    
    3223 3234
     
    
    3224 3235
                 case LVCFMT_CENTER:
    
    3236
    +                rc.left += PADDING_LEFT_FOR_TEXT;
    
    3237
    +                rc.right -= PADDING_RIGHT_FOR_TEXT;
    
    3225 3238
                     fmt |= DT_CENTER;
    
    3226 3239
                     break;
    
    3227 3240
     
    
    3228 3241
                 case LVCFMT_RIGHT:
    
    3229 3242
                     fmt |= DT_RIGHT;
    
    3230
    -                rc.right -= PADDING_FOR_TEXT;
    
    3243
    +                rc.right -= PADDING_RIGHT_FOR_TEXT;
    
    3231 3244
                     break;
    
    3232 3245
             }
    
    3233 3246
         }
    
    ... ... @@ -3254,6 +3267,44 @@ void HandleItemPostpaint(NMCUSTOMDRAW nmcd)
    3254 3267
         }
    
    3255 3268
     }
    
    3256 3269
     
    
    3270
    +void DrawGridLines(wxListCtrl* listctrl, int item, int gap = 0)
    
    3271
    +{
    
    3272
    +    const bool drawHRules = listctrl->HasFlag(wxLC_HRULES);
    
    3273
    +    const bool drawVRules = listctrl->HasFlag(wxLC_VRULES);
    
    3274
    +    if ( !(drawHRules || drawVRules) )
    
    3275
    +        return;
    
    3276
    +
    
    3277
    +    wxWindowDC wdc(listctrl);
    
    3278
    +    HDC hdc = GetHdcOf(wdc.GetTempHDC());
    
    3279
    +
    
    3280
    +    RECT rc;
    
    3281
    +    wxGetListCtrlItemRect(GetHwndOf(listctrl), item, LVIR_BOUNDS, rc);
    
    3282
    +
    
    3283
    +    const wxColour penColour(wxSystemSettings::GetColour(wxMSWDarkMode::IsActive()
    
    3284
    +                                                         ? wxSYS_COLOUR_GRAYTEXT
    
    3285
    +                                                         : wxSYS_COLOUR_3DLIGHT));
    
    3286
    +    COLORREF clrGrid = wxColourToRGB(penColour);
    
    3287
    +
    
    3288
    +    if ( drawHRules )
    
    3289
    +    {
    
    3290
    +        wxDrawHVLine(hdc, rc.left, rc.bottom, rc.right, rc.bottom, clrGrid, 1);
    
    3291
    +    }
    
    3292
    +
    
    3293
    +    if ( drawVRules )
    
    3294
    +    {
    
    3295
    +        for ( auto col : listctrl->GetColumnsOrder() )
    
    3296
    +        {
    
    3297
    +            wxRect rectSubItem;
    
    3298
    +            if ( !listctrl->GetSubItemRect(item, col, rectSubItem, wxLIST_RECT_BOUNDS) )
    
    3299
    +                continue;
    
    3300
    +
    
    3301
    +            // add 1 to match the header lines
    
    3302
    +            const int x = rectSubItem.GetRight() + 1;
    
    3303
    +            wxDrawHVLine(hdc, x, rc.top - gap, x, rc.bottom, clrGrid, 1);
    
    3304
    +        }
    
    3305
    +    }
    
    3306
    +}
    
    3307
    +
    
    3257 3308
     // This function is normally called only if we use custom colours, but it's
    
    3258 3309
     // also called when using dark mode as we have to draw the selected item
    
    3259 3310
     // ourselves when using it, and if we do this, we have to paint all the items
    
    ... ... @@ -3265,6 +3316,9 @@ void HandleItemPaint(wxListCtrl* listctrl, LPNMLVCUSTOMDRAW pLVCD)
    3265 3316
         const HWND hwndList = nmcd.hdr.hwndFrom;
    
    3266 3317
         const int item = nmcd.dwItemSpec;
    
    3267 3318
     
    
    3319
    +    RECT rc = GetCustomDrawnItemRect(nmcd);
    
    3320
    +    HDC hdc = nmcd.hdc;
    
    3321
    +
    
    3268 3322
         // unfortunately we can't trust CDIS_SELECTED, it is often set even when
    
    3269 3323
         // the item is not at all selected for some reason (comctl32 6), but we
    
    3270 3324
         // also can't always trust ListView_GetItem() as it could return the old
    
    ... ... @@ -3297,11 +3351,26 @@ void HandleItemPaint(wxListCtrl* listctrl, LPNMLVCUSTOMDRAW pLVCD)
    3297 3351
             nmcd.uItemState &= ~CDIS_FOCUS;
    
    3298 3352
         }
    
    3299 3353
     
    
    3300
    -    HDC hdc = nmcd.hdc;
    
    3301
    -    RECT rc = GetCustomDrawnItemRect(nmcd);
    
    3302
    -    COLORREF clrFullBG = wxColourToRGB((nmcd.uItemState & CDIS_SELECTED)
    
    3303
    -        ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)
    
    3304
    -        : listctrl->GetBackgroundColour());
    
    3354
    +    // determine if the item is hot (mouse hovering over it)
    
    3355
    +    POINT point;
    
    3356
    +    wxGetCursorPosMSW(&point);
    
    3357
    +    ::ScreenToClient(GetHwndOf(listctrl), &point);
    
    3358
    +    if ( listctrl->IsEnabled() && ::PtInRect(&rc, point) != 0 )
    
    3359
    +    {
    
    3360
    +        nmcd.uItemState |= CDIS_HOT;
    
    3361
    +    }
    
    3362
    +    else
    
    3363
    +    {
    
    3364
    +        nmcd.uItemState &= ~CDIS_HOT;
    
    3365
    +    }
    
    3366
    +
    
    3367
    +    wxColour clrBg = listctrl->GetBackgroundColour();
    
    3368
    +    if ( nmcd.uItemState & CDIS_SELECTED )
    
    3369
    +        clrBg = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
    
    3370
    +    else if ( nmcd.uItemState & CDIS_HOT )
    
    3371
    +        // closest match to colour when hovering over the header (0x434343)
    
    3372
    +        clrBg = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW);
    
    3373
    +    COLORREF clrFullBG = wxColourToRGB(clrBg);
    
    3305 3374
     
    
    3306 3375
         // clear the entire row with the listctrl's bg colour
    
    3307 3376
         // otherwise, it'd keep the hover color but only for the regions
    
    ... ... @@ -3335,20 +3404,15 @@ void HandleItemPaint(wxListCtrl* listctrl, LPNMLVCUSTOMDRAW pLVCD)
    3335 3404
             }
    
    3336 3405
             HFONT hfont = font.IsOk() ? GetHfontOf(font) : nullptr;
    
    3337 3406
     
    
    3407
    +        pLVCD->clrText = attr && attr->HasTextColour()
    
    3408
    +            ? wxColourToRGB(attr->GetTextColour())
    
    3409
    +            : wxColourToRGB(listctrl->GetTextColour());
    
    3410
    +        pLVCD->clrTextBk = clrFullBG;
    
    3338 3411
             if ( nmcd.uItemState & CDIS_SELECTED )
    
    3339
    -        {
    
    3340 3412
                 pLVCD->clrText = wxColourToRGB(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
    
    3341
    -            pLVCD->clrTextBk = wxColourToRGB(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
    
    3342
    -        }
    
    3343
    -        else
    
    3344
    -        {
    
    3345
    -            pLVCD->clrText = attr && attr->HasTextColour()
    
    3346
    -                ? wxColourToRGB(attr->GetTextColour())
    
    3347
    -                : wxColourToRGB(listctrl->GetTextColour());
    
    3348
    -            pLVCD->clrTextBk = attr && attr->HasBackgroundColour()
    
    3349
    -                ? wxColourToRGB(attr->GetBackgroundColour())
    
    3350
    -                : wxColourToRGB(listctrl->GetBackgroundColour());
    
    3351
    -        }
    
    3413
    +        if ( !(nmcd.uItemState & CDIS_SELECTED) && !(nmcd.uItemState & CDIS_HOT)
    
    3414
    +                                          && attr && attr->HasBackgroundColour() )
    
    3415
    +            pLVCD->clrTextBk = wxColourToRGB(attr->GetBackgroundColour());
    
    3352 3416
     
    
    3353 3417
             COLORREF colTextOld = ::SetTextColor(hdc, pLVCD->clrText);
    
    3354 3418
     
    
    ... ... @@ -3357,6 +3421,8 @@ void HandleItemPaint(wxListCtrl* listctrl, LPNMLVCUSTOMDRAW pLVCD)
    3357 3421
             ::SetTextColor(hdc, colTextOld);
    
    3358 3422
         }
    
    3359 3423
     
    
    3424
    +    DrawGridLines(listctrl, item);
    
    3425
    +
    
    3360 3426
         HandleItemPostpaint(nmcd);
    
    3361 3427
     }
    
    3362 3428
     
    
    ... ... @@ -3369,6 +3435,14 @@ WXLPARAM HandleItemPrepaint(wxListCtrl* listctrl, LPNMLVCUSTOMDRAW pLVCD)
    3369 3435
         }
    
    3370 3436
     
    
    3371 3437
         wxItemAttr* attr = listctrl->MSWGetItemColumnAttr(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem);
    
    3438
    +
    
    3439
    +    pLVCD->clrText = attr && attr->HasTextColour()
    
    3440
    +        ? wxColourToRGB(attr->GetTextColour())
    
    3441
    +        : wxColourToRGB(listctrl->GetTextColour());
    
    3442
    +    pLVCD->clrTextBk = attr && attr->HasBackgroundColour()
    
    3443
    +        ? wxColourToRGB(attr->GetBackgroundColour())
    
    3444
    +        : wxColourToRGB(listctrl->GetBackgroundColour());
    
    3445
    +
    
    3372 3446
         if ( !attr )
    
    3373 3447
         {
    
    3374 3448
             // nothing to do for this item
    
    ... ... @@ -3439,10 +3513,16 @@ WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam)
    3439 3513
                 break;
    
    3440 3514
     
    
    3441 3515
             case CDDS_ITEMPREPAINT:
    
    3516
    +            // set the text foreground and background colour for listview
    
    3517
    +            // and icon view, these don't get messages for subitems
    
    3518
    +            pLVCD->clrText = wxColourToRGB(GetForegroundColour());
    
    3519
    +            pLVCD->clrTextBk = wxColourToRGB(GetBackgroundColour());
    
    3520
    +
    
    3442 3521
                 // get a message for each subitem
    
    3443 3522
                 return CDRF_NOTIFYITEMDRAW;
    
    3444 3523
     
    
    3445 3524
             case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
    
    3525
    +        {
    
    3446 3526
                 const int item = nmcd.dwItemSpec;
    
    3447 3527
                 const int column = pLVCD->iSubItem;
    
    3448 3528
     
    
    ... ... @@ -3455,6 +3535,7 @@ WXLPARAM wxListCtrl::OnCustomDraw(WXLPARAM lParam)
    3455 3535
                     break;
    
    3456 3536
     
    
    3457 3537
                 return HandleItemPrepaint(this, pLVCD);
    
    3538
    +        }
    
    3458 3539
         }
    
    3459 3540
     
    
    3460 3541
         return CDRF_DODEFAULT;
    
    ... ... @@ -3471,16 +3552,17 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)
    3471 3552
         const bool drawVRules = HasFlag(wxLC_VRULES);
    
    3472 3553
     
    
    3473 3554
         // Check if we need to do anything ourselves: either draw the rules or, in
    
    3474
    -    // case of using dark mode under Windows 11, erase the unwanted separator
    
    3555
    +    // case of using dark mode, draw the default background colour below and
    
    3556
    +    // behind the list items, and erase the unwanted separator
    
    3475 3557
         // lines drawn below the items by default, which are ugly because they
    
    3476 3558
         // don't align with the separators drawn by the header control.
    
    3477 3559
         bool needToDraw = false,
    
    3478 3560
              needToErase = false;
    
    3479
    -    if ( InReportView() && itemCount )
    
    3561
    +    if ( InReportView() )
    
    3480 3562
         {
    
    3481
    -        if ( (drawHRules || drawVRules) )
    
    3563
    +        if ( itemCount > 0 && (drawHRules || drawVRules) )
    
    3482 3564
                 needToDraw = true;
    
    3483
    -        else if ( wxMSWDarkMode::IsActive() && wxGetWinVersion() >= wxWinVersion_11 )
    
    3565
    +        if ( wxMSWDarkMode::IsActive() )
    
    3484 3566
                 needToErase = true;
    
    3485 3567
         }
    
    3486 3568
     
    
    ... ... @@ -3509,35 +3591,22 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)
    3509 3591
         if ( needToErase )
    
    3510 3592
         {
    
    3511 3593
             wxRect lastRect;
    
    3512
    -        GetItemRect(bottom, lastRect);
    
    3594
    +        if ( itemCount > 0 )
    
    3595
    +            GetItemRect(bottom, lastRect);
    
    3513 3596
     
    
    3514 3597
             dc.SetPen(*wxTRANSPARENT_PEN);
    
    3515 3598
             dc.SetBrush(GetBackgroundColour());
    
    3516
    -        dc.DrawRectangle(0, lastRect.GetBottom(), clientSize.x, clientSize.y - lastRect.GetBottom());
    
    3517
    -        return;
    
    3599
    +        dc.DrawRectangle(lastRect.GetRight() + 1, 0, clientSize.x - lastRect.GetRight(), clientSize.GetHeight());
    
    3600
    +        dc.DrawRectangle(0, lastRect.GetBottom() + 1, clientSize.x, clientSize.y - lastRect.GetBottom());
    
    3518 3601
         }
    
    3519 3602
     
    
    3520
    -    const wxColour penColour(wxSystemSettings::GetColour(wxMSWDarkMode::IsActive()
    
    3521
    -                                                         ? wxSYS_COLOUR_GRAYTEXT
    
    3522
    -                                                         : wxSYS_COLOUR_3DLIGHT));
    
    3523
    -    wxPen pen(penColour);
    
    3524
    -    dc.SetPen(pen);
    
    3525
    -    dc.SetBrush(* wxTRANSPARENT_BRUSH);
    
    3603
    +    if ( !needToDraw )
    
    3604
    +        return;
    
    3526 3605
     
    
    3527
    -    if (drawHRules)
    
    3528
    -    {
    
    3529
    -        wxRect itemRect;
    
    3530
    -        for ( long i = top; i <= bottom; i++ )
    
    3531
    -        {
    
    3532
    -            if (GetItemRect(i, itemRect))
    
    3533
    -            {
    
    3534
    -                const int cy = itemRect.GetBottom();
    
    3535
    -                dc.DrawLine(0, cy, clientSize.x, cy);
    
    3536
    -            }
    
    3537
    -        }
    
    3538
    -    }
    
    3606
    +    static const bool useDrawFix = wxApp::GetComCtl32Version() < 600;
    
    3607
    +    static const int gap = useDrawFix ? 2 : 0;
    
    3539 3608
     
    
    3540
    -    if (drawVRules)
    
    3609
    +    if ( drawVRules && useDrawFix )
    
    3541 3610
         {
    
    3542 3611
             wxRect topItemRect, bottomItemRect;
    
    3543 3612
             GetItemRect(top, topItemRect);
    
    ... ... @@ -3565,40 +3634,18 @@ void wxListCtrl::OnPaint(wxPaintEvent& event)
    3565 3634
                     EVT_LIST_COL_DRAGGING and also set useDrawFix to false and gap
    
    3566 3635
                     to 2 (not 0).
    
    3567 3636
                 */
    
    3637
    +            wxDCPenChanger changePen(dc, *wxTRANSPARENT_PEN);
    
    3638
    +            wxDCBrushChanger changeBrush(dc, GetBackgroundColour());
    
    3568 3639
     
    
    3569
    -            static const bool useDrawFix = wxApp::GetComCtl32Version() < 600;
    
    3570
    -
    
    3571
    -            static const int gap = useDrawFix ? 2 : 0;
    
    3572
    -
    
    3573
    -            if (useDrawFix)
    
    3574
    -            {
    
    3575
    -                wxDCPenChanger changePen(dc, *wxTRANSPARENT_PEN);
    
    3576
    -                wxDCBrushChanger changeBrush(dc, GetBackgroundColour());
    
    3577
    -
    
    3578
    -                dc.DrawRectangle(0, topItemRect.GetY() - gap,
    
    3579
    -                                 clientSize.GetWidth(), gap);
    
    3580
    -            }
    
    3581
    -
    
    3582
    -            const int numCols = GetColumnCount();
    
    3583
    -            wxVector<int> indexArray(numCols);
    
    3584
    -            if ( !ListView_GetColumnOrderArray(GetHwnd(),
    
    3585
    -                                               numCols,
    
    3586
    -                                               &indexArray[0]) )
    
    3587
    -            {
    
    3588
    -                wxFAIL_MSG( wxT("invalid column index array in OnPaint()") );
    
    3589
    -                return;
    
    3590
    -            }
    
    3591
    -
    
    3592
    -            int x = bottomItemRect.GetX();
    
    3593
    -            for (int col = 0; col < numCols; col++)
    
    3594
    -            {
    
    3595
    -                int colWidth = GetColumnWidth(indexArray[col]);
    
    3596
    -                x += colWidth ;
    
    3597
    -                dc.DrawLine(x-1, topItemRect.GetY() - gap,
    
    3598
    -                            x-1, bottomItemRect.GetBottom());
    
    3599
    -            }
    
    3640
    +            dc.DrawRectangle(0, topItemRect.GetY() - gap,
    
    3641
    +                             clientSize.GetWidth(), gap);
    
    3600 3642
             }
    
    3601 3643
         }
    
    3644
    +
    
    3645
    +    for ( long i = top; i <= bottom; i++ )
    
    3646
    +    {
    
    3647
    +        DrawGridLines(this, i, gap);
    
    3648
    +    }
    
    3602 3649
     }
    
    3603 3650
     
    
    3604 3651
     void wxListCtrl::OnCharHook(wxKeyEvent& event)
    

Reply all
Reply to author
Forward
0 new messages