X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/373a5fb355f4023f96b14bbf8161cbd1de5b846e..e69d5138dc8f95e294ae6d03beb4f321406f4e34:/src/msw/palette.cpp diff --git a/src/msw/palette.cpp b/src/msw/palette.cpp index 0d46158e02..d72f0adc40 100644 --- a/src/msw/palette.cpp +++ b/src/msw/palette.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: palette.cpp +// Name: src/msw/palette.cpp // Purpose: wxPalette // Author: Julian Smart // Modified by: @@ -9,10 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "palette.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -22,8 +18,9 @@ #if wxUSE_PALETTE +#include "wx/palette.h" + #ifndef WX_PRECOMP - #include "wx/palette.h" #endif #include "wx/msw/private.h" @@ -37,7 +34,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject) wxPaletteRefData::wxPaletteRefData(void) { - m_hPalette = 0; + m_hPalette = 0; } wxPaletteRefData::~wxPaletteRefData(void) @@ -46,13 +43,13 @@ wxPaletteRefData::~wxPaletteRefData(void) ::DeleteObject((HPALETTE) m_hPalette); } -wxPalette::wxPalette(void) +wxPalette::wxPalette() { } wxPalette::wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue) { - Create(n, red, green, blue); + Create(n, red, green, blue); } wxPalette::~wxPalette(void) @@ -64,78 +61,90 @@ bool wxPalette::FreeResource(bool WXUNUSED(force)) { if ( M_PALETTEDATA && M_PALETTEDATA->m_hPalette) { - DeleteObject((HPALETTE)M_PALETTEDATA->m_hPalette); + DeleteObject((HPALETTE)M_PALETTEDATA->m_hPalette); } + return true; } +int wxPalette::GetColoursCount() const +{ + if ( M_PALETTEDATA && M_PALETTEDATA->m_hPalette) + { + return ::GetPaletteEntries((HPALETTE) M_PALETTEDATA->m_hPalette, 0, 0, NULL ); + } + + return 0; +} + bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue) { - UnRef(); + UnRef(); #if defined(__WXMICROWIN__) - return false; + return false; #else - m_refData = new wxPaletteRefData; + m_refData = new wxPaletteRefData; - NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) + - (WORD)n * sizeof(PALETTEENTRY)); - if (!npPal) - return false; + NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) + + (WORD)n * sizeof(PALETTEENTRY)); + if (!npPal) + return false; - npPal->palVersion = 0x300; - npPal->palNumEntries = (WORD)n; - - int i; - for (i = 0; i < n; i ++) - { - npPal->palPalEntry[i].peRed = red[i]; - npPal->palPalEntry[i].peGreen = green[i]; - npPal->palPalEntry[i].peBlue = blue[i]; - npPal->palPalEntry[i].peFlags = 0; - } - M_PALETTEDATA->m_hPalette = (WXHPALETTE) CreatePalette((LPLOGPALETTE)npPal); - LocalFree((HANDLE)npPal); - return true; + npPal->palVersion = 0x300; + npPal->palNumEntries = (WORD)n; + + int i; + for (i = 0; i < n; i ++) + { + npPal->palPalEntry[i].peRed = red[i]; + npPal->palPalEntry[i].peGreen = green[i]; + npPal->palPalEntry[i].peBlue = blue[i]; + npPal->palPalEntry[i].peFlags = 0; + } + M_PALETTEDATA->m_hPalette = (WXHPALETTE) CreatePalette((LPLOGPALETTE)npPal); + LocalFree((HANDLE)npPal); + return true; #endif } -int wxPalette::GetPixel(const unsigned char red, const unsigned char green, const unsigned char blue) const +int wxPalette::GetPixel(unsigned char red, unsigned char green, unsigned char blue) const { #ifdef __WXMICROWIN__ - return 0; + return wxNOT_FOUND; #else - if ( !m_refData ) - return 0; + if ( !m_refData ) + return wxNOT_FOUND; - return ::GetNearestPaletteIndex((HPALETTE) M_PALETTEDATA->m_hPalette, PALETTERGB(red, green, blue)); + return ::GetNearestPaletteIndex((HPALETTE) M_PALETTEDATA->m_hPalette, PALETTERGB(red, green, blue)); #endif } bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsigned char *blue) const { #ifdef __WXMICROWIN__ - return false; -#else - if ( !m_refData ) return false; +#else + if ( !m_refData ) + return false; + + if (index < 0 || index > 255) + return false; - if (index < 0 || index > 255) - return false; - - PALETTEENTRY entry; - if (::GetPaletteEntries((HPALETTE) M_PALETTEDATA->m_hPalette, index, 1, &entry)) - { - *red = entry.peRed; - *green = entry.peGreen; - *blue = entry.peBlue; - return true; - } else - return false; + PALETTEENTRY entry; + if (::GetPaletteEntries((HPALETTE) M_PALETTEDATA->m_hPalette, index, 1, &entry)) + { + *red = entry.peRed; + *green = entry.peGreen; + *blue = entry.peBlue; + return true; + } + else + return false; #endif } @@ -148,4 +157,3 @@ void wxPalette::SetHPALETTE(WXHPALETTE pal) } #endif // wxUSE_PALETTE -