]>
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"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
20 #define XtParent XTPARENT
21 #define XtDisplay XTDISPLAY
25 #include "wx/motif/bmpmotif.h"
28 #pragma message disable nosimpint
32 #pragma message enable nosimpint
35 #include "wx/motif/private.h"
43 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
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
;
117 sprintf( tmp
, "Im%x", (unsigned int)ximage
);
118 XmInstallImage( ximage
, tmp
);
122 WXPixmap
wxBitmapCache::GetLabelPixmap( WXWidget w
)
124 if( m_labelPixmap
&& !m_recalcPixmaps
.label
)
125 return m_labelPixmap
;
127 CreateImageIfNeeded( w
);
129 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
132 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
135 return (WXPixmap
)NULL
;
138 sprintf( tmp
, "Im%x", (unsigned int)m_image
);
141 Widget widget
= (Widget
)w
;
143 while( XmIsGadget( widget
) )
144 widget
= XtParent( widget
);
145 XtVaGetValues( widget
,
150 m_labelPixmap
= (WXPixmap
)XmGetPixmap( screen
, tmp
, fg
, bg
);
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
;
172 sprintf( tmp
, "Im%x", (unsigned int)m_image
);
175 Widget widget
= (Widget
) w
;
177 XtVaGetValues( widget
, XmNarmColor
, &bg
, NULL
);
178 while( XmIsGadget( widget
) )
179 widget
= XtParent( widget
);
180 XtVaGetValues( widget
, XmNforeground
, &fg
, NULL
);
182 m_armPixmap
= (WXPixmap
)XmGetPixmap( screen
, tmp
, fg
, bg
);
184 m_recalcPixmaps
.arm
= !m_armPixmap
;
188 WXPixmap
wxBitmapCache::GetInsensPixmap( WXWidget w
)
190 if( m_insensPixmap
&& !m_recalcPixmaps
.insens
)
191 return m_insensPixmap
;
193 CreateImageIfNeeded( w
);
195 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
198 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
201 return (WXPixmap
)NULL
;
204 (WXPixmap
)XCreateInsensitivePixmap( (Display
*)m_display
,
205 (Pixmap
)m_bitmap
.GetDrawable() );
207 m_recalcPixmaps
.insens
= !m_insensPixmap
;
208 return m_insensPixmap
;
211 //////////////////////////////////////////////////////////////////////////////
213 //////////////////////////////////////////////////////////////////////////////
215 /****************************************************************************
218 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
221 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
224 This function creates a grayed-out copy of the argument pixmap, suitable
225 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
228 The return value is the new Pixmap id or zero on error. Errors include
229 a NULL display argument or an invalid Pixmap argument.
232 If one of the XLib functions fail, it will produce a X error. The
233 default X error handler prints a diagnostic and calls exit().
236 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
237 XFillRectangle(3), exit(2)
240 John R Veregge - john@puente.jpl.nasa.gov
241 Advanced Engineering and Prototyping Group (AEG)
242 Information Systems Technology Section (395)
243 Jet Propulsion Lab - Calif Institute of Technology
245 *****************************************************************************/
248 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
251 static char stipple_data
[] =
253 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
254 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
255 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
256 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA
259 Pixmap ipixmap
, stipple
;
260 unsigned width
, height
, depth
;
262 Window window
; /* These return values */
263 unsigned border
; /* from XGetGeometry() */
264 int x
, y
; /* are not needed. */
268 if ( NULL
== display
|| 0 == pixmap
)
271 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
272 &width
, &height
, &border
, &depth
)
274 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
276 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
278 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
281 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
284 /* Create an identical copy of the argument pixmap.
286 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
289 /* Copy the argument pixmap into the new pixmap.
291 XCopyArea( display
, pixmap
, ipixmap
,
292 gc
, 0, 0, width
, height
, 0, 0 );
294 /* Refill the new pixmap using the stipple algorithm/pixmap.
296 XSetStipple( display
, gc
, stipple
);
297 XSetFillStyle( display
, gc
, FillStippled
);
298 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
300 XFreeGC( display
, gc
);
302 XFreePixmap( display
, stipple
);