]>
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"
16 #define XtParent XTPARENT
17 #define XtDisplay XTDISPLAY
20 #include "wx/motif/bmpmotif.h"
27 #pragma message disable nosimpint
31 #pragma message enable nosimpint
34 #include "wx/motif/private.h"
40 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
42 static inline wxCharBuffer
GetCacheImageName(WXImage image
)
44 return wxString::Format(_T("wxBitmap_%p"), image
).ToAscii();
47 wxBitmapCache::~wxBitmapCache()
51 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
54 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
57 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
60 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
66 XmUninstallImage( (XImage
*)m_image
);
67 XtFree( (char*)(XImage
*)m_image
);
71 void wxBitmapCache::SetBitmap( const wxBitmap
& bitmap
)
73 if( m_bitmap
!= bitmap
)
80 XmUninstallImage( (XImage
*)m_image
);
81 XtFree( (char*)(XImage
*)m_image
);
82 m_image
= (WXImage
*)NULL
;
87 void wxBitmapCache::InvalidateCache()
89 m_recalcPixmaps
.label
= true;
90 m_recalcPixmaps
.arm
= true;
91 m_recalcPixmaps
.insens
= true;
94 void wxBitmapCache::SetColoursChanged()
99 void wxBitmapCache::CreateImageIfNeeded( WXWidget w
)
105 (WXDisplay
*)XtDisplay( (Widget
)w
) :
106 (WXDisplay
*)wxGetDisplay();
108 XImage
*ximage
= XGetImage( (Display
*)m_display
,
109 (Drawable
)m_bitmap
.GetDrawable(),
111 m_bitmap
.GetWidth(), m_bitmap
.GetHeight(),
112 AllPlanes
, ZPixmap
);
114 m_image
= (WXImage
*)ximage
;
118 XmInstallImage( ximage
, GetCacheImageName(m_image
).data() );
122 WXPixmap
wxBitmapCache::GetPixmapFromCache(WXWidget w
)
124 Widget widget
= (Widget
)w
;
125 while( XmIsGadget( widget
) )
126 widget
= XtParent( widget
);
129 XtVaGetValues( widget
,
134 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
135 return (WXPixmap
)XmGetPixmap(screen
, GetCacheImageName(m_image
).data(), fg
, bg
);
138 WXPixmap
wxBitmapCache::GetLabelPixmap( WXWidget w
)
140 if( m_labelPixmap
&& !m_recalcPixmaps
.label
)
141 return m_labelPixmap
;
143 CreateImageIfNeeded( w
);
145 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
148 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
151 return (WXPixmap
)NULL
;
153 m_labelPixmap
= GetPixmapFromCache(w
);
154 m_recalcPixmaps
.label
= !m_labelPixmap
;
155 return m_labelPixmap
;
158 WXPixmap
wxBitmapCache::GetArmPixmap( WXWidget w
)
160 if( m_armPixmap
&& !m_recalcPixmaps
.arm
)
163 CreateImageIfNeeded( w
);
165 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
168 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
171 return (WXPixmap
)NULL
;
173 m_armPixmap
= GetPixmapFromCache(w
);
174 m_recalcPixmaps
.arm
= !m_armPixmap
;
178 WXPixmap
wxBitmapCache::GetInsensPixmap( WXWidget w
)
180 if( m_insensPixmap
&& !m_recalcPixmaps
.insens
)
181 return m_insensPixmap
;
183 CreateImageIfNeeded( w
);
185 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
188 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
191 return (WXPixmap
)NULL
;
194 (WXPixmap
)XCreateInsensitivePixmap( (Display
*)m_display
,
195 (Pixmap
)m_bitmap
.GetDrawable() );
197 m_recalcPixmaps
.insens
= !m_insensPixmap
;
198 return m_insensPixmap
;
201 //////////////////////////////////////////////////////////////////////////////
203 //////////////////////////////////////////////////////////////////////////////
205 /****************************************************************************
208 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
211 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
214 This function creates a grayed-out copy of the argument pixmap, suitable
215 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
218 The return value is the new Pixmap id or zero on error. Errors include
219 a NULL display argument or an invalid Pixmap argument.
222 If one of the XLib functions fail, it will produce a X error. The
223 default X error handler prints a diagnostic and calls exit().
226 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
227 XFillRectangle(3), exit(2)
230 John R Veregge - john@puente.jpl.nasa.gov
231 Advanced Engineering and Prototyping Group (AEG)
232 Information Systems Technology Section (395)
233 Jet Propulsion Lab - Calif Institute of Technology
235 *****************************************************************************/
238 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
241 static char stipple_data
[] =
243 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
244 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
245 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
246 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA
249 Pixmap ipixmap
, stipple
;
250 unsigned width
, height
, depth
;
252 Window window
; /* These return values */
253 unsigned border
; /* from XGetGeometry() */
254 int x
, y
; /* are not needed. */
258 if ( NULL
== display
|| 0 == pixmap
)
261 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
262 &width
, &height
, &border
, &depth
)
264 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
266 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
268 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
271 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
274 /* Create an identical copy of the argument pixmap.
276 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
279 /* Copy the argument pixmap into the new pixmap.
281 XCopyArea( display
, pixmap
, ipixmap
,
282 gc
, 0, 0, width
, height
, 0, 0 );
284 /* Refill the new pixmap using the stipple algorithm/pixmap.
286 XSetStipple( display
, gc
, stipple
);
287 XSetFillStyle( display
, gc
, FillStippled
);
288 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
290 XFreeGC( display
, gc
);
292 XFreePixmap( display
, stipple
);