1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxIcon class 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  28 #include "wx/os2/private.h" 
  33     IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxGDIObject
) 
  35 // ============================================================================ 
  37 // ============================================================================ 
  39 // ---------------------------------------------------------------------------- 
  41 // ---------------------------------------------------------------------------- 
  43 void wxIconRefData::Free() 
  46         ::WinFreeFileIcon((HPOINTER
)m_hIcon
); 
  49 // ---------------------------------------------------------------------------- 
  51 // ---------------------------------------------------------------------------- 
  58 wxIcon::wxIcon( const char WXUNUSED(bits
)[], 
  60                 int        WXUNUSED(nHeight
) ) 
  65 wxIcon::wxIcon( const wxString
& rIconFile
, 
  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. 
  76     wxString sOs2Name 
= rIconFile
.Mid(0, rIconFile
.Length() - 3); 
  78     sOs2Name 
+= wxT("Os2.ico"); 
  90 void wxIcon::CreateIconFromXpm( 
  94     wxBitmap                        
vBmp(ppData
); 
 102 } // end of wxIcon::CreateIconFromXpm 
 104 void wxIcon::CopyFromBitmap( const wxBitmap
& rBmp 
) 
 106     wxMask
*                         pMask 
= rBmp
.GetMask(); 
 107     HBITMAP                         hBmp 
= NULLHANDLE
; 
 108     HBITMAP                         hBmpMask 
= NULLHANDLE
; 
 109     HBITMAP                         hOldBitmap 
= NULLHANDLE
; 
 117         // We must have a mask for an icon, so even if it's probably incorrect, 
 118         // do create it (grey is the "standard" transparent colour) 
 120         pMask 
= new wxMask( rBmp
 
 125     BITMAPINFOHEADER2               vHeader
; 
 126     SIZEL                           vSize 
= {0, 0}; 
 127     DEVOPENSTRUC                    vDop 
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L}; 
 128     HDC                             hDCSrc 
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
); 
 129     HDC                             hDCDst 
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
); 
 130     HPS                             hPSSrc 
= ::GpiCreatePS(vHabmain
, hDCSrc
, &vSize
, PU_PELS 
| GPIA_ASSOC
); 
 131     HPS                             hPSDst 
= ::GpiCreatePS(vHabmain
, hDCDst
, &vSize
, PU_PELS 
| GPIA_ASSOC
); 
 132     POINTL                          vPoint
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()}, 
 133                                                   {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()} 
 135     POINTL                          vPointMask
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight() * 2}, 
 136                                                       {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()} 
 139     POINTERINFO                     vIconInfo
; 
 141     memset(&vIconInfo
, '\0', sizeof(POINTERINFO
)); 
 142     vIconInfo
.fPointer 
= FALSE
;  // we want an icon, not a pointer 
 144     memset(&vHeader
, '\0', 16); 
 146     vHeader
.cx              
= (ULONG
)rBmp
.GetWidth(); 
 147     vHeader
.cy              
= (ULONG
)rBmp
.GetHeight(); 
 148     vHeader
.cPlanes         
= 1L; 
 149     vHeader
.cBitCount       
= 24; 
 151     hBmp 
= ::GpiCreateBitmap( hPSDst
 
 158     if ((hOldBitmap 
= ::GpiSetBitmap(hPSDst
, hBmp
)) == HBM_ERROR
) 
 160         vError 
= ::WinGetLastError(vHabmain
); 
 161         sError 
= wxPMErrorToStr(vError
); 
 163     if ((hOldBitmap 
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)rBmp
.GetHBITMAP())) == HBM_ERROR
) 
 165         vError 
= ::WinGetLastError(vHabmain
); 
 166         sError 
= wxPMErrorToStr(vError
); 
 168     if ((lHits 
= ::GpiBitBlt( hPSDst
 
 176         vError 
= ::WinGetLastError(vHabmain
); 
 177         sError 
= wxPMErrorToStr(vError
); 
 179     if ((hOldBitmap 
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
) 
 181         vError 
= ::WinGetLastError(vHabmain
); 
 182         sError 
= wxPMErrorToStr(vError
); 
 184     if ((hOldBitmap 
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
) 
 186         vError 
= ::WinGetLastError(vHabmain
); 
 187         sError 
= wxPMErrorToStr(vError
); 
 189     vIconInfo
.hbmColor 
= hBmp
; 
 191     vHeader
.cy              
= (ULONG
)rBmp
.GetHeight() * 2; 
 192     hBmpMask 
= ::GpiCreateBitmap( hPSDst
 
 199     if ((hOldBitmap 
= ::GpiSetBitmap(hPSDst
, hBmpMask
)) == HBM_ERROR
) 
 201         vError 
= ::WinGetLastError(vHabmain
); 
 202         sError 
= wxPMErrorToStr(vError
); 
 204     if ((hOldBitmap 
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)pMask
->GetMaskBitmap())) == HBM_ERROR
) 
 206         vError 
= ::WinGetLastError(vHabmain
); 
 207         sError 
= wxPMErrorToStr(vError
); 
 209     if ((lHits 
= ::GpiBitBlt( hPSDst
 
 217         vError 
= ::WinGetLastError(vHabmain
); 
 218         sError 
= wxPMErrorToStr(vError
); 
 220     if ((hOldBitmap 
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
) 
 222         vError 
= ::WinGetLastError(vHabmain
); 
 223         sError 
= wxPMErrorToStr(vError
); 
 225     if ((hOldBitmap 
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
) 
 227         vError 
= ::WinGetLastError(vHabmain
); 
 228         sError 
= wxPMErrorToStr(vError
); 
 231     vIconInfo
.hbmPointer 
= hBmpMask
; 
 233 #if !(defined(__WATCOMC__) && __WATCOMC__ < 1240 ) 
 234 // Open Watcom 1.3 had incomplete headers 
 235 // that's reported and should be fixed for OW 1.4 
 237     HICON hIcon 
= ::WinCreatePointerIndirect( HWND_DESKTOP
, &vIconInfo
); 
 241         wxLogLastError(wxT("WinCreatePointerIndirect")); 
 242         vError 
= ::WinGetLastError(vHabmain
); 
 243         sError 
= wxPMErrorToStr(vError
); 
 247         SetHICON((WXHICON
)hIcon
); 
 248         SetSize( rBmp
.GetWidth() 
 257         // We created the mask, now delete it 
 261     ::GpiSetBitmap(hPSSrc
, NULL
); 
 262     ::GpiSetBitmap(hPSDst
, NULL
); 
 263     ::GpiDestroyPS(hPSSrc
); 
 264     ::GpiDestroyPS(hPSDst
); 
 265     ::DevCloseDC(hDCSrc
); 
 266     ::DevCloseDC(hDCDst
); 
 267 } // end of wxIcon::CopyFromBitmap 
 269 bool wxIcon::LoadFile( const wxString
& rFilename
, 
 274     HPS                             hPs 
= NULLHANDLE
; 
 278     wxGDIImageHandler
*              pHandler 
= FindHandler(lType
); 
 281         return(pHandler
->Load( this