⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wricon.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        ok = ( rnode != NULL );
    }

    if( ok ) {
        if( ornode != NULL ) {
            *ornode = rnode;
        }
        if( ltype != NULL ) {
            lang = *ltype;
        } else {
            lang.lang    = DEF_LANG;
            lang.sublang = DEF_SUBLANG;
        }
        *lnode = WRFindLangNodeFromLangType( rnode, &lang );
        ok = ( *lnode != NULL );
    }

    if( !ok ) {
        *lnode = NULL;
    }

    return( ok );
}

int WR_EXPORT WRAppendDataToData( BYTE **d1, uint_32 *d1size,
                                  BYTE *d2, uint_32 d2size )
{
    if( !d1 || !d1size || !d2 || !d2size ) {
        return( FALSE );
    }

    if( ( *d1size + d2size ) > INT_MAX ) {
        return( FALSE );
    }

    *d1 = WRMemRealloc( *d1, *d1size + d2size );
    if( !*d1 ) {
        return( FALSE );
    }

    memcpy( *d1 + *d1size, d2, d2size );
    *d1size += d2size;

    return( TRUE );
}

int WR_EXPORT WRAddCursorImageToData( WRInfo *info, WResLangNode*lnode,
                                      BYTE **data, uint_32 *size,
                                      CURSORHOTSPOT *hotspot )
{
    BYTE        *ldata;
    int         hs_size; // size of hotspot info
    int         ok;

    ldata = NULL;

    ok = ( info && lnode && data && size && hotspot );

    if( ok ) {
        ldata = WRCopyResData( info, lnode );
        ok = ( ldata != NULL );
    }

    if( ok ) {
        hs_size = sizeof(CURSORHOTSPOT);
        memcpy( hotspot, ldata, hs_size );
        ok = WRAppendDataToData( data, size, ldata + hs_size,
                                 lnode->Info.Length - hs_size );
    }

    if( ldata != NULL ) {
        WRMemFree( ldata );
    }

    return( ok );
}

int WR_EXPORT WRAddIconImageToData( WRInfo *info, WResLangNode *lnode,
                                    BYTE **data, uint_32 *size )
{
    BYTE        *ldata;
    int         ok;

    ldata = NULL;

    ok = ( info && lnode && data && size );

    if( ok ) {
        ldata = WRCopyResData( info, lnode );
        ok = ( ldata != NULL );
    }

    if( ok ) {
        ok = WRAppendDataToData( data, size, ldata, lnode->Info.Length );
    }

    if( ldata != NULL ) {
        WRMemFree( ldata );
    }

    return( ok );
}

int WR_EXPORT WRCreateCursorData( WRInfo *info, WResLangNode *lnode,
                                  BYTE **data, uint_32 *size )
{
    WResLangNode        *ilnode;
    BYTE                *ldata;
    RESCURSORHEADER     *rch;
    CURSORHEADER        *ch;
    CURSORHOTSPOT       hotspot;
    WResLangType        lt;
    uint_16             ord;
    uint_32             osize;
    int                 i;
    int                 ok;

    ok = ( info && lnode && data && size );

    if( ok ) {
        ldata = WRCopyResData( info, lnode );
        ok = ( ldata != NULL );
    }

    if( ok ) {
        rch = (RESCURSORHEADER *)ldata;
        *size = sizeof( CURSORHEADER );
        *size += sizeof(CURSORDIRENTRY)*(rch->cwCount-1);
        *data = (BYTE *)WRMemAlloc( *size );
        ch = (CURSORHEADER *)*data;
        ok = ( *data != NULL );
    }

    if( ok ) {
        memcpy( ch, rch, sizeof(WORD)*3 );
    }

    if( ok ) {
        for( i=0; ok && i<rch->cwCount; i++ ) {
            ord = (uint_16) rch->cdEntries[i].wNameOrdinal;
            lt = lnode->Info.lang;
            ok = WRFindImageId( info, NULL, NULL, &ilnode, (uint_16)RT_CURSOR, ord, &lt );
            if( ok ) {
                osize = *size;
                ok = WRAddCursorImageToData( info, ilnode, data, size, &hotspot );
                if( ok ) {
                    ch = (CURSORHEADER *)*data;
                    ch->cdEntries[i].bWidth = rch->cdEntries[i].bWidth;
                    ch->cdEntries[i].bHeight = rch->cdEntries[i].bHeight/2;
                    ch->cdEntries[i].bColorCount = 0;
                    ch->cdEntries[i].bReserved = 0;
                    ch->cdEntries[i].wXHotspot = hotspot.xHotspot;
                    ch->cdEntries[i].wYHotspot = hotspot.yHotspot;
                    ch->cdEntries[i].dwBytesInRes = *size - osize;
                    ch->cdEntries[i].dwImageOffset = osize;
                }
            }
        }
    }

    if( !ok ) {
        if( *data != NULL ) {
            WRMemFree( *data );
            *data = NULL;
        }
        *size = 0;
    }

    return( ok );
}

int WR_EXPORT WRCreateIconData( WRInfo *info, WResLangNode *lnode,
                                BYTE **data, uint_32 *size )
{
    WResLangNode        *ilnode;
    BYTE                *ldata;
    RESICONHEADER       *rih;
    ICONHEADER          *ih;
    WResLangType        lt;
    uint_16             ord;
    uint_32             osize;
    int                 i;
    int                 ok;

    ok = ( info && lnode && data && size );

    if( ok ) {
        ldata = WRCopyResData( info, lnode );
        ok = ( ldata != NULL );
    }

    if( ok ) {
        rih = (RESICONHEADER *)ldata;
        *size = sizeof( ICONHEADER );
        *size += sizeof( ICONDIRENTRY )*(rih->cwCount-1);
        *data = (BYTE *)WRMemAlloc( *size );
        ih = (ICONHEADER *)*data;
        ok = ( *data != NULL );
    }

    if( ok ) {
        memcpy( ih, rih, sizeof(WORD)*3 );
    }

    if( ok ) {
        for( i=0; ok && i<rih->cwCount; i++ ) {
            ord = (uint_16)rih->idEntries[i].wNameOrdinal;
            lt = lnode->Info.lang;
            ok = WRFindImageId( info, NULL, NULL, &ilnode, (uint_16)RT_ICON, ord, &lt );
            if( ok ) {
                osize = *size;
                ok = WRAddIconImageToData( info, ilnode, data, size );
                if( ok ) {
                    ih = (ICONHEADER *)*data;
                    ih->idEntries[i].bWidth = rih->idEntries[i].bWidth;
                    ih->idEntries[i].bHeight = rih->idEntries[i].bHeight;
                    ih->idEntries[i].bColorCount = rih->idEntries[i].bColorCount;
                    //ih->idEntries[i].wPlanes = rih->idEntries[i].wPlanes;
                    //ih->idEntries[i].wBitCount = rih->idEntries[i].wBitCount;
                    ih->idEntries[i].wPlanes = 0;
                    ih->idEntries[i].wBitCount = 0;
                    ih->idEntries[i].bReserved = 0;
                    ih->idEntries[i].dwBytesInRes = *size - osize;
                    ih->idEntries[i].dwImageOffset = osize;
                }
            }
        }
    }

    if( !ok ) {
        if( *data != NULL ) {
            WRMemFree( *data );
            *data = NULL;
        }
        *size = 0;
    }

    return( ok );
}

uint_16 WR_EXPORT WRFindUnusedImageId( WRInfo *info, uint_16 start )
{
    WResLangNode        *lnode;
    int                 found;
    int                 rollover;

    found = FALSE;
    rollover = FALSE;
    if( start == 0 ) {
        start = 1;
    }
    if( start == 1 ) {
        rollover = TRUE;
    }

    while( TRUE ) {
        if( start > 0x7fff ) {
            if( !rollover ) {
                rollover = TRUE;
                start = 1;
            } else {
                break;
            }
        }
        if( !WRFindImageId( info, NULL, NULL, &lnode, (uint_16)RT_ICON, start, NULL ) ) {
            if( !WRFindImageId( info, NULL, NULL, &lnode, (uint_16)RT_CURSOR, start, NULL ) ) {
                found = TRUE;
                break;
            }
        }
        start++;
    }

    if( !found ) {
        start = 0;
    }

    return( start );
}

int WR_EXPORT WRCreateCursorEntries( WRInfo *info, WResLangNode *lnode,
                                     void *data, uint_32 size )
{
    RESCURSORHEADER     *rch;
    CURSORHEADER        *ch;
    uint_16             ord;
    uint_32             rchsize;
    int                 i;
    int                 ok;

    ok = ( info && lnode && data && size );

    if( ok ) {
        if( lnode->data ) {
            WRMemFree( lnode->data );
            lnode->data = NULL;
        }
        lnode->Info.Length = 0;
        ok = WRCreateCursorResHeader( &rch, &rchsize, data, size );
    }

    if( ok ) {
        lnode->data        = (void *)rch;
        lnode->Info.Length = rchsize;
        ord = 0;
        ch = (CURSORHEADER *) data;
        for( i=0; ok && i<rch->cwCount; i++ ) {
            ord = WRFindUnusedImageId( info, ord );
            ok = ( ord != 0 );
            if( ok ) {
                rch->cdEntries[i].wNameOrdinal = ord;
                ok = WRGetAndAddCursorImage( data, info->dir,
                                             &ch->cdEntries[i], ord );
            }
        }
    }

    return( ok );
}

int WR_EXPORT WRCreateIconEntries( WRInfo *info, WResLangNode *lnode,
                                   void *data, uint_32 size )
{
    RESICONHEADER       *rih;
    ICONHEADER          *ih;
    uint_16             ord;
    uint_32             rihsize;
    int                 i;
    int                 ok;

    ok = ( info && lnode && data && size );

    if( ok ) {
        if( lnode->data ) {
            WRMemFree( lnode->data );
            lnode->data = NULL;
        }
        lnode->Info.Length = 0;
        ok = WRCreateIconResHeader( &rih, &rihsize, data, size );
    }

    if( ok ) {
        lnode->data        = (void *)rih;
        lnode->Info.Length = rihsize;
        ord = 0;
        ih = (ICONHEADER *) data;
        for( i=0; ok && i<rih->cwCount; i++ ) {
            ord = WRFindUnusedImageId( info, ord );
            ok = ( ord != 0 );
            if( ok ) {
                rih->idEntries[i].wNameOrdinal = ord;
                ok = WRGetAndAddIconImage( data, info->dir,
                                           &ih->idEntries[i], ord );
            }
        }
    }

    return( ok );
}

int WR_EXPORT WRDeleteGroupImages( WRInfo *info, WResLangNode *lnode,
                                   uint_16 type )
{
    WResLangType        lt;
    WResTypeNode        *itnode;
    WResResNode         *irnode;
    WResLangNode        *ilnode;
    void                *data;
    RESICONHEADER       *ih;
    RESCURSORHEADER     *ch;
    int                 i;
    uint_16             ord;
    int                 ok;

    ok = ( info && lnode &&
           ( ( type == (uint_16)RT_GROUP_ICON ) ||
             ( type == (uint_16)RT_GROUP_CURSOR ) ) );

    if( ok ) {
        data = WRCopyResData( info, lnode );
        ok = ( data != NULL );
    }

    if( ok ) {
        if( type == (uint_16)RT_GROUP_ICON ) {
            ih = (RESICONHEADER *)data;
            for( i = 0; ok && i < ih->cwCount; i++ ) {
                ord = (uint_16)ih->idEntries[i].wNameOrdinal;
                lt = lnode->Info.lang;
                if( WRFindImageId( info, &itnode, &irnode, &ilnode, (uint_16)RT_ICON, ord, &lt ) ) {
                    if( ilnode->data ) {
                        WRMemFree( ilnode->data );
                        ilnode->data = NULL;
                    }
                    ok = WRRemoveLangNodeFromDir( info->dir, &itnode,
                                                  &irnode, &ilnode );
                }
            }
        } else {
            ch = (RESCURSORHEADER *)data;
            for( i = 0; ok && i < ch->cwCount; i++ ) {
                ord = (uint_16)ch->cdEntries[i].wNameOrdinal;
                lt = lnode->Info.lang;
                if( WRFindImageId( info, &itnode, &irnode, &ilnode, (uint_16)RT_CURSOR, ord, &lt ) ) {
                    if( ilnode->data ) {
                        WRMemFree( ilnode->data );
                        ilnode->data = NULL;
                    }
                    ok = WRRemoveLangNodeFromDir( info->dir, &itnode,
                                                  &irnode, &ilnode );
                }
            }
        }
    }

    if( data != NULL ) {
        WRMemFree( data );
    }

    return( ok );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -