X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2d120f8391920145647ec10e84629bc21fa9f1bb..8d36b2167df7e86ecfc58d148eaf6abe0a5b7971:/src/motif/palette.cpp diff --git a/src/motif/palette.cpp b/src/motif/palette.cpp index 450c691097..2fef69d376 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,13 +17,13 @@ * 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 +wxWidgets, notably wxPalette::Create(). The way I did it is to allocate additional read-only color cells in the default colormap. In general you will get arbitrary pixel values assigned to these new -cells and therefore I added a method wxColourMap::TransferBitmap() +cells and therefore I added a method wxPalette::TransferBitmap() which maps the pixel values 0..n to the real ones obtained with Create(). This is only implemented for the popular case of 8-bit depth. @@ -34,22 +34,29 @@ recommended; only the window manager should do this... Also, it is not the functionality that wxPalette::Create() aims to provide. */ -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "palette.h" #endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + #include "wx/palette.h" #include "wx/window.h" #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 @@ -62,7 +69,7 @@ wxXPalette::wxXPalette() m_pix_array_n = 0; m_pix_array = (unsigned long*) 0; m_display = (WXDisplay*) 0; - m_destroyable = FALSE; + m_destroyable = false; } wxPaletteRefData::wxPaletteRefData() @@ -71,19 +78,18 @@ 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(); + + wxList::compatibility_iterator node, next; + + for (node = m_palettes.GetFirst(); node; node = next) { + wxXPalette *c = (wxXPalette *)node->GetData(); 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); @@ -96,12 +102,12 @@ wxPaletteRefData::~wxPaletteRefData() } delete [] pix_array; } - + if (destroyable) XFreeColormap(display, cmap); - - next = node->Next(); - m_palettes.DeleteNode(node); + + next = node->GetNext(); + m_palettes.Erase(node); delete c; } } @@ -122,26 +128,26 @@ wxPalette::~wxPalette() bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue) { UnRef(); - + if (!n) { - return FALSE; + return false; } - + m_refData = new wxPaletteRefData; - + XColor xcol; Display* display = (Display*) wxGetDisplay(); - + unsigned long *pix_array; Colormap cmap; int pix_array_n; - + cmap = (Colormap) wxTheApp->GetMainColormap(display); - + pix_array = new unsigned long[n]; if (!pix_array) - return FALSE; - + return false; + pix_array_n = n; xcol.flags = DoRed | DoGreen | DoBlue; for(int i = 0; i < n; i++) { @@ -150,86 +156,89 @@ bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *gre 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; + c->m_destroyable = false; M_PALETTEDATA->m_palettes.Append(c); - - return TRUE; + + 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; + 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; - + return false; + // TODO - return FALSE; + return false; } WXColormap wxPalette::GetXColormap(WXDisplay* display) const { - if (!M_PALETTEDATA || (M_PALETTEDATA->m_palettes.Number() == 0)) + if (!M_PALETTEDATA || (M_PALETTEDATA->m_palettes.GetCount() == 0)) return wxTheApp->GetMainColormap(display); - - wxNode* node = M_PALETTEDATA->m_palettes.First(); + + wxList::compatibility_iterator node = M_PALETTEDATA->m_palettes.GetFirst(); if (!display && node) { - wxXPalette* p = (wxXPalette*) node->Data(); + wxXPalette* p = (wxXPalette*) node->GetData(); return p->m_cmap; } while (node) { - wxXPalette* p = (wxXPalette*) node->Data(); + wxXPalette* p = (wxXPalette*) node->GetData(); if (p->m_display == display) return p->m_cmap; - - node = node->Next(); + + node = node->GetNext(); } - + /* Make a new one: */ wxXPalette *c = new wxXPalette; - wxXPalette *first = (wxXPalette *)M_PALETTEDATA->m_palettes.First()->Data(); + 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; - + 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); + 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; + (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; } @@ -247,11 +256,11 @@ bool wxPalette::TransferBitmap(void *data, int depth, int size) *uptr = (unsigned char)pix_array[*uptr]; uptr++; } - - return TRUE; + + return true; } default: - return FALSE; + return false; } } @@ -305,20 +314,21 @@ bool wxPalette::TransferBitmap8(unsigned char *data, unsigned long sz, break; } default: - return FALSE; + return false; } - return TRUE; + return true; } unsigned long *wxPalette::GetXPixArray(WXDisplay *display, int *n) { if (!M_PALETTEDATA) return (unsigned long*) 0; - wxNode *node; - - for (node = M_PALETTEDATA->m_palettes.First(); node; node = node->Next()) + wxList::compatibility_iterator node; + + for (node = M_PALETTEDATA->m_palettes.GetFirst(); node; + node = node->GetNext()) { - wxXPalette *c = (wxXPalette *)node->Data(); + wxXPalette *c = (wxXPalette *)node->GetData(); if (c->m_display == display) { if (n) @@ -326,7 +336,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); @@ -337,17 +347,17 @@ unsigned long *wxPalette::GetXPixArray(WXDisplay *display, int *n) void wxPalette::PutXColormap(WXDisplay* display, WXColormap cm, bool dp) { UnRef(); - + m_refData = new wxPaletteRefData; - + wxXPalette *c = new wxXPalette; - + c->m_pix_array_n = 0; c->m_pix_array = (unsigned long*) NULL; c->m_display = display; c->m_cmap = cm; c->m_destroyable = dp; - + M_PALETTEDATA->m_palettes.Append(c); }