]>
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()
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
);
70 int wxPalette::GetColoursCount() const
72 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
74 return ::GetPaletteEntries((HPALETTE
) M_PALETTEDATA
->m_hPalette
, 0, 0, NULL
);
80 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
84 #if defined(__WXMICROWIN__)
90 m_refData
= new wxPaletteRefData
;
92 NPLOGPALETTE npPal
= (NPLOGPALETTE
)LocalAlloc(LMEM_FIXED
, sizeof(LOGPALETTE
) +
93 (WORD
)n
* sizeof(PALETTEENTRY
));
97 npPal
->palVersion
= 0x300;
98 npPal
->palNumEntries
= (WORD
)n
;
101 for (i
= 0; i
< n
; i
++)
103 npPal
->palPalEntry
[i
].peRed
= red
[i
];
104 npPal
->palPalEntry
[i
].peGreen
= green
[i
];
105 npPal
->palPalEntry
[i
].peBlue
= blue
[i
];
106 npPal
->palPalEntry
[i
].peFlags
= 0;
108 M_PALETTEDATA
->m_hPalette
= (WXHPALETTE
) CreatePalette((LPLOGPALETTE
)npPal
);
109 LocalFree((HANDLE
)npPal
);
115 int wxPalette::GetPixel(unsigned char red
, unsigned char green
, unsigned char blue
) const
117 #ifdef __WXMICROWIN__
123 return ::GetNearestPaletteIndex((HPALETTE
) M_PALETTEDATA
->m_hPalette
, PALETTERGB(red
, green
, blue
));
127 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
129 #ifdef __WXMICROWIN__
135 if (index
< 0 || index
> 255)
139 if (::GetPaletteEntries((HPALETTE
) M_PALETTEDATA
->m_hPalette
, index
, 1, &entry
))
142 *green
= entry
.peGreen
;
143 *blue
= entry
.peBlue
;
151 void wxPalette::SetHPALETTE(WXHPALETTE pal
)
154 m_refData
= new wxPaletteRefData
;
156 M_PALETTEDATA
->m_hPalette
= pal
;
159 #endif // wxUSE_PALETTE