]>
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
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/motif/bmpmotif.h"
21 #pragma message disable nosimpint
25 #pragma message enable nosimpint
28 #include "wx/motif/private.h"
34 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
36 static inline wxCharBuffer
GetCacheImageName(WXImage image
)
38 return wxString::Format(wxT("wxBitmap_%p"), image
).ToAscii();
41 wxBitmapCache::~wxBitmapCache()
45 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
48 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
51 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
54 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
60 XmUninstallImage( (XImage
*)m_image
);
61 XtFree( (char*)(XImage
*)m_image
);
65 void wxBitmapCache::SetBitmap( const wxBitmap
& bitmap
)
67 if ( !m_bitmap
.IsSameAs(bitmap
) )
74 XmUninstallImage( (XImage
*)m_image
);
75 XtFree( (char*)(XImage
*)m_image
);
81 void wxBitmapCache::InvalidateCache()
83 m_recalcPixmaps
.label
= true;
84 m_recalcPixmaps
.arm
= true;
85 m_recalcPixmaps
.insens
= true;
88 void wxBitmapCache::SetColoursChanged()
93 void wxBitmapCache::CreateImageIfNeeded( WXWidget w
)
99 (WXDisplay
*)XtDisplay( (Widget
)w
) :
100 (WXDisplay
*)wxGetDisplay();
102 XImage
*ximage
= XGetImage( (Display
*)m_display
,
103 (Drawable
)m_bitmap
.GetDrawable(),
105 m_bitmap
.GetWidth(), m_bitmap
.GetHeight(),
106 AllPlanes
, ZPixmap
);
108 m_image
= (WXImage
*)ximage
;
112 XmInstallImage( ximage
, GetCacheImageName(m_image
).data() );
116 WXPixmap
wxBitmapCache::GetPixmapFromCache(WXWidget w
)
118 Widget widget
= (Widget
)w
;
119 while( XmIsGadget( widget
) )
120 widget
= XtParent( widget
);
123 XtVaGetValues( widget
,
128 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
129 return (WXPixmap
)XmGetPixmap(screen
, GetCacheImageName(m_image
).data(), fg
, bg
);
132 WXPixmap
wxBitmapCache::GetLabelPixmap( WXWidget w
)
134 if( m_labelPixmap
&& !m_recalcPixmaps
.label
)
135 return m_labelPixmap
;
137 CreateImageIfNeeded( w
);
139 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
142 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
145 return (WXPixmap
)NULL
;
147 m_labelPixmap
= GetPixmapFromCache(w
);
148 m_recalcPixmaps
.label
= !m_labelPixmap
;
149 return m_labelPixmap
;
152 WXPixmap
wxBitmapCache::GetArmPixmap( WXWidget w
)
154 if( m_armPixmap
&& !m_recalcPixmaps
.arm
)
157 CreateImageIfNeeded( w
);
159 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
162 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
165 return (WXPixmap
)NULL
;
167 m_armPixmap
= GetPixmapFromCache(w
);
168 m_recalcPixmaps
.arm
= !m_armPixmap
;
172 WXPixmap
wxBitmapCache::GetInsensPixmap( WXWidget w
)
174 if( m_insensPixmap
&& !m_recalcPixmaps
.insens
)
175 return m_insensPixmap
;
177 CreateImageIfNeeded( w
);
179 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
182 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
185 return (WXPixmap
)NULL
;
188 (WXPixmap
)XCreateInsensitivePixmap( (Display
*)m_display
,
189 (Pixmap
)m_bitmap
.GetDrawable() );
191 m_recalcPixmaps
.insens
= !m_insensPixmap
;
192 return m_insensPixmap
;
195 //////////////////////////////////////////////////////////////////////////////
197 //////////////////////////////////////////////////////////////////////////////
199 /****************************************************************************
202 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
205 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
208 This function creates a grayed-out copy of the argument pixmap, suitable
209 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
212 The return value is the new Pixmap id or zero on error. Errors include
213 a NULL display argument or an invalid Pixmap argument.
216 If one of the XLib functions fail, it will produce a X error. The
217 default X error handler prints a diagnostic and calls exit().
220 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
221 XFillRectangle(3), exit(2)
224 John R Veregge - john@puente.jpl.nasa.gov
225 Advanced Engineering and Prototyping Group (AEG)
226 Information Systems Technology Section (395)
227 Jet Propulsion Lab - Calif Institute of Technology
229 *****************************************************************************/
232 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
235 static char stipple_data
[] =
237 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
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
243 Pixmap ipixmap
, stipple
;
244 unsigned width
, height
, depth
;
246 Window window
; /* These return values */
247 unsigned border
; /* from XGetGeometry() */
248 int x
, y
; /* are not needed. */
252 if ( NULL
== display
|| 0 == pixmap
)
255 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
256 &width
, &height
, &border
, &depth
)
258 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
260 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
262 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
265 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, NULL
);
268 /* Create an identical copy of the argument pixmap.
270 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
273 /* Copy the argument pixmap into the new pixmap.
275 XCopyArea( display
, pixmap
, ipixmap
,
276 gc
, 0, 0, width
, height
, 0, 0 );
278 /* Refill the new pixmap using the stipple algorithm/pixmap.
280 XSetStipple( display
, gc
, stipple
);
281 XSetFillStyle( display
, gc
, FillStippled
);
282 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
284 XFreeGC( display
, gc
);
286 XFreePixmap( display
, stipple
);