]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/bmpmotif.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/motif/bmpmotif.cpp 
   4 // Author:      Julian Smart, originally in bitmap.cpp 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  15 #include "wx/motif/bmpmotif.h" 
  22 #pragma message disable nosimpint 
  26 #pragma message enable nosimpint 
  29 #include "wx/motif/private.h" 
  35 Pixmap 
XCreateInsensitivePixmap( Display 
*display
, Pixmap pixmap 
); 
  37 static inline wxCharBuffer 
GetCacheImageName(WXImage image
) 
  39     return wxString::Format(_T("wxBitmap_%p"), image
).ToAscii(); 
  42 wxBitmapCache::~wxBitmapCache() 
  46         Screen
* screen 
= DefaultScreenOfDisplay( (Display
*)m_display 
); 
  49             XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap 
); 
  52             XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap 
); 
  55             XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap 
); 
  61         XmUninstallImage( (XImage
*)m_image 
); 
  62         XtFree( (char*)(XImage
*)m_image 
); 
  66 void wxBitmapCache::SetBitmap( const wxBitmap
& bitmap 
) 
  68     if ( !m_bitmap
.IsSameAs(bitmap
) ) 
  75             XmUninstallImage( (XImage
*)m_image 
); 
  76             XtFree( (char*)(XImage
*)m_image 
); 
  77             m_image 
= (WXImage
*)NULL
; 
  82 void wxBitmapCache::InvalidateCache() 
  84     m_recalcPixmaps
.label  
= true; 
  85     m_recalcPixmaps
.arm    
= true; 
  86     m_recalcPixmaps
.insens 
= true; 
  89 void wxBitmapCache::SetColoursChanged() 
  94 void wxBitmapCache::CreateImageIfNeeded( WXWidget w 
) 
 100                 (WXDisplay
*)XtDisplay( (Widget
)w 
) : 
 101                 (WXDisplay
*)wxGetDisplay(); 
 103     XImage 
*ximage 
= XGetImage( (Display
*)m_display
, 
 104                                 (Drawable
)m_bitmap
.GetDrawable(), 
 106                                 m_bitmap
.GetWidth(), m_bitmap
.GetHeight(), 
 107                                 AllPlanes
, ZPixmap 
); 
 109     m_image 
= (WXImage
*)ximage
; 
 113         XmInstallImage( ximage
, GetCacheImageName(m_image
).data() ); 
 117 WXPixmap 
wxBitmapCache::GetPixmapFromCache(WXWidget w
) 
 119     Widget widget 
= (Widget
)w
; 
 120     while( XmIsGadget( widget 
) ) 
 121         widget 
= XtParent( widget 
); 
 124     XtVaGetValues( widget
, 
 129     Screen
* screen 
= DefaultScreenOfDisplay( (Display
*)m_display 
); 
 130     return (WXPixmap
)XmGetPixmap(screen
, GetCacheImageName(m_image
).data(), fg
, bg
); 
 133 WXPixmap 
wxBitmapCache::GetLabelPixmap( WXWidget w 
) 
 135     if( m_labelPixmap 
&& !m_recalcPixmaps
.label 
) 
 136         return m_labelPixmap
; 
 138     CreateImageIfNeeded( w 
); 
 140     Screen
* screen 
= DefaultScreenOfDisplay( (Display
*)m_display 
); 
 143         XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap 
); 
 146         return (WXPixmap
)NULL
; 
 148     m_labelPixmap 
= GetPixmapFromCache(w
); 
 149     m_recalcPixmaps
.label 
= !m_labelPixmap
; 
 150     return m_labelPixmap
; 
 153 WXPixmap 
wxBitmapCache::GetArmPixmap( WXWidget w 
) 
 155     if( m_armPixmap 
&& !m_recalcPixmaps
.arm 
) 
 158     CreateImageIfNeeded( w 
); 
 160     Screen
* screen 
= DefaultScreenOfDisplay( (Display
*)m_display 
); 
 163         XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap 
); 
 166         return (WXPixmap
)NULL
; 
 168     m_armPixmap 
= GetPixmapFromCache(w
); 
 169     m_recalcPixmaps
.arm 
= !m_armPixmap
; 
 173 WXPixmap 
wxBitmapCache::GetInsensPixmap( WXWidget w 
) 
 175     if( m_insensPixmap 
&& !m_recalcPixmaps
.insens 
) 
 176         return m_insensPixmap
; 
 178     CreateImageIfNeeded( w 
); 
 180     Screen
* screen 
= DefaultScreenOfDisplay( (Display
*)m_display 
); 
 183         XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap 
); 
 186         return (WXPixmap
)NULL
; 
 189         (WXPixmap
)XCreateInsensitivePixmap( (Display
*)m_display
, 
 190                                             (Pixmap
)m_bitmap
.GetDrawable() ); 
 192     m_recalcPixmaps
.insens 
= !m_insensPixmap
; 
 193     return m_insensPixmap
; 
 196 ////////////////////////////////////////////////////////////////////////////// 
 198 ////////////////////////////////////////////////////////////////////////////// 
 200 /**************************************************************************** 
 203   XCreateInsensitivePixmap - create a grayed-out copy of a pixmap 
 206   Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) 
 209   This function creates a grayed-out copy of the argument pixmap, suitable 
 210   for use as a XmLabel's XmNlabelInsensitivePixmap resource. 
 213   The return value is the new Pixmap id or zero on error.  Errors include 
 214   a NULL display argument or an invalid Pixmap argument. 
 217   If one of the XLib functions fail, it will produce a X error.  The 
 218   default X error handler prints a diagnostic and calls exit(). 
 221   XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3), 
 222   XFillRectangle(3), exit(2) 
 225   John R Veregge - john@puente.jpl.nasa.gov 
 226   Advanced Engineering and Prototyping Group (AEG) 
 227   Information Systems Technology Section (395) 
 228   Jet Propulsion Lab - Calif Institute of Technology 
 230 *****************************************************************************/ 
 233 XCreateInsensitivePixmap( Display 
*display
, Pixmap pixmap 
) 
 236     static char stipple_data
[] = 
 238             0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 
 239             0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 
 240             0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 
 241             0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA 
 244     Pixmap    ipixmap
, stipple
; 
 245     unsigned    width
, height
, depth
; 
 247     Window    window
;    /* These return values */ 
 248     unsigned    border
;    /* from XGetGeometry() */ 
 249     int        x
, y
;    /* are not needed.     */ 
 253     if ( NULL 
== display 
|| 0 == pixmap 
) 
 256     if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
, 
 257                 &width
, &height
, &border
, &depth 
) 
 259         return ipixmap
; /* BadDrawable: probably an invalid pixmap */ 
 261     /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap. 
 263     stipple 
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 ); 
 266         gc 
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL 
); 
 269             /* Create an identical copy of the argument pixmap. 
 271             ipixmap 
= XCreatePixmap( display
, pixmap
, width
, height
, depth 
); 
 274                 /* Copy the argument pixmap into the new pixmap. 
 276                 XCopyArea( display
, pixmap
, ipixmap
, 
 277                         gc
, 0, 0, width
, height
, 0, 0 ); 
 279                 /* Refill the new pixmap using the stipple algorithm/pixmap. 
 281                 XSetStipple( display
, gc
, stipple 
); 
 282                 XSetFillStyle( display
, gc
, FillStippled 
); 
 283                 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height 
); 
 285             XFreeGC( display
, gc 
); 
 287         XFreePixmap( display
, stipple 
);