]> git.saurik.com Git - wxWidgets.git/blame - src/os2/icon.cpp
several mac fixes (Mark Newsams patches)
[wxWidgets.git] / src / os2 / icon.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: icon.cpp
3// Purpose: wxIcon class
fb9010ed 4// Author: David Webster
0e320a79 5// Modified by:
fb9010ed 6// Created: 10/09/99
0e320a79 7// RCS-ID: $Id$
fb9010ed
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
fb9010ed
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
3b9e3455
DW
20 #include "wx/defs.h"
21 #include "wx/list.h"
22 #include "wx/utils.h"
23 #include "wx/app.h"
24 #include "wx/icon.h"
0e320a79
DW
25#endif
26
fb9010ed
DW
27#include "wx/os2/private.h"
28#include "assert.h"
29
0e320a79
DW
30#include "wx/icon.h"
31
3b9e3455 32 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxIconBase)
0e320a79 33
3b9e3455
DW
34// ============================================================================
35// implementation
36// ============================================================================
0e320a79 37
3b9e3455
DW
38// ----------------------------------------------------------------------------
39// wxIconRefData
40// ----------------------------------------------------------------------------
0e320a79 41
3b9e3455 42void wxIconRefData::Free()
0e320a79 43{
43543d98
DW
44 if (m_hIcon)
45 ::WinFreeFileIcon((HPOINTER)m_hIcon);
0e320a79
DW
46}
47
3b9e3455
DW
48// ----------------------------------------------------------------------------
49// wxIcon
50// ----------------------------------------------------------------------------
51
0e320a79
DW
52wxIcon::wxIcon()
53{
54}
55
3b9e3455
DW
56wxIcon::wxIcon(
57 const char WXUNUSED(bits)[]
58, int WXUNUSED(nWidth)
59, int WXUNUSED(nHeight)
60)
0e320a79
DW
61{
62}
63
3b9e3455
DW
64wxIcon::wxIcon(
65 const wxString& rIconFile
66, long lFlags
67, int nDesiredWidth
68, int nDesiredHeight
69)
0e320a79 70{
914589c2
DW
71 //
72 // A very poor hack, but we have to have separate icon files from windows
73 // So we have a modified name where replace the last three characters
74 // with os2. Also need the extension.
75 //
76 wxString sOs2Name = rIconFile.Mid(0, rIconFile.Length() - 3);
77
78 sOs2Name += "Os2.ico";
79 LoadFile( sOs2Name
3b9e3455
DW
80 ,lFlags
81 ,nDesiredWidth
82 ,nDesiredHeight
83 );
0e320a79
DW
84}
85
86wxIcon::~wxIcon()
87{
88}
89
6f38c86f
DW
90void wxIcon::CreateIconFromXpm(
91 const char** ppData
92)
93{
94 wxBitmap vBmp(ppData);
95
96 CopyFromBitmap(vBmp);
97} // end of wxIcon::CreateIconFromXpm
98
99void wxIcon::CopyFromBitmap(
100 const wxBitmap& rBmp
101)
102{
103 wxMask* pMask = rBmp.GetMask();
104
105 if (!pMask)
106 {
107 //
108 // We must have a mask for an icon, so even if it's probably incorrect,
109 // do create it (grey is the "standard" transparent colour)
110 //
111 pMask = new wxMask( rBmp
112 ,*wxLIGHT_GREY
113 );
114 }
115
116 POINTERINFO vIconInfo;
117
118 memset(&vIconInfo, '\0', sizeof(POINTERINFO));
119 vIconInfo.fPointer = FALSE; // we want an icon, not a pointer
120 vIconInfo.hbmColor = GetHbitmapOf(rBmp);
121
122 SIZEL vSize = {0, 0};
123 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
124 HDC hDCSrc = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
125 HDC hDCDst = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
126 HPS hPSSrc = ::GpiCreatePS(vHabmain, hDCSrc, &vSize, PU_PELS | GPIA_ASSOC);
127 HPS hPSDst = ::GpiCreatePS(vHabmain, hDCDst, &vSize, PU_PELS | GPIA_ASSOC);
128 POINTL vPoint[4] = { 0, 0, rBmp.GetWidth(), rBmp.GetHeight(),
129 0, 0, rBmp.GetWidth(), rBmp.GetHeight()
130 };
131 ::GpiSetBitmap(hPSSrc, (HBITMAP) pMask->GetMaskBitmap());
132 ::GpiSetBitmap(hPSDst, (HBITMAP) vIconInfo.hbmColor);
133 ::GpiBitBlt( hPSDst
134 ,hPSSrc
135 ,4L
136 ,vPoint
137 ,ROP_SRCAND
138 ,BBO_IGNORE
139 );
140
141 ::GpiSetBitmap(hPSSrc, NULL);
142 ::GpiSetBitmap(hPSDst, NULL);
143 ::GpiDestroyPS(hPSSrc);
144 ::GpiDestroyPS(hPSDst);
145 ::DevCloseDC(hDCSrc);
146 ::DevCloseDC(hDCDst);
147
148 HICON hIcon = ::WinCreatePointerIndirect( HWND_DESKTOP
149 ,&vIconInfo
150 );
151
152 if (!hIcon)
153 {
154 wxLogLastError(wxT("WinCreatePointerIndirect"));
155 }
156 else
157 {
158 SetHICON((WXHICON)hIcon);
159 SetSize( rBmp.GetWidth()
160 ,rBmp.GetHeight()
161 );
162 }
163
164 if (!rBmp.GetMask())
165 {
166 //
167 // We created the mask, now delete it
168 //
169 delete pMask;
170 }
171} // end of wxIcon::CopyFromBitmap
172
3b9e3455
DW
173bool wxIcon::LoadFile(
174 const wxString& rFilename
175, long lType
176, int nDesiredWidth
177, int nDesiredHeight
178)
fb9010ed 179{
8ea3f821 180 HPS hPs = NULLHANDLE;
3b9e3455
DW
181
182 UnRef();
b41cdbf4
DW
183
184 wxGDIImageHandler* pHandler = FindHandler(lType);
3b9e3455
DW
185
186 if (pHandler)
187 return(pHandler->Load( this
188 ,rFilename
8ea3f821 189 ,hPs
3b9e3455
DW
190 ,lType
191 ,nDesiredWidth
192 ,nDesiredHeight
193 ));
fb9010ed 194 else
3b9e3455 195 return(FALSE);
0e320a79
DW
196}
197