]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/bmpmotif.cpp
fixed MIPSpro version in the comment
[wxWidgets.git] / src / motif / bmpmotif.cpp
index c0b958ab78a851c435c820a3aeaf66a4bb055a42..2bd938cdab6ea712614ca9c029bfe7599c60c1b1 100644 (file)
@@ -9,12 +9,12 @@
 // 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"
 #if wxHAVE_LIB_XPM
     #include <X11/xpm.h>
 #endif
-#include <math.h>
+
+#include "wx/math.h"
 
 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 )
@@ -99,7 +105,7 @@ void wxBitmapCache::CreateImageIfNeeded( WXWidget w )
                 (WXDisplay*)wxGetDisplay();
 
     XImage *ximage = XGetImage( (Display*)m_display,
-                                (Drawable)m_bitmap.GetPixmap(),
+                                (Drawable)m_bitmap.GetDrawable(),
                                 0, 0,
                                 m_bitmap.GetWidth(), m_bitmap.GetHeight(),
                                 AllPlanes, ZPixmap );
@@ -108,12 +114,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 )
@@ -129,21 +149,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 +169,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;
 }
@@ -197,7 +191,7 @@ WXPixmap wxBitmapCache::GetInsensPixmap( WXWidget w )
 
     m_insensPixmap =
         (WXPixmap)XCreateInsensitivePixmap( (Display*)m_display,
-                                            (Pixmap)m_bitmap.GetPixmap() );
+                                            (Pixmap)m_bitmap.GetDrawable() );
 
     m_recalcPixmaps.insens = !m_insensPixmap;
     return m_insensPixmap;