]>
Commit | Line | Data |
---|---|---|
aae91497 MB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: bitmap.cpp | |
3 | // Purpose: wxBitmap | |
4 | // Author: Julian Smart, originally in bitmap.cpp | |
5 | // Modified by: | |
6 | // Created: 25/03/2003 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "bmpmotif.h" | |
14 | #endif | |
15 | ||
16 | #ifdef __VMS | |
17 | #define XtParent XTPARENT | |
18 | #endif | |
19 | ||
20 | #include "wx/defs.h" | |
21 | #include "wx/motif/bmpmotif.h" | |
22 | ||
23 | #ifdef __VMS__ | |
24 | #pragma message disable nosimpint | |
25 | #endif | |
26 | #include <Xm/Xm.h> | |
27 | #ifdef __VMS__ | |
28 | #pragma message enable nosimpint | |
29 | #endif | |
30 | ||
31 | #include "wx/motif/private.h" | |
32 | ||
33 | #if wxHAVE_LIB_XPM | |
34 | #include <X11/xpm.h> | |
35 | #endif | |
36 | #include <math.h> | |
37 | ||
38 | Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ); | |
39 | ||
40 | wxBitmapCache::~wxBitmapCache() | |
41 | { | |
42 | if( m_display ) | |
43 | { | |
44 | Screen* screen = DefaultScreenOfDisplay( (Display*)m_display ); | |
45 | ||
46 | if( m_labelPixmap ) | |
47 | XmDestroyPixmap( screen, (Pixmap)m_labelPixmap ); | |
48 | ||
49 | if( m_armPixmap ) | |
50 | XmDestroyPixmap( screen, (Pixmap)m_armPixmap ); | |
51 | ||
52 | if( m_insensPixmap ) | |
53 | XmDestroyPixmap( screen, (Pixmap)m_insensPixmap ); | |
54 | ||
55 | } | |
56 | ||
57 | if( m_image ) | |
58 | { | |
59 | XmUninstallImage( (XImage*)m_image ); | |
60 | XtFree( (char*)(XImage*)m_image ); | |
61 | } | |
62 | } | |
63 | ||
64 | void wxBitmapCache::SetBitmap( const wxBitmap& bitmap ) | |
65 | { | |
66 | if( m_bitmap != bitmap ) | |
67 | { | |
68 | InvalidateCache(); | |
69 | m_bitmap = bitmap; | |
70 | ||
71 | if( m_image ) | |
72 | { | |
73 | XmUninstallImage( (XImage*)m_image ); | |
74 | XtFree( (char*)(XImage*)m_image ); | |
75 | m_image = (WXImage*)NULL; | |
76 | } | |
77 | } | |
78 | } | |
79 | ||
80 | void wxBitmapCache::InvalidateCache() | |
81 | { | |
82 | m_recalcPixmaps.label = true; | |
83 | m_recalcPixmaps.arm = true; | |
84 | m_recalcPixmaps.insens = true; | |
85 | } | |
86 | ||
87 | void wxBitmapCache::SetColoursChanged() | |
88 | { | |
89 | InvalidateCache(); | |
90 | } | |
91 | ||
92 | void wxBitmapCache::CreateImageIfNeeded( WXWidget w ) | |
93 | { | |
94 | if( m_image ) | |
95 | return; | |
96 | ||
97 | m_display = w ? | |
98 | (WXDisplay*)XtDisplay( (Widget)w ) : | |
99 | (WXDisplay*)wxGetDisplay(); | |
100 | ||
101 | XImage *ximage = XGetImage( (Display*)m_display, | |
102 | (Drawable)m_bitmap.GetPixmap(), | |
103 | 0, 0, | |
104 | m_bitmap.GetWidth(), m_bitmap.GetHeight(), | |
105 | AllPlanes, ZPixmap ); | |
106 | ||
107 | m_image = (WXImage*)ximage; | |
108 | ||
109 | if( m_image ) | |
110 | { | |
111 | char tmp[128]; | |
112 | sprintf( tmp, "Im%x", (unsigned int)ximage ); | |
113 | XmInstallImage( ximage, tmp ); | |
114 | } | |
115 | } | |
116 | ||
117 | WXPixmap wxBitmapCache::GetLabelPixmap( WXWidget w ) | |
118 | { | |
119 | if( m_labelPixmap && !m_recalcPixmaps.label ) | |
120 | return m_labelPixmap; | |
121 | ||
122 | CreateImageIfNeeded( w ); | |
123 | ||
124 | Screen* screen = DefaultScreenOfDisplay( (Display*)m_display ); | |
125 | ||
126 | if( m_labelPixmap ) | |
127 | XmDestroyPixmap( screen, (Pixmap)m_labelPixmap ); | |
128 | ||
129 | if( !m_image ) | |
130 | return (WXPixmap)NULL; | |
131 | ||
132 | char tmp[128]; | |
133 | sprintf( tmp, "Im%x", (unsigned int)m_image ); | |
134 | ||
135 | Pixel fg, bg; | |
136 | Widget widget = (Widget)w; | |
137 | ||
138 | while( XmIsGadget( widget ) ) | |
139 | widget = XtParent( widget ); | |
140 | XtVaGetValues( widget, | |
141 | XmNbackground, &bg, | |
142 | XmNforeground, &fg, | |
143 | NULL ); | |
144 | ||
145 | m_labelPixmap = (WXPixmap)XmGetPixmap( screen, tmp, fg, bg ); | |
146 | ||
147 | m_recalcPixmaps.label = !m_labelPixmap; | |
148 | return m_labelPixmap; | |
149 | } | |
150 | ||
151 | WXPixmap wxBitmapCache::GetArmPixmap( WXWidget w ) | |
152 | { | |
153 | if( m_armPixmap && !m_recalcPixmaps.arm ) | |
154 | return m_armPixmap; | |
155 | ||
156 | CreateImageIfNeeded( w ); | |
157 | ||
158 | Screen* screen = DefaultScreenOfDisplay( (Display*)m_display ); | |
159 | ||
160 | if( m_armPixmap ) | |
161 | XmDestroyPixmap( screen, (Pixmap)m_armPixmap ); | |
162 | ||
163 | if( !m_image ) | |
164 | return (WXPixmap)NULL; | |
165 | ||
166 | char tmp[128]; | |
167 | sprintf( tmp, "Im%x", (unsigned int)m_image ); | |
168 | ||
169 | Pixel fg, bg; | |
170 | Widget widget = (Widget) w; | |
171 | ||
172 | XtVaGetValues( widget, XmNarmColor, &bg, NULL ); | |
173 | while( XmIsGadget( widget ) ) | |
174 | widget = XtParent( widget ); | |
175 | XtVaGetValues( widget, XmNforeground, &fg, NULL ); | |
176 | ||
177 | m_armPixmap = (WXPixmap)XmGetPixmap( screen, tmp, fg, bg ); | |
178 | ||
179 | m_recalcPixmaps.arm = !m_armPixmap; | |
180 | return m_armPixmap; | |
181 | } | |
182 | ||
183 | WXPixmap wxBitmapCache::GetInsensPixmap( WXWidget w ) | |
184 | { | |
185 | if( m_insensPixmap && !m_recalcPixmaps.insens ) | |
186 | return m_insensPixmap; | |
187 | ||
188 | CreateImageIfNeeded( w ); | |
189 | ||
190 | Screen* screen = DefaultScreenOfDisplay( (Display*)m_display ); | |
191 | ||
192 | if( m_insensPixmap ) | |
193 | XmDestroyPixmap( screen, (Pixmap)m_insensPixmap ); | |
194 | ||
195 | if( !m_image ) | |
196 | return (WXPixmap)NULL; | |
197 | ||
198 | m_insensPixmap = | |
199 | (WXPixmap)XCreateInsensitivePixmap( (Display*)m_display, | |
200 | (Pixmap)m_bitmap.GetPixmap() ); | |
201 | ||
202 | m_recalcPixmaps.insens = !m_insensPixmap; | |
203 | return m_insensPixmap; | |
204 | } |