// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
-// Copyright: (c) Julian Smart and Markus Holzem
+// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/dc.h"
#include "wx/utils.h"
#include "wx/settings.h"
+#include "wx/hashmap.h"
#include "wx/log.h"
#include <string.h>
#ifdef __WXMSW__
-#include <windows.h>
+#include "wx/msw/wrapwin.h"
#endif
#ifdef __WXMOTIF__
#include "wx/mac/private.h"
#include "wx/mac/uma.h"
#endif
-IMPLEMENT_CLASS(wxColourDatabase, wxList)
-IMPLEMENT_DYNAMIC_CLASS(wxFontList, wxList)
-IMPLEMENT_DYNAMIC_CLASS(wxPenList, wxList)
-IMPLEMENT_DYNAMIC_CLASS(wxBrushList, wxList)
-IMPLEMENT_DYNAMIC_CLASS(wxBitmapList, wxList)
-IMPLEMENT_DYNAMIC_CLASS(wxResourceCache, wxList)
+//IMPLEMENT_CLASS(wxColourDatabase, wxList)
+//IMPLEMENT_DYNAMIC_CLASS(wxFontList, wxList)
+//IMPLEMENT_DYNAMIC_CLASS(wxPenList, wxList)
+//IMPLEMENT_DYNAMIC_CLASS(wxBrushList, wxList)
+//IMPLEMENT_DYNAMIC_CLASS(wxBitmapList, wxList)
+//IMPLEMENT_DYNAMIC_CLASS(wxResourceCache, wxList)
IMPLEMENT_ABSTRACT_CLASS(wxDCBase, wxObject)
return r.width != 0;
}
-wxColourDatabase::wxColourDatabase (int type) : wxList (type)
+WX_DECLARE_STRING_HASH_MAP( wxColour*, wxStringToColourHashMap );
+
+wxColourDatabase::wxColourDatabase ()
{
+ m_map = new wxStringToColourHashMap;
}
wxColourDatabase::~wxColourDatabase ()
{
- // Cleanup Colour allocated in Initialize()
- wxNode *node = First ();
- while (node)
- {
- wxColour *col = (wxColour *) node->Data ();
- wxNode *next = node->Next ();
- delete col;
- node = next;
- }
+ WX_CLEAR_HASH_MAP(wxStringToColourHashMap, *m_map);
+
+ delete m_map;
+ m_map = NULL;
#ifdef __WXPM__
delete [] m_palTable;
#endif
// Colour database stuff
void wxColourDatabase::Initialize ()
{
+ // these colour definitions are taken from X consortium definitions with a
+ // few more colours added
static const struct wxColourDesc
{
const wxChar *name;
}
wxColourTable[] =
{
- {wxT("AQUAMARINE"),112, 219, 147},
+ {wxT("AQUAMARINE"),127, 255, 212},
{wxT("BLACK"),0, 0, 0},
{wxT("BLUE"), 0, 0, 255},
- {wxT("BLUE VIOLET"), 159, 95, 159},
+ {wxT("BLUE VIOLET"), 138, 43, 226},
{wxT("BROWN"), 165, 42, 42},
- {wxT("CADET BLUE"), 95, 159, 159},
- {wxT("CORAL"), 255, 127, 0},
- {wxT("CORNFLOWER BLUE"), 66, 66, 111},
+ {wxT("CADET BLUE"), 95, 158, 160},
+ {wxT("CORAL"), 255, 127, 80},
+ {wxT("CORNFLOWER BLUE"), 100, 149, 237},
{wxT("CYAN"), 0, 255, 255},
- {wxT("DARK GREY"), 47, 47, 47}, // ?
-
- {wxT("DARK GREEN"), 47, 79, 47},
- {wxT("DARK OLIVE GREEN"), 79, 79, 47},
+ {wxT("DARK GREY"), 169, 169, 169},
+ {wxT("DARK GREEN"), 0, 100, 0},
+ {wxT("DARK OLIVE GREEN"), 85, 107, 47},
{wxT("DARK ORCHID"), 153, 50, 204},
- {wxT("DARK SLATE BLUE"), 107, 35, 142},
+ {wxT("DARK SLATE BLUE"), 72, 61, 139},
{wxT("DARK SLATE GREY"), 47, 79, 79},
- {wxT("DARK TURQUOISE"), 112, 147, 219},
- {wxT("DIM GREY"), 84, 84, 84},
- {wxT("FIREBRICK"), 142, 35, 35},
- {wxT("FOREST GREEN"), 35, 142, 35},
- {wxT("GOLD"), 204, 127, 50},
- {wxT("GOLDENROD"), 219, 219, 112},
- {wxT("GREY"), 128, 128, 128},
+ {wxT("DARK TURQUOISE"), 0, 206, 209},
+ {wxT("DIM GREY"), 105, 105, 105},
+ {wxT("FIREBRICK"), 178, 34, 34},
+ {wxT("FOREST GREEN"), 34, 139, 34},
+ {wxT("GOLD"), 255, 215, 0},
+ {wxT("GOLDENROD"), 218, 165, 32},
+ {wxT("GREY"), 190, 190, 190},
{wxT("GREEN"), 0, 255, 0},
- {wxT("GREEN YELLOW"), 147, 219, 112},
- {wxT("INDIAN RED"), 79, 47, 47},
- {wxT("KHAKI"), 159, 159, 95},
- {wxT("LIGHT BLUE"), 191, 216, 216},
- {wxT("LIGHT GREY"), 192, 192, 192},
- {wxT("LIGHT STEEL BLUE"), 143, 143, 188},
- {wxT("LIME GREEN"), 50, 204, 50},
- {wxT("LIGHT MAGENTA"), 255, 0, 255},
+ {wxT("GREEN YELLOW"), 173, 255, 47},
+ {wxT("INDIAN RED"), 205, 92, 92},
+ {wxT("KHAKI"), 240, 230, 140},
+ {wxT("LIGHT BLUE"), 173, 216, 230},
+ {wxT("LIGHT GREY"), 211, 211, 211},
+ {wxT("LIGHT STEEL BLUE"), 176, 196, 222},
+ {wxT("LIME GREEN"), 50, 205, 50},
+ {wxT("LIGHT MAGENTA"), 255, 0, 255}, // not X colour
{wxT("MAGENTA"), 255, 0, 255},
- {wxT("MAROON"), 142, 35, 107},
- {wxT("MEDIUM AQUAMARINE"), 50, 204, 153},
- {wxT("MEDIUM GREY"), 100, 100, 100},
- {wxT("MEDIUM BLUE"), 50, 50, 204},
- {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
- {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
- {wxT("MEDIUM ORCHID"), 147, 112, 219},
- {wxT("MEDIUM SEA GREEN"), 66, 111, 66},
- {wxT("MEDIUM SLATE BLUE"), 127, 0, 255},
- {wxT("MEDIUM SPRING GREEN"), 127, 255, 0},
- {wxT("MEDIUM TURQUOISE"), 112, 219, 219},
- {wxT("MEDIUM VIOLET RED"), 219, 112, 147},
- {wxT("MIDNIGHT BLUE"), 47, 47, 79},
- {wxT("NAVY"), 35, 35, 142},
- {wxT("ORANGE"), 204, 50, 50},
- {wxT("ORANGE RED"), 255, 0, 127},
- {wxT("ORCHID"), 219, 112, 219},
- {wxT("PALE GREEN"), 143, 188, 143},
- {wxT("PINK"), 188, 143, 234},
- {wxT("PLUM"), 234, 173, 234},
- {wxT("PURPLE"), 176, 0, 255},
+ {wxT("MAROON"), 176, 48, 96},
+ {wxT("MEDIUM AQUAMARINE"), 102, 205, 170},
+ {wxT("MEDIUM GREY"), 100, 100, 100}, // not X colour
+ {wxT("MEDIUM BLUE"), 0, 0, 205},
+ {wxT("MEDIUM FOREST GREEN"), 107, 142, 35}, // not X colour
+ {wxT("MEDIUM GOLDENROD"), 234, 234, 173}, // not X colour
+ {wxT("MEDIUM ORCHID"), 186, 85, 211},
+ {wxT("MEDIUM SEA GREEN"), 60, 179, 113},
+ {wxT("MEDIUM SLATE BLUE"), 123, 104, 238},
+ {wxT("MEDIUM SPRING GREEN"), 0, 250, 154},
+ {wxT("MEDIUM TURQUOISE"), 72, 209, 204},
+ {wxT("MEDIUM VIOLET RED"), 199, 21, 133},
+ {wxT("MIDNIGHT BLUE"), 25, 25, 112},
+ {wxT("NAVY"), 0, 0, 128},
+ {wxT("ORANGE"), 255, 165, 0},
+ {wxT("ORANGE RED"), 255, 69, 0},
+ {wxT("ORCHID"), 218, 112, 214},
+ {wxT("PALE GREEN"), 152, 251, 152},
+ {wxT("PINK"), 255, 192, 203},
+ {wxT("PLUM"), 221, 160, 221},
+ {wxT("PURPLE"), 160, 32, 240},
{wxT("RED"), 255, 0, 0},
- {wxT("SALMON"), 111, 66, 66},
- {wxT("SEA GREEN"), 35, 142, 107},
- {wxT("SIENNA"), 142, 107, 35},
- {wxT("SKY BLUE"), 50, 153, 204},
- {wxT("SLATE BLUE"), 0, 127, 255},
+ {wxT("SALMON"), 250, 128, 114},
+ {wxT("SEA GREEN"), 46, 139, 87},
+ {wxT("SIENNA"), 160, 82, 45},
+ {wxT("SKY BLUE"), 135, 206, 235},
+ {wxT("SLATE BLUE"), 106, 90, 205},
{wxT("SPRING GREEN"), 0, 255, 127},
- {wxT("STEEL BLUE"), 35, 107, 142},
- {wxT("TAN"), 219, 147, 112},
+ {wxT("STEEL BLUE"), 70, 130, 180},
+ {wxT("TAN"), 210, 180, 140},
{wxT("THISTLE"), 216, 191, 216},
- {wxT("TURQUOISE"), 173, 234, 234},
- {wxT("VIOLET"), 79, 47, 79},
- {wxT("VIOLET RED"), 204, 50, 153},
- {wxT("WHEAT"), 216, 216, 191},
+ {wxT("TURQUOISE"), 64, 224, 208},
+ {wxT("VIOLET"), 238, 130, 238},
+ {wxT("VIOLET RED"), 208, 32, 144},
+ {wxT("WHEAT"), 245, 222, 179},
{wxT("WHITE"), 255, 255, 255},
{wxT("YELLOW"), 255, 255, 0},
- {wxT("YELLOW GREEN"), 153, 204, 50},
- {wxT("MEDIUM GOLDENROD"), 234, 234, 173},
- {wxT("MEDIUM FOREST GREEN"), 107, 142, 35},
- {wxT("LIGHT MAGENTA"), 255, 0, 255},
- {wxT("MEDIUM GREY"), 100, 100, 100},
+ {wxT("YELLOW GREEN"), 154, 205, 50},
};
size_t n;
for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
{
const wxColourDesc& cc = wxColourTable[n];
- Append(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];
*/
wxColour *wxColourDatabase::FindColour(const wxString& colour)
+{
+ return FindColour(colour, true);
+}
+
+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
// gray
if ( !colName2.Replace(_T("GRAY"), _T("GREY")) )
colName2.clear();
- wxNode *node = First();
- while ( node )
- {
- const wxChar *key = node->GetKeyString();
- if ( colName == key || colName2 == key )
- {
- return (wxColour *)node->Data();
- }
+ wxStringToColourHashMap::iterator it = m_map->find(colName);
+ if ( it == m_map->end() )
+ it = m_map->find(colName2);
+ if ( it != m_map->end() )
+ return it->second;
- node = node->Next();
- }
+ if ( !add )
+ return NULL;
#ifdef __WXMSW__
return NULL;
#ifdef __WXMAC__
return NULL;
#endif
+#ifdef __WXCOCOA__
+ return NULL;
+#endif
#ifdef __WXSTUBS__
return NULL;
#endif
#ifdef __WXGTK__
wxColour *col = new wxColour( colour );
- if (!(col->Ok())) {
+ if (!(col->Ok()))
+ {
delete col;
return (wxColour *) NULL;
}
- Append( colour, col );
+ AddColour(colour, col);
return col;
#endif
Display* display = (Display*) wxGetDisplay();
#endif
/* MATTHEW: [4] Use wxGetMainColormap */
- if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour,&xcolour))
+ if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour.ToAscii() ,&xcolour))
return NULL;
#if wxUSE_NANOX
#endif
wxColour *col = new wxColour(r, g, b);
- Append(colour, col);
+ AddColour(colour, col);
return col;
#endif // __X__
wxString wxColourDatabase::FindName (const wxColour& colour) const
{
- wxString name;
-
unsigned char red = colour.Red ();
unsigned char green = colour.Green ();
unsigned char blue = colour.Blue ();
- for (wxNode * node = First (); node; node = node->Next ())
+ typedef wxStringToColourHashMap::iterator iterator;
+
+ for (iterator it = m_map->begin(), en = m_map->end(); it != en; ++it )
{
- wxColour *col = (wxColour *) node->Data ();
+ wxColour *col = it->second;
if (col->Red () == red && col->Green () == green && col->Blue () == blue)
- {
- const wxChar *found = node->GetKeyString();
- if ( found )
- {
- name = found;
-
- break;
- }
- }
+ return it->first;
}
- return name;
+ return wxEmptyString;
}
void wxInitializeStockLists()
{
- wxTheBrushList = new wxBrushList;
- wxThePenList = new wxPenList;
- wxTheFontList = new wxFontList;
- wxTheBitmapList = new wxBitmapList;
+ wxTheColourDatabase = new wxColourDatabase;
+ wxTheColourDatabase->Initialize();
+
+ wxTheBrushList = new wxBrushList;
+ wxThePenList = new wxPenList;
+ wxTheFontList = new wxFontList;
+ wxTheBitmapList = new wxBitmapList;
}
void wxInitializeStockObjects ()
GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
sizeFont = fontSize ;
- p2cstrcpy( (char*) fontName , fontName ) ;
- wxSWISS_FONT = new wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , fontName );
+ wxSWISS_FONT = new wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , wxMacMakeStringFromPascal(fontName) );
#elif defined(__WXPM__)
static const int sizeFont = 12;
#else
wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxNORMAL);
wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
- p2cstrcpy( (char*) fontName , fontName ) ;
- wxSMALL_FONT = new wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , fontName );
+ wxSMALL_FONT = new wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , wxMacMakeStringFromPascal( fontName ) );
#else
wxSMALL_FONT = new wxFont (sizeFont - 2, wxSWISS, wxNORMAL, wxNORMAL);
wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
wxBitmapList::~wxBitmapList ()
{
- wxNode *node = First ();
+ wxList::compatibility_iterator node = GetFirst ();
while (node)
{
- wxBitmap *bitmap = (wxBitmap *) node->Data ();
- wxNode *next = node->Next ();
+ wxBitmap *bitmap = (wxBitmap *) node->GetData ();
+ wxList::compatibility_iterator next = node->GetNext ();
if (bitmap->GetVisible())
delete bitmap;
node = next;
// Pen and Brush lists
wxPenList::~wxPenList ()
{
- wxNode *node = First ();
+ wxList::compatibility_iterator node = GetFirst ();
while (node)
{
- wxPen *pen = (wxPen *) node->Data ();
- wxNode *next = node->Next ();
+ wxPen *pen = (wxPen *) node->GetData ();
+ wxList::compatibility_iterator next = node->GetNext ();
if (pen->GetVisible())
delete pen;
node = next;
wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style)
{
- for (wxNode * node = First (); node; node = node->Next ())
+ for (wxList::compatibility_iterator node = GetFirst (); node; node = node->GetNext ())
{
- wxPen *each_pen = (wxPen *) node->Data ();
+ wxPen *each_pen = (wxPen *) node->GetData ();
if (each_pen &&
each_pen->GetVisible() &&
each_pen->GetWidth () == width &&
wxBrushList::~wxBrushList ()
{
- wxNode *node = First ();
+ wxList::compatibility_iterator node = GetFirst ();
while (node)
{
- wxBrush *brush = (wxBrush *) node->Data ();
- wxNode *next = node->Next ();
+ wxBrush *brush = (wxBrush *) node->GetData ();
+ wxList::compatibility_iterator next = node->GetNext ();
if (brush && brush->GetVisible())
delete brush;
node = next;
wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style)
{
- for (wxNode * node = First (); node; node = node->Next ())
+ for (wxList::compatibility_iterator node = GetFirst (); node; node = node->GetNext ())
{
- wxBrush *each_brush = (wxBrush *) node->Data ();
+ wxBrush *each_brush = (wxBrush *) node->GetData ();
if (each_brush &&
each_brush->GetVisible() &&
each_brush->GetStyle () == style &&
wxFontList::~wxFontList ()
{
- wxNode *node = First ();
+ wxList::compatibility_iterator node = GetFirst ();
while (node)
{
// Only delete objects that are 'visible', i.e.
// that have been created using FindOrCreate...,
// where the pointers are expected to be shared
// (and therefore not deleted by any one part of an app).
- wxFont *font = (wxFont *) node->Data ();
- wxNode *next = node->Next ();
+ wxFont *font = (wxFont *) node->GetData ();
+ wxList::compatibility_iterator next = node->GetNext ();
if (font->GetVisible())
delete font;
node = next;
wxFontEncoding encoding)
{
wxFont *font = (wxFont *)NULL;
- wxNode *node;
- for ( node = First(); node; node = node->Next() )
+ wxList::compatibility_iterator node;
+ for ( node = GetFirst(); node; node = node->GetNext() )
{
- font = (wxFont *)node->Data();
+ font = (wxFont *)node->GetData();
if ( font->GetVisible() &&
font->Ok() &&
font->GetPointSize () == pointSize &&
wxResourceCache::~wxResourceCache ()
{
- wxNode *node = First ();
+ wxList::compatibility_iterator node = GetFirst ();
while (node) {
- wxObject *item = (wxObject *)node->Data();
+ wxObject *item = (wxObject *)node->GetData();
delete item;
- node = node->Next ();
+ node = node->GetNext ();
}
}