]> git.saurik.com Git - wxWidgets.git/blob - src/unix/utilsx11.cpp
Compile fix when not using WXR resources.
[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 if( ib.m_icons[i].Ok() )
36 size += 2 + ib.m_icons[i].GetWidth() * ib.m_icons[i].GetHeight();
37
38 Atom net_wm_icon = XInternAtom( (Display*)display, "_NET_WM_ICON", 0 );
39
40 if( size > 0 )
41 {
42 wxUint32* data = new wxUint32[size];
43 wxUint32* ptr = data;
44
45 for( i = 0; i < max; ++i )
46 {
47 const wxImage image = ib.m_icons[i].ConvertToImage();
48 int width = image.GetWidth(), height = image.GetHeight();
49 unsigned char* imageData = image.GetData();
50 unsigned char* imageDataEnd = imageData + ( width * height * 3 );
51 bool hasMask = image.HasMask();
52 unsigned char rMask, gMask, bMask;
53 unsigned char r, g, b, a;
54
55 if( hasMask )
56 {
57 rMask = image.GetMaskRed();
58 gMask = image.GetMaskGreen();
59 bMask = image.GetMaskBlue();
60 }
61
62 *ptr++ = width;
63 *ptr++ = height;
64
65 while( imageData < imageDataEnd ) {
66 r = imageData[0];
67 g = imageData[1];
68 b = imageData[2];
69 if( hasMask && r == rMask && g == gMask && b == bMask )
70 a = 0;
71 else
72 a = 255;
73
74 *ptr++ = ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b;
75
76 imageData += 3;
77 }
78 }
79
80 XChangeProperty( (Display*)display,
81 (Window)window,
82 net_wm_icon,
83 XA_CARDINAL, 32,
84 PropModeReplace,
85 (unsigned char*)data, size );
86 delete[] data;
87 }
88 else
89 {
90 XDeleteProperty( (Display*)display,
91 (Window)window,
92 net_wm_icon );
93 }
94 }
95
96 #endif