]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/palette.cpp
gtk_signal_connect -> g_signal_connect in unix/mediactrl.cpp
[wxWidgets.git] / src / msw / palette.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/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
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#if wxUSE_PALETTE
20
21#ifndef WX_PRECOMP
22 #include "wx/palette.h"
23#endif
24
25#include "wx/msw/private.h"
26
27IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject)
28
29/*
30 * Palette
31 *
32 */
33
34wxPaletteRefData::wxPaletteRefData(void)
35{
36 m_hPalette = 0;
37}
38
39wxPaletteRefData::~wxPaletteRefData(void)
40{
41 if ( m_hPalette )
42 ::DeleteObject((HPALETTE) m_hPalette);
43}
44
45wxPalette::wxPalette(void)
46{
47}
48
49wxPalette::wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
50{
51 Create(n, red, green, blue);
52}
53
54wxPalette::~wxPalette(void)
55{
56// FreeResource(true);
57}
58
59bool wxPalette::FreeResource(bool WXUNUSED(force))
60{
61 if ( M_PALETTEDATA && M_PALETTEDATA->m_hPalette)
62 {
63 DeleteObject((HPALETTE)M_PALETTEDATA->m_hPalette);
64 }
65 return true;
66}
67
68bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
69{
70 UnRef();
71
72#if defined(__WXMICROWIN__)
73
74 return false;
75
76#else
77
78 m_refData = new wxPaletteRefData;
79
80 NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) +
81 (WORD)n * sizeof(PALETTEENTRY));
82 if (!npPal)
83 return false;
84
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;
99
100#endif
101}
102
103int wxPalette::GetPixel(unsigned char red, unsigned char green, unsigned char blue) const
104{
105#ifdef __WXMICROWIN__
106 return wxNOT_FOUND;
107#else
108 if ( !m_refData )
109 return wxNOT_FOUND;
110
111 return ::GetNearestPaletteIndex((HPALETTE) M_PALETTEDATA->m_hPalette, PALETTERGB(red, green, blue));
112#endif
113}
114
115bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsigned char *blue) const
116{
117#ifdef __WXMICROWIN__
118 return false;
119#else
120 if ( !m_refData )
121 return false;
122
123 if (index < 0 || index > 255)
124 return false;
125
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;
136#endif
137}
138
139void wxPalette::SetHPALETTE(WXHPALETTE pal)
140{
141 if ( !m_refData )
142 m_refData = new wxPaletteRefData;
143
144 M_PALETTEDATA->m_hPalette = pal;
145}
146
147#endif // wxUSE_PALETTE