]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/bitmap.cpp
updated wxMac file list (use MoreFiles)
[wxWidgets.git] / src / mac / carbon / bitmap.cpp
index fd0f461f173833798c03ad22da21b7a9e10b681b..df8d319f43d25ac74893c5ab95742bdcb4f3cebd 100644 (file)
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
+#pragma implementation "bitmapbase.h"
 #pragma implementation "bitmap.h"
 #endif
 
 #pragma implementation "bitmap.h"
 #endif
 
-#include "wx/wx.h"
-#include "wx/setup.h"
-#include "wx/utils.h"
-#include "wx/palette.h"
+#include "wx/defs.h"
+
 #include "wx/bitmap.h"
 #include "wx/icon.h"
 #include "wx/log.h"
 #include "wx/bitmap.h"
 #include "wx/icon.h"
 #include "wx/log.h"
@@ -30,7 +29,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase , wxGDIObject )
 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase, wxObject ) 
 #endif
 
 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase, wxObject ) 
 #endif
 
-#ifdef __UNIX__
+#ifdef __DARWIN__
     #include <ApplicationServices/ApplicationServices.h>
 #else
     #include <PictUtils.h>
     #include <ApplicationServices/ApplicationServices.h>
 #else
     #include <PictUtils.h>
@@ -200,33 +199,34 @@ wxBitmapRefData::wxBitmapRefData()
     m_bitmapType = kMacBitmapTypeUnknownType ;
 }
 
     m_bitmapType = kMacBitmapTypeUnknownType ;
 }
 
-wxBitmapRefData::~wxBitmapRefData()
+// TODO move this do a public function of Bitmap Ref
+static void DisposeBitmapRefData(wxBitmapRefData *data)
 {
 {
-       switch (m_bitmapType)
+       switch (data->m_bitmapType)
        {
                case kMacBitmapTypePict :
                        {
        {
                case kMacBitmapTypePict :
                        {
-                               if ( m_hPict )
+                               if ( data->m_hPict )
                                {
                                {
-                                       KillPicture( m_hPict ) ;
-                                       m_hPict = NULL ;
+                                       KillPicture( data->m_hPict ) ;
+                                       data->m_hPict = NULL ;
                                }
                        }
                        break ;
                case kMacBitmapTypeGrafWorld :
                        {
                                }
                        }
                        break ;
                case kMacBitmapTypeGrafWorld :
                        {
-                               if ( m_hBitmap )
+                               if ( data->m_hBitmap )
                                {
                                {
-                                       wxMacDestroyGWorld( m_hBitmap ) ;
-                                       m_hBitmap = NULL ;
+                                       wxMacDestroyGWorld( data->m_hBitmap ) ;
+                                       data->m_hBitmap = NULL ;
                                }
                        }
                        break ;
                case kMacBitmapTypeIcon :
                                }
                        }
                        break ;
                case kMacBitmapTypeIcon :
-               if ( m_hIcon )
+               if ( data->m_hIcon )
                {
                {
-                       DisposeCIcon( m_hIcon ) ;
-                       m_hIcon = NULL ;
+                       DisposeCIcon( data->m_hIcon ) ;
+                       data->m_hIcon = NULL ;
                }
                
                default :
                }
                
                default :
@@ -234,19 +234,25 @@ wxBitmapRefData::~wxBitmapRefData()
                        break ;
        }
        
                        break ;
        }
        
-  if (m_bitmapMask)
+  if (data->m_bitmapMask)
   {
   {
-    delete m_bitmapMask;
-    m_bitmapMask = NULL;
+    delete data->m_bitmapMask;
+    data->m_bitmapMask = NULL;
   }
 }
 
   }
 }
 
-wxList wxBitmap::sm_handlers;
+wxBitmapRefData::~wxBitmapRefData()
+{
+  DisposeBitmapRefData( this ) ;
+}
+
+wxList wxBitmapBase::sm_handlers;
 
 
 bool wxBitmap::CopyFromIcon(const wxIcon& icon)
 {
     Ref(icon) ;
 
 
 bool wxBitmap::CopyFromIcon(const wxIcon& icon)
 {
     Ref(icon) ;
+    return true;
 }
 
 wxBitmap::wxBitmap()
 }
 
 wxBitmap::wxBitmap()
@@ -438,7 +444,7 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
            RGBColor  color;
 
            bitmap = GetHBITMAP();
            RGBColor  color;
 
            bitmap = GetHBITMAP();
-           subbitmap = wxMacCreateGWorld(rect.width, rect.height, GetDepth());
+           subbitmap = ref->m_hBitmap ;
            LockPixels(GetGWorldPixMap(bitmap));
            LockPixels(GetGWorldPixMap(subbitmap));
 
            LockPixels(GetGWorldPixMap(bitmap));
            LockPixels(GetGWorldPixMap(subbitmap));
 
@@ -454,7 +460,6 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
            }
            UnlockPixels(GetGWorldPixMap(bitmap));
            UnlockPixels(GetGWorldPixMap(subbitmap));
            }
            UnlockPixels(GetGWorldPixMap(bitmap));
            UnlockPixels(GetGWorldPixMap(subbitmap));
-           ret.SetHBITMAP(subbitmap);
        }
    }
    SetGWorld( origPort, origDevice );
        }
    }
    SetGWorld( origPort, origDevice );
@@ -487,9 +492,11 @@ int wxBitmap::GetBitmapType() const
 
 void wxBitmap::SetHBITMAP(WXHBITMAP bmp)
 {
 
 void wxBitmap::SetHBITMAP(WXHBITMAP bmp)
 {
+    DisposeBitmapRefData( M_BITMAPDATA ) ;
+    
     M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
     M_BITMAPDATA->m_hBitmap = bmp ;
     M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
     M_BITMAPDATA->m_hBitmap = bmp ;
-       M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
+         M_BITMAPDATA->m_ok = (M_BITMAPDATA->m_hBitmap != NULL ) ;
 }
 
 bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
 }
 
 bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
@@ -548,55 +555,68 @@ wxBitmap::wxBitmap(const wxImage& image, int depth)
 
     // Create picture
 
 
     // Create picture
 
-    Create( width , height , wxDisplayDepth() ) ;
-    wxBitmap maskBitmap( width, height, 1);
+    Create( width , height , 32 ) ;
     
     CGrafPtr origPort ;
     GDHandle origDevice ;
 
     
     CGrafPtr origPort ;
     GDHandle origDevice ;
 
-    LockPixels( GetGWorldPixMap(GetHBITMAP()) );
-    LockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) );
+    PixMapHandle pixMap = GetGWorldPixMap(GetHBITMAP()) ;
+    LockPixels( pixMap );
 
     GetGWorld( &origPort , &origDevice ) ;
     SetGWorld( GetHBITMAP() , NULL ) ;
     
     // Render image
 
     GetGWorld( &origPort , &origDevice ) ;
     SetGWorld( GetHBITMAP() , NULL ) ;
     
     // Render image
-    wxColour rgb, maskcolor(image.GetMaskRed(), image.GetMaskGreen(), image.GetMaskBlue());
-    RGBColor color;
-    RGBColor white = { 0xffff, 0xffff, 0xffff };
-    RGBColor black = { 0     , 0     , 0      };
+    RGBColor colorRGB ;
 
     register unsigned char* data = image.GetData();
 
     register unsigned char* data = image.GetData();
-
-    int index = 0;
+    char* destinationBase = GetPixBaseAddr( pixMap );
+    register unsigned char* destination = (unsigned char*) destinationBase ;
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
-            rgb.Set(data[index++], data[index++], data[index++]);
-            color = rgb.GetPixel();
-            SetCPixel( x , y , &color ) ;
-            if (image.HasMask())
-            {
-                SetGWorld(maskBitmap.GetHBITMAP(), NULL);
-                if (rgb == maskcolor) {
-                    SetCPixel(x,y, &white);
-                }
-                else {
-                    SetCPixel(x,y, &black);
-                }
-                SetGWorld(GetHBITMAP(), NULL);
-            }
+            *destination++ = 0 ;
+            *destination++ = *data++ ;              
+            *destination++ = *data++ ;              
+            *destination++ = *data++ ;              
         }
         }
-    }  // for height
+        destinationBase += ((**pixMap).rowBytes & 0x7fff);  
+        destination = (unsigned char*) destinationBase ;    
+    }  
+    if ( image.HasMask() )
+    {
+      data = image.GetData(); 
+      
+      wxColour maskcolor(image.GetMaskRed(), image.GetMaskGreen(), image.GetMaskBlue());
+      RGBColor white = { 0xffff, 0xffff, 0xffff };
+      RGBColor black = { 0     , 0     , 0      };
+      wxBitmap maskBitmap ;
 
 
-    // Create mask
-    if ( image.HasMask() ) {
-        SetMask(new wxMask( maskBitmap ));
+      maskBitmap.Create( width, height, 1);
+      LockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) );
+      SetGWorld(maskBitmap.GetHBITMAP(), NULL);
+
+      for (int y = 0; y < height; y++)
+      {
+          for (int x = 0; x < width; x++)
+          {
+              if ( data[0] == image.GetMaskRed() && data[1] == image.GetMaskGreen() && data[2] == image.GetMaskBlue() )
+              {
+                SetCPixel(x,y, &white);
+              }
+              else {
+                      SetCPixel(x,y, &black);
+              }
+              data += 3 ;
+          }
+      }  // for height
+      SetGWorld(GetHBITMAP(), NULL);
+      SetMask(new wxMask( maskBitmap ));
+      UnlockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) );
     }
     
     UnlockPixels( GetGWorldPixMap(GetHBITMAP()) );
     }
     
     UnlockPixels( GetGWorldPixMap(GetHBITMAP()) );
-    UnlockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) );
     SetGWorld( origPort, origDevice );
 }
 
     SetGWorld( origPort, origDevice );
 }
 
@@ -842,7 +862,7 @@ PicHandle wxBitmap::GetPict() const
 
    if( mask )
    {
 
    if( mask )
    {
-#ifdef __UNIX__
+#ifdef __DARWIN__
        RGBColor trans = white;
 #else
        RGBBackColor( &gray );
        RGBColor trans = white;
 #else
        RGBBackColor( &gray );