]> git.saurik.com Git - wxWidgets.git/blame - src/unix/utilsx11.cpp
include stddef.h to get ptrdiff_t decl (IRIX compilation problem)
[wxWidgets.git] / src / unix / utilsx11.cpp
CommitLineData
f618020a
MB
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
130d96dc
JJ
19#ifdef __VMS
20#pragma message disable nosimpint
21#endif
f618020a
MB
22#include <X11/Xlib.h>
23#include <X11/Xatom.h>
130d96dc
JJ
24#ifdef __VMS
25#pragma message enable nosimpint
26#endif
f618020a
MB
27
28void wxSetIconsX11( WXDisplay* display, WXWindow window,
29 const wxIconBundle& ib )
30{
8601b2e1 31#if !wxUSE_NANOX
f618020a
MB
32 size_t size = 0;
33 size_t i, max = ib.m_icons.GetCount();
34
35 for( i = 0; i < max; ++i )
7efaed4d
MB
36 if( ib.m_icons[i].Ok() )
37 size += 2 + ib.m_icons[i].GetWidth() * ib.m_icons[i].GetHeight();
f618020a
MB
38
39 Atom net_wm_icon = XInternAtom( (Display*)display, "_NET_WM_ICON", 0 );
40
41 if( size > 0 )
42 {
43 wxUint32* data = new wxUint32[size];
44 wxUint32* ptr = data;
45
46 for( i = 0; i < max; ++i )
47 {
48 const wxImage image = ib.m_icons[i].ConvertToImage();
49 int width = image.GetWidth(), height = image.GetHeight();
50 unsigned char* imageData = image.GetData();
51 unsigned char* imageDataEnd = imageData + ( width * height * 3 );
52 bool hasMask = image.HasMask();
53 unsigned char rMask, gMask, bMask;
54 unsigned char r, g, b, a;
55
56 if( hasMask )
57 {
58 rMask = image.GetMaskRed();
59 gMask = image.GetMaskGreen();
60 bMask = image.GetMaskBlue();
61 }
0fc5dbf5
VZ
62 else // no mask, but still init the variables to avoid warnings
63 {
64 rMask =
65 gMask =
66 bMask = 0;
67 }
f618020a
MB
68
69 *ptr++ = width;
70 *ptr++ = height;
71
72 while( imageData < imageDataEnd ) {
73 r = imageData[0];
74 g = imageData[1];
75 b = imageData[2];
76 if( hasMask && r == rMask && g == gMask && b == bMask )
77 a = 0;
78 else
79 a = 255;
80
81 *ptr++ = ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b;
82
83 imageData += 3;
84 }
85 }
86
87 XChangeProperty( (Display*)display,
88 (Window)window,
89 net_wm_icon,
90 XA_CARDINAL, 32,
91 PropModeReplace,
92 (unsigned char*)data, size );
93 delete[] data;
94 }
95 else
96 {
97 XDeleteProperty( (Display*)display,
98 (Window)window,
99 net_wm_icon );
100 }
8601b2e1 101#endif
f618020a
MB
102}
103
104#endif