]> git.saurik.com Git - wxWidgets.git/blame - src/msw/palette.cpp
Remove the busy-wait loops in wxAMMediaBackend::Play as they didn't
[wxWidgets.git] / src / msw / palette.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
88ef3a57 2// Name: src/msw/palette.cpp
2bda0e17
KB
3// Purpose: wxPalette
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
2bda0e17
KB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
d275c7eb 16 #pragma hdrstop
2bda0e17
KB
17#endif
18
d275c7eb
VZ
19#if wxUSE_PALETTE
20
2bda0e17 21#ifndef WX_PRECOMP
d275c7eb 22 #include "wx/palette.h"
2bda0e17
KB
23#endif
24
d275c7eb 25#include "wx/msw/private.h"
2bda0e17 26
2bda0e17 27IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject)
2bda0e17
KB
28
29/*
30 * Palette
31 *
32 */
33
34wxPaletteRefData::wxPaletteRefData(void)
35{
88ef3a57 36 m_hPalette = 0;
2bda0e17
KB
37}
38
39wxPaletteRefData::~wxPaletteRefData(void)
40{
d275c7eb
VZ
41 if ( m_hPalette )
42 ::DeleteObject((HPALETTE) m_hPalette);
2bda0e17
KB
43}
44
45wxPalette::wxPalette(void)
46{
47}
48
debe6624 49wxPalette::wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
2bda0e17
KB
50{
51 Create(n, red, green, blue);
52}
53
54wxPalette::~wxPalette(void)
55{
078cf5cb 56// FreeResource(true);
2bda0e17
KB
57}
58
33ac7e6f 59bool wxPalette::FreeResource(bool WXUNUSED(force))
2bda0e17 60{
d275c7eb
VZ
61 if ( M_PALETTEDATA && M_PALETTEDATA->m_hPalette)
62 {
2bda0e17 63 DeleteObject((HPALETTE)M_PALETTEDATA->m_hPalette);
d275c7eb 64 }
078cf5cb 65 return true;
2bda0e17
KB
66}
67
debe6624 68bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
2bda0e17 69{
88ef3a57 70 UnRef();
2bda0e17 71
b4da152e 72#if defined(__WXMICROWIN__)
5ea105e0 73
88ef3a57 74 return false;
33ac7e6f 75
5ea105e0
RR
76#else
77
88ef3a57 78 m_refData = new wxPaletteRefData;
2bda0e17 79
88ef3a57
WS
80 NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) +
81 (WORD)n * sizeof(PALETTEENTRY));
82 if (!npPal)
83 return false;
2bda0e17 84
88ef3a57
WS
85 npPal->palVersion = 0x300;
86 npPal->palNumEntries = (WORD)n;
87
88 int i;
89 for (i = 0; i < n; i ++)
90 {
91 npPal->palPalEntry[i].peRed = red[i];
92 npPal->palPalEntry[i].peGreen = green[i];
93 npPal->palPalEntry[i].peBlue = blue[i];
94 npPal->palPalEntry[i].peFlags = 0;
95 }
96 M_PALETTEDATA->m_hPalette = (WXHPALETTE) CreatePalette((LPLOGPALETTE)npPal);
97 LocalFree((HANDLE)npPal);
98 return true;
33ac7e6f 99
5ea105e0 100#endif
2bda0e17
KB
101}
102
88ef3a57 103int wxPalette::GetPixel(unsigned char red, unsigned char green, unsigned char blue) const
2bda0e17 104{
04ef50df 105#ifdef __WXMICROWIN__
88ef3a57 106 return wxNOT_FOUND;
04ef50df 107#else
88ef3a57
WS
108 if ( !m_refData )
109 return wxNOT_FOUND;
2bda0e17 110
88ef3a57 111 return ::GetNearestPaletteIndex((HPALETTE) M_PALETTEDATA->m_hPalette, PALETTERGB(red, green, blue));
04ef50df 112#endif
2bda0e17
KB
113}
114
debe6624 115bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsigned char *blue) const
2bda0e17 116{
04ef50df 117#ifdef __WXMICROWIN__
078cf5cb 118 return false;
88ef3a57
WS
119#else
120 if ( !m_refData )
121 return false;
122
123 if (index < 0 || index > 255)
124 return false;
2bda0e17 125
88ef3a57
WS
126 PALETTEENTRY entry;
127 if (::GetPaletteEntries((HPALETTE) M_PALETTEDATA->m_hPalette, index, 1, &entry))
128 {
129 *red = entry.peRed;
130 *green = entry.peGreen;
131 *blue = entry.peBlue;
132 return true;
133 }
134 else
135 return false;
04ef50df 136#endif
2bda0e17
KB
137}
138
139void wxPalette::SetHPALETTE(WXHPALETTE pal)
140{
d275c7eb
VZ
141 if ( !m_refData )
142 m_refData = new wxPaletteRefData;
2bda0e17
KB
143
144 M_PALETTEDATA->m_hPalette = pal;
145}
146
d275c7eb 147#endif // wxUSE_PALETTE