Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

oslibres.cpp

Go to the documentation of this file.
00001 /* $Id: oslibres.cpp,v 1.29 2001/10/27 10:30:10 sandervl Exp $ */
00002 /*
00003  * Window API wrappers for OS/2
00004  *
00005  *
00006  * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
00007  *
00008  *
00009  * Project Odin Software License can be found in LICENSE.TXT
00010  *
00011  */
00012 #define  INCL_WIN
00013 #define  INCL_PM
00014 #include <os2wrap.h>
00015 #include <stdlib.h>
00016 #include <stdio.h>
00017 #include <string.h>
00018 
00019 #include <misc.h>
00020 #include <winconst.h>
00021 #include "oslibwin.h"
00022 #include "oslibutil.h"
00023 #include "oslibmsg.h"
00024 #include "oslibgdi.h"
00025 #include "oslibres.h"
00026 #include "pmwindow.h"
00027 #include <wingdi32.h>
00028 
00029 #define DBG_LOCALLOG    DBG_oslibres
00030 #include "dbglocal.h"
00031 
00032 //******************************************************************************
00033 //******************************************************************************
00034 HANDLE OSLibWinSetAccelTable(HWND hwnd, HANDLE hAccel, PVOID acceltemplate)
00035 {
00036  HAB    hab = WinQueryAnchorBlock(hwnd);
00037 
00038     if(hAccel == 0) {
00039         hAccel = WinCreateAccelTable(hab, (PACCELTABLE)acceltemplate);
00040         if(hAccel == 0) {
00041             dprintf(("OSLibWinSetAccelTable: WinCreateAccelTable returned 0"));
00042             return FALSE;
00043         }
00044     }
00045     if(WinSetAccelTable(hab, hAccel, hwnd) == TRUE) {
00046             return hAccel;
00047     }
00048     else    return 0;
00049 }
00050 #if 0
00051 //******************************************************************************
00052 //TODO: change search method for icon array (cxDesired, cyDesired)
00053 //TODO: PM rescales the icon internally!!! ($W(#*&$(*%&)
00054 //******************************************************************************
00055 HANDLE OSLibWinCreateIcon(PVOID iconbitmap, ULONG cxDesired, ULONG cyDesired)
00056 {
00057  POINTERINFO pointerInfo = {0};
00058  HBITMAP     hbmColor, hbmMask;
00059  BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)iconbitmap;
00060  BITMAPFILEHEADER2 *bfhBW;
00061  BITMAPFILEHEADER2 *bfhColor;
00062  HPS         hps;
00063  HANDLE      hIcon;
00064 
00065     if(iconbitmap == NULL) {
00066         dprintf(("OSLibWinCreateIcon iconbitmap == NULL!!"));
00067         return 0;
00068     }
00069     if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
00070         // search best icon for the current screen,
00071         // TODO: maybe compare icon size with screen size.
00072         // Some bugs with black/white Icons ?
00073         BITMAPARRAYFILEHEADER2 *next, *found;
00074         LONG bitcountScreen, bitcountIcon=-1, cxIcon=-1, cyIcon=-1;
00075 
00076         HPS hps = WinGetPS(HWND_DESKTOP);
00077         HDC hdc = GpiQueryDevice(hps);
00078         DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, &bitcountScreen);
00079         WinReleasePS(hps);
00080 
00081         next = found = bafh;
00082         while(TRUE)
00083         {
00084             bfhColor = (BITMAPFILEHEADER2 *)((char *)&next->bfh2 + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
00085             if(bfhColor->bmp2.cBitCount <= bitcountScreen &&
00086                bfhColor->bmp2.cBitCount > bitcountIcon ||
00087                (bfhColor->bmp2.cBitCount == bitcountIcon &&
00088                (cxIcon < bfhColor->bmp2.cx || cyIcon < bfhColor->bmp2.cy)))
00089             {
00090                 found = next;
00091                 bitcountIcon = bfhColor->bmp2.cBitCount;
00092                 cxIcon = bfhColor->bmp2.cx;
00093                 cyIcon = bfhColor->bmp2.cy;
00094             }
00095             if(next->offNext != 0)
00096                 next = (BITMAPARRAYFILEHEADER2 *) ((char *)bafh + next->offNext);
00097             else
00098                 break;
00099         }
00100         bfhBW    = &found->bfh2;
00101         bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
00102     }
00103     else {//single icon
00104         bfhBW    = (BITMAPFILEHEADER2 *)iconbitmap;
00105         bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
00106         bafh     = (BITMAPARRAYFILEHEADER2 *)bfhBW; //for calculation bitmap offset
00107     }
00108     hps = WinGetScreenPS(HWND_DESKTOP);
00109 
00110     //Resize icon bitmap if requested size is different
00111     if(cxDesired != bfhColor->bmp2.cx|| cyDesired != bfhColor->bmp2.cy)
00112     {
00113         BITMAPINFOHEADER2 infohdr = bfhColor->bmp2;
00114 
00115         infohdr.cx = cxDesired;
00116         infohdr.cy = cyDesired;
00117         hbmColor = GpiCreateBitmap(hps, &infohdr, CBM_INIT,
00118                                    (char *)bafh + bfhColor->offBits,
00119                                    (BITMAPINFO2 *)&bfhColor->bmp2);
00120     }
00121     else {
00122         hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
00123                                    (char *)bafh + bfhColor->offBits,
00124                                    (BITMAPINFO2 *)&bfhColor->bmp2);
00125     }
00126     if(hbmColor == GPI_ERROR) {
00127         dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
00128         WinReleasePS(hps);
00129         return 0;
00130     }
00131     //Resize icon mask if requested size is different
00132     if(cxDesired != bfhBW->bmp2.cx|| cyDesired*2 != bfhBW->bmp2.cy)
00133     {
00134         BITMAPINFOHEADER2 infohdr = bfhBW->bmp2;
00135 
00136         infohdr.cx = cxDesired;
00137         infohdr.cy = cyDesired;
00138         hbmMask = GpiCreateBitmap(hps, &infohdr, CBM_INIT,
00139                                   (char *)bafh + bfhBW->offBits,
00140                                   (BITMAPINFO2 *)&bfhBW->bmp2);
00141     }
00142     else {
00143         hbmMask = GpiCreateBitmap(hps, &bfhBW->bmp2, CBM_INIT,
00144                                   (char *)bafh + bfhBW->offBits,
00145                                   (BITMAPINFO2 *)&bfhBW->bmp2);
00146     }
00147     if(hbmMask == GPI_ERROR) {
00148         dprintf(("OSLibWinCreateIcon: GpiCreateBitmap hbmMask failed!"));
00149         GpiDeleteBitmap(hbmColor);
00150         WinReleasePS(hps);
00151         return 0;
00152     }
00153 
00154     pointerInfo.fPointer   = FALSE; //icon
00155     pointerInfo.xHotspot   = bfhBW->xHotspot;
00156     pointerInfo.yHotspot   = bfhBW->yHotspot;
00157     pointerInfo.hbmColor   = hbmColor;
00158     pointerInfo.hbmPointer = hbmMask;
00159     hIcon = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
00160     if(hIcon == NULL) {
00161         dprintf(("OSLibWinCreateIcon: WinCreatePointerIndirect failed!"));
00162     }
00163     GpiDeleteBitmap(hbmMask);
00164     GpiDeleteBitmap(hbmColor);
00165     WinReleasePS(hps);
00166 
00167     return hIcon;
00168 }
00169 //******************************************************************************
00170 //TODO: change cursor size if required!! (cxDesired, cyDesired)
00171 //******************************************************************************
00172 HANDLE OSLibWinCreatePointer(PVOID cursorbitmap, ULONG cxDesired, ULONG cyDesired)
00173 {
00174  POINTERINFO pointerInfo = {0};
00175  HBITMAP     hbmColor = 0, hbmMask = 0;
00176  BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)cursorbitmap;
00177  BITMAPFILEHEADER2 *bfh = (BITMAPFILEHEADER2 *)cursorbitmap, *bfhColor = 0;
00178  HPS         hps;
00179  HANDLE      hPointer;
00180 
00181     if(cursorbitmap == NULL) {
00182         dprintf(("OSLibWinCreatePointer cursorbitmap == NULL!!"));
00183         return 0;
00184     }
00185     if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
00186         bfh  = &bafh->bfh2;
00187         bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
00188     }
00189     else {//single cursor
00190         bfh  = (BITMAPFILEHEADER2 *)cursorbitmap;
00191         bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
00192         bafh = (BITMAPARRAYFILEHEADER2 *)bfh; //for calculation bitmap offset
00193     }
00194     //skip xor/and mask
00195     hps = WinGetScreenPS(HWND_DESKTOP);
00196     hbmMask = GpiCreateBitmap(hps, &bfh->bmp2, CBM_INIT,
00197                               (char *)bafh + bfh->offBits,
00198                               (BITMAPINFO2 *)&bfh->bmp2);
00199     if(hbmMask == GPI_ERROR) {
00200         dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
00201         WinReleasePS(hps);
00202         return 0;
00203     }
00204 
00205     if((ULONG)((char *)bafh+bfh->offBits) != (ULONG)bfhColor)
00206     {//color bitmap present
00207         hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
00208                                (char *)bafh + bfhColor->offBits,
00209                                (BITMAPINFO2 *)&bfhColor->bmp2);
00210         if(hbmColor == GPI_ERROR) {
00211                 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
00212                 GpiDeleteBitmap(hbmMask);
00213                 WinReleasePS(hps);
00214                 return 0;
00215         }
00216     }
00217 
00218     pointerInfo.fPointer   = TRUE;
00219     pointerInfo.xHotspot   = bfh->xHotspot;
00220     pointerInfo.yHotspot   = bfh->yHotspot;
00221     pointerInfo.hbmColor   = hbmColor;
00222     pointerInfo.hbmPointer = hbmMask;
00223     hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
00224 
00225     if(hPointer == NULL) {
00226         dprintf(("OSLibWinCreatePointer: WinCreatePointerIndirect failed!"));
00227     }
00228     GpiDeleteBitmap(hbmMask);
00229     if(hbmColor) GpiDeleteBitmap(hbmColor);
00230     WinReleasePS(hps);
00231     return hPointer;
00232 }
00233 #endif
00234 //******************************************************************************
00235 //******************************************************************************
00236 BOOL isMonoBitmap(BITMAP_W *pXorBmp, PBYTE os2rgb)
00237 {
00238   ULONG pixel, color[2];
00239   char *bmpdata;
00240   int i, j, nrcolors = 0, increment;
00241 
00242     increment = pXorBmp->bmBitsPixel/8;
00243 
00244     for(i=0;i<pXorBmp->bmHeight;i++) {
00245         bmpdata = (char *)os2rgb;
00246         for(j=0;j<pXorBmp->bmWidth;j++) {
00247             pixel = 0;
00248             memcpy(&pixel, os2rgb, increment);
00249             if(nrcolors == 0) { 
00250                 color[0] = pixel;
00251                 nrcolors = 1;
00252             }
00253             else
00254             if(nrcolors == 1 && color[0] != pixel) {
00255                 color[1] = pixel;
00256                 nrcolors = 2;
00257             }
00258             else {
00259                 if(color[0] != pixel && color[1] != pixel) 
00260                 {
00261                     return FALSE;
00262                 }
00263             }
00264             os2rgb += increment;
00265         }
00266         os2rgb = bmpdata + pXorBmp->bmWidthBytes;
00267     }
00268     return TRUE;
00269 }
00270 //******************************************************************************
00271 //******************************************************************************
00272 char *colorToMonoBitmap(HBITMAP bmpsrc, BITMAPINFO2 *pBmpDest)
00273 { 
00274     HDC hdcDest = 0;            /* device context handle                */
00275     HPS hpsDest = 0;
00276     SIZEL sizl = { 0, 0 };  /* use same page size as device         */
00277     DEVOPENSTRUC dop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
00278     LONG lHits; 
00279     char *bmpbuffer = 0;
00280     BITMAPINFO2 *bmpinfo = NULL;
00281     HAB hab;
00282 
00283     dprintf2(("Convert color bitmap to mono (%d,%d) %d", pBmpDest->cx, pBmpDest->cy, pBmpDest->cBitCount));
00284 
00285     hab = GetThreadHAB();
00286 
00287     /* create memory device context */
00288     hdcDest = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
00289  
00290     /* Create the presentation and associate the memory device
00291        context. */
00292     hpsDest = GpiCreatePS(hab, hdcDest, &sizl, PU_PELS |
00293                           GPIT_MICRO | GPIA_ASSOC);
00294     if(!hpsDest) goto fail; 
00295 
00296     GpiSetBitmap(hpsDest, bmpsrc);
00297 
00298     bmpinfo   = (BITMAPINFO2 *)malloc(2*sizeof(BITMAPINFOHEADER2) + sizeof(RGB2));
00299     bmpbuffer = (char *)malloc(pBmpDest->cy*pBmpDest->cx);
00300     memset(bmpinfo, 0, sizeof(BITMAPINFOHEADER2) + sizeof(RGB2));
00301     bmpinfo->cbFix            = sizeof(BITMAPINFOHEADER2);
00302     bmpinfo->cx               = pBmpDest->cx;
00303     bmpinfo->cy               = pBmpDest->cy;
00304     bmpinfo->cPlanes          = 1;
00305     bmpinfo->cBitCount        = 1;
00306     bmpinfo->ulCompression    = BCA_UNCOMP;
00307     bmpinfo->ulColorEncoding  = BCE_RGB;
00308 
00309     lHits = GpiQueryBitmapBits(hpsDest, 0, pBmpDest->cy, bmpbuffer, bmpinfo);
00310     if(lHits == GPI_ERROR) goto fail;
00311 
00312 //#define DEBUG_CURSOR
00313 #ifdef DEBUG_CURSOR
00314  {
00315     dprintf(("colorToMonoBitmap %d %d (%x,%x,%x)(%x,%x,%x)", pBmpDest->cx, pBmpDest->cy, bmpinfo->argbColor[0].bRed, bmpinfo->argbColor[0].bGreen, bmpinfo->argbColor[0].bBlue, bmpinfo->argbColor[1].bRed, bmpinfo->argbColor[1].bGreen, bmpinfo->argbColor[1].bBlue));
00316     for(int i=pBmpDest->cy-1;i>=0;i--) {
00317         for(int j=0;j<pBmpDest->cx;j++) {
00318             if(j<8) {
00319                 if((*(bmpbuffer+i*4)) & (1<<(7-j))) {
00320                     WriteLogNoEOL("X");
00321                 }
00322                 else WriteLogNoEOL(".");
00323             }
00324             else 
00325             if(j<16) {
00326                 if((*(bmpbuffer+1+i*4)) & (1<<(15-j))) {
00327                     WriteLogNoEOL("X");
00328                 }
00329                 else WriteLogNoEOL(".");
00330             }
00331             else
00332             if(j<24) {
00333                 if((*(bmpbuffer+2+i*4)) & (1<<(23-j))) {
00334                     WriteLogNoEOL("X");
00335                 }
00336                 else WriteLogNoEOL(".");
00337             }
00338             else {
00339                 if((*(bmpbuffer+3+i*4)) & (1<<(31-j))) {
00340                     WriteLogNoEOL("X");
00341                 }
00342                 else WriteLogNoEOL(".");
00343             }
00344         }
00345         WriteLogNoEOL("\n");
00346     }
00347 }
00348 #endif
00349 
00350     GpiSetBitmap(hpsDest, NULL);
00351 
00352     GpiAssociate(hpsDest, NULLHANDLE); /* disassociate device context */
00353     GpiDestroyPS(hpsDest);       /* destroys presentation space */
00354     DevCloseDC(hdcDest);         /* closes device context       */
00355     free(bmpinfo);
00356 
00357     return bmpbuffer; 
00358 
00359 fail:
00360     if(bmpinfo)   free(bmpinfo);
00361     if(bmpbuffer) free(bmpbuffer);
00362 
00363     if(hpsDest) {
00364         GpiSetBitmap(hpsDest, NULL);
00365         GpiAssociate(hpsDest, NULLHANDLE); /* disassociate device context */
00366         GpiDestroyPS(hpsDest);       /* destroys presentation space */
00367     }
00368     if(hdcDest) DevCloseDC(hdcDest);         /* closes device context       */
00369     return 0;
00370 }
00371 //******************************************************************************
00372 //******************************************************************************
00373 //NOTE: Depends on origin of bitmap data!!!
00374 //      Assumes 1 bpp bitmaps have a top left origin and all others have a bottom left origin
00375 //******************************************************************************
00376 HANDLE OSLibWinCreatePointer(CURSORICONINFO *pInfo, char *pAndBits, BITMAP_W *pAndBmp, char *pXorBits, 
00377                              BITMAP_W *pXorBmp, BOOL fCursor)
00378 {
00379  POINTERINFO  pointerInfo = {0};
00380  HANDLE       hPointer;
00381  HBITMAP      hbmColor = 0, hbmMask = 0;
00382  BITMAPINFO2 *pBmpColor = 0, *pBmpMask = 0;
00383  int          masksize, colorsize, rgbsize, i;
00384  HPS          hps;
00385  char        *dest, *src, *pOS2XorBits = 0;
00386 
00387     hps = WinGetScreenPS(HWND_DESKTOP);
00388 
00389     if(pXorBits)
00390     {//color bitmap present
00391         RGBQUAD *rgb;
00392         RGB2    *os2rgb;
00393 
00394         if(pXorBmp->bmBitsPixel <= 8)
00395              rgbsize = (1<<pXorBmp->bmBitsPixel)*sizeof(RGB2);
00396         else rgbsize = 0;
00397 
00398         colorsize = sizeof(BITMAPINFO2) + (pXorBmp->bmHeight * pXorBmp->bmWidthBytes) + rgbsize;
00399         pBmpColor = (BITMAPINFO2 *)malloc(colorsize);
00400         if(pBmpColor == NULL) {
00401             DebugInt3();
00402             return 0;
00403         }
00404         memset(pBmpColor, 0, colorsize);
00405         pBmpColor->cbFix            = sizeof(BITMAPINFOHEADER2);
00406         pBmpColor->cx               = (USHORT)pXorBmp->bmWidth;
00407         pBmpColor->cy               = (USHORT)pXorBmp->bmHeight;
00408         pBmpColor->cPlanes          = pXorBmp->bmPlanes;
00409         pBmpColor->cBitCount        = pXorBmp->bmBitsPixel;
00410         pBmpColor->ulCompression    = BCA_UNCOMP;
00411         pBmpColor->ulColorEncoding  = BCE_RGB;
00412 
00413         os2rgb                      = &pBmpColor->argbColor[0];
00414         rgb                         = (RGBQUAD *)(pXorBits);
00415 
00416         if(pXorBmp->bmBitsPixel <= 8) {
00417             for(i=0;i<(1<<pXorBmp->bmBitsPixel);i++) {
00418                     os2rgb->bRed   = rgb->rgbRed;
00419                     os2rgb->bBlue  = rgb->rgbBlue;
00420                     os2rgb->bGreen = rgb->rgbGreen;
00421                     os2rgb++;
00422                     rgb++;
00423             }
00424         }
00425 
00426         if(pXorBmp->bmBitsPixel == 1) {
00427                 //copy Xor bits (must reverse scanlines because origin is top left instead of bottom left)
00428                 src  = (char *)rgb;
00429                 dest = ((char *)os2rgb) + (pXorBmp->bmHeight - 1) * pXorBmp->bmWidthBytes;
00430                 for(i=0;i<pXorBmp->bmHeight;i++) {
00431                     memcpy(dest, src, pXorBmp->bmWidthBytes);
00432                     dest -= pXorBmp->bmWidthBytes;
00433                     src  += pXorBmp->bmWidthBytes;
00434                 }
00435         }
00436         else    
00437         if(pXorBmp->bmBitsPixel == 16) {
00438                 ConvertRGB555to565(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes);
00439         }
00440         else    memcpy(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes);
00441 
00442         hbmColor = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpColor, CBM_INIT,
00443                               (PBYTE)os2rgb, pBmpColor);
00444 
00445         if(hbmColor == GPI_ERROR) {
00446                 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
00447                 goto fail;
00448         }
00449         if(fCursor && pXorBmp->bmBitsPixel >= 8) 
00450         {
00451             if(isMonoBitmap(pXorBmp, (PBYTE)os2rgb) == TRUE) 
00452             {
00453                 pOS2XorBits = colorToMonoBitmap(hbmColor, pBmpColor);
00454                 if(pOS2XorBits) {
00455                     GpiDeleteBitmap(hbmColor);
00456                     hbmColor = 0;
00457                 }
00458             }
00459         }
00460         if(hbmColor) {
00461              dprintf2(("OSLibWinCreatePointer: using real color cursor/icon (fCursor %d)", fCursor));
00462         }
00463         else dprintf2(("OSLibWinCreatePointer: converted color cursor/icon to mono (fCursor %d)", fCursor));
00464     }
00465 
00466     //SvL: 2*sizeof(RGB2) is enough, but GpiCreateBitmap seems to touch more
00467     //     memory. (Adobe Photoshop 6 running in the debugger)
00468     masksize = sizeof(BITMAPINFO2) + (pAndBmp->bmHeight * 2 * pAndBmp->bmWidthBytes) + 16*sizeof(RGB2);
00469     pBmpMask = (BITMAPINFO2 *)malloc(masksize);
00470     if(pBmpMask == NULL) {
00471         DebugInt3();
00472         return 0;
00473     }
00474     memset(pBmpMask, 0, masksize);
00475     pBmpMask->cbFix             = sizeof(BITMAPINFOHEADER2);
00476     pBmpMask->cx                = (USHORT)pAndBmp->bmWidth;
00477     pBmpMask->cy                = (USHORT)pAndBmp->bmHeight*2;
00478     pBmpMask->cPlanes           = pAndBmp->bmPlanes;
00479     pBmpMask->cBitCount         = 1;
00480     pBmpMask->ulCompression     = BCA_UNCOMP;
00481     pBmpMask->ulColorEncoding   = BCE_RGB;
00482     memset(&pBmpMask->argbColor[0], 0, sizeof(RGB2));
00483     memset(&pBmpMask->argbColor[1], 0xff, sizeof(RGB)); //not the reserved byte
00484     if(pOS2XorBits) {
00485          dest = ((char *)&pBmpMask->argbColor[2]);
00486          memcpy(dest, pOS2XorBits, pAndBmp->bmWidthBytes*pAndBmp->bmHeight);
00487          free(pOS2XorBits);
00488          pOS2XorBits = NULL;
00489     }
00490     // else Xor bits are already 0
00491 
00492     //copy And bits (must reverse scanlines because origin is top left instead of bottom left)
00493     src  = pAndBits;
00494     dest = ((char *)&pBmpMask->argbColor[2]) + (pAndBmp->bmHeight * 2 - 1) * (pAndBmp->bmWidthBytes);
00495     for(i=0;i<pAndBmp->bmHeight;i++) {
00496         memcpy(dest, src, pAndBmp->bmWidthBytes);
00497         dest -= pAndBmp->bmWidthBytes;
00498         src  += pAndBmp->bmWidthBytes;
00499     }
00500     hbmMask = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpMask, CBM_INIT,
00501                               (PBYTE)&pBmpMask->argbColor[2], pBmpMask);
00502 
00503     if(hbmMask == GPI_ERROR) {
00504         dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
00505         goto fail;
00506     }
00507 
00508     pointerInfo.fPointer   = fCursor; //FALSE = icon
00509     pointerInfo.xHotspot   = pInfo->ptHotSpot.x;
00510     pointerInfo.yHotspot   = mapY(pInfo->nHeight, pInfo->ptHotSpot.y);
00511     pointerInfo.hbmColor   = hbmColor;
00512     pointerInfo.hbmPointer = hbmMask;
00513     dprintf2(("WinCreatePointerIndirect %d (%d,%d) (org %d,%d)", pointerInfo.fPointer, pointerInfo.xHotspot, pointerInfo.yHotspot, pInfo->ptHotSpot.x, pInfo->ptHotSpot.y));
00514     hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
00515 
00516     if(hPointer == NULL) {
00517         dprintf(("OSLibWinCreateCursor: WinCreatePointerIndirect failed! (lasterr=%x)", WinGetLastError(GetThreadHAB())));
00518     }
00519     GpiDeleteBitmap(hbmMask);
00520     if(hbmColor) GpiDeleteBitmap(hbmColor);
00521     WinReleasePS(hps);
00522 
00523     free(pBmpMask);
00524     free(pBmpColor);
00525 
00526     dprintf2(("OSLibWinCreatePointer: PM pointer %x", hPointer));
00527     return hPointer;
00528 
00529 fail:
00530     if(hbmMask) GpiDeleteBitmap(hbmMask);
00531     if(hbmColor) GpiDeleteBitmap(hbmColor);
00532     WinReleasePS(hps);
00533     if(pBmpMask)  free(pBmpMask);
00534     if(pBmpColor) free(pBmpColor);
00535     return 0;
00536 }
00537 //******************************************************************************
00538 //******************************************************************************
00539 HANDLE OSLibWinQuerySysIcon(ULONG type,INT w,INT h)
00540 {
00541  ULONG os2type = 0;
00542  HPOINTER hPointer;
00543 
00544     switch(type) {
00545     case IDI_APPLICATION_W:
00546         os2type = SPTR_PROGRAM;
00547         break;
00548     case IDI_HAND_W:
00549         os2type = SPTR_ICONWARNING;
00550         break;
00551     case IDI_QUESTION_W:
00552         os2type = SPTR_ICONQUESTION;
00553         break;
00554     case IDI_EXCLAMATION_W:
00555         os2type = SPTR_ICONWARNING;
00556         break;
00557     case IDI_ASTERISK_W:
00558         os2type = SPTR_ICONINFORMATION;
00559         break;
00560     default:
00561         return 0;
00562     }
00563 
00564     hPointer = WinQuerySysPointer(HWND_DESKTOP, os2type, TRUE);
00565 
00566     if (hPointer)
00567     {
00568       INT sysW = WinQuerySysValue(HWND_DESKTOP,SV_CXICON),sysH = WinQuerySysValue(HWND_DESKTOP,SV_CYICON);
00569 
00570       if (sysW != w || sysH != h)
00571       {
00572         POINTERINFO pi;
00573 
00574         WinQueryPointerInfo(hPointer,&pi);
00575         //CB: todo: change icon size
00576 
00577       }
00578     }
00579 
00580     return hPointer;
00581 }
00582 //******************************************************************************
00583 //******************************************************************************
00584 HANDLE OSLibWinQuerySysPointer(ULONG type,INT w,INT h)
00585 {
00586  ULONG os2type = 0;
00587 
00588     switch(type) {
00589     case IDC_ARROW_W:
00590         os2type = SPTR_ARROW;
00591         break;
00592     case IDC_UPARROW_W:
00593         os2type = SPTR_ARROW;
00594         break;
00595     case IDC_IBEAM_W:
00596         os2type = SPTR_TEXT;
00597         break;
00598     case IDC_ICON_W:
00599         os2type = SPTR_PROGRAM;
00600         break;
00601     case IDC_NO_W:
00602         os2type = SPTR_ILLEGAL;
00603         break;
00604     case IDC_CROSS_W:
00605         os2type = SPTR_MOVE;
00606         break;
00607     case IDC_SIZE_W:
00608         os2type = SPTR_MOVE;
00609         break;
00610     case IDC_SIZEALL_W:
00611         os2type = SPTR_MOVE;
00612         break;
00613     case IDC_SIZENESW_W:
00614         os2type = SPTR_SIZENESW;
00615         break;
00616     case IDC_SIZENS_W:
00617         os2type = SPTR_SIZENS;
00618         break;
00619     case IDC_SIZENWSE_W:
00620         os2type = SPTR_SIZENWSE;
00621         break;
00622     case IDC_SIZEWE_W:
00623         os2type = SPTR_SIZEWE;
00624         break;
00625     case IDC_WAIT_W:
00626         os2type = SPTR_WAIT;
00627         break;
00628     case IDC_APPSTARTING_W:
00629         os2type = SPTR_WAIT;
00630         break;
00631     case IDC_HELP_W: //TODO: Create a cursor for this one
00632         os2type = SPTR_WAIT;
00633         break;
00634     default:
00635         return 0;
00636     }
00637     //Note: Does not create a copy
00638     return WinQuerySysPointer(HWND_DESKTOP, os2type, FALSE);
00639 }
00640 //******************************************************************************
00641 //******************************************************************************
00642 VOID OSLibWinDestroyPointer(HANDLE hPointer)
00643 {
00644     WinDestroyPointer(hPointer);
00645 }
00646 //******************************************************************************
00647 //******************************************************************************
00648 BOOL OSLibWinSetPointer(HANDLE hPointer)
00649 {
00650     return WinSetPointer(HWND_DESKTOP, hPointer);
00651 }
00652 //******************************************************************************
00653 //******************************************************************************
00654 HANDLE  OSLibWinQueryPointer()
00655 {
00656     return WinQueryPointer(HWND_DESKTOP);
00657 }
00658 //******************************************************************************
00659 //******************************************************************************
00660 BOOL OSLibWinClipCursor(const RECT * pRect)
00661 {
00662    RECTL  rectl;
00663    PRECTL ptr = NULL;
00664 
00665    if (pRect != NULL)
00666    {
00667       rectl.xLeft = max(pRect->left, 0);
00668       rectl.xRight = min(pRect->right, ScreenWidth-1);
00669       rectl.yBottom = max(ScreenHeight - pRect->bottom, 0);
00670       rectl.yTop = min(ScreenHeight - pRect->top, ScreenHeight-1);
00671       ptr = &rectl;
00672    }
00673    return WinSetPointerClipRect (HWND_DESKTOP, ptr);
00674 }
00675 //******************************************************************************
00676 //******************************************************************************
00677 BOOL OSLibWinGetClipCursor(LPRECT pRect)
00678 {
00679    RECTL  rectl;
00680 
00681    if (WinQueryPointerClipRect(HWND_DESKTOP, &rectl))
00682    {
00683       pRect->left   = rectl.xLeft;
00684       pRect->right  = rectl.xRight;
00685       pRect->bottom = ScreenHeight - rectl.yBottom;
00686       pRect->top    = ScreenHeight - rectl.yTop;
00687       return TRUE;
00688    }
00689    return FALSE;
00690 }
00691 //******************************************************************************
00692 //******************************************************************************
00693 static char *OSLibStripPath(char *path)
00694 {
00695   char *pszFilename;
00696   char *pszFilename1;
00697 
00698   pszFilename  = strrchr(path, '\\');                 /* find rightmost backslash */
00699   pszFilename1 = strrchr(path, '/');                  /* find rightmost slash */
00700   if(pszFilename > pszFilename1 && pszFilename != NULL)
00701     return (++pszFilename);              /* return pointer to next character */
00702 
00703   if (pszFilename1 != NULL)
00704     return (++pszFilename1);              /* return pointer to next character */
00705 
00706   return (path);                                     /* default return value */
00707 }
00708 //******************************************************************************
00709 //******************************************************************************
00710 void OSLibStripFile(char *path)
00711 {
00712   char *pszFilename;
00713   char *pszFilename1;
00714 
00715    pszFilename  = strrchr(path, '\\');                 /* find rightmost backslash */
00716    pszFilename1 = strrchr(path, '/');                  /* find rightmost slash */
00717    if(pszFilename > pszFilename1 && pszFilename != NULL)
00718      *pszFilename = 0;
00719    else
00720    if (pszFilename1 != NULL)
00721      *pszFilename1 = 0;
00722 }
00723 //******************************************************************************
00724 //******************************************************************************
00725 BOOL WIN32API OSLibWinCreateObject(LPSTR pszPath, LPSTR pszArgs, 
00726                                    LPSTR pszWorkDir, LPSTR pszLink, 
00727                                    LPSTR pszDescription, LPSTR pszIcoPath,
00728                                    INT iIcoNdx, BOOL fDesktop)
00729 {
00730    HOBJECT hObject = 0;
00731    LPSTR   pszName;
00732    LPSTR   pszSetupString;
00733    LPSTR   pszFolder;
00734    char    szSystemDir[256];
00735    char    temp[128];
00736    char    szWorkDir[256];
00737 
00738    if(pszName) {
00739        char *tmp;
00740        pszName = OSLibStripPath(pszLink);
00741        tmp = pszName;
00742        while(*tmp) {
00743            if(*tmp == '.') {
00744                *tmp = 0;
00745                break;
00746            }
00747            tmp++;
00748        }
00749    }
00750    dprintf(("OSLibWinCreateObject %s %s %s\n    %s %s %s %d %d", pszPath, pszArgs, 
00751             pszWorkDir, pszName, pszDescription, pszIcoPath, iIcoNdx, fDesktop));
00752    dprintf(("Link path %s", pszLink));
00753 
00754    GetSystemDirectoryA(szSystemDir, sizeof(szSystemDir));
00755    if(pszWorkDir && *pszWorkDir) {
00756        strcpy(szWorkDir, pszWorkDir);
00757    }
00758    else {
00759        strcpy(szWorkDir, pszPath);
00760        OSLibStripFile(szWorkDir);
00761    }
00762 
00763    pszSetupString = (LPSTR)malloc(128 + strlen(pszPath) + strlen(pszName) + 
00764                                   strlen(pszLink) + 2*strlen(szSystemDir) +
00765                                   strlen(szWorkDir) + strlen(pszIcoPath) +
00766                                   ((pszArgs) ? strlen(pszArgs) : 0) + 
00767                                   ((pszWorkDir) ? strlen(pszWorkDir) : 0)); 
00768 
00769    sprintf(pszSetupString, "PROGTYPE=PM;OBJECTID=<%s>;EXENAME=%s\\PE.EXE;SET BEGINLIBPATH=%s;STARTUPDIR=%s;ICONFILE=%s;PARAMETERS=\"%s\"", pszName, szSystemDir, szSystemDir, szWorkDir, pszIcoPath, pszPath);
00770    if(pszArgs && *pszArgs) {
00771        strcat(pszSetupString, " ");
00772        strcat(pszSetupString, pszArgs);
00773    }
00774    strcat(pszSetupString, ";");
00775 
00776    if(fDesktop) {
00777        dprintf(("Name = %s", pszName));
00778        dprintf(("Setup string = %s", pszSetupString));
00779        hObject = WinCreateObject("WPProgram", pszName, pszSetupString, 
00780                                  "<WP_DESKTOP>", CO_REPLACEIFEXISTS);
00781    }
00782    else {
00783        //e.g.: Link path k:\source\odin32\bin\win\Start Menu\Programs\Winamp\Winamp
00784        OSLibStripFile(pszLink);
00785        pszFolder = OSLibStripPath(pszLink);
00786        sprintf(temp, "<FOLDER_%s>", pszFolder);
00787        sprintf(szWorkDir, "OBJECTID=%s;", temp);
00788        hObject = WinCreateObject("WPFolder", pszFolder, szWorkDir,
00789                                  "<ODINFOLDER>", CO_UPDATEIFEXISTS);
00790        hObject = WinCreateObject("WPProgram", pszName, pszSetupString, 
00791                                  temp, CO_REPLACEIFEXISTS);
00792    }
00793 // If SysCreateObject("WPProgram", "WarpMix", "<ICHAUDIO>",,
00794 //                    "PROGTYPE=PM;OBJECTID=<WARPMIX>;ICONFILE=WARPMIX.ICO;EXENAME="||bootDrive||"\MMOS2\WARPMIX.EXE")  
00795 
00796    free(pszSetupString);
00797    if(!hObject) {
00798        dprintf(("ERROR: WinCreateObject failed!!"));
00799    }
00800    return hObject != 0;
00801 }
00802 //******************************************************************************
00803 //******************************************************************************
00804 

Generated on Wed Jan 23 23:17:39 2002 for ODIN-user32 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001