Changeset 9851 for trunk/src


Ignore:
Timestamp:
Feb 24, 2003, 6:03:00 PM (23 years ago)
Author:
sandervl
Message:

Convert win32 icon file to os2 format when creating a shell link

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/shell32/shelllink.c

    r8699 r9851  
    263263
    264264#ifdef __WIN32OS2__
     265static BOOL SaveIconFileAsOS2ICO(char *szFileName, char *szXPMFileName)
     266{
     267    FILE *fXPMFile = NULL, *fICOFile = NULL;
     268    void *lpOS2Icon = NULL, *lpWinIcon = NULL;
     269    DWORD ressize, filesize;
     270    BOOL  ret = FALSE;
     271
     272    if (!(fICOFile = fopen(szFileName, "r")))
     273        goto failure;
     274    fseek(fICOFile, 0, SEEK_END);
     275    filesize = ftell(fICOFile);
     276    fseek(fICOFile, 0, SEEK_SET);
     277
     278    lpWinIcon = malloc(filesize);
     279    if(lpWinIcon == NULL) goto failure;
     280    if (fread(lpWinIcon, filesize, 1, fICOFile) != 1)
     281        goto failure;
     282
     283    if (!(fXPMFile = fopen(szXPMFileName, "wb")))
     284        goto failure;
     285
     286    lpOS2Icon = ConvertIconGroupIndirect(lpWinIcon, filesize, &ressize);
     287    if(lpOS2Icon) {
     288        fwrite(lpOS2Icon, 1, ressize, fXPMFile);
     289    }
     290    ret = TRUE;
     291
     292failure:
     293    if(fICOFile) fclose(fICOFile);
     294    if(fXPMFile) fclose(fXPMFile);
     295    if(lpWinIcon) free(lpWinIcon);
     296    if(lpOS2Icon) free(lpOS2Icon);
     297    return ret;
     298}
     299
    265300static BOOL SaveIconResAsOS2ICO(GRPICONDIR *pIconDir, HINSTANCE hInstance,
    266301                                const char *szXPMFileName)
     
    533568static int ExtractFromICO(const char *szFileName, const char *szXPMFileName)
    534569{
     570#ifdef __WIN32OS2__
     571    if(!SaveIconFileAsOS2ICO(szFileName, szXPMFileName))
     572    {
     573        TRACE("Failed saving icon as XPM, error %ld\n", GetLastError());
     574        return 0;
     575    }
     576    return 1;
     577#else
    535578    FILE *fICOFile;
    536579    ICONDIR iconDir;
     
    540583    void *pIcon;
    541584    int i;
    542 #ifdef __WIN32OS2__
    543     int size;
    544 #endif
    545585
    546586    if (!(fICOFile = fopen(szFileName, "r")))
    547587        goto error1;
    548 
    549 #ifdef __WIN32OS2__
    550      //TODO:
    551     dprintf(("TODO: Icon file conversion not yet supported!!"));
    552     goto error2;
    553 #else
    554588
    555589    if (fread(&iconDir, sizeof (ICONDIR), 1, fICOFile) != 1)
     
    579613        goto error4;
    580614
    581 #endif
    582615    free(pIcon);
    583616    free(pIconDirEntry);
     
    594627 error1:
    595628    return 0;
     629#endif
    596630}
    597631
     
    655689    HKEY hkey;
    656690#ifdef __WIN32OS2__
    657     char *tmp;
     691    char *tmp, szAppName[MAX_PATH];
    658692#endif
    659693
     
    664698    if (!pszFileName || !This->sPath)
    665699        return ERROR_UNKNOWN;
    666 
    667     /* check for .exe extension */
    668     if (!(p = strrchr( This->sPath, '.' ))) return NOERROR;
    669     if (strchr( p, '\\' ) || strchr( p, '/' )) return NOERROR;
    670     if (strcasecmp( p, ".exe" )) return NOERROR;
    671700
    672701    /* check if ShellLinker configured */
     
    723752                       icon_name, This->iIcoNdx)) goto done;
    724753
    725     if(OSLibWinCreateObject(This->sPath, This->sArgs, This->sWorkDir, filename,
     754    if(SearchPathA( NULL, This->sPath, ".exe", sizeof(szAppName), szAppName, NULL) == NULL)
     755    {
     756        ret = E_INVALIDARG;
     757        goto done;
     758    }
     759
     760    if(OSLibWinCreateObject(szAppName, This->sArgs, This->sWorkDir, filename,
    726761                            This->sDescription, icon_name,
    727762                            This->iIcoNdx, bDesktop) == FALSE)
     
    739774
    740775#else
     776
     777    /* check for .exe extension */
     778    if (!(p = strrchr( This->sPath, '.' ))) return NOERROR;
     779    if (strchr( p, '\\' ) || strchr( p, '/' )) return NOERROR;
     780    if (strcasecmp( p, ".exe" )) return NOERROR;
     781
    741782    buffer[0] = 0;
    742783    if (!RegOpenKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine",
  • trunk/src/user32/USER32.DEF

    r9810 r9851  
    1 ; $Id: USER32.DEF,v 1.76 2003-02-16 15:31:08 sandervl Exp $
     1; $Id: USER32.DEF,v 1.77 2003-02-24 17:02:42 sandervl Exp $
    22
    33LIBRARY USER32 INITINSTANCE TERMINSTANCE
     
    718718    _OSLibWinCreateObject@32                                     @2031 NONAME
    719719    _ConvertIconGroup@12                                         @2032 NONAME
     720    _ConvertIconGroupIndirect@12                                 @2037 NONAME
    720721
    721722    _WinSetVisibleRgnNotifyProc@12                               @2033 NONAME
  • trunk/src/user32/icon.cpp

    r7733 r9851  
    1 /* $Id: icon.cpp,v 1.14 2002-01-07 11:17:52 sandervl Exp $ */
     1/* $Id: icon.cpp,v 1.15 2003-02-24 17:02:43 sandervl Exp $ */
    22
    33/*
     
    371371//******************************************************************************
    372372//******************************************************************************
     373void *WIN32API ConvertIconGroupIndirect(void *lpIconData, DWORD iconsize,
     374                                        DWORD *ressize)
     375{
     376 ICONDIR *ihdr = (ICONDIR *)lpIconData;
     377 ICONDIRENTRY *rdir = (ICONDIRENTRY *)(ihdr + 1);
     378 int i, groupsize = 0, os2iconsize;
     379 BITMAPARRAYFILEHEADER2 *bafh, *orgbafh;
     380 WINBITMAPINFOHEADER    *iconhdr;
     381 void                   *os2icon;
     382 int                     nricons = 0;
     383 void                   *winicon;
     384
     385  dprintf(("Icon Group type :%d", ihdr->idType));
     386  dprintf(("Icon Group count:%d", ihdr->idCount));
     387  for(i=0;i<ihdr->idCount;i++) {
     388        dprintf2(("Icon    : %x", rdir->dwImageOffset));
     389        dprintf2(("Width   : %d", (int)rdir->bWidth));
     390        dprintf2(("Height  : %d", (int)rdir->bHeight));
     391        dprintf2(("Colors  : %d", (int)rdir->bColorCount));
     392        dprintf2(("Bits    : %d", rdir->wBitCount));
     393        dprintf2(("ResBytes: %d", rdir->dwBytesInRes));
     394
     395        winicon = (char *)lpIconData + rdir->dwImageOffset;
     396        groupsize += QueryConvertedIconSize((WINBITMAPINFOHEADER *)winicon,
     397                                            rdir->dwBytesInRes);
     398        //add centered icon if size is 32x32
     399        if(rdir->bWidth == 32 && rdir->bHeight == 32 && rdir->wBitCount >= 4)
     400        {
     401            groupsize += QueryConvertedIconSize((WINBITMAPINFOHEADER *)winicon,
     402                                                rdir->dwBytesInRes, TRUE);
     403            //extra pixels
     404            groupsize += (40*8 + 8*32)*rdir->wBitCount/8;
     405            nricons++;
     406        }
     407        nricons++;
     408        rdir++;
     409  }
     410  groupsize = groupsize+nricons*(sizeof(BITMAPARRAYFILEHEADER2) - sizeof(BITMAPFILEHEADER2));
     411  bafh    = (BITMAPARRAYFILEHEADER2 *)malloc(groupsize);
     412  memset(bafh, 0, groupsize);
     413  orgbafh = bafh;
     414
     415  rdir = (ICONDIRENTRY *)(ihdr + 1);
     416  for(i=0;i<ihdr->idCount;i++) {
     417        bafh->usType    = BFT_BITMAPARRAY;
     418        bafh->cbSize    = sizeof(BITMAPARRAYFILEHEADER2);
     419        bafh->cxDisplay = 0;
     420        bafh->cyDisplay = 0;
     421
     422        winicon = (char *)lpIconData + rdir->dwImageOffset;
     423        iconhdr = (WINBITMAPINFOHEADER *)winicon;
     424
     425        os2icon = ConvertIcon(iconhdr, rdir->dwBytesInRes, &os2iconsize, (ULONG)bafh - (ULONG)orgbafh + sizeof(BITMAPARRAYFILEHEADER2)-sizeof(BITMAPFILEHEADER2));
     426        if(os2icon == NULL) {
     427                dprintf(("Can't convert icon!"));
     428                rdir++;
     429                continue;
     430        }
     431
     432        if(rdir->bWidth == 32 && rdir->bHeight == 32 && rdir->wBitCount >= 4)
     433        {
     434                //add 40x40 icon by centering 32x32 icon in 40x40 grid
     435                //(resize is really ugly)
     436                bafh->offNext = (ULONG)&bafh->bfh2 - (ULONG)orgbafh + os2iconsize;
     437                memcpy((char *)&bafh->bfh2, os2icon, os2iconsize);
     438                free(os2icon);
     439
     440                bafh = (BITMAPARRAYFILEHEADER2 *)((ULONG)&bafh->bfh2 + os2iconsize);
     441
     442                os2icon = ConvertIcon(iconhdr, rdir->dwBytesInRes, &os2iconsize, (ULONG)bafh - (ULONG)orgbafh + sizeof(BITMAPARRAYFILEHEADER2)-sizeof(BITMAPFILEHEADER2), TRUE);
     443                if(os2icon == NULL) {
     444                        dprintf(("Can't convert icon!"));
     445                        rdir++;
     446                        continue;
     447                }
     448        }
     449
     450        if(i != ihdr->idCount -1) {
     451                bafh->offNext = (ULONG)&bafh->bfh2 - (ULONG)orgbafh + os2iconsize;
     452        }
     453        else    bafh->offNext = 0;
     454
     455        memcpy((char *)&bafh->bfh2, os2icon, os2iconsize);
     456        free(os2icon);
     457
     458        bafh = (BITMAPARRAYFILEHEADER2 *)((ULONG)&bafh->bfh2 + os2iconsize);
     459
     460        rdir++;
     461  }
     462  *ressize = groupsize;
     463  return (void *)orgbafh;
     464}
     465//******************************************************************************
     466//******************************************************************************
  • trunk/src/user32/oslibres.cpp

    r9624 r9851  
    1 /* $Id: oslibres.cpp,v 1.34 2003-01-05 16:34:58 sandervl Exp $ */
     1/* $Id: oslibres.cpp,v 1.35 2003-02-24 17:02:43 sandervl Exp $ */
    22/*
    33 * Window API wrappers for OS/2
     
    749749   char    szWorkDir[256];
    750750   char    szPEGUILoaderPath[256];
     751   BOOL    fWin32App;
    751752
    752753   if(pszName) {
     
    784785                                  ((pszWorkDir) ? strlen(pszWorkDir) : 0));
    785786
    786    sprintf(pszSetupString, "PROGTYPE=PM;OBJECTID=<%s>;EXENAME=%s;SET BEGINLIBPATH=%s;STARTUPDIR=%s;ICONFILE=%s;PARAMETERS=\"%s\"", pszName, szPEGUILoaderPath, szSystemDir, szWorkDir, pszIcoPath, pszPath);
     787   fWin32App = ODIN_IsWin32App(pszPath);
     788   if(!fWin32App)
     789   {//don't use the PE loader; use the program path directly
     790        sprintf(pszSetupString, "PROGTYPE=PM;OBJECTID=<%s%s>;EXENAME=%s;SET BEGINLIBPATH=%s;STARTUPDIR=%s;ICONFILE=%s;PARAMETERS=", (fDesktop) ? "DESKTOP_" : "", pszName, pszPath, szSystemDir, szWorkDir, pszIcoPath);
     791   }
     792   else sprintf(pszSetupString, "PROGTYPE=PM;OBJECTID=<%s%s>;EXENAME=%s;SET BEGINLIBPATH=%s;STARTUPDIR=%s;ICONFILE=%s;PARAMETERS=\"%s\"", (fDesktop) ? "DESKTOP_" : "", pszName, szPEGUILoaderPath, szSystemDir, szWorkDir, pszIcoPath, pszPath);
     793
    787794   if(pszArgs && *pszArgs) {
    788795       strcat(pszSetupString, " ");
     
    794801       dprintf(("Name = %s", pszName));
    795802       dprintf(("Setup string = %s", pszSetupString));
     803
     804       //Use a different name for desktop objects
    796805       hObject = WinCreateObject("WPProgram", pszName, pszSetupString,
    797806                                 "<WP_DESKTOP>", CO_REPLACEIFEXISTS);
     
    805814       hObject = WinCreateObject("WPFolder", pszFolder, szWorkDir,
    806815                                 "<ODINFOLDER>", CO_UPDATEIFEXISTS);
    807        hObject = WinCreateObject("WPProgram", pszName, pszSetupString,
    808                                  temp, CO_REPLACEIFEXISTS);
     816       if(hObject) {
     817           hObject = WinCreateObject("WPProgram", pszName, pszSetupString,
     818                                     temp, CO_REPLACEIFEXISTS);
     819       }
     820       else {
     821           hObject = 1; //force silent failure
     822       }
    809823   }
    810824
  • trunk/src/user32/user32dbg.def

    r9810 r9851  
    1 ; $Id: user32dbg.def,v 1.9 2003-02-16 15:31:11 sandervl Exp $
     1; $Id: user32dbg.def,v 1.10 2003-02-24 17:02:43 sandervl Exp $
    22
    33LIBRARY USER32 INITINSTANCE TERMINSTANCE
     
    717717    _OSLibWinCreateObject@32                                     @2031 NONAME
    718718    _ConvertIconGroup@12                                         @2032 NONAME
     719    _ConvertIconGroupIndirect@12                                 @2037 NONAME
    719720
    720721    _WinSetVisibleRgnNotifyProc@12                               @2033 NONAME
Note: See TracChangeset for help on using the changeset viewer.