Ticket #14892 (closed defect: fixed)

Opened 6 months ago

Last modified 7 weeks ago

wxBitmapComboBox::SetItemBitmap clear client object pointer.

Reported by: Feneck91 Owned by:
Priority: normal Milestone:
Component: wxMSW Version: 2.9.4
Keywords: wxBitmapComboBox SetItemBitmap GetClientObject regression Cc:
Blocked By: Patch: yes
Blocking:

Description

When creating a wxBitmapComboBox control under Windows, calling SetItemBitmap clear the client object on item.

To make it, create a wxBitmapComboBox, add a new item without bitmap that contains a client object. Then set the bitmap : the client object is now set to null.

It's works well on wxWidgets 2.8.12, fails on wxWidgets 2.9.4

wxBitmapComboBox *pCombo = new wxBitmapComboBox(this, idChoiceCtrlListTeam1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY, wxDefaultValidator, _T("idChoiceCtrlListTeam1"));

pCombo->Insert(wxT("my text"),wxNullBitmap,0,new wxClientData());

wxBitmap myImage(wxImage(_T("myImage.png"));

pCombo->SetItemBitmap(0,myImage);

wxASSERT_MSG(pCombo->GetClientObject(0) != NULL,wxT("Client data is NULL !"));

!! THIS FAILED !!

To set the item text and bitmap, I must use the code: 

void SetItem(wxString strText,int iIndex,wxBitmap bitmap)

{

#if wxCHECK_VERSION(2,9,0)

// Calling SetItemBitmap remove wxClientData item, change way of how the item is inserted

bool bSelected = this->IsSelected(iIndex);

wxClientData *pClient = m_pCombo->DetachClientObject (iIndex);

pCombo->Delete(iIndex);

pCombo->Insert(strText,bitmap,iIndex,pClient);

if (bSelected)

{

pCombo->SetSelection(iIndex);

}

wxASSERT_MSG(pCombo->GetClientObject(_iIndex) != NULL,wxT("Client data is NULL !"));

#else

pCombo->SetString(iIndex,strText);

m_pCombo->SetItemBitmap(iIndex,bitmap);

#endif // wxCHECK_VERSION

}

Attachments

14892test.diff download (1.5 KB) - added by catalin 4 months ago.
14892fix.diff download (0.9 KB) - added by catalin 4 months ago.

Change History

Changed 6 months ago by vadz

  • keywords regression added
  • priority changed from high to normal

It would be great if you could please make a patch to the combo sample allowing to reproduce the problem with the minimal amount of code to allow me to debug this easily.

Of course, if you could debug it yourself and make a patch fixing the problem, it would be even greater, please consider doing it, it shouldn't be very difficult to see what is going on wrong here but I just don't have enough time for it.

Changed 4 months ago by catalin

Changed 4 months ago by catalin

Changed 4 months ago by catalin

  • patch set

Saving the pointers to old client data (it is not deleted) and using them when the control is recreated fixes this problem. Patches attached.

Changed 4 months ago by VZ

  • status changed from new to closed
  • resolution set to fixed

(In [73567]) Preserve client data pointers when setting bitmaps in wxBitmapComboBox.

Changing the bitmap could recreate the control if the height of the bitmap
changed but recreating wxBitmapComboBox lost all the client data pointers.

Do preserve them now when recreating.

Closes #14892.

Changed 7 weeks ago by VZ

(In [73880]) Fix assert when adding items with bitmaps wxBitmapComboBox.

The change of r73567 resulted in an assert when adding items with bitmaps to
wxBitmapComboBox without object client data. Fix the code added by this commit
to work for all kinds of client data, including wxClientData_None.

See #14892.

Note: See TracTickets for help on using tickets.