]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/palette.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "palette.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/palette.h"
29 #include "wx/msw/private.h"
31 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
)
38 wxPaletteRefData::wxPaletteRefData(void)
43 wxPaletteRefData::~wxPaletteRefData(void)
46 ::DeleteObject((HPALETTE
) m_hPalette
);
49 wxPalette::wxPalette(void)
53 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
55 Create(n
, red
, green
, blue
);
58 wxPalette::~wxPalette(void)
60 // FreeResource(TRUE);
63 bool wxPalette::FreeResource(bool WXUNUSED(force
))
65 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
67 DeleteObject((HPALETTE
)M_PALETTEDATA
->m_hPalette
);
72 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
76 #if defined(__WXMICROWIN__)
82 m_refData
= new wxPaletteRefData
;
84 NPLOGPALETTE npPal
= (NPLOGPALETTE
)LocalAlloc(LMEM_FIXED
, sizeof(LOGPALETTE
) +
85 (WORD
)n
* sizeof(PALETTEENTRY
));
89 npPal
->palVersion
= 0x300;
90 npPal
->palNumEntries
= n
;
93 for (i
= 0; i
< n
; i
++)
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;
100 M_PALETTEDATA
->m_hPalette
= (WXHPALETTE
) CreatePalette((LPLOGPALETTE
)npPal
);
101 LocalFree((HANDLE
)npPal
);
107 int wxPalette::GetPixel(const unsigned char red
, const unsigned char green
, const unsigned char blue
) const
109 #ifdef __WXMICROWIN__
115 return ::GetNearestPaletteIndex((HPALETTE
) M_PALETTEDATA
->m_hPalette
, PALETTERGB(red
, green
, blue
));
119 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
121 #ifdef __WXMICROWIN__
127 if (index
< 0 || index
> 255)
131 if (::GetPaletteEntries((HPALETTE
) M_PALETTEDATA
->m_hPalette
, index
, 1, &entry
))
134 *green
= entry
.peGreen
;
135 *blue
= entry
.peBlue
;
142 void wxPalette::SetHPALETTE(WXHPALETTE pal
)
145 m_refData
= new wxPaletteRefData
;
147 M_PALETTEDATA
->m_hPalette
= pal
;
150 #endif // wxUSE_PALETTE