]> git.saurik.com Git - wxWidgets.git/blame - src/msw/palette.cpp
Added missing wx_aui.dsp file
[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
559a723c
WS
21#include "wx/palette.h"
22
2bda0e17 23#ifndef WX_PRECOMP
2bda0e17
KB
24#endif
25
d275c7eb 26#include "wx/msw/private.h"
2bda0e17 27
2bda0e17 28IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject)
2bda0e17
KB
29
30/*
31 * Palette
32 *
33 */
34
35wxPaletteRefData::wxPaletteRefData(void)
36{
88ef3a57 37 m_hPalette = 0;
2bda0e17
KB
38}
39
40wxPaletteRefData::~wxPaletteRefData(void)
41{
d275c7eb
VZ
42 if ( m_hPalette )
43 ::DeleteObject((HPALETTE) m_hPalette);
2bda0e17
KB
44}
45
46wxPalette::wxPalette(void)
47{
48}
49
debe6624 50wxPalette::wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
2bda0e17
KB
51{
52 Create(n, red, green, blue);
53}
54
55wxPalette::~wxPalette(void)
56{
078cf5cb 57// FreeResource(true);
2bda0e17
KB
58}
59
33ac7e6f 60bool wxPalette::FreeResource(bool WXUNUSED(force))
2bda0e17 61{
d275c7eb
VZ
62 if ( M_PALETTEDATA && M_PALETTEDATA->m_hPalette)
63 {
2bda0e17 64 DeleteObject((HPALETTE)M_PALETTEDATA->m_hPalette);
d275c7eb 65 }
078cf5cb 66 return true;
2bda0e17
KB
67}
68
debe6624 69bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
2bda0e17 70{
88ef3a57 71 UnRef();
2bda0e17 72
b4da152e 73#if defined(__WXMICROWIN__)
5ea105e0 74
88ef3a57 75 return false;
33ac7e6f 76
5ea105e0
RR
77#else
78
88ef3a57 79 m_refData = new wxPaletteRefData;
2bda0e17 80
88ef3a57
WS
81 NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) +
82 (WORD)n * sizeof(PALETTEENTRY));
83 if (!npPal)
84 return false;
2bda0e17 85
88ef3a57
WS
86 npPal->palVersion = 0x300;
87 npPal->palNumEntries = (WORD)n;
88
89 int i;
90 for (i = 0; i < n; i ++)
91 {
92 npPal->palPalEntry[i].peRed = red[i];
93 npPal->palPalEntry[i].peGreen = green[i];
94 npPal->palPalEntry[i].peBlue = blue[i];
95 npPal->palPalEntry[i].peFlags = 0;
96 }
97 M_PALETTEDATA->m_hPalette = (WXHPALETTE) CreatePalette((LPLOGPALETTE)npPal);
98 LocalFree((HANDLE)npPal);
99 return true;
33ac7e6f 100
5ea105e0 101#endif
2bda0e17
KB
102}
103
88ef3a57 104int wxPalette::GetPixel(unsigned char red, unsigned char green, unsigned char blue) const
2bda0e17 105{
04ef50df 106#ifdef __WXMICROWIN__
88ef3a57 107 return wxNOT_FOUND;
04ef50df 108#else
88ef3a57
WS
109 if ( !m_refData )
110 return wxNOT_FOUND;
2bda0e17 111
88ef3a57 112 return ::GetNearestPaletteIndex((HPALETTE) M_PALETTEDATA->m_hPalette, PALETTERGB(red, green, blue));
04ef50df 113#endif
2bda0e17
KB
114}
115
debe6624 116bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsigned char *blue) const
2bda0e17 117{
04ef50df 118#ifdef __WXMICROWIN__
078cf5cb 119 return false;
88ef3a57
WS
120#else
121 if ( !m_refData )
122 return false;
123
124 if (index < 0 || index > 255)
125 return false;
2bda0e17 126
88ef3a57
WS
127 PALETTEENTRY entry;
128 if (::GetPaletteEntries((HPALETTE) M_PALETTEDATA->m_hPalette, index, 1, &entry))
129 {
130 *red = entry.peRed;
131 *green = entry.peGreen;
132 *blue = entry.peBlue;
133 return true;
134 }
135 else
136 return false;
04ef50df 137#endif
2bda0e17
KB
138}
139
140void wxPalette::SetHPALETTE(WXHPALETTE pal)
141{
d275c7eb
VZ
142 if ( !m_refData )
143 m_refData = new wxPaletteRefData;
2bda0e17
KB
144
145 M_PALETTEDATA->m_hPalette = pal;
146}
147
d275c7eb 148#endif // wxUSE_PALETTE