From c8d380be4db7bf72539072949209dc816f3e01a7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 22 Dec 2007 14:56:56 +0000 Subject: [PATCH] don't use rand() for selecting the colour of the bitmaps to append, this results in 2 pairs of identical colours here without srand() and looks too much like a bug git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50896 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/widgets/bmpcombobox.cpp | 65 ++++++++------------------------- 1 file changed, 15 insertions(+), 50 deletions(-) diff --git a/samples/widgets/bmpcombobox.cpp b/samples/widgets/bmpcombobox.cpp index 162ba73421..9c055063af 100644 --- a/samples/widgets/bmpcombobox.cpp +++ b/samples/widgets/bmpcombobox.cpp @@ -145,7 +145,6 @@ protected: // helpers for creating bitmaps wxBitmap CreateBitmap(const wxColour& colour); - wxBitmap CreateRandomBitmap(wxString* pStr); wxBitmap LoadBitmap(const wxString& filepath); wxBitmap QueryBitmap(wxString* pStr); @@ -553,13 +552,22 @@ void BitmapComboBoxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(even void BitmapComboBoxWidgetsPage::OnButtonAddSeveralWithImages(wxCommandEvent& WXUNUSED(event)) { - int i; + static const struct TestEntry + { + const char *text; + unsigned long rgb; + } s_entries[] = + { + { "Red circle", 0x0000ff }, + { "Blue circle", 0xff0000 }, + { "Green circle", 0x00ff00 }, + { "Black circle", 0x000000 }, + }; - for ( i=0; i<4; i++ ) + for ( int i = 0; i < WXSIZEOF(s_entries); i++ ) { - wxString s; - wxBitmap bmp = CreateRandomBitmap(&s); - m_combobox->Append(s, bmp); + const TestEntry& e = s_entries[i]; + m_combobox->Append(e.text, CreateBitmap(wxColour(e.rgb))); } } @@ -870,47 +878,4 @@ wxBitmap BitmapComboBoxWidgetsPage::CreateBitmap(const wxColour& colour) return bmp; } -wxBitmap BitmapComboBoxWidgetsPage::CreateRandomBitmap( wxString* pStr ) -{ - int i = rand() % 6; - const wxChar* str = wxT(""); - wxBitmap bmp; - - if ( i == 0 ) - { - str = wxT("Red Circle"); - bmp = CreateBitmap( *wxRED ); - } - else if ( i == 1 ) - { - str = wxT("Green Circle"); - bmp = CreateBitmap( *wxGREEN ); - } - else if ( i == 2 ) - { - str = wxT("Blue Circle"); - bmp = CreateBitmap( *wxBLUE ); - } - else if ( i == 3 ) - { - str = wxT("Black Circle"); - bmp = CreateBitmap( *wxBLACK ); - } - else if ( i == 4 ) - { - str = wxT("Cyan Circle"); - bmp = CreateBitmap( *wxCYAN ); - } - else if ( i == 5 ) - { - str = wxT("Light Grey Circle"); - bmp = CreateBitmap( *wxLIGHT_GREY ); - } - - if ( pStr ) - *pStr = str; - - return bmp; -} - -#endif //wxUSE_BITMAPCOMBOBOX +#endif // wxUSE_BITMAPCOMBOBOX -- 2.47.2