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