X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e4bfb5c0cd6376bf1a3ac41b5dc0f3758714eeac..97e324eff05f010ce59985c670bbe501edfa75c2:/src/common/gdicmn.cpp diff --git a/src/common/gdicmn.cpp b/src/common/gdicmn.cpp index 01273b854b..ac407e93d9 100644 --- a/src/common/gdicmn.cpp +++ b/src/common/gdicmn.cpp @@ -331,7 +331,7 @@ void wxColourDatabase::Initialize() {wxT("WHEAT"), 216, 216, 191}, {wxT("WHITE"), 255, 255, 255}, {wxT("YELLOW"), 255, 255, 0}, - {wxT("YELLOW GREEN"), 153, 204, 50}, + {wxT("YELLOW GREEN"), 153, 204, 50} }; size_t n; @@ -473,18 +473,31 @@ wxString wxColourDatabase::FindName(const wxColour& colour) const wxColour *wxColourDatabase::FindColour(const wxString& name) { - wxColour col = Find(name); - if ( !col.Ok() ) + // This function is deprecated, use Find() instead. + // Formerly this function sometimes would return a deletable pointer and + // sometimes a non-deletable one (when returning a colour from the database). + // Trying to delete the latter anyway results in problems, so probably + // nobody ever freed the pointers. Currently it always returns a new + // instance, which means there will be memory leaks. + wxLogDebug(wxT("wxColourDataBase::FindColour():") + wxT(" Please use wxColourDataBase::Find() instead")); + + // using a static variable here is not the most elegant solution but unless + // we want to make wxStringToColourHashMap public (i.e. move it to the + // header) so that we could have a member function returning + // wxStringToColourHashMap::iterator, there is really no good way to do it + // otherwise + // + // and knowing that this function is going to disappear in the next release + // anyhow I don't want to waste time on this + + static wxColour s_col; + + s_col = Find(name); + if ( !s_col.Ok() ) return NULL; - return new wxColour(col); -} - -void wxColourDatabase::AddColour(const wxString& name, wxColour *colour) -{ - wxCHECK_RET( colour, _T("NULL pointer in wxColourDatabase::AddColour") ); - - AddColour(name, wxColour(*colour)); + return new wxColour(s_col); } // ============================================================================