]>
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 static inline wxCharBuffer
GetCacheImageName(WXImage image
)
47 return wxString::Format(_T("wxBitmap_%p"), image
).ToAscii();
50 wxBitmapCache::~wxBitmapCache()
54 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
57 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
60 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
63 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
69 XmUninstallImage( (XImage
*)m_image
);
70 XtFree( (char*)(XImage
*)m_image
);
74 void wxBitmapCache::SetBitmap( const wxBitmap
& bitmap
)
76 if( m_bitmap
!= bitmap
)
83 XmUninstallImage( (XImage
*)m_image
);
84 XtFree( (char*)(XImage
*)m_image
);
85 m_image
= (WXImage
*)NULL
;
90 void wxBitmapCache::InvalidateCache()
92 m_recalcPixmaps
.label
= true;
93 m_recalcPixmaps
.arm
= true;
94 m_recalcPixmaps
.insens
= true;
97 void wxBitmapCache::SetColoursChanged()
102 void wxBitmapCache::CreateImageIfNeeded( WXWidget w
)
108 (WXDisplay
*)XtDisplay( (Widget
)w
) :
109 (WXDisplay
*)wxGetDisplay();
111 XImage
*ximage
= XGetImage( (Display
*)m_display
,
112 (Drawable
)m_bitmap
.GetDrawable(),
114 m_bitmap
.GetWidth(), m_bitmap
.GetHeight(),
115 AllPlanes
, ZPixmap
);
117 m_image
= (WXImage
*)ximage
;
121 XmInstallImage( ximage
, GetCacheImageName(m_image
).data() );
125 WXPixmap
wxBitmapCache::GetPixmapFromCache(WXWidget w
)
127 Widget widget
= (Widget
)w
;
128 while( XmIsGadget( widget
) )
129 widget
= XtParent( widget
);
132 XtVaGetValues( widget
,
137 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
138 return (WXPixmap
)XmGetPixmap(screen
, GetCacheImageName(m_image
).data(), fg
, bg
);
141 WXPixmap
wxBitmapCache::GetLabelPixmap( WXWidget w
)
143 if( m_labelPixmap
&& !m_recalcPixmaps
.label
)
144 return m_labelPixmap
;
146 CreateImageIfNeeded( w
);
148 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
151 XmDestroyPixmap( screen
, (Pixmap
)m_labelPixmap
);
154 return (WXPixmap
)NULL
;
156 m_labelPixmap
= GetPixmapFromCache(w
);
157 m_recalcPixmaps
.label
= !m_labelPixmap
;
158 return m_labelPixmap
;
161 WXPixmap
wxBitmapCache::GetArmPixmap( WXWidget w
)
163 if( m_armPixmap
&& !m_recalcPixmaps
.arm
)
166 CreateImageIfNeeded( w
);
168 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
171 XmDestroyPixmap( screen
, (Pixmap
)m_armPixmap
);
174 return (WXPixmap
)NULL
;
176 m_armPixmap
= GetPixmapFromCache(w
);
177 m_recalcPixmaps
.arm
= !m_armPixmap
;
181 WXPixmap
wxBitmapCache::GetInsensPixmap( WXWidget w
)
183 if( m_insensPixmap
&& !m_recalcPixmaps
.insens
)
184 return m_insensPixmap
;
186 CreateImageIfNeeded( w
);
188 Screen
* screen
= DefaultScreenOfDisplay( (Display
*)m_display
);
191 XmDestroyPixmap( screen
, (Pixmap
)m_insensPixmap
);
194 return (WXPixmap
)NULL
;
197 (WXPixmap
)XCreateInsensitivePixmap( (Display
*)m_display
,
198 (Pixmap
)m_bitmap
.GetDrawable() );
200 m_recalcPixmaps
.insens
= !m_insensPixmap
;
201 return m_insensPixmap
;
204 //////////////////////////////////////////////////////////////////////////////
206 //////////////////////////////////////////////////////////////////////////////
208 /****************************************************************************
211 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
214 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
217 This function creates a grayed-out copy of the argument pixmap, suitable
218 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
221 The return value is the new Pixmap id or zero on error. Errors include
222 a NULL display argument or an invalid Pixmap argument.
225 If one of the XLib functions fail, it will produce a X error. The
226 default X error handler prints a diagnostic and calls exit().
229 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
230 XFillRectangle(3), exit(2)
233 John R Veregge - john@puente.jpl.nasa.gov
234 Advanced Engineering and Prototyping Group (AEG)
235 Information Systems Technology Section (395)
236 Jet Propulsion Lab - Calif Institute of Technology
238 *****************************************************************************/
241 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
244 static char stipple_data
[] =
246 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
247 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
248 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
249 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA
252 Pixmap ipixmap
, stipple
;
253 unsigned width
, height
, depth
;
255 Window window
; /* These return values */
256 unsigned border
; /* from XGetGeometry() */
257 int x
, y
; /* are not needed. */
261 if ( NULL
== display
|| 0 == pixmap
)
264 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
265 &width
, &height
, &border
, &depth
)
267 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
269 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
271 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
274 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
277 /* Create an identical copy of the argument pixmap.
279 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
282 /* Copy the argument pixmap into the new pixmap.
284 XCopyArea( display
, pixmap
, ipixmap
,
285 gc
, 0, 0, width
, height
, 0, 0 );
287 /* Refill the new pixmap using the stipple algorithm/pixmap.
289 XSetStipple( display
, gc
, stipple
);
290 XSetFillStyle( display
, gc
, FillStippled
);
291 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
293 XFreeGC( display
, gc
);
295 XFreePixmap( display
, stipple
);