]>
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "bmpmotif.h"
17 #define XtParent XTPARENT
18 #define XtDisplay XTDISPLAY
22 #include "wx/motif/bmpmotif.h"
25 #pragma message disable nosimpint
29 #pragma message enable nosimpint
32 #include "wx/motif/private.h"
39 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
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
!= bitmap
)
74 XmUninstallImage( (XImage
*)m_image
);
75 XtFree( (char*)(XImage
*)m_image
);
76 m_image
= (WXImage
*)NULL
;
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
;
113 sprintf( tmp
, "Im%x", (unsigned int)ximage
);
114 XmInstallImage( ximage
, tmp
);
118 WXPixmap
wxBitmapCache::GetLabelPixmap( WXWidget w
)
120 if( m_labelPixmap
&& !m_recalcPixmaps
.label
)
121 return m_labelPixmap
;
123 CreateImageIfNeeded( w
);
125 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
128 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
131 return (WXPixmap
)NULL
;
134 sprintf( tmp
, "Im%x", (unsigned int)m_image
);
137 Widget widget
= (Widget
)w
;
139 while( XmIsGadget( widget
) )
140 widget
= XtParent( widget
);
141 XtVaGetValues( widget
,
146 m_labelPixmap
= (WXPixmap
)XmGetPixmap( screen
, tmp
, fg
, bg
);
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
;
168 sprintf( tmp
, "Im%x", (unsigned int)m_image
);
171 Widget widget
= (Widget
) w
;
173 XtVaGetValues( widget
, XmNarmColor
, &bg
, NULL
);
174 while( XmIsGadget( widget
) )
175 widget
= XtParent( widget
);
176 XtVaGetValues( widget
, XmNforeground
, &fg
, NULL
);
178 m_armPixmap
= (WXPixmap
)XmGetPixmap( screen
, tmp
, fg
, bg
);
180 m_recalcPixmaps
.arm
= !m_armPixmap
;
184 WXPixmap
wxBitmapCache::GetInsensPixmap( WXWidget w
)
186 if( m_insensPixmap
&& !m_recalcPixmaps
.insens
)
187 return m_insensPixmap
;
189 CreateImageIfNeeded( w
);
191 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
194 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
197 return (WXPixmap
)NULL
;
200 (WXPixmap
)XCreateInsensitivePixmap( (Display
*)m_display
,
201 (Pixmap
)m_bitmap
.GetDrawable() );
203 m_recalcPixmaps
.insens
= !m_insensPixmap
;
204 return m_insensPixmap
;
207 //////////////////////////////////////////////////////////////////////////////
209 //////////////////////////////////////////////////////////////////////////////
211 /****************************************************************************
214 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
217 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
220 This function creates a grayed-out copy of the argument pixmap, suitable
221 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
224 The return value is the new Pixmap id or zero on error. Errors include
225 a NULL display argument or an invalid Pixmap argument.
228 If one of the XLib functions fail, it will produce a X error. The
229 default X error handler prints a diagnostic and calls exit().
232 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
233 XFillRectangle(3), exit(2)
236 John R Veregge - john@puente.jpl.nasa.gov
237 Advanced Engineering and Prototyping Group (AEG)
238 Information Systems Technology Section (395)
239 Jet Propulsion Lab - Calif Institute of Technology
241 *****************************************************************************/
244 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
247 static char stipple_data
[] =
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,
252 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA
255 Pixmap ipixmap
, stipple
;
256 unsigned width
, height
, depth
;
258 Window window
; /* These return values */
259 unsigned border
; /* from XGetGeometry() */
260 int x
, y
; /* are not needed. */
264 if ( NULL
== display
|| 0 == pixmap
)
267 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
268 &width
, &height
, &border
, &depth
)
270 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
272 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
274 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
277 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
280 /* Create an identical copy of the argument pixmap.
282 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
285 /* Copy the argument pixmap into the new pixmap.
287 XCopyArea( display
, pixmap
, ipixmap
,
288 gc
, 0, 0, width
, height
, 0, 0 );
290 /* Refill the new pixmap using the stipple algorithm/pixmap.
292 XSetStipple( display
, gc
, stipple
);
293 XSetFillStyle( display
, gc
, FillStippled
);
294 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
296 XFreeGC( display
, gc
);
298 XFreePixmap( display
, stipple
);