X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c6eba8f8b204b0d722db0007e3e0d5e2d2d20085..4b2424bcadbc87babd3367d243b957e49333eeae:/src/msw/dibutils.cpp?ds=sidebyside diff --git a/src/msw/dibutils.cpp b/src/msw/dibutils.cpp index 10a61b9249..6ee22bf304 100644 --- a/src/msw/dibutils.cpp +++ b/src/msw/dibutils.cpp @@ -21,9 +21,9 @@ #endif #ifndef WX_PRECOMP -#include #include "wx/setup.h" #include "wx/defs.h" +#include "wx/string.h" #endif #include @@ -32,6 +32,10 @@ #include "wx/msw/dibutils.h" +#ifdef __WXWINE__ + #include +#endif + #if defined(__WIN32__) #if !defined(__MWERKS__) && !defined(__SALFORDC__) #include // for _fmemcpy() @@ -44,20 +48,41 @@ #define BFT_ICON 0x4349 /* 'IC' */ #define BFT_BITMAP 0x4d42 /* 'BM' */ -#define BFT_CURSOR 0x5450 /* 'PT' */ +#define BFT_CURSOR 0x5450 /* 'PT(' */ +#ifndef SEEK_CUR /* flags for _lseek */ #define SEEK_CUR 1 #define SEEK_END 2 #define SEEK_SET 0 +#endif + +/* Copied from PNGhandler for coompilation with MingW32, RR */ + +#ifndef GlobalAllocPtr +#define GlobalPtrHandle(lp) \ + ((HGLOBAL)GlobalHandle(lp)) + +#define GlobalLockPtr(lp) \ + ((BOOL)GlobalLock(GlobalPtrHandle(lp))) +#define GlobalUnlockPtr(lp) \ + GlobalUnlock(GlobalPtrHandle(lp)) + +#define GlobalAllocPtr(flags, cb) \ + (GlobalLock(GlobalAlloc((flags), (cb)))) +#define GlobalReAllocPtr(lp, cbNew, flags) \ + (GlobalUnlockPtr(lp), GlobalLock(GlobalReAlloc(GlobalPtrHandle(lp) , (cbNew), (flags)))) +#define GlobalFreePtr(lp) \ + (GlobalUnlockPtr(lp), (BOOL)GlobalFree(GlobalPtrHandle(lp))) +#endif /* - * Clear the System Palette so that we can ensure an identity palette + * Clear the System Palette so that we can ensure an identity palette * mapping for fast performance. */ -void ClearSystemPalette(void) +void wxClearSystemPalette(void) { //*** A dummy palette setup struct @@ -77,8 +102,8 @@ void ClearSystemPalette(void) UINT nMapped = 0; BOOL bOK = FALSE; int nOK = 0; - - //*** Reset everything in the system palette to black + + // *** Reset everything in the system palette to black for(Counter = 0; Counter < 256; Counter++) { Palette.aEntries[Counter].peRed = 0; @@ -87,8 +112,12 @@ void ClearSystemPalette(void) Palette.aEntries[Counter].peFlags = PC_NOCOLLAPSE; } - //*** Create, select, realize, deselect, and delete the palette + // *** Create, select, realize, deselect, and delete the palette +#ifdef __WXWINE__ + ScreenDC = GetDC((HWND)NULL); +#else ScreenDC = GetDC(NULL); +#endif ScreenPalette = CreatePalette((LOGPALETTE *)&Palette); if (ScreenPalette) @@ -99,7 +128,11 @@ void ClearSystemPalette(void) bOK = DeleteObject(ScreenPalette); } +#ifdef __WXWINE__ + nOK = ReleaseDC((HWND)NULL, ScreenDC); +#else nOK = ReleaseDC(NULL, ScreenDC); +#endif return; } @@ -113,48 +146,47 @@ void ClearSystemPalette(void) * bits.... */ -int DibWriteFile(LPSTR szFile, LPBITMAPINFOHEADER lpbi) +int wxDibWriteFile(LPTSTR szFile, LPBITMAPINFOHEADER lpbi) { HFILE fh; OFSTRUCT of; - fh = OpenFile(szFile, &of, OF_WRITE | OF_CREATE); + fh = OpenFile(wxConvFile.cWX2MB(szFile), &of, OF_WRITE | OF_CREATE); if (!fh) { // printf("la regamos0"); return 0; } - long size = DibSize(lpbi); + long size = wxDibSize(lpbi); // write file header BITMAPFILEHEADER bmf; - bmf.bfType = 'BM'; + bmf.bfType = BFT_BITMAP; bmf.bfSize = sizeof(bmf) + size; bmf.bfReserved1 = 0; bmf.bfReserved2 = 0; - bmf.bfOffBits = sizeof(bmf) + (char far*)(DibPtr(lpbi)) - (char far*)lpbi; -#if defined( __WATCOMC__) || defined(__VISUALC__) || defined(__SC__) || defined(__SALFORDC__) || defined(__MWERKS__) - if (_hwrite(fh, (LPCSTR)(&bmf), sizeof(bmf))<0 || - _hwrite(fh, (LPCSTR)lpbi, size)<0) { - _lclose(fh); -// printf("la regamos1"); - return 0; - } -#else - if (_hwrite(fh, (LPBYTE)(&bmf), sizeof(bmf))<0 || - _hwrite(fh, (LPBYTE)lpbi, size)<0) { + bmf.bfOffBits = sizeof(bmf) + (char FAR*)(wxDibPtr(lpbi)) - (char FAR*)lpbi; +#if 1 // defined( __WATCOMC__) || defined(__VISUALC__) || defined(__SC__) || defined(__SALFORDC__) || defined(__MWERKS__) || wxUSE_NORLANDER_HEADERS + #define HWRITE_2ND_ARG_TYPE LPCSTR +#else // don't know who needs this... + #define HWRITE_2ND_ARG_TYPE LPBYTE +#endif + + if ( _hwrite(fh, (HWRITE_2ND_ARG_TYPE)(&bmf), sizeof(bmf)) < 0 || + _hwrite(fh, (HWRITE_2ND_ARG_TYPE)lpbi, size) < 0 ) + { _lclose(fh); -// printf("la regamos1"); return 0; } -#endif + +#undef HWRITE_2ND_ARG_TYPE _lclose(fh); return 1; } -PDIB DibOpenFile(LPSTR szFile) +PDIB wxDibOpenFile(LPTSTR szFile) { HFILE fh; DWORD dwLen; @@ -169,7 +201,7 @@ PDIB DibOpenFile(LPSTR szFile) #define GetCurrentInstance() (HINSTANCE)SELECTOROF((LPVOID)&of) #endif - fh = OpenFile(szFile, &of, OF_READ); + fh = OpenFile(wxConvFile.cWX2MB(szFile), &of, OF_READ); if (fh == -1) { @@ -178,6 +210,8 @@ PDIB DibOpenFile(LPSTR szFile) // TODO: Unicode version #ifdef __WIN16__ h = FindResource(GetCurrentInstance(), szFile, RT_BITMAP); +#elif wxUSE_UNICODE + h = FindResourceW(GetCurrentInstance(), szFile, RT_BITMAP); #else h = FindResourceA(GetCurrentInstance(), szFile, RT_BITMAP); #endif @@ -196,7 +230,7 @@ PDIB DibOpenFile(LPSTR szFile) if (fh == -1) return NULL; - pdib = DibReadBitmapInfo(fh); + pdib = wxDibReadBitmapInfo(fh); if (!pdib) return NULL; @@ -204,7 +238,7 @@ PDIB DibOpenFile(LPSTR szFile) /* How much memory do we need to hold the DIB */ dwBits = pdib->biSizeImage; - dwLen = pdib->biSize + DibPaletteSize(pdib) + dwBits; + dwLen = pdib->biSize + wxDibPaletteSize(pdib) + dwBits; /* Can we get more memory? */ @@ -223,7 +257,7 @@ PDIB DibOpenFile(LPSTR szFile) if (pdib) { /* read in the bits */ - _hread(fh, (LPBYTE)pdib + (UINT)pdib->biSize + DibPaletteSize(pdib), dwBits); + _hread(fh, (LPBYTE)pdib + (UINT)pdib->biSize + wxDibPaletteSize(pdib), dwBits); } _lclose(fh); @@ -240,7 +274,7 @@ PDIB DibOpenFile(LPSTR szFile) * bitmap formats, but will always return a "new" BITMAPINFO. */ -PDIB DibReadBitmapInfo(HFILE fh) +PDIB wxDibReadBitmapInfo(HFILE fh) { DWORD off; int size; @@ -287,8 +321,8 @@ PDIB DibReadBitmapInfo(HFILE fh) bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = (DWORD)bc.bcWidth; bi.biHeight = (DWORD)bc.bcHeight; - bi.biPlanes = (UINT)bc.bcPlanes; - bi.biBitCount = (UINT)bc.bcBitCount; + bi.biPlanes = (WORD)bc.bcPlanes; + bi.biBitCount = (WORD)bc.bcBitCount; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; @@ -301,16 +335,16 @@ PDIB DibReadBitmapInfo(HFILE fh) break; } - nNumColors = DibNumColors(&bi); + nNumColors = wxDibNumColors(&bi); #if 0 if (bi.biSizeImage == 0) bi.biSizeImage = DibSizeImage(&bi); if (bi.biClrUsed == 0) - bi.biClrUsed = DibNumColors(&bi); + bi.biClrUsed = wxDibNumColors(&bi); #else - FixBitmapInfo(&bi); + wxFixBitmapInfo(&bi); #endif pdib = (PDIB)GlobalAllocPtr(GMEM_MOVEABLE,(LONG)bi.biSize + nNumColors * sizeof(RGBQUAD)); @@ -320,7 +354,7 @@ PDIB DibReadBitmapInfo(HFILE fh) *pdib = bi; - pRgb = DibColors(pdib); + pRgb = wxDibColors(pdib); if (nNumColors) { @@ -367,7 +401,7 @@ PDIB DibReadBitmapInfo(HFILE fh) * in the passed palette */ -BOOL DibSetUsage(PDIB pdib, HPALETTE hpal,UINT wUsage) +BOOL wxDibSetUsage(PDIB pdib, HPALETTE hpal,UINT wUsage) { PALETTEENTRY ape[256]; RGBQUAD FAR * pRgb; @@ -381,14 +415,14 @@ BOOL DibSetUsage(PDIB pdib, HPALETTE hpal,UINT wUsage) if (!pdib) return FALSE; - nColors = DibNumColors(pdib); - - if (nColors == 3 && DibCompression(pdib) == BI_BITFIELDS) + nColors = wxDibNumColors(pdib); + + if (nColors == 3 && wxDibCompression(pdib) == BI_BITFIELDS) nColors = 0; if (nColors > 0) { - pRgb = DibColors(pdib); + pRgb = wxDibColors(pdib); switch (wUsage) { @@ -429,7 +463,7 @@ BOOL DibSetUsage(PDIB pdib, HPALETTE hpal,UINT wUsage) * given number of bits per pixel */ -PDIB DibCreate(int bits, int dx, int dy) +PDIB wxDibCreate(int bits, int dx, int dy) { LPBITMAPINFOHEADER lpbi ; DWORD dwSizeImage; @@ -515,7 +549,7 @@ static void xlatClut4(BYTE FAR *pb, DWORD dwSize, BYTE FAR *xlat) #define RLE_EOF 1 #define RLE_JMP 2 -static void xlatRle8(BYTE FAR *pb, DWORD dwSize, BYTE FAR *xlat) +static void xlatRle8(BYTE FAR *pb, DWORD WXUNUSED(dwSize), BYTE FAR *xlat) { BYTE cnt; BYTE b; @@ -561,7 +595,7 @@ static void xlatRle8(BYTE FAR *pb, DWORD dwSize, BYTE FAR *xlat) } } -static void xlatRle4(BYTE FAR *pb, DWORD dwSize, BYTE FAR *xlat) +static void xlatRle4(BYTE FAR *WXUNUSED(pb), DWORD WXUNUSED(dwSize), BYTE FAR *WXUNUSED(xlat)) { } @@ -581,7 +615,7 @@ static void hmemmove(BYTE _huge *d, BYTE _huge *s, LONG len) * the colors of the given palette. */ -BOOL DibMapToPalette(PDIB pdib, HPALETTE hpal) +BOOL wxDibMapToPalette(PDIB pdib, HPALETTE hpal) { LPBITMAPINFOHEADER lpbi; PALETTEENTRY pe; @@ -597,13 +631,13 @@ BOOL DibMapToPalette(PDIB pdib, HPALETTE hpal) return FALSE; lpbi = (LPBITMAPINFOHEADER)pdib; - lpRgb = DibColors(pdib); + lpRgb = wxDibColors(pdib); GetObject(hpal,sizeof(int),(LPSTR)&nPalColors); - nDibColors = DibNumColors(pdib); + nDibColors = wxDibNumColors(pdib); if ((SizeImage = lpbi->biSizeImage) == 0) - SizeImage = DibSizeImage(lpbi); + SizeImage = wxDibSizeImage(lpbi); // // build a xlat table. from the current DIB colors to the given @@ -612,7 +646,7 @@ BOOL DibMapToPalette(PDIB pdib, HPALETTE hpal) for (n=0; nbiClrUsed = nPalColors; // @@ -621,14 +655,14 @@ BOOL DibMapToPalette(PDIB pdib, HPALETTE hpal) if (nPalColors > nDibColors) { GlobalReAllocPtr(lpbi, lpbi->biSize + nPalColors*sizeof(RGBQUAD) + SizeImage, 0); - hmemmove((BYTE _huge *)DibPtr(lpbi), (BYTE _huge *)lpBits, SizeImage); - lpBits = (LPBYTE)DibPtr(lpbi); + hmemmove((BYTE _huge *)wxDibPtr(lpbi), (BYTE _huge *)lpBits, SizeImage); + lpBits = (LPBYTE)wxDibPtr(lpbi); } else if (nPalColors < nDibColors) { - hmemcpy(DibPtr(lpbi), lpBits, SizeImage); + hmemcpy(wxDibPtr(lpbi), lpBits, SizeImage); GlobalReAllocPtr(lpbi, lpbi->biSize + nPalColors*sizeof(RGBQUAD) + SizeImage, 0); - lpBits = (LPBYTE)DibPtr(lpbi); + lpBits = (LPBYTE)wxDibPtr(lpbi); } // @@ -669,19 +703,19 @@ BOOL DibMapToPalette(PDIB pdib, HPALETTE hpal) } -HPALETTE MakePalette(const BITMAPINFO FAR* Info, UINT flags) +HPALETTE wxMakePalette(const BITMAPINFO FAR* Info, UINT flags) { HPALETTE hPalette; - const RGBQUAD far* rgb = Info->bmiColors; + const RGBQUAD FAR* rgb = Info->bmiColors; - WORD nColors = Info->bmiHeader.biClrUsed; + WORD nColors = (WORD)Info->bmiHeader.biClrUsed; if (nColors) { LOGPALETTE* logPal = (LOGPALETTE*) new BYTE[sizeof(LOGPALETTE) + (nColors-1)*sizeof(PALETTEENTRY)]; logPal->palVersion = 0x300; // Windows 3.0 version logPal->palNumEntries = nColors; - for (short n = 0; n < nColors; n++) { + for (WORD n = 0; n < nColors; n++) { logPal->palPalEntry[n].peRed = rgb[n].rgbRed; logPal->palPalEntry[n].peGreen = rgb[n].rgbGreen; logPal->palPalEntry[n].peBlue = rgb[n].rgbBlue;