-
- wxBitmap ret( rect.width, rect.height, GetDepth() );
- wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
-
- GWorldPtr origPort;
- GDHandle origDevice;
-
- GetGWorld( &origPort, &origDevice );
-
- // Update the subbitmaps reference data
- wxBitmapRefData *ref = (wxBitmapRefData *)ret.GetRefData();
-
- ref->m_numColors = M_BITMAPDATA->m_numColors;
- ref->m_bitmapPalette = M_BITMAPDATA->m_bitmapPalette;
- ref->m_bitmapType = M_BITMAPDATA->m_bitmapType;
-
- // Copy sub region of this bitmap
- if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypePict)
- {
- printf("GetSubBitmap: Copy a region of a Pict structure - TODO\n");
- }
- else if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypeGrafWorld)
- {
- // Copy mask
- if(GetMask())
- {
- GWorldPtr submask, mask;
- RGBColor color;
-
- mask = (GWorldPtr) GetMask()->GetMaskBitmap();
- submask = wxMacCreateGWorld(rect.width, rect.height, 1);
- LockPixels(GetGWorldPixMap(mask));
- LockPixels(GetGWorldPixMap(submask));
-
- for(int yy = 0; yy < rect.height; yy++)
- {
- for(int xx = 0; xx < rect.width; xx++)
- {
- SetGWorld(mask, NULL);
- GetCPixel(rect.x + xx, rect.y + yy, &color);
- SetGWorld(submask, NULL);
- SetCPixel(xx,yy, &color);
- }
- }
- UnlockPixels(GetGWorldPixMap(mask));
- UnlockPixels(GetGWorldPixMap(submask));
- ref->m_bitmapMask = new wxMask;
- ref->m_bitmapMask->SetMaskBitmap(submask);
- }
-
- // Copy bitmap
- if(GetHBITMAP())
- {
- GWorldPtr subbitmap, bitmap;
- RGBColor color;
-
- bitmap = (GWorldPtr) GetHBITMAP();
- subbitmap = (GWorldPtr) ref->m_hBitmap ;
- LockPixels(GetGWorldPixMap(bitmap));
- LockPixels(GetGWorldPixMap(subbitmap));
-
- for(int yy = 0; yy < rect.height; yy++)
- {
- for(int xx = 0; xx < rect.width; xx++)
- {
- SetGWorld(bitmap, NULL);
- GetCPixel(rect.x + xx, rect.y + yy, &color);
- SetGWorld(subbitmap, NULL);
- SetCPixel(xx, yy, &color);
- }
- }
- UnlockPixels(GetGWorldPixMap(bitmap));
- UnlockPixels(GetGWorldPixMap(subbitmap));
- }
- }
- SetGWorld( origPort, origDevice );
-
- return ret;