]> git.saurik.com Git - wxWidgets.git/blob - src/unix/utilsx11.cpp
More changes for better redraw flow under X11.
[wxWidgets.git] / src / unix / utilsx11.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/utilsx11.cpp
3 // Purpose: Miscellaneous X11 functions
4 // Author: Mattia Barbon
5 // Modified by:
6 // Created: 25.03.02
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__WXX11__) || defined(__WXGTK__) || defined(__WXMOTIF__)
13
14 #include "wx/unix/utilsx11.h"
15 #include "wx/iconbndl.h"
16 #include "wx/image.h"
17 #include "wx/icon.h"
18
19 #ifdef __VMS
20 #pragma message disable nosimpint
21 #endif
22 #include <X11/Xlib.h>
23 #include <X11/Xatom.h>
24 #ifdef __VMS
25 #pragma message enable nosimpint
26 #endif
27
28 void wxSetIconsX11( WXDisplay* display, WXWindow window,
29 const wxIconBundle& ib )
30 {
31 size_t size = 0;
32 size_t i, max = ib.m_icons.GetCount();
33
34 for( i = 0; i < max; ++i )
35 size += 2 + ib.m_icons[i].GetWidth() * ib.m_icons[i].GetHeight();
36
37 Atom net_wm_icon = XInternAtom( (Display*)display, "_NET_WM_ICON", 0 );
38
39 if( size > 0 )
40 {
41 wxUint32* data = new wxUint32[size];
42 wxUint32* ptr = data;
43
44 for( i = 0; i < max; ++i )
45 {
46 const wxImage image = ib.m_icons[i].ConvertToImage();
47 int width = image.GetWidth(), height = image.GetHeight();
48 unsigned char* imageData = image.GetData();
49 unsigned char* imageDataEnd = imageData + ( width * height * 3 );
50 bool hasMask = image.HasMask();
51 unsigned char rMask, gMask, bMask;
52 unsigned char r, g, b, a;
53
54 if( hasMask )
55 {
56 rMask = image.GetMaskRed();
57 gMask = image.GetMaskGreen();
58 bMask = image.GetMaskBlue();
59 }
60
61 *ptr++ = width;
62 *ptr++ = height;
63
64 while( imageData < imageDataEnd ) {
65 r = imageData[0];
66 g = imageData[1];
67 b = imageData[2];
68 if( hasMask && r == rMask && g == gMask && b == bMask )
69 a = 0;
70 else
71 a = 255;
72
73 *ptr++ = ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b;
74
75 imageData += 3;
76 }
77 }
78
79 XChangeProperty( (Display*)display,
80 (Window)window,
81 net_wm_icon,
82 XA_CARDINAL, 32,
83 PropModeReplace,
84 (unsigned char*)data, size );
85 delete[] data;
86 }
87 else
88 {
89 XDeleteProperty( (Display*)display,
90 (Window)window,
91 net_wm_icon );
92 }
93 }
94
95 #endif