X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f97c985452b20a8c2f0bbfb1d0275298bf09fb45..e1910715af0629ad65976e87cdeca23ede2fd6ee:/src/motif/palette.cpp diff --git a/src/motif/palette.cpp b/src/motif/palette.cpp index 58262fb1be..ef2b2597a6 100644 --- a/src/motif/palette.cpp +++ b/src/motif/palette.cpp @@ -6,7 +6,7 @@ // Created: 17/09/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// /* @@ -17,7 +17,7 @@ * in Create(). The cells are freed on the next call to Create() * or when the destructor is called. */ - + /* Wolfram Gloger I have implemented basic colormap support for the X11 versions of wxWindows, notably wxPalette::Create(). The way I did it is to @@ -43,18 +43,22 @@ not the functionality that wxPalette::Create() aims to provide. #include "wx/app.h" #include "wx/utils.h" +#ifdef __VMS__ +#pragma message disable nosimpint +#endif #include +#ifdef __VMS__ +#pragma message enable nosimpint +#endif #include "wx/motif/private.h" -#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxXPalette, wxObject) -#endif /* - * Palette - * - */ +* Palette +* +*/ wxXPalette::wxXPalette() { @@ -71,39 +75,38 @@ wxPaletteRefData::wxPaletteRefData() wxPaletteRefData::~wxPaletteRefData() { - XColor xcol; - Display *display = (Display*) NULL; - - wxNode *node, *next; - - for (node = m_palettes.First(); node; node = next) { - wxXPalette *c = (wxXPalette *)node->Data(); - unsigned long *pix_array = c->m_pix_array; - Colormap cmap = (Colormap) c->m_cmap; - bool destroyable = c->m_destroyable; - int pix_array_n = c->m_pix_array_n; - display = (Display*) c->m_display; - - if (pix_array_n > 0) - { -// XFreeColors(display, cmap, pix_array, pix_array_n, 0); - // Be careful not to free '0' pixels... - int i, j; - for(i=j=0; i i) XFreeColors(display, cmap, &pix_array[i], j-i, 0); - while(jNext(); - m_palettes.DeleteNode(node); - delete c; - } + for (node = m_palettes.First(); node; node = next) { + wxXPalette *c = (wxXPalette *)node->Data(); + unsigned long *pix_array = c->m_pix_array; + Colormap cmap = (Colormap) c->m_cmap; + bool destroyable = c->m_destroyable; + int pix_array_n = c->m_pix_array_n; + display = (Display*) c->m_display; + + if (pix_array_n > 0) + { + // XFreeColors(display, cmap, pix_array, pix_array_n, 0); + // Be careful not to free '0' pixels... + int i, j; + for(i=j=0; i i) XFreeColors(display, cmap, &pix_array[i], j-i, 0); + while(jNext(); + m_palettes.DeleteNode(node); + delete c; + } } wxPalette::wxPalette() @@ -121,61 +124,61 @@ wxPalette::~wxPalette() bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue) { - UnRef(); + UnRef(); - if (!n) { - return FALSE; - } + if (!n) { + return FALSE; + } - m_refData = new wxPaletteRefData; + m_refData = new wxPaletteRefData; - XColor xcol; - Display* display = (Display*) wxGetDisplay(); + XColor xcol; + Display* display = (Display*) wxGetDisplay(); - unsigned long *pix_array; - Colormap cmap; - int pix_array_n; + unsigned long *pix_array; + Colormap cmap; + int pix_array_n; - cmap = (Colormap) wxTheApp->GetMainColormap(display); + cmap = (Colormap) wxTheApp->GetMainColormap(display); - pix_array = new unsigned long[n]; - if (!pix_array) - return FALSE; + pix_array = new unsigned long[n]; + if (!pix_array) + return FALSE; - pix_array_n = n; - xcol.flags = DoRed | DoGreen | DoBlue; - for(int i = 0; i < n; i++) { - xcol.red = (unsigned short)red[i] << 8; - xcol.green = (unsigned short)green[i] << 8; - xcol.blue = (unsigned short)blue[i] << 8; - pix_array[i] = (XAllocColor(display, cmap, &xcol) == 0) ? 0 : xcol.pixel; - } - - wxXPalette *c = new wxXPalette; - - c->m_pix_array_n = pix_array_n; - c->m_pix_array = pix_array; - c->m_cmap = (WXColormap) cmap; - c->m_display = (WXDisplay*) display; - c->m_destroyable = FALSE; - M_PALETTEDATA->m_palettes.Append(c); - - return TRUE; + pix_array_n = n; + xcol.flags = DoRed | DoGreen | DoBlue; + for(int i = 0; i < n; i++) { + xcol.red = (unsigned short)red[i] << 8; + xcol.green = (unsigned short)green[i] << 8; + xcol.blue = (unsigned short)blue[i] << 8; + pix_array[i] = (XAllocColor(display, cmap, &xcol) == 0) ? 0 : xcol.pixel; + } + + wxXPalette *c = new wxXPalette; + + c->m_pix_array_n = pix_array_n; + c->m_pix_array = pix_array; + c->m_cmap = (WXColormap) cmap; + c->m_display = (WXDisplay*) display; + c->m_destroyable = FALSE; + M_PALETTEDATA->m_palettes.Append(c); + + return TRUE; } int wxPalette::GetPixel(const unsigned char red, const unsigned char green, const unsigned char blue) const { if ( !m_refData ) - return FALSE; + return FALSE; // TODO return FALSE; } -bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsigned char *blue) const +bool wxPalette::GetRGB(int index, unsigned char *WXUNUSED(red), unsigned char *WXUNUSED(green), unsigned char *WXUNUSED(blue)) const { if ( !m_refData ) - return FALSE; + return FALSE; if (index < 0 || index > 255) return FALSE; @@ -209,7 +212,7 @@ WXColormap wxPalette::GetXColormap(WXDisplay* display) const wxXPalette *first = (wxXPalette *)M_PALETTEDATA->m_palettes.First()->Data(); 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; @@ -235,77 +238,77 @@ WXColormap wxPalette::GetXColormap(WXDisplay* display) const 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++; + 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; } - - return TRUE; - } - default: - return FALSE; - } } bool wxPalette::TransferBitmap8(unsigned char *data, unsigned long sz, - void *dest, unsigned int bpp) + void *dest, unsigned int bpp) { - int pix_array_n; - unsigned long *pix_array = GetXPixArray((Display*) wxGetDisplay(), &pix_array_n); + 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; - } + 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; - } + 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 = pix_array[*data] & 0xFF; - dptr->g = (pix_array[*data] >> 8) & 0xFF; - dptr->b = (pix_array[*data] >> 16) & 0xFF; + struct rgb24 { unsigned char r, g, b; } *dptr = (struct rgb24 *)dest; + while(sz-- > 0) { + if((int)*data < pix_array_n) { + dptr->r = pix_array[*data] & 0xFF; + dptr->g = (pix_array[*data] >> 8) & 0xFF; + dptr->b = (pix_array[*data] >> 16) & 0xFF; + } + data++; + dptr++; } - data++; - dptr++; - } - break; - } + 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; - } + 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 FALSE; } return TRUE; } @@ -326,7 +329,7 @@ unsigned long *wxPalette::GetXPixArray(WXDisplay *display, int *n) return c->m_pix_array; } } - + /* Not found; call GetXColormap, which will create it, then this again */ if (GetXColormap(display)) return GetXPixArray(display, n);