[Git][wxwidgets/wxwidgets][master] 4 commits: Avoid spurious debug warnings when loading wxICON_XXX icons

1 view
Skip to first unread message

Vadim Zeitlin (@_VZ_)

unread,
Nov 21, 2025, 11:47:41 AM (6 days ago) Nov 21
to wx-commi...@googlegroups.com

Vadim Zeitlin pushed to branch master at wxWidgets / wxWidgets

Commits:

  • dfb0af50
    by Vadim Zeitlin at 2025-11-21T16:13:31+01:00
    Avoid spurious debug warnings when loading wxICON_XXX icons
    
    Because we provide fallbacks for these icons, don't give an annoying
    debug message about failing to load them from resources -- while these
    icons may be defined there to override the default icons, they don't
    need to be and typically are not, so this is not a real problem at all.
    
  • 84e8be12
    by Vadim Zeitlin at 2025-11-21T17:35:38+01:00
    Don't bother with wxGrid tests using native header under non-MSW
    
    wxMSW is the only port in which the header is really native and its
    behaviour may/does differ from the generic one and so these tests are
    valuable there, but not with the other ports.
    
  • 1efc0895
    by Vadim Zeitlin at 2025-11-21T17:38:46+01:00
    Ignore recurrent wxQt test failure in Grid::ResizeScrolledHeader
    
    This test keeps failing, mostly (but not only) with Qt 6.10, so disable
    it until this can be investigated.
    
  • dac1996e
    by Lauri Nurmi at 2025-11-21T17:40:32+01:00
    Remove commented out wxGetCurrentDir() that was never used
    
    This implementation was surrounded by #if 0 ever since it was added in
    7c07201 (don't disable hidden windows in wxWindowDisabler, it's at best
    useless, 2003-06-21).
    
    Closes #25982.
    

3 changed files:

Changes:

  • src/common/utilscmn.cpp
    ... ... @@ -470,40 +470,6 @@ wxString wxGetHomeDir()
    470 470
         return home;
    
    471 471
     }
    
    472 472
     
    
    473
    -#if 0
    
    474
    -
    
    475
    -wxString wxGetCurrentDir()
    
    476
    -{
    
    477
    -    wxString dir;
    
    478
    -    size_t len = 1024;
    
    479
    -    bool ok;
    
    480
    -    do
    
    481
    -    {
    
    482
    -        ok = getcwd(dir.GetWriteBuf(len + 1), len) != nullptr;
    
    483
    -        dir.UngetWriteBuf();
    
    484
    -
    
    485
    -        if ( !ok )
    
    486
    -        {
    
    487
    -            if ( errno != ERANGE )
    
    488
    -            {
    
    489
    -                wxLogSysError(wxT("Failed to get current directory"));
    
    490
    -
    
    491
    -                return wxEmptyString;
    
    492
    -            }
    
    493
    -            else
    
    494
    -            {
    
    495
    -                // buffer was too small, retry with a larger one
    
    496
    -                len *= 2;
    
    497
    -            }
    
    498
    -        }
    
    499
    -        //else: ok
    
    500
    -    } while ( !ok );
    
    501
    -
    
    502
    -    return dir;
    
    503
    -}
    
    504
    -
    
    505
    -#endif // 0
    
    506
    -
    
    507 473
     // ----------------------------------------------------------------------------
    
    508 474
     // Environment
    
    509 475
     // ----------------------------------------------------------------------------
    

  • src/msw/gdiimage.cpp
    ... ... @@ -583,6 +583,26 @@ bool wxICOResourceHandler::LoadIcon(wxIcon *icon,
    583 583
                                         wxBitmapType WXUNUSED(flags),
    
    584 584
                                         int desiredWidth, int desiredHeight)
    
    585 585
     {
    
    586
    +    static const struct
    
    587
    +    {
    
    588
    +        const wxChar *name;
    
    589
    +        LPTSTR id;
    
    590
    +    } stdIcons[] =
    
    591
    +    {
    
    592
    +        { wxT("wxICON_QUESTION"),   IDI_QUESTION    },
    
    593
    +        { wxT("wxICON_WARNING"),    IDI_EXCLAMATION },
    
    594
    +        { wxT("wxICON_ERROR"),      IDI_HAND        },
    
    595
    +        { wxT("wxICON_INFORMATION"),IDI_ASTERISK    },
    
    596
    +    };
    
    597
    +
    
    598
    +    // Check if it's one of the standard icons.
    
    599
    +    size_t nStdIcon;
    
    600
    +    for ( nStdIcon = 0; nStdIcon < WXSIZEOF(stdIcons); nStdIcon++ )
    
    601
    +    {
    
    602
    +        if ( name == stdIcons[nStdIcon].name )
    
    603
    +            break;
    
    604
    +    }
    
    605
    +
    
    586 606
         HICON hicon;
    
    587 607
     
    
    588 608
         // do we need the icon of the specific size or would any icon do?
    
    ... ... @@ -602,7 +622,11 @@ bool wxICOResourceHandler::LoadIcon(wxIcon *icon,
    602 622
             hicon = (HICON)::LoadImage(wxGetInstance(), name.t_str(), IMAGE_ICON,
    
    603 623
                                         desiredWidth, desiredHeight,
    
    604 624
                                         LR_DEFAULTCOLOR);
    
    605
    -        if ( !hicon )
    
    625
    +
    
    626
    +        // Don't give errors when looking for a standard icon because we
    
    627
    +        // provide fallback for them below, but do indicate that we failed to
    
    628
    +        // load other icons because this is probably not expected.
    
    629
    +        if ( !hicon && nStdIcon == WXSIZEOF(stdIcons) )
    
    606 630
             {
    
    607 631
                 wxLogLastError(wxString::Format("LoadImage(%s)", name));
    
    608 632
             }
    
    ... ... @@ -610,38 +634,21 @@ bool wxICOResourceHandler::LoadIcon(wxIcon *icon,
    610 634
         else
    
    611 635
         {
    
    612 636
             hicon = ::LoadIcon(wxGetInstance(), name.t_str());
    
    613
    -        if ( !hicon )
    
    637
    +
    
    638
    +        // As above, only warn for non standard icons.
    
    639
    +        if ( !hicon && nStdIcon == WXSIZEOF(stdIcons) )
    
    614 640
             {
    
    615 641
                 wxLogLastError(wxString::Format("LoadIcon(%s)", name));
    
    616 642
             }
    
    617 643
         }
    
    618 644
     
    
    619 645
         // next check if it's not a standard icon
    
    620
    -    if ( !hicon && !hasSize )
    
    646
    +    if ( !hicon && !hasSize && nStdIcon < WXSIZEOF(stdIcons) )
    
    621 647
         {
    
    622
    -        static const struct
    
    623
    -        {
    
    624
    -            const wxChar *name;
    
    625
    -            LPTSTR id;
    
    626
    -        } stdIcons[] =
    
    627
    -        {
    
    628
    -            { wxT("wxICON_QUESTION"),   IDI_QUESTION    },
    
    629
    -            { wxT("wxICON_WARNING"),    IDI_EXCLAMATION },
    
    630
    -            { wxT("wxICON_ERROR"),      IDI_HAND        },
    
    631
    -            { wxT("wxICON_INFORMATION"),       IDI_ASTERISK    },
    
    632
    -        };
    
    633
    -
    
    634
    -        for ( size_t nIcon = 0; !hicon && nIcon < WXSIZEOF(stdIcons); nIcon++ )
    
    648
    +        hicon = ::LoadIcon((HINSTANCE)nullptr, stdIcons[nStdIcon].id);
    
    649
    +        if ( !hicon )
    
    635 650
             {
    
    636
    -            if ( name == stdIcons[nIcon].name )
    
    637
    -            {
    
    638
    -                hicon = ::LoadIcon((HINSTANCE)nullptr, stdIcons[nIcon].id);
    
    639
    -                if ( !hicon )
    
    640
    -                {
    
    641
    -                    wxLogLastError(wxString::Format("LoadIcon(%s)", stdIcons[nIcon].name));
    
    642
    -                }
    
    643
    -                break;
    
    644
    -            }
    
    651
    +            wxLogLastError(wxString::Format("LoadIcon(%s)", stdIcons[nStdIcon].name));
    
    645 652
             }
    
    646 653
         }
    
    647 654
     
    

  • tests/controls/gridtest.cpp
    ... ... @@ -42,6 +42,12 @@
    42 42
         #define wxSKIP_AUTOMATIC_TEST_IF_GTK2()
    
    43 43
     #endif
    
    44 44
     
    
    45
    +// Only wxMSW supports native header, so the tests would be redundant under
    
    46
    +// other platforms.
    
    47
    +#ifdef __WXMSW__
    
    48
    +    #define wxHAS_NATIVE_HEADER
    
    49
    +#endif // __WXMSW__
    
    50
    +
    
    45 51
     namespace
    
    46 52
     {
    
    47 53
     
    
    ... ... @@ -612,6 +618,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::LabelClick", "[grid]")
    612 618
         if ( !EnableUITests() )
    
    613 619
             return;
    
    614 620
     
    
    621
    +#ifdef wxHAS_NATIVE_HEADER
    
    615 622
         wxString desc;
    
    616 623
     
    
    617 624
         SECTION("Default") { desc = "default header"; }
    
    ... ... @@ -619,6 +626,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::LabelClick", "[grid]")
    619 626
         SECTION("Native labels") { desc = "native labels"; m_grid->SetUseNativeColLabels(); }
    
    620 627
     
    
    621 628
         INFO("Using " << desc);
    
    629
    +#endif // wxHAS_NATIVE_HEADER
    
    622 630
     
    
    623 631
         EventCounter lclick(m_grid, wxEVT_GRID_LABEL_LEFT_CLICK);
    
    624 632
         EventCounter ldclick(m_grid, wxEVT_GRID_LABEL_LEFT_DCLICK);
    
    ... ... @@ -681,6 +689,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::SortClick", "[grid]")
    681 689
         if ( !EnableUITests() )
    
    682 690
             return;
    
    683 691
     
    
    692
    +#ifdef wxHAS_NATIVE_HEADER
    
    684 693
         wxString desc;
    
    685 694
     
    
    686 695
         SECTION("Default") { desc = "default header"; }
    
    ... ... @@ -688,6 +697,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::SortClick", "[grid]")
    688 697
         SECTION("Native labels") { desc = "native labels"; m_grid->SetUseNativeColLabels(); }
    
    689 698
     
    
    690 699
         INFO("Using " << desc);
    
    700
    +#endif // wxHAS_NATIVE_HEADER
    
    691 701
     
    
    692 702
         m_grid->SetSortingColumn(0);
    
    693 703
     
    
    ... ... @@ -1166,12 +1176,14 @@ TEST_CASE_METHOD(GridTestCase, "Grid::AddRowCol", "[grid]")
    1166 1176
     
    
    1167 1177
     TEST_CASE_METHOD(GridTestCase, "Grid::DeleteAndAddRowCol", "[grid]")
    
    1168 1178
     {
    
    1179
    +#ifdef wxHAS_NATIVE_HEADER
    
    1169 1180
         wxString desc;
    
    1170 1181
     
    
    1171 1182
         SECTION("Default") { desc = "default header"; }
    
    1172 1183
         SECTION("Native header") { desc = "native header"; m_grid->UseNativeColHeader(); }
    
    1173 1184
     
    
    1174 1185
         INFO("Using " << desc);
    
    1186
    +#endif // wxHAS_NATIVE_HEADER
    
    1175 1187
     
    
    1176 1188
         CHECK(m_grid->GetNumberRows() == 10);
    
    1177 1189
         CHECK(m_grid->GetNumberCols() == 2);
    
    ... ... @@ -1202,6 +1214,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::DeleteAndAddRowCol", "[grid]")
    1202 1214
     
    
    1203 1215
     TEST_CASE_METHOD(GridTestCase, "Grid::ColumnOrder", "[grid]")
    
    1204 1216
     {
    
    1217
    +#ifdef wxHAS_NATIVE_HEADER
    
    1205 1218
         wxString desc;
    
    1206 1219
     
    
    1207 1220
         SECTION("Default") { desc = "default header"; }
    
    ... ... @@ -1209,6 +1222,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ColumnOrder", "[grid]")
    1209 1222
         SECTION("Native labels") { desc = "native labels"; m_grid->SetUseNativeColLabels(); }
    
    1210 1223
     
    
    1211 1224
         INFO("Using " << desc);
    
    1225
    +#endif // wxHAS_NATIVE_HEADER
    
    1212 1226
     
    
    1213 1227
         m_grid->AppendCols(2);
    
    1214 1228
     
    
    ... ... @@ -1621,12 +1635,14 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ResizeScrolledHeader", "[grid]")
    1621 1635
     
    
    1622 1636
         wxSKIP_AUTOMATIC_TEST_IF_GTK2();
    
    1623 1637
     
    
    1638
    +#ifdef wxHAS_NATIVE_HEADER
    
    1624 1639
         wxString desc;
    
    1625 1640
     
    
    1626 1641
         SECTION("Default") { desc = "default header"; }
    
    1627 1642
         SECTION("Native header") { desc = "native header"; m_grid->UseNativeColHeader(); }
    
    1628 1643
     
    
    1629 1644
         INFO("Using " << desc);
    
    1645
    +#endif // wxHAS_NATIVE_HEADER
    
    1630 1646
     
    
    1631 1647
         int const startwidth = m_grid->GetColSize(0);
    
    1632 1648
         int const draglength = 100;
    
    ... ... @@ -1663,6 +1679,16 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ResizeScrolledHeader", "[grid]")
    1663 1679
     
    
    1664 1680
         wxYield();
    
    1665 1681
     
    
    1682
    +#ifdef __WXQT__
    
    1683
    +    if (m_grid->GetColSize(0) != startwidth + draglength)
    
    1684
    +    {
    
    1685
    +        WARN("Ignoring known test failure under Qt: column width is "
    
    1686
    +             << m_grid->GetColSize(0) << " instead of expected "
    
    1687
    +             << startwidth << " + " << draglength);
    
    1688
    +        return;
    
    1689
    +    }
    
    1690
    +#endif // __WXQT__
    
    1691
    +
    
    1666 1692
         CHECK(m_grid->GetColSize(0) == startwidth + draglength);
    
    1667 1693
     #endif
    
    1668 1694
     }
    
    ... ... @@ -1676,6 +1702,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ColumnMinWidth", "[grid]")
    1676 1702
     
    
    1677 1703
         wxSKIP_AUTOMATIC_TEST_IF_GTK2();
    
    1678 1704
     
    
    1705
    +#ifdef wxHAS_NATIVE_HEADER
    
    1679 1706
         wxString desc;
    
    1680 1707
     
    
    1681 1708
         SECTION("Default") { desc = "default header"; }
    
    ... ... @@ -1692,6 +1719,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::ColumnMinWidth", "[grid]")
    1692 1719
         }
    
    1693 1720
     
    
    1694 1721
         INFO("Using " << desc);
    
    1722
    +#endif // wxHAS_NATIVE_HEADER
    
    1695 1723
     
    
    1696 1724
         int const startminwidth = m_grid->GetColMinimalAcceptableWidth();
    
    1697 1725
         m_grid->SetColMinimalAcceptableWidth(startminwidth*2);
    
    ... ... @@ -1750,6 +1778,7 @@ void GridTestCase::CheckFirstColAutoSize(int expected)
    1750 1778
     
    
    1751 1779
     TEST_CASE_METHOD(GridTestCase, "Grid::AutoSizeColumn", "[grid]")
    
    1752 1780
     {
    
    1781
    +#ifdef wxHAS_NATIVE_HEADER
    
    1753 1782
         wxString desc;
    
    1754 1783
     
    
    1755 1784
         SECTION("Default") { desc = "default header"; }
    
    ... ... @@ -1757,6 +1786,7 @@ TEST_CASE_METHOD(GridTestCase, "Grid::AutoSizeColumn", "[grid]")
    1757 1786
         SECTION("Native labels") { desc = "native labels"; m_grid->SetUseNativeColLabels(); }
    
    1758 1787
     
    
    1759 1788
         INFO("Using " << desc);
    
    1789
    +#endif // wxHAS_NATIVE_HEADER
    
    1760 1790
     
    
    1761 1791
         // Hardcoded extra margin for the columns used in grid.cpp.
    
    1762 1792
         const int margin = m_grid->FromDIP(10);
    

Reply all
Reply to author
Forward
0 new messages