]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/palette.cpp
correcting Drag Data handling for 'TEXT' and 'utxt'
[wxWidgets.git] / src / mac / carbon / palette.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: palette.cpp
3// Purpose: wxPalette
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "palette.h"
14#endif
15
3d1a4878 16#include "wx/wxprec.h"
fedad417
GD
17
18#if wxUSE_PALETTE
19
e9576ca5
SC
20#include "wx/palette.h"
21
e9576ca5 22IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject)
e9576ca5
SC
23
24/*
25 * Palette
26 *
27 */
28
29wxPaletteRefData::wxPaletteRefData()
30{
e40298d5
JS
31 m_palette = NULL ;
32 m_count = 0 ;
e9576ca5
SC
33}
34
35wxPaletteRefData::~wxPaletteRefData()
36{
f5bb2251
GD
37 if (m_palette != NULL) {
38 delete[] m_palette ;
39 m_palette = NULL;
40 }
e9576ca5
SC
41}
42
43wxPalette::wxPalette()
44{
45}
46
47wxPalette::wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
48{
49 Create(n, red, green, blue);
50}
51
52wxPalette::~wxPalette()
53{
54}
55
56bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue)
57{
e40298d5
JS
58 UnRef();
59
60 m_refData = new wxPaletteRefData;
61
62 M_PALETTEDATA->m_count = n ;
63 M_PALETTEDATA->m_palette = new wxColour[n] ;
64
65 for ( int i = 0 ; i < n ; ++i)
66 {
67 M_PALETTEDATA->m_palette[i].Set( red[i] , green[i] , blue[i] ) ;
68 }
69
70 return FALSE;
e9576ca5
SC
71}
72
73int wxPalette::GetPixel(const unsigned char red, const unsigned char green, const unsigned char blue) const
74{
75 if ( !m_refData )
e40298d5
JS
76 return -1;
77
519cb848
SC
78 long bestdiff = 3 * 256 ;
79 long bestpos = 0 ;
80 long currentdiff ;
81
82 for ( int i = 0 ; i < M_PALETTEDATA->m_count ; ++i )
83 {
4b524c27 84 const wxColour& col = M_PALETTEDATA->m_palette[i] ;
e40298d5
JS
85 currentdiff = abs ( col.Red() - red ) + abs( col.Green() - green ) + abs ( col.Blue() - blue ) ;
86 if ( currentdiff < bestdiff )
87 {
88 bestdiff = currentdiff ;
89 bestpos = i ;
90 if ( bestdiff == 0 )
91 break ;
92 }
519cb848
SC
93 }
94
95 return bestpos;
e9576ca5
SC
96}
97
98bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsigned char *blue) const
99{
100 if ( !m_refData )
e40298d5
JS
101 return FALSE;
102
519cb848 103 if (index < 0 || index >= M_PALETTEDATA->m_count)
e9576ca5 104 return FALSE;
e40298d5 105
4b524c27 106 const wxColour& col = M_PALETTEDATA->m_palette[index] ;
519cb848
SC
107 *red = col.Red() ;
108 *green = col.Green() ;
109 *blue = col.Blue() ;
110
111 return TRUE;
e9576ca5
SC
112}
113
fedad417 114#endif
e40298d5 115// wxUSE_PALETTE
e9576ca5 116