Added and documented wxColourDatabase::AddColour.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21925 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon 2003-07-12 20:11:51 +00:00
parent 7a02658071
commit 8f520a56b7
3 changed files with 34 additions and 9 deletions

View File

@ -246,8 +246,7 @@ is only one instance of this class: {\bf wxTheColourDatabase}.
\wxheading{Derived from}
\helpref{wxList}{wxlist}\\
\helpref{wxObject}{wxobject}
None
\wxheading{Include files}
@ -282,6 +281,13 @@ YELLOW GREEN.
Constructs the colour database.
\membersection{wxColourDatabase::AddColour}\label{wxcolourdatabaseaddcolour}
\func{void}{AddColour}{\param{const wxString\& }{colourName}, \param{wxColour* }{colour}}
Adds a colour to the database. If a colour with the same name already exists,
it is replaced.
\membersection{wxColourDatabase::FindColour}\label{wxcolourdatabasefindcolour}
\func{wxColour*}{FindColour}{\param{const wxString\& }{colourName}}

View File

@ -431,6 +431,7 @@ public:
wxColour *FindColour(const wxString& colour) ;
wxColour *FindColourNoAdd(const wxString& colour) const;
wxString FindName(const wxColour& colour) const;
void AddColour(const wxString& name, wxColour* colour);
void Initialize();
#ifdef __WXPM__
// PM keeps its own type of colour table

View File

@ -196,10 +196,7 @@ wxColourDatabase::wxColourDatabase ()
wxColourDatabase::~wxColourDatabase ()
{
typedef wxStringToColourHashMap::iterator iterator;
for( iterator it = m_map->begin(), en = m_map->end(); it != en; ++it )
delete it->second;
WX_CLEAR_HASH_MAP(wxStringToColourHashMap, *m_map);
delete m_map;
m_map = NULL;
@ -289,6 +286,7 @@ void wxColourDatabase::Initialize ()
{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;
@ -296,7 +294,7 @@ void wxColourDatabase::Initialize ()
for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
{
const wxColourDesc& cc = wxColourTable[n];
(*m_map)[cc.name] = new wxColour(cc.r,cc.g,cc.b);
AddColour(cc.name, new wxColour(cc.r,cc.g,cc.b));
}
#ifdef __WXPM__
m_palTable = new long[n];
@ -328,6 +326,26 @@ wxColour *wxColourDatabase::FindColourNoAdd(const wxString& colour) const
return ((wxColourDatabase*)this)->FindColour(colour, false);
}
void wxColourDatabase::AddColour (const wxString& name, wxColour* colour)
{
wxString colName = name;
colName.MakeUpper();
wxString colName2 = colName;
if ( !colName2.Replace(_T("GRAY"), _T("GREY")) )
colName2.clear();
wxStringToColourHashMap::iterator it = m_map->find(colName);
if ( it == m_map->end() )
it = m_map->find(colName2);
if ( it != m_map->end() )
{
delete it->second;
it->second = colour;
}
(*m_map)[name] = colour;
}
wxColour *wxColourDatabase::FindColour(const wxString& colour, bool add)
{
// VZ: make the comparaison case insensitive and also match both grey and
@ -377,7 +395,7 @@ wxColour *wxColourDatabase::FindColour(const wxString& colour, bool add)
delete col;
return (wxColour *) NULL;
}
(*m_map)[colour] = col;
AddColour(colour, col);
return col;
#endif
@ -405,7 +423,7 @@ wxColour *wxColourDatabase::FindColour(const wxString& colour, bool add)
#endif
wxColour *col = new wxColour(r, g, b);
(*m_map)[colour] = col;
AddColour(colour, col);
return col;
#endif // __X__