]>
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"
21 #include "wx/palette.h"
26 #include "wx/msw/private.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
)
35 wxPaletteRefData::wxPaletteRefData(void)
40 wxPaletteRefData::~wxPaletteRefData(void)
43 ::DeleteObject((HPALETTE
) m_hPalette
);
46 wxPalette::wxPalette(void)
50 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
52 Create(n
, red
, green
, blue
);
55 wxPalette::~wxPalette(void)
57 // FreeResource(true);
60 bool wxPalette::FreeResource(bool WXUNUSED(force
))
62 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
64 DeleteObject((HPALETTE
)M_PALETTEDATA
->m_hPalette
);
69 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
73 #if defined(__WXMICROWIN__)
79 m_refData
= new wxPaletteRefData
;
81 NPLOGPALETTE npPal
= (NPLOGPALETTE
)LocalAlloc(LMEM_FIXED
, sizeof(LOGPALETTE
) +
82 (WORD
)n
* sizeof(PALETTEENTRY
));
86 npPal
->palVersion
= 0x300;
87 npPal
->palNumEntries
= (WORD
)n
;
90 for (i
= 0; i
< n
; i
++)
92 npPal
->palPalEntry
[i
].peRed
= red
[i
];
93 npPal
->palPalEntry
[i
].peGreen
= green
[i
];
94 npPal
->palPalEntry
[i
].peBlue
= blue
[i
];
95 npPal
->palPalEntry
[i
].peFlags
= 0;
97 M_PALETTEDATA
->m_hPalette
= (WXHPALETTE
) CreatePalette((LPLOGPALETTE
)npPal
);
98 LocalFree((HANDLE
)npPal
);
104 int wxPalette::GetPixel(unsigned char red
, unsigned char green
, unsigned char blue
) const
106 #ifdef __WXMICROWIN__
112 return ::GetNearestPaletteIndex((HPALETTE
) M_PALETTEDATA
->m_hPalette
, PALETTERGB(red
, green
, blue
));
116 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
118 #ifdef __WXMICROWIN__
124 if (index
< 0 || index
> 255)
128 if (::GetPaletteEntries((HPALETTE
) M_PALETTEDATA
->m_hPalette
, index
, 1, &entry
))
131 *green
= entry
.peGreen
;
132 *blue
= entry
.peBlue
;
140 void wxPalette::SetHPALETTE(WXHPALETTE pal
)
143 m_refData
= new wxPaletteRefData
;
145 M_PALETTEDATA
->m_hPalette
= pal
;
148 #endif // wxUSE_PALETTE