]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxInvertMask for OS/2 xpm processing
authorDavid Webster <Dave.Webster@bhmi.com>
Mon, 29 Jan 2001 21:42:53 +0000 (21:42 +0000)
committerDavid Webster <Dave.Webster@bhmi.com>
Mon, 29 Jan 2001 21:42:53 +0000 (21:42 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9217 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/os2/xpmhand.h [new file with mode: 0644]
src/os2/bitmap.cpp
src/os2/xpmhand.cpp

diff --git a/include/wx/os2/xpmhand.h b/include/wx/os2/xpmhand.h
new file mode 100644 (file)
index 0000000..662f954
--- /dev/null
@@ -0,0 +1,64 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        xpmhand.h
+// Purpose:     XPM bitmap handler
+// Author:      Julian Smart
+// Modified by:
+// Created:     04/01/98
+// RCS-ID:      $Id$
+// Copyright:   (c) Julian Smart
+// Licence:    wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma interface "xpmhand.h"
+#endif
+
+#ifndef _WX_XPMHAND_H_
+#define _WX_XPMHAND_H_
+
+class WXDLLEXPORT wxXPMFileHandler: public wxBitmapHandler
+{
+    DECLARE_DYNAMIC_CLASS(wxXPMFileHandler)
+public:
+    inline wxXPMFileHandler(void)
+    {
+        m_sName = "XPM bitmap file";
+        m_sExtension = "xpm";
+        m_lType = wxBITMAP_TYPE_XPM;
+    };
+
+    virtual bool LoadFile( wxBitmap*       pBitmap
+                          ,const wxString& rsName
+                          ,long            lFlags
+                          ,int             nDesiredWidth = -1
+                          ,int             nDesiredHeight = -1
+                         );
+    virtual bool SaveFile( wxBitmap*        pBitmap
+                          ,const wxString&  rsName
+                          ,int              nType
+                          ,const wxPalette* pPalette = NULL
+                         );
+}; // end of CLASS wxWPMFileHandler
+
+class WXDLLEXPORT wxXPMDataHandler: public wxBitmapHandler
+{
+    DECLARE_DYNAMIC_CLASS(wxXPMDataHandler)
+public:
+    inline wxXPMDataHandler(void)
+    {
+        m_sName = "XPM bitmap data";
+        m_sExtension = "xpm";
+        m_lType = wxBITMAP_TYPE_XPM_DATA;
+    };
+    virtual bool Create( wxBitmap* pBitmap
+                        ,void*     pData
+                        ,long      lFlags
+                        ,int       lWidth
+                        ,int       lHeight
+                        ,int       lDepth = 1
+                       );
+}; // end of wxXPMDataHandler
+
+#endif
+  // _WX_XPMHAND_H_
+
index 62d8a3bc6fe91cdb4d0897f8b668e83756df01f6..2bf5a7dc483d20c7f144970bf554b8319fae095d 100644 (file)
@@ -965,3 +965,73 @@ bool wxBitmapHandler::SaveFile(
     return(FALSE);
 }
 
     return(FALSE);
 }
 
+// ----------------------------------------------------------------------------
+// Utility functions
+// ----------------------------------------------------------------------------
+HBITMAP wxInvertMask(
+  HBITMAP                           hBmpMask
+, int                               nWidth
+, int                               nHeight
+)
+{
+    HBITMAP                         hBmpInvMask = 0;
+
+    wxCHECK_MSG( hBmpMask, 0, _T("invalid bitmap in wxInvertMask") );
+
+    //
+    // Get width/height from the bitmap if not given
+    //
+    if (!nWidth || !nHeight)
+    {
+        BITMAPINFOHEADER2           vBmhdr;
+
+        ::GpiQueryBitmapInfoHeader( hBmpMask
+                                   ,&vBmhdr
+                                  );
+        nWidth  = (int)vBmhdr.cx;
+        nHeight = (int)vBmhdr.cyt;
+    }
+
+    BITMAPINFOHEADER2               vBmih;
+    SIZEL                           vSize = {0, 0};
+    DEVOPENSTRUC                    vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
+    HDC                             hDCSrc = ::DevOpenDC(ghAb, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
+    HDC                             hDCDst = ::DevOpenDC(ghAb, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
+    HPS                             hPSSrc = ::GpiCreatePS(ghAb, hDCSrc, &vSize, PU_PELS | GPIA_ASSOC);
+    HPS                             hPSDst = ::GpiCreatePS(ghAb, hDCDst, &vSize, PU_PELS | GPIA_ASSOC);
+    POINTL                          vPoint[4] = { 0 ,0, rBitmap.GetWidth(), rBitmap.GetHeight(),
+                                                  0, 0, rBitmap.GetWidth(), rBitmap.GetHeight()
+                                                };
+
+    memset(&vBmih, NULLC, sizeof(BITMAPINFOHEADER2));
+    vBmih.cbFix     =  sizeof(BITMAPINFOHEADER2);
+    vBmih.cx        = lWidth;
+    vBmih.cy        = lHeight;
+    vBmih.cPlanes   = 1;
+    vBmih.cBitCount = 1;
+
+    hBmpInvMask = ::GpiCreateBitmap( hPSDst
+                                    ,&vBmih
+                                    ,0L
+                                    ,NULL
+                                    ,NULL
+                                   );
+
+    ::GpiSetBitmap(hPSSrc, (HBITMAP) hBmpMask);
+    ::GpiSetBitmap(hPSDst, (HBITMAP) hBmpInvMask);
+
+    ::GpiBitBlt( hPSDst
+                ,hPSSrc
+                ,4L
+                ,&vPoint
+                ,ROP_SRCCOPY
+                ,BBO_IGNORE
+               );
+
+    ::GpiDestroyPS(hPSSrc);
+    ::GpiDestroyPS(hPSDst);
+    ::DevCloseDC(hDCSrc);
+    ::DevCloseDC(hDCDtl);
+
+    return hBmpInvMask;
+} // end of WxWinGdi_InvertMask
index 71eac3afa4f7e548e0f393210446c5cc3c3e6935..ee64879e4a35ee774853644a167350c0c518b394 100644 (file)
@@ -69,7 +69,7 @@ static void XpmToBitmap(
     pRefData->m_nHeight    = vBm.cy;
     pRefData->m_nDepth     = vBm.cPlanes * vBm.cBitCount;
     pRefData->m_nNumColors = rXpmAttr.npixels;
     pRefData->m_nHeight    = vBm.cy;
     pRefData->m_nDepth     = vBm.cPlanes * vBm.cBitCount;
     pRefData->m_nNumColors = rXpmAttr.npixels;
-#if 0
+
     if (pXmask)
     {
         wxMask*                     pMask = new wxMask();
     if (pXmask)
     {
         wxMask*                     pMask = new wxMask();
@@ -80,7 +80,6 @@ static void XpmToBitmap(
                                                      ));
         pBitmap->SetMask(pMask);
     }
                                                      ));
         pBitmap->SetMask(pMask);
     }
-#endif
 } // end of XpmToBitmap
 
 IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler, wxBitmapHandler)
 } // end of XpmToBitmap
 
 IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler, wxBitmapHandler)
@@ -114,6 +113,7 @@ bool wxXPMFileHandler::LoadFile(
                                                                       ,&vXpmAttr
                                                                      );
         ::GpiDestroyPS(hPS);
                                                                       ,&vXpmAttr
                                                                      );
         ::GpiDestroyPS(hPS);
+        ::DevCloseDC(hDC);
         if (nErrorStatus == XpmSuccess)
         {
             XpmToBitmap( pBitmap
         if (nErrorStatus == XpmSuccess)
         {
             XpmToBitmap( pBitmap
@@ -181,6 +181,7 @@ bool wxXPMFileHandler::SaveFile(
                                                                          ,(XpmAttributes *) NULL
                                                                         );
         ::GpiDestroyPS(hPS);
                                                                          ,(XpmAttributes *) NULL
                                                                         );
         ::GpiDestroyPS(hPS);
+        ::DevCloseDC(hDC);
         return (nErrorStatus == XpmSuccess);
     }
     return FALSE;
         return (nErrorStatus == XpmSuccess);
     }
     return FALSE;
@@ -210,13 +211,15 @@ bool wxXPMDataHandler::Create(
     if (hPS)
     {
         vXpmAttr.valuemask = XpmReturnInfos | XpmColorTable;
     if (hPS)
     {
         vXpmAttr.valuemask = XpmReturnInfos | XpmColorTable;
+
         int                         nErrorStatus = XpmCreateImageFromData( &hPS
                                                                           ,(char **)pData
                                                                           ,&pXimage
                                                                           ,&pXmask
                                                                           ,&vXpmAttr
                                                                          );
         int                         nErrorStatus = XpmCreateImageFromData( &hPS
                                                                           ,(char **)pData
                                                                           ,&pXimage
                                                                           ,&pXmask
                                                                           ,&vXpmAttr
                                                                          );
-        GpiDestroyPS(hPS);
+        ::GpiDestroyPS(hPS);
+        ::DevCloseDC(hDC);
         if (nErrorStatus == XpmSuccess)
         {
             XpmToBitmap( pBitmap
         if (nErrorStatus == XpmSuccess)
         {
             XpmToBitmap( pBitmap