]>
Commit | Line | Data |
---|---|---|
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 | #include <X11/Xlib.h> | |
20 | #include <X11/Xatom.h> | |
21 | ||
22 | void wxSetIconsX11( WXDisplay* display, WXWindow window, | |
23 | const wxIconBundle& ib ) | |
24 | { | |
25 | size_t size = 0; | |
26 | size_t i, max = ib.m_icons.GetCount(); | |
27 | ||
28 | for( i = 0; i < max; ++i ) | |
29 | size += 2 + ib.m_icons[i].GetWidth() * ib.m_icons[i].GetHeight(); | |
30 | ||
31 | Atom net_wm_icon = XInternAtom( (Display*)display, "_NET_WM_ICON", 0 ); | |
32 | ||
33 | if( size > 0 ) | |
34 | { | |
35 | wxUint32* data = new wxUint32[size]; | |
36 | wxUint32* ptr = data; | |
37 | ||
38 | for( i = 0; i < max; ++i ) | |
39 | { | |
40 | const wxImage image = ib.m_icons[i].ConvertToImage(); | |
41 | int width = image.GetWidth(), height = image.GetHeight(); | |
42 | unsigned char* imageData = image.GetData(); | |
43 | unsigned char* imageDataEnd = imageData + ( width * height * 3 ); | |
44 | bool hasMask = image.HasMask(); | |
45 | unsigned char rMask, gMask, bMask; | |
46 | unsigned char r, g, b, a; | |
47 | ||
48 | if( hasMask ) | |
49 | { | |
50 | rMask = image.GetMaskRed(); | |
51 | gMask = image.GetMaskGreen(); | |
52 | bMask = image.GetMaskBlue(); | |
53 | } | |
54 | ||
55 | *ptr++ = width; | |
56 | *ptr++ = height; | |
57 | ||
58 | while( imageData < imageDataEnd ) { | |
59 | r = imageData[0]; | |
60 | g = imageData[1]; | |
61 | b = imageData[2]; | |
62 | if( hasMask && r == rMask && g == gMask && b == bMask ) | |
63 | a = 0; | |
64 | else | |
65 | a = 255; | |
66 | ||
67 | *ptr++ = ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b; | |
68 | ||
69 | imageData += 3; | |
70 | } | |
71 | } | |
72 | ||
73 | XChangeProperty( (Display*)display, | |
74 | (Window)window, | |
75 | net_wm_icon, | |
76 | XA_CARDINAL, 32, | |
77 | PropModeReplace, | |
78 | (unsigned char*)data, size ); | |
79 | delete[] data; | |
80 | } | |
81 | else | |
82 | { | |
83 | XDeleteProperty( (Display*)display, | |
84 | (Window)window, | |
85 | net_wm_icon ); | |
86 | } | |
87 | } | |
88 | ||
89 | #endif |