]>
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"
23 #pragma message disable nosimpint
27 #pragma message enable nosimpint
30 #include "wx/motif/private.h"
38 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
40 static inline wxCharBuffer
GetCacheImageName(WXImage image
)
42 return wxString::Format(_T("wxBitmap_%p"), image
).ToAscii();
45 wxBitmapCache::~wxBitmapCache()
49 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
52 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
55 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
58 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
64 XmUninstallImage( (XImage
*)m_image
);
65 XtFree( (char*)(XImage
*)m_image
);
69 void wxBitmapCache::SetBitmap( const wxBitmap
& bitmap
)
71 if( m_bitmap
!= bitmap
)
78 XmUninstallImage( (XImage
*)m_image
);
79 XtFree( (char*)(XImage
*)m_image
);
80 m_image
= (WXImage
*)NULL
;
85 void wxBitmapCache::InvalidateCache()
87 m_recalcPixmaps
.label
= true;
88 m_recalcPixmaps
.arm
= true;
89 m_recalcPixmaps
.insens
= true;
92 void wxBitmapCache::SetColoursChanged()
97 void wxBitmapCache::CreateImageIfNeeded( WXWidget w
)
103 (WXDisplay
*)XtDisplay( (Widget
)w
) :
104 (WXDisplay
*)wxGetDisplay();
106 XImage
*ximage
= XGetImage( (Display
*)m_display
,
107 (Drawable
)m_bitmap
.GetDrawable(),
109 m_bitmap
.GetWidth(), m_bitmap
.GetHeight(),
110 AllPlanes
, ZPixmap
);
112 m_image
= (WXImage
*)ximage
;
116 XmInstallImage( ximage
, GetCacheImageName(m_image
).data() );
120 WXPixmap
wxBitmapCache::GetPixmapFromCache(WXWidget w
)
122 Widget widget
= (Widget
)w
;
123 while( XmIsGadget( widget
) )
124 widget
= XtParent( widget
);
127 XtVaGetValues( widget
,
132 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
133 return (WXPixmap
)XmGetPixmap(screen
, GetCacheImageName(m_image
).data(), fg
, bg
);
136 WXPixmap
wxBitmapCache::GetLabelPixmap( WXWidget w
)
138 if( m_labelPixmap
&& !m_recalcPixmaps
.label
)
139 return m_labelPixmap
;
141 CreateImageIfNeeded( w
);
143 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
146 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
149 return (WXPixmap
)NULL
;
151 m_labelPixmap
= GetPixmapFromCache(w
);
152 m_recalcPixmaps
.label
= !m_labelPixmap
;
153 return m_labelPixmap
;
156 WXPixmap
wxBitmapCache::GetArmPixmap( WXWidget w
)
158 if( m_armPixmap
&& !m_recalcPixmaps
.arm
)
161 CreateImageIfNeeded( w
);
163 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
166 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
169 return (WXPixmap
)NULL
;
171 m_armPixmap
= GetPixmapFromCache(w
);
172 m_recalcPixmaps
.arm
= !m_armPixmap
;
176 WXPixmap
wxBitmapCache::GetInsensPixmap( WXWidget w
)
178 if( m_insensPixmap
&& !m_recalcPixmaps
.insens
)
179 return m_insensPixmap
;
181 CreateImageIfNeeded( w
);
183 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
186 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
189 return (WXPixmap
)NULL
;
192 (WXPixmap
)XCreateInsensitivePixmap( (Display
*)m_display
,
193 (Pixmap
)m_bitmap
.GetDrawable() );
195 m_recalcPixmaps
.insens
= !m_insensPixmap
;
196 return m_insensPixmap
;
199 //////////////////////////////////////////////////////////////////////////////
201 //////////////////////////////////////////////////////////////////////////////
203 /****************************************************************************
206 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
209 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
212 This function creates a grayed-out copy of the argument pixmap, suitable
213 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
216 The return value is the new Pixmap id or zero on error. Errors include
217 a NULL display argument or an invalid Pixmap argument.
220 If one of the XLib functions fail, it will produce a X error. The
221 default X error handler prints a diagnostic and calls exit().
224 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
225 XFillRectangle(3), exit(2)
228 John R Veregge - john@puente.jpl.nasa.gov
229 Advanced Engineering and Prototyping Group (AEG)
230 Information Systems Technology Section (395)
231 Jet Propulsion Lab - Calif Institute of Technology
233 *****************************************************************************/
236 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
239 static char stipple_data
[] =
241 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
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
247 Pixmap ipixmap
, stipple
;
248 unsigned width
, height
, depth
;
250 Window window
; /* These return values */
251 unsigned border
; /* from XGetGeometry() */
252 int x
, y
; /* are not needed. */
256 if ( NULL
== display
|| 0 == pixmap
)
259 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
260 &width
, &height
, &border
, &depth
)
262 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
264 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
266 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
269 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
272 /* Create an identical copy of the argument pixmap.
274 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
277 /* Copy the argument pixmap into the new pixmap.
279 XCopyArea( display
, pixmap
, ipixmap
,
280 gc
, 0, 0, width
, height
, 0, 0 );
282 /* Refill the new pixmap using the stipple algorithm/pixmap.
284 XSetStipple( display
, gc
, stipple
);
285 XSetFillStyle( display
, gc
, FillStippled
);
286 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
288 XFreeGC( display
, gc
);
290 XFreePixmap( display
, stipple
);