+ return false;
+}
+
+WXColormap wxPalette::GetXColormap(WXDisplay* display) const
+{
+ if (!M_PALETTEDATA || (M_PALETTEDATA->m_palettes.GetCount() == 0))
+ return wxTheApp->GetMainColormap(display);
+
+ wxList::compatibility_iterator node = M_PALETTEDATA->m_palettes.GetFirst();
+ if (!display && node)
+ {
+ wxXPalette* p = (wxXPalette*) node->GetData();
+ return p->m_cmap;
+ }
+ while (node)
+ {
+ wxXPalette* p = (wxXPalette*) node->GetData();
+ if (p->m_display == display)
+ return p->m_cmap;
+
+ node = node->GetNext();
+ }
+
+ /* Make a new one: */
+ wxXPalette *c = new wxXPalette;
+ wxXPalette *first =
+ (wxXPalette *)M_PALETTEDATA->m_palettes.GetFirst()->GetData();
+ XColor xcol;
+ int pix_array_n = first->m_pix_array_n;
+
+ c->m_pix_array_n = pix_array_n;
+ c->m_pix_array = new unsigned long[pix_array_n];
+ c->m_display = display;
+ c->m_cmap = wxTheApp->GetMainColormap(display);
+ c->m_destroyable = false;
+
+ xcol.flags = DoRed | DoGreen | DoBlue;
+ int i;
+ for (i = 0; i < pix_array_n; i++)
+ {
+ xcol.pixel = first->m_pix_array[i];
+ XQueryColor((Display*) first->m_display,
+ (Colormap) first->m_cmap, &xcol);
+ c->m_pix_array[i] =
+ (XAllocColor((Display*) display, (Colormap) c->m_cmap, &xcol) == 0)
+ ? 0 : xcol.pixel;
+ }
+
+ // wxPalette* nonConstThis = (wxPalette*) this;
+
+ M_PALETTEDATA->m_palettes.Append(c);
+
+ return c->m_cmap;
+}
+
+bool wxPalette::TransferBitmap(void *data, int depth, int size)
+{
+ switch(depth) {
+ case 8:
+ {
+ unsigned char *uptr = (unsigned char *)data;
+ int pix_array_n;
+ unsigned long *pix_array = GetXPixArray((Display*) wxGetDisplay(), &pix_array_n);
+ while(size-- > 0)
+ {
+ if((int)*uptr < pix_array_n)
+ *uptr = (unsigned char)pix_array[*uptr];
+ uptr++;
+ }
+
+ return true;
+ }
+ default:
+ return false;
+ }
+}
+
+bool wxPalette::TransferBitmap8(unsigned char *data, unsigned long sz,
+ void *dest, unsigned int bpp)
+{
+ int pix_array_n;
+ unsigned long *pix_array = GetXPixArray((Display*) wxGetDisplay(), &pix_array_n);
+ switch(bpp) {
+ case 8: {
+ unsigned char *dptr = (unsigned char *)dest;
+ while(sz-- > 0) {
+ if((int)*data < pix_array_n)
+ *dptr = (unsigned char)pix_array[*data];
+ data++;
+ dptr++;
+ }
+ break;
+ }
+ case 16: {
+ unsigned short *dptr = (unsigned short *)dest;
+ while(sz-- > 0) {
+ if((int)*data < pix_array_n)
+ *dptr = (unsigned short)pix_array[*data];
+ data++;
+ dptr++;
+ }
+ break;
+ }
+ case 24: {
+ struct rgb24 { unsigned char r, g, b; } *dptr = (struct rgb24 *)dest;
+ while(sz-- > 0) {
+ if((int)*data < pix_array_n) {
+ dptr->r = (unsigned char)(pix_array[*data] & 0xFF);
+ dptr->g = (unsigned char)((pix_array[*data] >> 8) & 0xFF);
+ dptr->b = (unsigned char)((pix_array[*data] >> 16) & 0xFF);
+ }
+ data++;
+ dptr++;
+ }
+ break;
+ }
+ case 32: {
+ unsigned long *dptr = (unsigned long *)dest;
+ while(sz-- > 0) {
+ if((int)*data < pix_array_n)
+ *dptr = pix_array[*data];
+ data++;
+ dptr++;
+ }
+ break;
+ }
+ default:
+ return false;
+ }
+ return true;