]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/bmpmotif.cpp
1 /////////////////////////////////////////////////////////////////////////////
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
21 #include "wx/motif/bmpmotif.h"
24 #pragma message disable nosimpint
28 #pragma message enable nosimpint
31 #include "wx/motif/private.h"
39 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
41 static inline wxCharBuffer
GetCacheImageName(WXImage image
)
43 return wxString::Format(_T("wxBitmap_%p"), image
).ToAscii();
46 wxBitmapCache::~wxBitmapCache()
50 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
53 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
56 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
59 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
65 XmUninstallImage( (XImage
*)m_image
);
66 XtFree( (char*)(XImage
*)m_image
);
70 void wxBitmapCache::SetBitmap( const wxBitmap
& bitmap
)
72 if( m_bitmap
!= bitmap
)
79 XmUninstallImage( (XImage
*)m_image
);
80 XtFree( (char*)(XImage
*)m_image
);
81 m_image
= (WXImage
*)NULL
;
86 void wxBitmapCache::InvalidateCache()
88 m_recalcPixmaps
.label
= true;
89 m_recalcPixmaps
.arm
= true;
90 m_recalcPixmaps
.insens
= true;
93 void wxBitmapCache::SetColoursChanged()
98 void wxBitmapCache::CreateImageIfNeeded( WXWidget w
)
104 (WXDisplay
*)XtDisplay( (Widget
)w
) :
105 (WXDisplay
*)wxGetDisplay();
107 XImage
*ximage
= XGetImage( (Display
*)m_display
,
108 (Drawable
)m_bitmap
.GetDrawable(),
110 m_bitmap
.GetWidth(), m_bitmap
.GetHeight(),
111 AllPlanes
, ZPixmap
);
113 m_image
= (WXImage
*)ximage
;
117 XmInstallImage( ximage
, GetCacheImageName(m_image
).data() );
121 WXPixmap
wxBitmapCache::GetPixmapFromCache(WXWidget w
)
123 Widget widget
= (Widget
)w
;
124 while( XmIsGadget( widget
) )
125 widget
= XtParent( widget
);
128 XtVaGetValues( widget
,
133 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
134 return (WXPixmap
)XmGetPixmap(screen
, GetCacheImageName(m_image
).data(), fg
, bg
);
137 WXPixmap
wxBitmapCache::GetLabelPixmap( WXWidget w
)
139 if( m_labelPixmap
&& !m_recalcPixmaps
.label
)
140 return m_labelPixmap
;
142 CreateImageIfNeeded( w
);
144 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
147 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
150 return (WXPixmap
)NULL
;
152 m_labelPixmap
= GetPixmapFromCache(w
);
153 m_recalcPixmaps
.label
= !m_labelPixmap
;
154 return m_labelPixmap
;
157 WXPixmap
wxBitmapCache::GetArmPixmap( WXWidget w
)
159 if( m_armPixmap
&& !m_recalcPixmaps
.arm
)
162 CreateImageIfNeeded( w
);
164 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
167 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
170 return (WXPixmap
)NULL
;
172 m_armPixmap
= GetPixmapFromCache(w
);
173 m_recalcPixmaps
.arm
= !m_armPixmap
;
177 WXPixmap
wxBitmapCache::GetInsensPixmap( WXWidget w
)
179 if( m_insensPixmap
&& !m_recalcPixmaps
.insens
)
180 return m_insensPixmap
;
182 CreateImageIfNeeded( w
);
184 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
187 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
190 return (WXPixmap
)NULL
;
193 (WXPixmap
)XCreateInsensitivePixmap( (Display
*)m_display
,
194 (Pixmap
)m_bitmap
.GetDrawable() );
196 m_recalcPixmaps
.insens
= !m_insensPixmap
;
197 return m_insensPixmap
;
200 //////////////////////////////////////////////////////////////////////////////
202 //////////////////////////////////////////////////////////////////////////////
204 /****************************************************************************
207 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
210 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
213 This function creates a grayed-out copy of the argument pixmap, suitable
214 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
217 The return value is the new Pixmap id or zero on error. Errors include
218 a NULL display argument or an invalid Pixmap argument.
221 If one of the XLib functions fail, it will produce a X error. The
222 default X error handler prints a diagnostic and calls exit().
225 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
226 XFillRectangle(3), exit(2)
229 John R Veregge - john@puente.jpl.nasa.gov
230 Advanced Engineering and Prototyping Group (AEG)
231 Information Systems Technology Section (395)
232 Jet Propulsion Lab - Calif Institute of Technology
234 *****************************************************************************/
237 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
240 static char stipple_data
[] =
242 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
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
248 Pixmap ipixmap
, stipple
;
249 unsigned width
, height
, depth
;
251 Window window
; /* These return values */
252 unsigned border
; /* from XGetGeometry() */
253 int x
, y
; /* are not needed. */
257 if ( NULL
== display
|| 0 == pixmap
)
260 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
261 &width
, &height
, &border
, &depth
)
263 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
265 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
267 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
270 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
273 /* Create an identical copy of the argument pixmap.
275 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
278 /* Copy the argument pixmap into the new pixmap.
280 XCopyArea( display
, pixmap
, ipixmap
,
281 gc
, 0, 0, width
, height
, 0, 0 );
283 /* Refill the new pixmap using the stipple algorithm/pixmap.
285 XSetStipple( display
, gc
, stipple
);
286 XSetFillStyle( display
, gc
, FillStippled
);
287 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
289 XFreeGC( display
, gc
);
291 XFreePixmap( display
, stipple
);