Opened 4 years ago

Closed 12 months ago

Last modified 12 months ago

#13569 closed defect (fixed)

wxMSW: SetBitmap cannot remove bitmap

Reported by: Auria Owned by: VZ
Priority: low Milestone:
Component: wxMSW Version: dev-latest
Keywords: wxButton wxAnyButton SetBitmap Cc:
Blocked By: Blocking:
Patch: yes

Description

The docs for wxButton::SetBitmap ( http://docs.wxwidgets.org/2.9.2/classwx_button.html#5caa1163418c868140ba3021fc20578e ) say

"bitmap The bitmap to display in the button. May be invalid to remove any currently displayed bitmap. "

This is however not true under wxMSW, when you do that you get an assertion failure

Attachments (1)

button-setbitmap.patch download (1.4 KB) - added by awi 13 months ago.
Handling invalid bitmaps.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 22 months ago by vadz

  • Priority changed from normal to low
  • Status changed from new to confirmed
  • Version changed from 2.9-svn to 2.9.5

comment:2 Changed 22 months ago by VZ

(In [74430]) Don't pretend that wxAnyButton::SetBitmap() supports invalid bitmaps.

Because it doesn't under MSW.

See #13569.

comment:3 Changed 13 months ago by awi

  • Keywords wxButton wxAnyButton SetBitmap added
  • Patch set
  • Version changed from 2.9.5 to dev-latest

Attached patch implements handling of invalid bitmaps in way similar to wxGTK (attachment:ticket:13569:button-setbitmap.patch)

Test case:

  • samples/minimal/minimal.cpp

    old new  
    141141// main frame
    142142// ----------------------------------------------------------------------------
    143143
     144#include "wx/artprov.h"
     145
    144146// frame constructor
    145147MyFrame::MyFrame(const wxString& title)
    146148       : wxFrame(NULL, wxID_ANY, title)
     
    172174    CreateStatusBar(2);
    173175    SetStatusText("Welcome to wxWidgets!");
    174176#endif // wxUSE_STATUSBAR
     177    wxButton *bt1 = new wxButton(this, wxID_HIGHEST+1, wxEmptyString, wxPoint(10,10), wxSize(100, 40));
     178    bt1->SetBitmap(wxArtProvider::GetBitmap(wxART_COPY));
     179    bt1->SetBitmapFocus(wxArtProvider::GetBitmap(wxART_NEW));
     180    bt1->SetBitmapDisabled(wxArtProvider::GetBitmap(wxART_PASTE));
     181
     182    wxButton *bt2 = new wxButton(this, wxID_HIGHEST+2, "Test", wxPoint(10, 90), wxSize(100,40));
     183    bt2->SetBitmap(wxArtProvider::GetBitmap(wxART_COPY));
     184    bt2->SetBitmapFocus(wxArtProvider::GetBitmap(wxART_NEW));
     185    bt2->SetBitmapDisabled(wxArtProvider::GetBitmap(wxART_PASTE));
     186
     187//    bt1->SetBitmap(wxNullBitmap);
     188    bt2->SetBitmap(wxNullBitmap);
     189//    bt1->SetBitmapFocus(wxNullBitmap);
     190//    bt2->SetBitmapFocus(wxNullBitmap);
     191//    bt1->SetBitmapDisabled(wxNullBitmap);
     192    bt1->Disable();
     193//    bt2->Disable();
    175194}

Changed 13 months ago by awi

Handling invalid bitmaps.

comment:4 Changed 12 months ago by VZ

  • Owner set to VZ
  • Resolution set to fixed
  • Status changed from confirmed to closed

In 76404:

Bring wxMSW wxBitmap::SetBitmapXXX(wxBitmap()) in line with wxGTK.

Remove or reset the corresponding bitmap if the provided one is invalid
instead of asserting, this is what wxGTK does and this behaviour seems to be
more useful.

Also document this behaviour as it's now implemented in both wxMSW and wxGTK.

Closes #13569.

comment:5 Changed 12 months ago by VZ

In 76415:

Bring wxMSW wxBitmap::SetBitmapXXX(wxBitmap()) in line with wxGTK.

Remove or reset the corresponding bitmap if the provided one is invalid
instead of asserting, this is what wxGTK does and this behaviour seems to be
more useful.

Also document this behaviour as it's now implemented in both wxMSW and wxGTK.

Closes #13569.

Note: See TracTickets for help on using tickets.