From: Robin Dunn Date: Thu, 7 Feb 2002 01:44:05 +0000 (+0000) Subject: Check for existing colour names when adding to wxTheColourDatabase X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/fe40185d40076711e97ef33de0b934da01f68e0a Check for existing colour names when adding to wxTheColourDatabase git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14041 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/wxPython/demo/ColourDB.py b/wxPython/demo/ColourDB.py index 9187807513..8e00407dba 100644 --- a/wxPython/demo/ColourDB.py +++ b/wxPython/demo/ColourDB.py @@ -17,6 +17,7 @@ class TestWindow(wxScrolledWindow): wxScrolledWindow.__init__(self, parent, -1) self.clrList = colourdb.getColourList() + #self.clrList.sort() self.bg_bmp = images.getGridBGBitmap() EVT_PAINT(self, self.OnPaint) diff --git a/wxPython/src/gdi.i b/wxPython/src/gdi.i index 117d7c9779..a8d6dd79bc 100644 --- a/wxPython/src/gdi.i +++ b/wxPython/src/gdi.i @@ -643,6 +643,25 @@ public: %addmethods { void Append(const wxString& name, int red, int green, int blue) { + // first see if the name is already there + wxString cName = name; + cName.MakeUpper(); + wxString cName2 = cName; + if ( !cName2.Replace("GRAY", "GREY") ) + cName2.clear(); + + wxNode *node = self->First(); + while ( node ) { + const wxChar *key = node->GetKeyString(); + if ( cName == key || cName2 == key ) { + wxColour* c = (wxColour *)node->Data(); + c->Set(red, green, blue); + return; + } + node = node->Next(); + } + + // otherwise append the new colour self->Append(name.c_str(), new wxColour(red, green, blue)); } } diff --git a/wxPython/src/msw/gdi.cpp b/wxPython/src/msw/gdi.cpp index 4b21d4fe4e..7edbe17540 100644 --- a/wxPython/src/msw/gdi.cpp +++ b/wxPython/src/msw/gdi.cpp @@ -5775,6 +5775,25 @@ static PyObject *_wrap_wxColourDatabase_FindName(PyObject *self, PyObject *args, } static void wxColourDatabase_Append(wxColourDatabase *self,const wxString & name,int red,int green,int blue) { + // first see if the name is already there + wxString cName = name; + cName.MakeUpper(); + wxString cName2 = cName; + if ( !cName2.Replace("GRAY", "GREY") ) + cName2.clear(); + + wxNode *node = self->First(); + while ( node ) { + const wxChar *key = node->GetKeyString(); + if ( cName == key || cName2 == key ) { + wxColour* c = (wxColour *)node->Data(); + c->Set(red, green, blue); + return; + } + node = node->Next(); + } + + // otherwise append the new colour self->Append(name.c_str(), new wxColour(red, green, blue)); } static PyObject *_wrap_wxColourDatabase_Append(PyObject *self, PyObject *args, PyObject *kwargs) {