X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2bda0e173844e8e0f8acf4e8ad8b5c26e5c6fe5d..4fa0a5b44341885a0886f2ae6723d2441bd1f62f:/src/msw/curico.cpp diff --git a/src/msw/curico.cpp b/src/msw/curico.cpp index 7644dead8a..34b895da03 100644 --- a/src/msw/curico.cpp +++ b/src/msw/curico.cpp @@ -19,12 +19,19 @@ #include #include -#ifdef __GNUWIN32__ -#include "wx/msw/gnuwin32/extra.h" +#if defined(__MWERKS__) +#include +#include #endif +#ifdef __GNUWIN32_OLD__ + #include "wx/msw/gnuwin32/extra.h" +#endif + +#include "wx/wxchar.h" #include "wx/msw/curicop.h" #include "wx/msw/curico.h" +#include "wx/string.h" //***************************************************************************** //* Function : ReadIconFile() * @@ -35,13 +42,13 @@ //* be created for any reason. * //***************************************************************************** -HICON ReadIconFile( char *szFileName, HINSTANCE hInst, int *W, int *H) +HICON ReadIconFile( wxChar *szFileName, HINSTANCE hInst, int *W, int *H) { HICON hIcon; HANDLE hDIB; - if( (hDIB = ReadIcon(szFileName, W, H)) == NULL) + if( (hDIB = ReadIcon(szFileName, W, H)) == (HANDLE) NULL) // read the icon DIB from file - return NULL; + return (HICON) NULL; hIcon = MakeIcon( hDIB, hInst); // create an icon from DIB GlobalFree( hDIB); return hIcon; @@ -58,13 +65,13 @@ HICON ReadIconFile( char *szFileName, HINSTANCE hInst, int *W, int *H) //* monochrome. * //***************************************************************************** -HICON CursorToIcon( char *szFileName, HINSTANCE hInst, int *W, int *H) +HICON CursorToIcon( wxChar *szFileName, HINSTANCE hInst, int *W, int *H) { HANDLE hDIB; // Handle to DIB memory HICON hIcon; // Handle to Icon - if( (hDIB = ReadCur( szFileName, NULL, W, H)) == NULL) + if( (hDIB = ReadCur( szFileName, NULL, W, H)) == (HANDLE) NULL) // Read cursor DIB - return NULL; + return (HICON) NULL; hIcon = MakeIcon( hDIB, hInst); // make icon from cursor DIB GlobalFree( hDIB); return hIcon; @@ -78,10 +85,10 @@ HICON CursorToIcon( char *szFileName, HINSTANCE hInst, int *W, int *H) //* is corrupt or if memory cannot be allocated for the DIB info. * //***************************************************************************** -HANDLE ReadIcon( char *szFileName, int *W, int *H) +HANDLE ReadIcon( wxChar *szFileName, int *W, int *H) { ICONFILEHEADER iconFileHead; // ICON file header structure ICONFILERES iconFileRes; // ICON file resource - WORD cbHead, + UINT cbHead, cbRes, cbBits; // Used for reading in file int hFile; // File handle @@ -92,17 +99,16 @@ HANDLE ReadIcon( char *szFileName, int *W, int *H) nDirEntries = 0; // Open and read the .ICO file header and the first ICONFILERES - hFile = _lopen( szFileName, OF_READ); + hFile = _lopen( wxConvertWX2MB(szFileName), OF_READ); cbHead = _lread( hFile, (LPSTR)&iconFileHead, sizeof(ICONFILEHEADER)); cbRes = _lread( hFile, (LPSTR)&iconFileRes, sizeof(ICONFILERES)); ++nDirEntries; if((cbHead != sizeof( ICONFILEHEADER)) || (cbRes != sizeof( ICONFILERES))) - return NULL; - + return (HANDLE) NULL; // Verify that it's an .ICON file if( iconFileHead.wResourceType != 1) - return NULL; + return (HANDLE) NULL; // inserted by P.S. while( (nDirEntries < iconFileHead.wResourceCount) && @@ -110,7 +116,7 @@ HANDLE ReadIcon( char *szFileName, int *W, int *H) { cbRes = _lread( hFile, (LPSTR )&iconFileRes, sizeof( ICONFILERES)); if(cbRes != sizeof( ICONFILERES)) - return NULL; + return (HANDLE) NULL; else ++nDirEntries; } @@ -122,8 +128,9 @@ HANDLE ReadIcon( char *szFileName, int *W, int *H) // Allocate and lock memory to read in the DIB hDIB = GlobalAlloc(GHND, iconFileRes.dwDIBSize); - if(hDIB == NULL) - return NULL; + if(hDIB == (HANDLE) NULL) + return (HANDLE) NULL; + #ifdef __WINDOWS_386__ lpDIB = (LPBITMAPINFO)MK_FP32(GlobalLock(hDIB)); #else @@ -143,7 +150,7 @@ HANDLE ReadIcon( char *szFileName, int *W, int *H) if( (DWORD )cbBits != iconFileRes.dwDIBSize) { GlobalFree( hDIB); - return NULL; + return (HANDLE) NULL; } return hDIB; } @@ -168,7 +175,7 @@ HANDLE ReadIcon( char *szFileName, int *W, int *H) //* bitmaps. So, no need to convert the AND bitmask. * //* 7) Since a DIB is stored upside down, flip the monochrome AND bits* //* by scanlines. * -//* 8) Use the XOR and AND bits and create an icon with CreateIcon. * +//* 8) Use the XOR and AND bits and create an icon with CreateIcon. * //***************************************************************************** HICON MakeIcon( HANDLE hDIB, HINSTANCE hInst) @@ -209,7 +216,7 @@ HICON MakeIcon( HANDLE hDIB, HINSTANCE hInst) lpDIB->bmiHeader.biBitCount))); // Get a hDC so we can create a bitmap compatible with it - hDC = CreateDC( "DISPLAY", NULL, NULL, NULL); + hDC = CreateDC( wxT("DISPLAY"), NULL, NULL, NULL); // 5) Create a device dependent bitmap with the XOR bits. hbmXor = CreateDIBitmap( hDC, (LPBITMAPINFOHEADER)&(lpDIB->bmiHeader), @@ -219,13 +226,13 @@ HICON MakeIcon( HANDLE hDIB, HINSTANCE hInst) dwBmpSize = (DWORD )(bmpXor.bmWidthBytes * bmpXor.bmHeight * bmpXor.bmPlanes); hXorDDB = GlobalAlloc( GHND, dwBmpSize); - if(hXorDDB == NULL) + if(hXorDDB == (HANDLE) NULL) { // clean up before quitting DeleteObject( hbmXor); DeleteDC( hDC); GlobalUnlock( hDIB); - return NULL; + return (HICON) NULL; } #ifdef __WINDOWS_386__ @@ -246,8 +253,8 @@ HICON MakeIcon( HANDLE hDIB, HINSTANCE hInst) szFlip[(k - 1) - j] = *(DWORD FAR *)lpANDbits; // 8) Use the XOR and AND bits and create an icon with CreateIcon. - hIcon = CreateIcon( hInst, bmpXor.bmWidth, bmpXor.bmHeight, bmpXor.bmPlanes, - bmpXor.bmBitsPixel, (const BYTE *)szFlip, (const BYTE *)lpXorDDB); + hIcon = CreateIcon( hInst, bmpXor.bmWidth, bmpXor.bmHeight, (BYTE)bmpXor.bmPlanes, + (BYTE)bmpXor.bmBitsPixel, (const BYTE *)szFlip, (const BYTE *)lpXorDDB); // Clean up before exiting. DeleteObject( hbmXor); @@ -270,15 +277,15 @@ HICON MakeIcon( HANDLE hDIB, HINSTANCE hInst) //* be created for any reason. * //***************************************************************************** -HCURSOR ReadCursorFile( char *szFileName, HINSTANCE hInst, int *W, int *H, +HCURSOR ReadCursorFile( wxChar *szFileName, HINSTANCE hInst, int *W, int *H, int *XHot, int *YHot) { HANDLE hDIB; // Handle to DIB memory HCURSOR hCursor; POINT ptHotSpot; // read cur DIB from file - if( (hDIB = ReadCur( szFileName, (LPPOINT )&ptHotSpot, W, H)) == NULL) - return NULL; + if( (hDIB = ReadCur( szFileName, (LPPOINT )&ptHotSpot, W, H)) == (HANDLE) NULL) + return (HCURSOR) NULL; hCursor = MakeCursor( hDIB, (LPPOINT )&ptHotSpot, hInst);//create cur from DIB if(XHot != 0) *XHot = ptHotSpot.x; @@ -299,15 +306,15 @@ HCURSOR ReadCursorFile( char *szFileName, HINSTANCE hInst, int *W, int *H, //* monochrome. * //***************************************************************************** -HCURSOR IconToCursor( char *szFileName, HINSTANCE hInst, int XHot, int YHot, +HCURSOR IconToCursor( wxChar *szFileName, HINSTANCE hInst, int XHot, int YHot, int *W, int *H) { HCURSOR hCursor; HANDLE hDIB; POINT ptHotSpot; - if( (hDIB = ReadIcon( szFileName, W, H)) == NULL) + if( (hDIB = ReadIcon( szFileName, W, H)) == (HANDLE) NULL) //read icon file to get icon DIB - return NULL; + return (HCURSOR) NULL; // Set the hot spot of the cursor ptHotSpot.x = XHot; ptHotSpot.y = YHot; @@ -325,10 +332,10 @@ HCURSOR IconToCursor( char *szFileName, HINSTANCE hInst, int XHot, int YHot, //* is corrupt or if memory cannot be allocated for the DIB info. * //***************************************************************************** -HANDLE ReadCur( char *szFileName, LPPOINT lpptHotSpot, int *W, int *H) +HANDLE ReadCur( wxChar *szFileName, LPPOINT lpptHotSpot, int *W, int *H) { CURFILEHEADER curFileHead; // CURSOR file header structure CURFILERES curFileRes; // CURSOR file resource - WORD cbHead, + UINT cbHead, cbRes, cbBits; // Used for reading in file LPBITMAPINFO lpDIB; // Pointer to DIB memory @@ -339,17 +346,17 @@ HANDLE ReadCur( char *szFileName, LPPOINT lpptHotSpot, int *W, int *H) nDirEntries = 0; // Open and read the .ICO file header and the first ICONFILERES - hFile = _lopen( szFileName, OF_READ); + hFile = _lopen( wxConvertWX2MB(szFileName), OF_READ); cbHead = _lread( hFile, (LPSTR )&curFileHead, sizeof( CURFILEHEADER)); cbRes = _lread( hFile, (LPSTR )&curFileRes, sizeof( CURFILERES)); ++nDirEntries; if((cbHead != sizeof( CURFILEHEADER)) || (cbRes != sizeof( CURFILERES))) - return NULL; + return (HANDLE) NULL; // Verify that it's an .CUR file if ((curFileRes.bReserved1 != 0) || (curFileHead.wResourceType != 2)) - return NULL; + return (HANDLE) NULL; // following added by P.S. while( (nDirEntries < curFileHead.wResourceCount) && @@ -357,7 +364,7 @@ HANDLE ReadCur( char *szFileName, LPPOINT lpptHotSpot, int *W, int *H) { cbRes = _lread( hFile, (LPSTR )&curFileRes, sizeof( CURFILERES)); if(cbRes != sizeof( CURFILERES)) - return NULL; + return (HANDLE) NULL; else ++nDirEntries; } @@ -369,8 +376,8 @@ HANDLE ReadCur( char *szFileName, LPPOINT lpptHotSpot, int *W, int *H) // Allocate & lock memory to read in the DIB hDIB = GlobalAlloc(GHND, curFileRes.dwDIBSize); - if(hDIB == NULL) - return NULL; + if(hDIB == (HANDLE) NULL) + return (HANDLE) NULL; #ifdef __WINDOWS_386__ lpDIB = (LPBITMAPINFO )MK_FP32(GlobalLock(hDIB)); @@ -390,9 +397,9 @@ HANDLE ReadCur( char *szFileName, LPPOINT lpptHotSpot, int *W, int *H) { GlobalUnlock( hDIB); GlobalFree( hDIB); - return NULL; + return (HANDLE) NULL; } - if(lpptHotSpot != NULL) // If it is necessary to know the hot spot + if(lpptHotSpot != (LPPOINT) NULL) // If it is necessary to know the hot spot { lpptHotSpot->x = (int )curFileRes.wXHotspot; lpptHotSpot->y = (int )curFileRes.wYHotspot; @@ -433,13 +440,13 @@ HBITMAP ColorDDBToMonoDDB ( HBITMAP hbm) dwLen = bi.biSize + PaletteSize((LPSTR)&bi); - hdc = GetDC( NULL); + hdc = GetDC( (HWND) NULL); hdib = GlobalAlloc( GHND, dwLen); - if (hdib == NULL) + if (hdib == (HANDLE) NULL) { - ReleaseDC( NULL, hdc); - return NULL; + ReleaseDC( (HWND) NULL, hdc); + return (HBITMAP) NULL; } #ifdef __WINDOWS_386__ @@ -469,8 +476,8 @@ HBITMAP ColorDDBToMonoDDB ( HBITMAP hbm) else { GlobalFree( hdib); - ReleaseDC( NULL, hdc); - return NULL; + ReleaseDC( (HWND) NULL, hdc); + return (HBITMAP) NULL; } // Call GetDIBits with a NON-NULL lpBits parameter, to actually @@ -487,9 +494,9 @@ HBITMAP ColorDDBToMonoDDB ( HBITMAP hbm) (LPBITMAPINFO)lpbi, DIB_RGB_COLORS) == 0) { GlobalUnlock( hdib); - hdib = NULL; - ReleaseDC( NULL, hdc); - return NULL; + hdib = (HANDLE) NULL; + ReleaseDC( (HWND) NULL, hdc); + return (HBITMAP) NULL; } // Finally, create a monochrome DDB, and put the DIB into @@ -503,7 +510,7 @@ HBITMAP ColorDDBToMonoDDB ( HBITMAP hbm) GlobalUnlock( hdib); GlobalFree( hdib); - ReleaseDC(NULL, hdc); + ReleaseDC((HWND) NULL, hdc); return hbmMono; } @@ -570,7 +577,7 @@ HCURSOR MakeCursor( HANDLE hDIB, LPPOINT lpptHotSpot, HINSTANCE hInst) lpDIB->bmiHeader.biBitCount))); // Get a hDC so we can create a bitmap compatible with it - hDC = CreateDC( "DISPLAY", NULL, NULL, NULL); + hDC = CreateDC( wxT("DISPLAY"), NULL, NULL, NULL); // 5) Create a device dependent bitmap with the XOR bits. hbmXor = CreateBitmap( (int )lpDIB->bmiHeader.biWidth, @@ -581,12 +588,12 @@ HCURSOR MakeCursor( HANDLE hDIB, LPPOINT lpptHotSpot, HINSTANCE hInst) dwBmpSize = (DWORD )(bmpXor.bmWidthBytes * bmpXor.bmHeight * bmpXor.bmPlanes); hXorDDB = GlobalAlloc( GHND, dwBmpSize); - if(hXorDDB == NULL) + if(hXorDDB == (HANDLE) NULL) { // clean up before quitting DeleteObject( hbmXor); DeleteDC( hDC); GlobalUnlock( hDIB); - return NULL; + return (HCURSOR) NULL; } #ifdef __WINDOWS_386__ lpXorDDB = (LPSTR)MK_FP32(GlobalLock( hXorDDB)); @@ -637,9 +644,9 @@ WORD PaletteSize( LPSTR pv) NumColors = DIBNumColors((LPSTR )lpbi); if(lpbi->biSize == sizeof( BITMAPCOREHEADER)) // OS/2 style DIBs - return NumColors * sizeof( RGBTRIPLE); + return (WORD)(NumColors * sizeof( RGBTRIPLE)); else - return NumColors * sizeof( RGBQUAD); + return (WORD)(NumColors * sizeof( RGBQUAD)); } //***************************************************************************** @@ -665,7 +672,7 @@ WORD DIBNumColors ( LPSTR pv) // is in biClrUsed, whereas in the BITMAPCORE - style headers, it // is dependent on the bits per pixel ( = 2 raised to the power of // bits/pixel). - + if(lpbi->biSize != sizeof( BITMAPCOREHEADER)) { if(lpbi->biClrUsed != 0) @@ -691,7 +698,7 @@ WORD DIBNumColors ( LPSTR pv) #if 0 // ****************************************************************** -BOOL fGetXPixmap( BOOL fIsIcon, char *szFileName, HINSTANCE hInst, +BOOL fGetXPixmap( BOOL fIsIcon, wxChar *szFileName, HINSTANCE hInst, char cData[], int &width, int &height) { HDC hdc, hdcMemory; @@ -766,13 +773,13 @@ HCURSOR MakeCursorFromBitmap(HINSTANCE hInst, HBITMAP hBitmap, POINT *pPoint) NPSTR andBits; NPSTR xorBits; - hDC = GetDC(NULL); + hDC = GetDC((HWND) NULL); hDCColor = CreateCompatibleDC(hDC); hDCMono = CreateCompatibleDC(hDC); hAndBmp = CreateCompatibleBitmap(hDCMono, 32, 32); hXorBmp = CreateCompatibleBitmap(hDCMono, 32, 32); - hBmpOld = SelectObject(hDCColor, hBitmap); + hBmpOld = (HBITMAP) SelectObject(hDCColor, hBitmap); SelectObject(hDCMono, hAndBmp); SetBkColor(hDCColor, RGB(191, 191, 191)); @@ -813,10 +820,17 @@ HCURSOR MakeCursorFromBitmap(HINSTANCE hInst, HBITMAP hBitmap, POINT *pPoint) DeleteObject(hXorBmp); ReleaseDC(NULL, hDC); #ifndef __WIN32__ +#ifdef STRICT + LocalUnlock(LocalHandle((void NEAR*) andBits)); + LocalUnlock(LocalHandle((void NEAR*) xorBits)); + LocalFree(LocalHandle((void NEAR*) andBits)); + LocalFree(LocalHandle((void NEAR*) xorBits)); +#else LocalUnlock(LocalHandle((WORD) andBits)); LocalUnlock(LocalHandle((WORD) xorBits)); LocalFree(LocalHandle((WORD) andBits)); LocalFree(LocalHandle((WORD) xorBits)); +#endif #else LocalUnlock(LocalHandle((LPCVOID) andBits)); LocalUnlock(LocalHandle((LPCVOID) xorBits)); @@ -829,7 +843,7 @@ HCURSOR MakeCursorFromBitmap(HINSTANCE hInst, HBITMAP hBitmap, POINT *pPoint) /* * This doesn't work: just gives us a grey square. Ideas, anyone? */ - + HICON MakeIconFromBitmap(HINSTANCE hInst, HBITMAP hBitmap) { HDC hDCColor, hDCMono; @@ -843,13 +857,13 @@ HICON MakeIconFromBitmap(HINSTANCE hInst, HBITMAP hBitmap) NPSTR andBits; NPSTR xorBits; - hDC = GetDC(NULL); + hDC = GetDC((HWND) NULL); hDCColor = CreateCompatibleDC(hDC); hDCMono = CreateCompatibleDC(hDC); hAndBmp = CreateCompatibleBitmap(hDCMono, 32, 32); hXorBmp = CreateCompatibleBitmap(hDCMono, 32, 32); - hBmpOld = SelectObject(hDCColor, hBitmap); + hBmpOld = (HBITMAP) SelectObject(hDCColor, hBitmap); SelectObject(hDCMono, hAndBmp); SetBkColor(hDCColor, RGB(191, 191, 191)); @@ -882,12 +896,19 @@ HICON MakeIconFromBitmap(HINSTANCE hInst, HBITMAP hBitmap) DeleteDC(hDCMono); DeleteObject(hAndBmp); DeleteObject(hXorBmp); - ReleaseDC(NULL, hDC); + ReleaseDC((HWND) NULL, hDC); #ifndef __WIN32__ +#ifdef STRICT + LocalUnlock(LocalHandle((void NEAR*) andBits)); + LocalUnlock(LocalHandle((void NEAR*) xorBits)); + LocalFree(LocalHandle((void NEAR*) andBits)); + LocalFree(LocalHandle((void NEAR*) xorBits)); +#else LocalUnlock(LocalHandle((WORD) andBits)); LocalUnlock(LocalHandle((WORD) xorBits)); LocalFree(LocalHandle((WORD) andBits)); LocalFree(LocalHandle((WORD) xorBits)); +#endif #else LocalUnlock(LocalHandle((LPCVOID) andBits)); LocalUnlock(LocalHandle((LPCVOID) xorBits));