]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "bmpmotif.h"
17 #define XtParent XTPARENT
21 #include "wx/motif/bmpmotif.h"
24 #pragma message disable nosimpint
28 #pragma message enable nosimpint
31 #include "wx/motif/private.h"
38 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
40 wxBitmapCache::~wxBitmapCache()
44 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
47 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
50 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
53 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
59 XmUninstallImage( (XImage
*)m_image
);
60 XtFree( (char*)(XImage
*)m_image
);
64 void wxBitmapCache::SetBitmap( const wxBitmap
& bitmap
)
66 if( m_bitmap
!= bitmap
)
73 XmUninstallImage( (XImage
*)m_image
);
74 XtFree( (char*)(XImage
*)m_image
);
75 m_image
= (WXImage
*)NULL
;
80 void wxBitmapCache::InvalidateCache()
82 m_recalcPixmaps
.label
= true;
83 m_recalcPixmaps
.arm
= true;
84 m_recalcPixmaps
.insens
= true;
87 void wxBitmapCache::SetColoursChanged()
92 void wxBitmapCache::CreateImageIfNeeded( WXWidget w
)
98 (WXDisplay
*)XtDisplay( (Widget
)w
) :
99 (WXDisplay
*)wxGetDisplay();
101 XImage
*ximage
= XGetImage( (Display
*)m_display
,
102 (Drawable
)m_bitmap
.GetDrawable(),
104 m_bitmap
.GetWidth(), m_bitmap
.GetHeight(),
105 AllPlanes
, ZPixmap
);
107 m_image
= (WXImage
*)ximage
;
112 sprintf( tmp
, "Im%x", (unsigned int)ximage
);
113 XmInstallImage( ximage
, tmp
);
117 WXPixmap
wxBitmapCache::GetLabelPixmap( WXWidget w
)
119 if( m_labelPixmap
&& !m_recalcPixmaps
.label
)
120 return m_labelPixmap
;
122 CreateImageIfNeeded( w
);
124 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
127 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
130 return (WXPixmap
)NULL
;
133 sprintf( tmp
, "Im%x", (unsigned int)m_image
);
136 Widget widget
= (Widget
)w
;
138 while( XmIsGadget( widget
) )
139 widget
= XtParent( widget
);
140 XtVaGetValues( widget
,
145 m_labelPixmap
= (WXPixmap
)XmGetPixmap( screen
, tmp
, fg
, bg
);
147 m_recalcPixmaps
.label
= !m_labelPixmap
;
148 return m_labelPixmap
;
151 WXPixmap
wxBitmapCache::GetArmPixmap( WXWidget w
)
153 if( m_armPixmap
&& !m_recalcPixmaps
.arm
)
156 CreateImageIfNeeded( w
);
158 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
161 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
164 return (WXPixmap
)NULL
;
167 sprintf( tmp
, "Im%x", (unsigned int)m_image
);
170 Widget widget
= (Widget
) w
;
172 XtVaGetValues( widget
, XmNarmColor
, &bg
, NULL
);
173 while( XmIsGadget( widget
) )
174 widget
= XtParent( widget
);
175 XtVaGetValues( widget
, XmNforeground
, &fg
, NULL
);
177 m_armPixmap
= (WXPixmap
)XmGetPixmap( screen
, tmp
, fg
, bg
);
179 m_recalcPixmaps
.arm
= !m_armPixmap
;
183 WXPixmap
wxBitmapCache::GetInsensPixmap( WXWidget w
)
185 if( m_insensPixmap
&& !m_recalcPixmaps
.insens
)
186 return m_insensPixmap
;
188 CreateImageIfNeeded( w
);
190 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
193 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
196 return (WXPixmap
)NULL
;
199 (WXPixmap
)XCreateInsensitivePixmap( (Display
*)m_display
,
200 (Pixmap
)m_bitmap
.GetDrawable() );
202 m_recalcPixmaps
.insens
= !m_insensPixmap
;
203 return m_insensPixmap
;
206 //////////////////////////////////////////////////////////////////////////////
208 //////////////////////////////////////////////////////////////////////////////
210 /****************************************************************************
213 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
216 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
219 This function creates a grayed-out copy of the argument pixmap, suitable
220 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
223 The return value is the new Pixmap id or zero on error. Errors include
224 a NULL display argument or an invalid Pixmap argument.
227 If one of the XLib functions fail, it will produce a X error. The
228 default X error handler prints a diagnostic and calls exit().
231 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
232 XFillRectangle(3), exit(2)
235 John R Veregge - john@puente.jpl.nasa.gov
236 Advanced Engineering and Prototyping Group (AEG)
237 Information Systems Technology Section (395)
238 Jet Propulsion Lab - Calif Institute of Technology
240 *****************************************************************************/
243 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
246 static char stipple_data
[] =
248 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
249 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
250 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
251 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA
254 Pixmap ipixmap
, stipple
;
255 unsigned width
, height
, depth
;
257 Window window
; /* These return values */
258 unsigned border
; /* from XGetGeometry() */
259 int x
, y
; /* are not needed. */
263 if ( NULL
== display
|| 0 == pixmap
)
266 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
267 &width
, &height
, &border
, &depth
)
269 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
271 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
273 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
276 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
279 /* Create an identical copy of the argument pixmap.
281 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
284 /* Copy the argument pixmap into the new pixmap.
286 XCopyArea( display
, pixmap
, ipixmap
,
287 gc
, 0, 0, width
, height
, 0, 0 );
289 /* Refill the new pixmap using the stipple algorithm/pixmap.
291 XSetStipple( display
, gc
, stipple
);
292 XSetFillStyle( display
, gc
, FillStippled
);
293 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
295 XFreeGC( display
, gc
);
297 XFreePixmap( display
, stipple
);