X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1248b41f9f71110347659db8c54c75786eba23c6..76b0f8384ed211c5f6b48597a62da743b604e666:/src/motif/bmpmotif.cpp diff --git a/src/motif/bmpmotif.cpp b/src/motif/bmpmotif.cpp index e588d19a87..a04c74e4cb 100644 --- a/src/motif/bmpmotif.cpp +++ b/src/motif/bmpmotif.cpp @@ -1,29 +1,22 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: bitmap.cpp +// Name: src/motif/bmpmotif.cpp // Purpose: wxBitmap // Author: Julian Smart, originally in bitmap.cpp // Modified by: // Created: 25/03/2003 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#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 @@ -37,10 +30,14 @@ #if wxHAVE_LIB_XPM #include #endif -#include Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ); +static inline wxCharBuffer GetCacheImageName(WXImage image) +{ + return wxString::Format(wxT("wxBitmap_%p"), image).ToAscii(); +} + wxBitmapCache::~wxBitmapCache() { if( m_display ) @@ -67,7 +64,7 @@ wxBitmapCache::~wxBitmapCache() void wxBitmapCache::SetBitmap( const wxBitmap& bitmap ) { - if( m_bitmap != bitmap ) + if ( !m_bitmap.IsSameAs(bitmap) ) { InvalidateCache(); m_bitmap = bitmap; @@ -76,7 +73,7 @@ void wxBitmapCache::SetBitmap( const wxBitmap& bitmap ) { XmUninstallImage( (XImage*)m_image ); XtFree( (char*)(XImage*)m_image ); - m_image = (WXImage*)NULL; + m_image = NULL; } } } @@ -112,12 +109,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 ) @@ -133,21 +144,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; } @@ -167,19 +164,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; } @@ -277,7 +262,7 @@ XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) stipple = XCreateBitmapFromData( display, pixmap, stipple_data, 16, 16 ); if ( 0 != stipple ) { - gc = XCreateGC( display, pixmap, (XtGCMask)0, (XGCValues*)NULL ); + gc = XCreateGC( display, pixmap, (XtGCMask)0, NULL ); if ( NULL != gc ) { /* Create an identical copy of the argument pixmap.