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