]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/palette.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/palette.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
22 #include "wx/palette.h"
25 #include "wx/msw/private.h"
27 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
)
34 wxPaletteRefData::wxPaletteRefData(void)
39 wxPaletteRefData::~wxPaletteRefData(void)
42 ::DeleteObject((HPALETTE
) m_hPalette
);
45 wxPalette::wxPalette(void)
49 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
51 Create(n
, red
, green
, blue
);
54 wxPalette::~wxPalette(void)
56 // FreeResource(true);
59 bool wxPalette::FreeResource(bool WXUNUSED(force
))
61 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
63 DeleteObject((HPALETTE
)M_PALETTEDATA
->m_hPalette
);
68 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
72 #if defined(__WXMICROWIN__)
78 m_refData
= new wxPaletteRefData
;
80 NPLOGPALETTE npPal
= (NPLOGPALETTE
)LocalAlloc(LMEM_FIXED
, sizeof(LOGPALETTE
) +
81 (WORD
)n
* sizeof(PALETTEENTRY
));
85 npPal
->palVersion
= 0x300;
86 npPal
->palNumEntries
= (WORD
)n
;
89 for (i
= 0; i
< n
; i
++)
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;
96 M_PALETTEDATA
->m_hPalette
= (WXHPALETTE
) CreatePalette((LPLOGPALETTE
)npPal
);
97 LocalFree((HANDLE
)npPal
);
103 int wxPalette::GetPixel(unsigned char red
, unsigned char green
, unsigned char blue
) const
105 #ifdef __WXMICROWIN__
111 return ::GetNearestPaletteIndex((HPALETTE
) M_PALETTEDATA
->m_hPalette
, PALETTERGB(red
, green
, blue
));
115 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
117 #ifdef __WXMICROWIN__
123 if (index
< 0 || index
> 255)
127 if (::GetPaletteEntries((HPALETTE
) M_PALETTEDATA
->m_hPalette
, index
, 1, &entry
))
130 *green
= entry
.peGreen
;
131 *blue
= entry
.peBlue
;
139 void wxPalette::SetHPALETTE(WXHPALETTE pal
)
142 m_refData
= new wxPaletteRefData
;
144 M_PALETTEDATA
->m_hPalette
= pal
;
147 #endif // wxUSE_PALETTE