]> git.saurik.com Git - wxWidgets.git/blob - src/os2/icon.cpp
Some new interfaces in common code requires an updated module definition file.
[wxWidgets.git] / src / os2 / icon.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: icon.cpp
3 // Purpose: wxIcon class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/09/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
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
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"
25 #endif
26
27 #include "wx/os2/private.h"
28 #include "assert.h"
29
30 #include "wx/icon.h"
31
32 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxIconBase)
33
34 // ============================================================================
35 // implementation
36 // ============================================================================
37
38 // ----------------------------------------------------------------------------
39 // wxIconRefData
40 // ----------------------------------------------------------------------------
41
42 void wxIconRefData::Free()
43 {
44 if (m_hIcon)
45 ::WinFreeFileIcon((HPOINTER)m_hIcon);
46 }
47
48 // ----------------------------------------------------------------------------
49 // wxIcon
50 // ----------------------------------------------------------------------------
51
52 wxIcon::wxIcon()
53 {
54 }
55
56 wxIcon::wxIcon(
57 const char WXUNUSED(bits)[]
58 , int WXUNUSED(nWidth)
59 , int WXUNUSED(nHeight)
60 )
61 {
62 }
63
64 wxIcon::wxIcon(
65 const wxString& rIconFile
66 , long lFlags
67 , int nDesiredWidth
68 , int nDesiredHeight
69 )
70 {
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
80 ,lFlags
81 ,nDesiredWidth
82 ,nDesiredHeight
83 );
84 }
85
86 wxIcon::~wxIcon()
87 {
88 }
89
90 void wxIcon::CreateIconFromXpm(
91 const char** ppData
92 )
93 {
94 wxBitmap vBmp(ppData);
95
96 CopyFromBitmap(vBmp);
97 } // end of wxIcon::CreateIconFromXpm
98
99 void 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
173 bool wxIcon::LoadFile(
174 const wxString& rFilename
175 , long lType
176 , int nDesiredWidth
177 , int nDesiredHeight
178 )
179 {
180 HPS hPs = NULLHANDLE;
181
182 UnRef();
183
184 wxGDIImageHandler* pHandler = FindHandler(lType);
185
186 if (pHandler)
187 return(pHandler->Load( this
188 ,rFilename
189 ,hPs
190 ,lType
191 ,nDesiredWidth
192 ,nDesiredHeight
193 ));
194 else
195 return(FALSE);
196 }
197