From 2263a14efc121f52675be4408f26185779838c96 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 17 Sep 2005 21:54:54 +0000 Subject: [PATCH] 64 bit compilation fix (pointer can't be cast to int); code simplification (don't duplicate code in GetArm/LabelPixmap) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35541 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/motif/bmpmotif.h | 2 ++ src/motif/bmpmotif.cpp | 55 ++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/include/wx/motif/bmpmotif.h b/include/wx/motif/bmpmotif.h index 1e88d23c75..58eba0aa1e 100644 --- a/include/wx/motif/bmpmotif.h +++ b/include/wx/motif/bmpmotif.h @@ -44,6 +44,8 @@ private: void InvalidateCache(); void CreateImageIfNeeded( WXWidget w ); + WXPixmap GetPixmapFromCache(WXWidget w); + struct { bool label : 1; diff --git a/src/motif/bmpmotif.cpp b/src/motif/bmpmotif.cpp index d0f70c18c4..4275b214fb 100644 --- a/src/motif/bmpmotif.cpp +++ b/src/motif/bmpmotif.cpp @@ -42,6 +42,11 @@ 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 ) @@ -113,12 +118,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 ); + + Pixel 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 ) @@ -134,21 +153,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; } @@ -168,19 +173,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; } -- 2.45.2