X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aae0472bf3086707216125e4caa8650caeeeaf97..c5bc21bd1fa3a8224fd49c4f9d7f673a571f0d9e:/src/motif/bmpmotif.cpp?ds=sidebyside diff --git a/src/motif/bmpmotif.cpp b/src/motif/bmpmotif.cpp index 2e800542f2..155adc1cf4 100644 --- a/src/motif/bmpmotif.cpp +++ b/src/motif/bmpmotif.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: bitmap.cpp +// Name: src/motif/bmpmotif.cpp // Purpose: wxBitmap // Author: Julian Smart, originally in bitmap.cpp // Modified by: @@ -9,17 +9,20 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "bmpmotif.h" -#endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" #ifdef __VMS #define XtParent XTPARENT +#define XtDisplay XTDISPLAY #endif -#include "wx/defs.h" #include "wx/motif/bmpmotif.h" +#ifndef WX_PRECOMP + #include "wx/math.h" +#endif + #ifdef __VMS__ #pragma message disable nosimpint #endif @@ -33,10 +36,14 @@ #if wxHAVE_LIB_XPM #include #endif -#include Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ); +static inline wxCharBuffer GetCacheImageName(WXImage image) +{ + return wxString::Format(_T("wxBitmap_%p"), image).ToAscii(); +} + wxBitmapCache::~wxBitmapCache() { if( m_display ) @@ -63,7 +70,7 @@ wxBitmapCache::~wxBitmapCache() void wxBitmapCache::SetBitmap( const wxBitmap& bitmap ) { - if( m_bitmap != bitmap ) + if ( !m_bitmap.IsSameAs(bitmap) ) { InvalidateCache(); m_bitmap = bitmap; @@ -108,12 +115,26 @@ void wxBitmapCache::CreateImageIfNeeded( WXWidget w ) if( m_image ) { - char tmp[128]; - sprintf( tmp, "Im%x", (unsigned int)ximage ); - XmInstallImage( ximage, tmp ); + XmInstallImage( ximage, GetCacheImageName(m_image).data() ); } } +WXPixmap wxBitmapCache::GetPixmapFromCache(WXWidget w) +{ + Widget widget = (Widget)w; + while( XmIsGadget( widget ) ) + widget = XtParent( widget ); + + WXPixel fg, bg; + XtVaGetValues( widget, + XmNbackground, &bg, + XmNforeground, &fg, + NULL ); + + Screen* screen = DefaultScreenOfDisplay( (Display*)m_display ); + return (WXPixmap)XmGetPixmap(screen, GetCacheImageName(m_image).data(), fg, bg); +} + WXPixmap wxBitmapCache::GetLabelPixmap( WXWidget w ) { if( m_labelPixmap && !m_recalcPixmaps.label ) @@ -129,21 +150,7 @@ WXPixmap wxBitmapCache::GetLabelPixmap( WXWidget w ) if( !m_image ) return (WXPixmap)NULL; - char tmp[128]; - sprintf( tmp, "Im%x", (unsigned int)m_image ); - - Pixel fg, bg; - Widget widget = (Widget)w; - - while( XmIsGadget( widget ) ) - widget = XtParent( widget ); - XtVaGetValues( widget, - XmNbackground, &bg, - XmNforeground, &fg, - NULL ); - - m_labelPixmap = (WXPixmap)XmGetPixmap( screen, tmp, fg, bg ); - + m_labelPixmap = GetPixmapFromCache(w); m_recalcPixmaps.label = !m_labelPixmap; return m_labelPixmap; } @@ -163,19 +170,7 @@ WXPixmap wxBitmapCache::GetArmPixmap( WXWidget w ) if( !m_image ) return (WXPixmap)NULL; - char tmp[128]; - sprintf( tmp, "Im%x", (unsigned int)m_image ); - - Pixel fg, bg; - Widget widget = (Widget) w; - - XtVaGetValues( widget, XmNarmColor, &bg, NULL ); - while( XmIsGadget( widget ) ) - widget = XtParent( widget ); - XtVaGetValues( widget, XmNforeground, &fg, NULL ); - - m_armPixmap = (WXPixmap)XmGetPixmap( screen, tmp, fg, bg ); - + m_armPixmap = GetPixmapFromCache(w); m_recalcPixmaps.arm = !m_armPixmap; return m_armPixmap; }