]>
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"
42 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
44 wxBitmapCache::~wxBitmapCache()
48 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
51 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
54 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
57 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
63 XmUninstallImage( (XImage
*)m_image
);
64 XtFree( (char*)(XImage
*)m_image
);
68 void wxBitmapCache::SetBitmap( const wxBitmap
& bitmap
)
70 if( m_bitmap
!= bitmap
)
77 XmUninstallImage( (XImage
*)m_image
);
78 XtFree( (char*)(XImage
*)m_image
);
79 m_image
= (WXImage
*)NULL
;
84 void wxBitmapCache::InvalidateCache()
86 m_recalcPixmaps
.label
= true;
87 m_recalcPixmaps
.arm
= true;
88 m_recalcPixmaps
.insens
= true;
91 void wxBitmapCache::SetColoursChanged()
96 void wxBitmapCache::CreateImageIfNeeded( WXWidget w
)
102 (WXDisplay
*)XtDisplay( (Widget
)w
) :
103 (WXDisplay
*)wxGetDisplay();
105 XImage
*ximage
= XGetImage( (Display
*)m_display
,
106 (Drawable
)m_bitmap
.GetDrawable(),
108 m_bitmap
.GetWidth(), m_bitmap
.GetHeight(),
109 AllPlanes
, ZPixmap
);
111 m_image
= (WXImage
*)ximage
;
116 sprintf( tmp
, "Im%x", (unsigned int)ximage
);
117 XmInstallImage( ximage
, tmp
);
121 WXPixmap
wxBitmapCache::GetLabelPixmap( WXWidget w
)
123 if( m_labelPixmap
&& !m_recalcPixmaps
.label
)
124 return m_labelPixmap
;
126 CreateImageIfNeeded( w
);
128 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
131 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
134 return (WXPixmap
)NULL
;
137 sprintf( tmp
, "Im%x", (unsigned int)m_image
);
140 Widget widget
= (Widget
)w
;
142 while( XmIsGadget( widget
) )
143 widget
= XtParent( widget
);
144 XtVaGetValues( widget
,
149 m_labelPixmap
= (WXPixmap
)XmGetPixmap( screen
, tmp
, fg
, bg
);
151 m_recalcPixmaps
.label
= !m_labelPixmap
;
152 return m_labelPixmap
;
155 WXPixmap
wxBitmapCache::GetArmPixmap( WXWidget w
)
157 if( m_armPixmap
&& !m_recalcPixmaps
.arm
)
160 CreateImageIfNeeded( w
);
162 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
165 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
168 return (WXPixmap
)NULL
;
171 sprintf( tmp
, "Im%x", (unsigned int)m_image
);
174 Widget widget
= (Widget
) w
;
176 XtVaGetValues( widget
, XmNarmColor
, &bg
, NULL
);
177 while( XmIsGadget( widget
) )
178 widget
= XtParent( widget
);
179 XtVaGetValues( widget
, XmNforeground
, &fg
, NULL
);
181 m_armPixmap
= (WXPixmap
)XmGetPixmap( screen
, tmp
, fg
, bg
);
183 m_recalcPixmaps
.arm
= !m_armPixmap
;
187 WXPixmap
wxBitmapCache::GetInsensPixmap( WXWidget w
)
189 if( m_insensPixmap
&& !m_recalcPixmaps
.insens
)
190 return m_insensPixmap
;
192 CreateImageIfNeeded( w
);
194 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
197 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
200 return (WXPixmap
)NULL
;
203 (WXPixmap
)XCreateInsensitivePixmap( (Display
*)m_display
,
204 (Pixmap
)m_bitmap
.GetDrawable() );
206 m_recalcPixmaps
.insens
= !m_insensPixmap
;
207 return m_insensPixmap
;
210 //////////////////////////////////////////////////////////////////////////////
212 //////////////////////////////////////////////////////////////////////////////
214 /****************************************************************************
217 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
220 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
223 This function creates a grayed-out copy of the argument pixmap, suitable
224 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
227 The return value is the new Pixmap id or zero on error. Errors include
228 a NULL display argument or an invalid Pixmap argument.
231 If one of the XLib functions fail, it will produce a X error. The
232 default X error handler prints a diagnostic and calls exit().
235 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
236 XFillRectangle(3), exit(2)
239 John R Veregge - john@puente.jpl.nasa.gov
240 Advanced Engineering and Prototyping Group (AEG)
241 Information Systems Technology Section (395)
242 Jet Propulsion Lab - Calif Institute of Technology
244 *****************************************************************************/
247 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
250 static char stipple_data
[] =
252 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
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
258 Pixmap ipixmap
, stipple
;
259 unsigned width
, height
, depth
;
261 Window window
; /* These return values */
262 unsigned border
; /* from XGetGeometry() */
263 int x
, y
; /* are not needed. */
267 if ( NULL
== display
|| 0 == pixmap
)
270 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
271 &width
, &height
, &border
, &depth
)
273 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
275 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
277 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
280 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
283 /* Create an identical copy of the argument pixmap.
285 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
288 /* Copy the argument pixmap into the new pixmap.
290 XCopyArea( display
, pixmap
, ipixmap
,
291 gc
, 0, 0, width
, height
, 0, 0 );
293 /* Refill the new pixmap using the stipple algorithm/pixmap.
295 XSetStipple( display
, gc
, stipple
);
296 XSetFillStyle( display
, gc
, FillStippled
);
297 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
299 XFreeGC( display
, gc
);
301 XFreePixmap( display
, stipple
);