示例#1
0
int WResLoadResourceX( PHANDLE_INFO hinfo, lpcstr idType, lpcstr idResource,
                                    lpstr *lpszBuffer, size_t *bufferSize )
/*************************************************************************/
{
    WResID              *resource_type;
    WResID              *resource_id;
    int                 rc;

    if( IS_INTRESOURCE( idResource ) ) {
        resource_id = WResIDFromNum( (uint_16)RESOURCE2INT( idResource ) );
    } else {
        resource_id = WResIDFromStrF( idResource );
    }
    if( IS_INTRESOURCE( idType ) ) {
        resource_type = WResIDFromNum( (uint_16)RESOURCE2INT( idType ) );
    } else {
        resource_type = WResIDFromStrF( idType );
    }
    rc = WResLoadResource2( MainDir, hinfo, resource_type, resource_id, lpszBuffer, bufferSize );
    if( resource_type != NULL )
        WResIDFree( resource_type );
    if( resource_id != NULL )
        WResIDFree( resource_id );
    return( rc );
}
示例#2
0
bool WRAPI 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;
    bool                ok;

    ok = (info != NULL && lnode != NULL && (type == RESOURCE2INT( RT_GROUP_ICON ) || type == RESOURCE2INT( RT_GROUP_CURSOR )));

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

    if( ok ) {
        if( type == RESOURCE2INT( 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, RESOURCE2INT( RT_ICON ), ord, &lt ) ) {
                    if( ilnode->data != NULL ) {
                        MemFree( 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, RESOURCE2INT( RT_CURSOR ), ord, &lt ) ) {
                    if( ilnode->data != NULL ) {
                        MemFree( ilnode->data );
                        ilnode->data = NULL;
                    }
                    ok = WRRemoveLangNodeFromDir( info->dir, &itnode, &irnode, &ilnode );
                }
            }
        }
    }

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

    return( ok );
}
示例#3
0
bool DumpContents( WResTypeInfo *type, WResResInfo *res,
                    WResLangInfo *lang, WResFileID handle, uint_16 os )
/*********************************************************************/
{
    bool    error;

    res = res;
    fprintf( stdout, "\tOffset: 0x%08lx  Length: 0x%08lx\n",
            lang->Offset, lang->Length );

    if (type->TypeName.IsName) {
        /* it is not one of the predefined types */
        error = false;
    } else {
        switch (type->TypeName.ID.Num) {
        case RESOURCE2INT( RT_MENU ):
            if( os == WRES_OS_WIN16 ) {
                error = DumpMenu( lang->Offset, lang->Length, handle );
            } else {
                error = false;
            }
            break;
        case RESOURCE2INT( RT_DIALOG ):
            if( os == WRES_OS_WIN16 ) {
                error = DumpDialog( lang->Offset, lang->Length, handle );
            } else {
                error = false;
            }
            break;
        case RESOURCE2INT( RT_GROUP_ICON ):
            error = DumpIconGroup( lang->Offset, lang->Length, handle );
            break;
        case RESOURCE2INT( RT_GROUP_CURSOR ):
            error = DumpCursorGroup( lang->Offset, lang->Length, handle );
            break;
        case RESOURCE2INT( RT_STRING ):
            if( os == WRES_OS_WIN16 ) {
                error = DumpString( lang->Offset, lang->Length, handle );
            } else {
                error = false;
            }
            break;
        default:
            error = false;
            break;
        }
    }

    return( error );
}
示例#4
0
static void WriteWINTables( void )
/********************************/
{
    if( CurrResFile.StringTable != NULL ) {
        SemWINWriteStringTable( CurrResFile.StringTable,
                    WResIDFromNum( RESOURCE2INT( RT_STRING ) ) );
    }
    if( CurrResFile.ErrorTable != NULL ) {
        SemWINWriteStringTable( CurrResFile.ErrorTable,
                    WResIDFromNum( RESOURCE2INT( RT_ERRTABLE ) ) );
    }
    if( CurrResFile.FontDir != NULL ) {
        SemWINWriteFontDir();
    }
}
示例#5
0
static RcStatus copyBitmap( BitmapFileHeader *head, WResFileID fid,
                            WResID *name, ResMemFlags flags, int *err_code )
/**************************************************************************/
{
    RcStatus            ret;
    char *              buffer;
    ResLocation         loc;
    WResFileOffset      pos;

    buffer = RESALLOC( BITMAP_BUFFER_SIZE );

    loc.start = SemStartResource();

    pos = RESTELL( fid );
    if( pos == -1 ) {
        ret = RS_READ_ERROR;
        *err_code = errno;
    } else {
        ret = CopyData( pos, head->Size - sizeof(BitmapFileHeader),
                          fid, buffer, BITMAP_BUFFER_SIZE, err_code );
    }

    loc.len = SemEndResource( loc.start );
    /* add the bitmap to the RES file directory */
    SemAddResourceFree( name, WResIDFromNum( RESOURCE2INT( RT_BITMAP ) ), flags, loc );

    RESFREE( buffer );

    return( ret );
} /* copyBitmap */
示例#6
0
WdeResInfo *WdeLoadResource( const char *file_name )
{
    WdeResInfo  *res_info;
    WRFileType  file_type;
    bool        ok;

    WdeSetWaitCursor( TRUE );

    ok = ((res_info = WdeAllocResInfo()) != NULL);

    if( ok ) {
        file_type = WRIdentifyFile( file_name );
        ok = (file_type != WR_INVALID_FILE);
    }

    if( ok ) {
        res_info->info = WRLoadResource( file_name, file_type );
        ok = (res_info->info != NULL);
    }

    if( ok ) {
        res_info->dlg_entry = WdeFindTypeNode( res_info->info->dir, RESOURCE2INT( RT_DIALOG ), "DIALOG" );
    }

    if( !ok ) {
        if( res_info != NULL ) {
            WdeFreeResInfo( res_info );
            res_info = NULL;
        }
    }

    WdeSetWaitCursor( FALSE );

    return( res_info );
}
示例#7
0
static RcStatus copyFont( FontInfo *info, WResFileID handle, WResID *name,
                                ResMemFlags flags, int *err_code )
/************************************************************************/
{
    RcStatus            ret;
    char *              buffer;
    ResLocation         loc;
    WResFileOffset      pos;

    buffer = RCALLOC( FONT_BUFFER_SIZE );

    loc.start = SemStartResource();

    if( ResWriteFontInfo( info, CurrResFile.handle ) ) {
        ret = RS_WRITE_ERROR;
        *err_code = LastWresErr();
    } else {
        pos = RCTELL( handle );
        if( pos == -1 ) {
            ret = RS_READ_ERROR;
            *err_code = errno;
        } else {
            ret = SemCopyDataUntilEOF( pos, handle, buffer,
                                         FONT_BUFFER_SIZE, err_code );
        }
    }

    loc.len = SemEndResource( loc.start );
    /* add the font to the RES file directory */
    SemAddResourceFree( name, WResIDFromNum( RESOURCE2INT( RT_FONT ) ), flags, loc );

    RCFREE( buffer );

    return( ret );
} /* copyFont */
示例#8
0
bool WRAPI WRGetAndAddIconImage( BYTE *data, WResDir dir, ICONDIRENTRY *id, int ord )
{
    BYTE                *icon;
    bool                dup;
    WResID              *tname;
    WResID              *rname;
    WResLangType        lang;
    bool                ok;

    dup = false;
    lang.lang = DEF_LANG;
    lang.sublang = DEF_SUBLANG;
    tname = NULL;
    rname = NULL;

    ok = (data != NULL && dir != NULL && id != NULL && id->dwBytesInRes != 0);

    if( ok ) {
        icon = (BYTE *)MemAlloc( id->dwBytesInRes );
        ok = (icon != NULL);
    }

    if( ok ) {
        memcpy( icon, data + id->dwImageOffset, id->dwBytesInRes );
        tname = WResIDFromNum( RESOURCE2INT( RT_ICON ) );
        ok = (tname != NULL);
    }

    if( ok ) {
        rname = WResIDFromNum( ord );
        ok = (rname != NULL);
    }

    if( ok ) {
        ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0,
                               id->dwBytesInRes, dir, &lang, &dup );
    }

    if( ok ) {
        ok = WRFindAndSetData( dir, tname, rname, &lang, icon );
    }

    if( !ok ) {
        if( icon != NULL ) {
            MemFree( icon );
        }
    }

    if( tname != NULL ) {
        MemFree( tname );
    }

    if( rname != NULL ) {
        MemFree( rname );
    }

    return( ok );
}
示例#9
0
bool WRAPI WRFindImageId( WRInfo *info, WResTypeNode **otnode,
                             WResResNode **ornode, WResLangNode **lnode,
                             uint_16 type, uint_16 id, WResLangType *ltype )
{
    WResTypeNode        *tnode;
    WResResNode         *rnode;
    WResLangType        lang;
    bool                ok;

    ok = (info != NULL && lnode != NULL &&
          (type == RESOURCE2INT( RT_ICON ) || type == RESOURCE2INT( RT_CURSOR )));

    if( ok ) {
        tnode = WRFindTypeNode( info->dir, type, NULL );
        ok = (tnode != NULL);
    }

    if( ok ) {
        if( otnode != NULL ) {
            *otnode = tnode;
        }
        rnode = WRFindResNode( tnode, id, NULL );
        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 );
}
示例#10
0
bool WREClipCurrentResource( HWND main, bool cut )
{
    WRECurrentResInfo   curr;
    WREClipFormat       *fmt;
    uint_16             type;
    bool                ok;

    WREGetCurrentResource( &curr );

    ok = (curr.info != NULL && curr.type != NULL);

    if( ok ) {
        type = 0;
        if( !curr.type->Info.TypeName.IsName ) {
            type = curr.type->Info.TypeName.ID.Num;
        }
        ok = (type != 0);
    }

    if( ok ) {
        fmt = WREFindClipFormatFromType( type );
        ok = (fmt != NULL);
    }

    if( ok ) {
        if( curr.info->current_type == RESOURCE2INT( RT_BITMAP ) ) {
            ok = WREClipBitmap( &curr, main );
        } else if( curr.info->current_type == RESOURCE2INT( RT_STRING ) ||
                   curr.info->current_type == 0 ) {
            ok = false;
        } else {
            ok = WREClipResource( &curr, main, fmt->fmt );
        }
    }

    if( ok ) {
        if( cut ) {
            ok = WREDeleteCurrResource( TRUE );
        }
    }

    return( ok );
}
示例#11
0
static RcStatus copyCursors( FullCurDir * dir, WResFileID fid, ResMemFlags flags, int *err_code )
/***********************************************************************************************/
/* This function uses the same size of buffers to copy info as for icons */
{
    RcStatus            ret = RS_OK; // should this be RS_PARAM_ERROR ??
    char *              buffer;
    FullCurDirEntry *   entry;
    CurFileDirEntry     fileentry;
    CurHotspot          hotspot;
    BitmapInfoHeader    dibhead;
    ResLocation         loc;

    buffer = RESALLOC( BUFFER_SIZE );

    for( entry = dir->Head; entry != NULL; entry = entry->Next ) {
        /* copy the cursor */
        loc.start = SemStartResource();

        hotspot.X = entry->Entry.Cur.XHotspot;
        hotspot.Y = entry->Entry.Cur.YHotspot;
        if( ResWriteCurHotspot( &hotspot, CurrResFile.fid ) ) {
            ret = RS_WRITE_ERROR;
            *err_code = LastWresErr();
            break;
        }

        /* NOTE: the dibhead structure is filled in as a result of this call */
        ret = copyOneCursor( &(entry->Entry.Cur), fid, buffer,
                        BUFFER_SIZE, &(dibhead), err_code );
        if( ret != RS_OK )
            break;

        loc.len = SemEndResource( loc.start );
        /* add the cursor to the RES file directory */
        SemAddResourceFree( WResIDFromNum( CurrResFile.NextCurOrIcon ),
                WResIDFromNum( RESOURCE2INT( RT_CURSOR ) ), flags, loc );
        /* change the reference in the cursor directory */
        fileentry = entry->Entry.Cur;
        entry->IsCurFileEntry = false;
        entry->Entry.Res.Width = dibhead.Width;
        entry->Entry.Res.Height = dibhead.Height;
        entry->Entry.Res.Planes = dibhead.Planes;
        entry->Entry.Res.BitCount = dibhead.BitCount;
        /* the hotspot data is now part of the components */
        entry->Entry.Res.Length = fileentry.Length + sizeof(CurHotspot);
        entry->Entry.Res.CurID = CurrResFile.NextCurOrIcon;
        CurrResFile.NextCurOrIcon += 1;
    }

    RESFREE( buffer );

    return( ret );
} /* copyCursors */
示例#12
0
uint_16 WRAPI 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;
    }

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

    if( !found ) {
        start = 0;
    }

    return( start );
}
示例#13
0
bool WREPasteResource( HWND main )
{
    uint_16             type;
    WREClipFormat       *fmt;
    bool                clipbd_open;
    bool                ok;

    type = 0;
    clipbd_open = FALSE;
    ok = OpenClipboard( main ) != 0;

    if( ok ) {
        clipbd_open = TRUE;
        fmt = WREGetClipFormat();
        ok = (fmt != NULL);
    }

    if( ok ) {
        if( fmt->fmt == CF_BITMAP ) {
            ok = WREGetAndPasteHBITMAP( fmt );
        } else if( fmt->fmt == CF_DIB ) {
            ok = WREGetAndPasteDIB( fmt );
        } else if( fmt->type == RESOURCE2INT( RT_GROUP_ICON ) ) {
            ok = WREGetAndPasteIconOrCursor( fmt );
        } else if( fmt->type == RESOURCE2INT( RT_GROUP_CURSOR ) ) {
            ok = WREGetAndPasteIconOrCursor( fmt );
        } else {
            ok = WREGetAndPasteResource( fmt );
        }
    }

    if( clipbd_open ) {
        CloseClipboard();
    }

    return( ok );
}
示例#14
0
static bool ConvertMResources( FILE *in_fp, FILE *out_fp, WResDir outdir )
/************************************************************************/
{
    MResResourceHeader *    mheader;
    WResID *                name;
    WResID *                type;
    bool                    error;
    bool                    lastheader; /* true if lastheader has been read */
    uint_32                 offset;
    bool                    duplicate;

    mheader = MResReadResourceHeader( in_fp );
    /* assume that any error reading here means end of file */
    lastheader = ( mheader == NULL );
    error = false;

    while( !lastheader && !error ) {
        name = ConvertNameOrOrdToID( mheader->Name );
        type = ConvertNameOrOrdToID( mheader->Type );
        offset = RESTELL( out_fp );

        /* copy the resource if it isn't a name table or if the user */
        /* requested that name tables be copied */
        if( type->IsName || type->ID.Num != RESOURCE2INT( RT_NAMETABLE ) ||
                        CmdLineParms.KeepNameTable ) {
            error = WResAddResource( type, name, mheader->MemoryFlags, offset,
                        mheader->Size, outdir, NULL, &duplicate );
            if( duplicate ) {
                /* print message and continue */
                puts( "Error: duplicate entry" );
                error = false;
            } else {
                error = BinaryCopy( in_fp, out_fp, mheader->Size );
            }
        } else {
            RESSEEK( in_fp, mheader->Size, SEEK_CUR );
        }

        WResIDFree( name );
        WResIDFree( type );
        MResFreeResourceHeader( mheader );

        mheader = MResReadResourceHeader( in_fp );
        /* assume that any error reading here means end of file */
        lastheader = ( mheader == NULL );
    }

    return( error );
} /* ConvertMResources */
示例#15
0
void WRESetCopyMenuItem( HWND main )
{
    int                 enable;
    WRECurrentResInfo   curr;
    HMENU               hmenu;

    hmenu = GetMenu( main );
    WREGetCurrentResource( &curr );
    enable = MF_GRAYED;
    if( curr.info != NULL ) {
        if( curr.info->current_type != 0 && curr.info->current_type != RESOURCE2INT( RT_STRING ) ) {
            enable = MF_ENABLED;
        }
    }
    EnableMenuItem( hmenu, IDM_CUT, enable );
    EnableMenuItem( hmenu, IDM_COPY, enable );
}
示例#16
0
static bool WRSetWinInfo( HWND hdlg, WRSelectImageInfo *info )
{
    WResTypeNode        *tnode;
    bool                lbox_set;

    if( info == NULL || hdlg == (HWND)NULL ) {
        return( false );
    }

    lbox_set = false;

    tnode = WRFindTypeNode( info->info->dir, RESOURCE2INT( RT_BITMAP ), NULL );
    if( tnode != NULL ) {
        CheckDlgButton( hdlg, IDM_SELIMGBMP, BST_CHECKED );
        info->type = RESOURCE2INT( RT_BITMAP );
        WRSetEntries( hdlg, info );
        lbox_set = true;
    } else {
        EnableWindow( GetDlgItem( hdlg, IDM_SELIMGBMP ), FALSE );
    }

    tnode = WRFindTypeNode( info->info->dir, RESOURCE2INT( RT_GROUP_CURSOR ), NULL );
    if( tnode != NULL ) {
        if( !lbox_set ) {
            CheckDlgButton( hdlg, IDM_SELIMGCUR, BST_CHECKED );
            info->type = RESOURCE2INT( RT_GROUP_CURSOR );
            WRSetEntries( hdlg, info );
            lbox_set = true;
        }
    } else {
        EnableWindow( GetDlgItem( hdlg, IDM_SELIMGCUR ), FALSE );
    }

    tnode = WRFindTypeNode( info->info->dir, RESOURCE2INT( RT_GROUP_ICON ), NULL );
    if( tnode != NULL ) {
        if( !lbox_set ) {
            CheckDlgButton( hdlg, IDM_SELIMGICO, BST_CHECKED );
            info->type = RESOURCE2INT( RT_GROUP_ICON );
            WRSetEntries( hdlg, info );
            lbox_set = true;
        }
    } else {
        EnableWindow( GetDlgItem( hdlg, IDM_SELIMGICO ), FALSE );
    }

    if( !lbox_set ) {
        WRDisplayErrorMsg( WR_PRJNOIMAGES );
    }

    return( lbox_set );
}
示例#17
0
void SemWINWriteFontDir( void )
/*****************************/
{
    FullFontDirEntry *  currentry;
    ResLocation         loc;
    bool                error;

    if( CurrResFile.FontDir == NULL ) {
        return;
    }

    loc.start = SemStartResource();

    error = ResWriteUint16( CurrResFile.FontDir->NumOfFonts, CurrResFile.fid );
    if( error )
        goto OUTPUT_WRITE_ERROR;

    for( currentry = CurrResFile.FontDir->Head; currentry != NULL;
                currentry = currentry->Next ) {
        error = ResWriteFontDirEntry( &(currentry->Entry), CurrResFile.fid );
        if( error ) {
            goto OUTPUT_WRITE_ERROR;
        }
    }

    loc.len = SemEndResource( loc.start );

    SemAddResourceFree( WResIDFromStr( FONT_DIR_NAME ),
                WResIDFromNum( RESOURCE2INT( RT_FONTDIR ) ), FONT_DIR_FLAGS, loc );

    FreeFontDir( CurrResFile.FontDir );
    CurrResFile.FontDir = NULL;

    return;


OUTPUT_WRITE_ERROR:
    RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, LastWresErrStr() );
    ErrorHasOccured = true;
    FreeFontDir( CurrResFile.FontDir );
    CurrResFile.FontDir = NULL;
    return;
}
示例#18
0
void SemWINAddMessageTable( WResID *name, ScanString *filename ) {
/****************************************************************/

    ResLocation         start;

    if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 ) {
        start = SemCopyRawFile( filename->string );
        RESFREE( filename->string );
        RESFREE( filename );
        SemAddResourceFree( name, WResIDFromNum( RESOURCE2INT( RT_MESSAGETABLE ) ),
                            MEMFLAG_MOVEABLE | MEMFLAG_PURE, start );
    } else {
        RcError( ERR_NT_KEYWORD, SemWINTokenToString( Y_MESSAGETABLE ) );
        ErrorHasOccured = true;
        RESFREE( name );
        RESFREE( filename->string );
        RESFREE( filename );
    }
}
示例#19
0
bool WREGetAccelSessionData( WREAccelSession *session, bool close )
{
    bool ok;

    ok = (session != NULL && session->hndl != 0 && session->lnode != NULL);

    if( ok ) {
        if( close ) {
            session->info = WAccelEndEdit( session->hndl );
        } else {
            session->info = WAccelGetEditInfo( session->hndl );
        }
        ok = (session->info != NULL);
    }

    if( ok && session->info->modified ) {
        ok = WRERenameWResResNode( session->tnode, &session->rnode,
                                   session->info->res_name );
        WRESetResNamesFromType( session->rinfo, RESOURCE2INT( RT_ACCELERATOR ), TRUE,
                                session->info->res_name, 0 );
    }

    if( ok && session->info->modified ) {
        if( session->lnode->data != NULL ) {
            WRMemFree( session->lnode->data );
        }
        session->lnode->data = session->info->data;
        session->lnode->Info.lang = session->info->lang;
        session->lnode->Info.Length = session->info->data_size;
        session->lnode->Info.MemoryFlags = session->info->MemFlags;
        session->lnode->Info.Offset = 0;
        session->info->data = NULL;
        session->info->data_size = 0;
        session->info->modified = false;
        session->rinfo->modified = true;
    }

    return( ok );
}
示例#20
0
bool WREDeleteStringResources( WRECurrentResInfo *curr, bool removing )
{
    WResTypeNode        *tnode;
    char                *text;
    bool                ok;

    ok = true;

    if( !removing ) {
        text = AllocRCString( WRE_ALLSTRINGS );
        ok = WREQueryDeleteName( text );
        if( text != NULL ) {
            FreeRCString( text );
        }
    }

    if( ok ) {
        tnode = curr->type;
        if( tnode == NULL ) {
            tnode = WRFindTypeNode( curr->info->info->dir, RESOURCE2INT( RT_STRING ), NULL );
        }
        if( tnode != NULL ) {
            curr->info->modified = true;
            ok = WRRemoveTypeNodeFromDir( curr->info->info->dir, tnode );
        }
    }

    // nuke any edit sessions on these string resources
    if( ok ) {
        curr->type = NULL;
        if( !removing ) {
            WREEndResStringSessions( curr->info );
        }
        curr->info->current_type = 0;
        ok = WREInitResourceWindow( curr->info, 0 );
    }

    return( ok );
}
示例#21
0
void SemWINWriteToolBar( WResID *name, ToolBar *toolbar,
                      unsigned long item1, unsigned long item2,
                      ResMemFlags flags ) {

    ResLocation              loc;
    unsigned                 cnt;
    ToolBarItems            *cur;

    if( !ErrorHasOccured ) {
        loc.start = SemStartResource();
        cnt = ( toolbar->nodecnt - 1 ) * TB_ITEM_CNT;
        cnt += toolbar->last->cnt;
        ResWriteToolBarHeader( CurrResFile.handle, item1, item2, cnt );
        cur = &toolbar->first;
        while( cur != NULL ) {
            ResWriteToolBarItems( CurrResFile.handle, cur->items, cur->cnt );
            cur = cur->next;
        }
        loc.len = SemEndResource( loc.start );
        SemAddResourceFree( name, WResIDFromNum( RESOURCE2INT( RT_TOOLBAR ) ), flags, loc );
    }
    semFreeToolBar( toolbar );
}
示例#22
0
static RcStatus copyIcons( FullIconDir * dir, WResFileID fid, ResMemFlags flags, int *err_code )
/**********************************************************************************************/
{
    RcStatus            ret;
    char *              buffer;
    FullIconDirEntry *  entry;
    BitmapInfoHeader    dibhead;
    ResLocation         loc;

    ret = RS_OK;
    buffer = RESALLOC( BUFFER_SIZE );

    for( entry = dir->Head; entry != NULL; entry = entry->Next ) {
        /* copy the icon */
        loc.start = SemStartResource();

        /* NOTE: the dibhead structure is filled in as a result of this call */
        ret = copyOneIcon( &(entry->Entry.Ico), fid, buffer, BUFFER_SIZE, &(dibhead), err_code );
        if( ret != RS_OK )
            break;

        loc.len = SemEndResource( loc.start );
        /* add the icon to the RES file directory */
        SemAddResourceFree( WResIDFromNum( CurrResFile.NextCurOrIcon ),
                WResIDFromNum( RESOURCE2INT( RT_ICON ) ), flags, loc );
        /* change the reference in the ICON directory */
        entry->IsIcoFileEntry = false;
        entry->Entry.Res.IconID = CurrResFile.NextCurOrIcon;
        entry->Entry.Res.Info.Planes = dibhead.Planes;
        entry->Entry.Res.Info.BitCount = dibhead.BitCount;
        CurrResFile.NextCurOrIcon += 1;
    }

    RESFREE( buffer );

    return( ret );
} /* copyIcons */
示例#23
0
static bool writeCurDir( FullCurDir *dir, WResID *name, ResMemFlags flags,
                        int *err_code )
/****************************************************************************/
{
    bool                error;
    FullCurDirEntry *   entry;
    ResLocation         loc;

    loc.start = SemStartResource();
    error = ResWriteIconCurDirHeader( &(dir->Header), CurrResFile.fid );

    for( entry = dir->Head; !error && entry != NULL; entry = entry->Next ) {
        error = ResWriteCurDirEntry( &(entry->Entry.Res), CurrResFile.fid );
    }

    if( !error ) {
        loc.len = SemEndResource( loc.start );
        SemAddResourceFree( name, WResIDFromNum( RESOURCE2INT( RT_GROUP_CURSOR ) ), flags, loc );
    } else {
        *err_code = LastWresErr();
    }

    return( error );
}
示例#24
0
bool WREDeleteResource( WRECurrentResInfo *curr, bool force )
{
    char                *name;
    int                 type;
    bool                ok;
    LRESULT             index;
    HWND                res_lbox;
    WResLangNode        *lnode;

    name = NULL;
    lnode = NULL;

    if( curr->info->current_type == RESOURCE2INT( RT_STRING ) ) {
        return( WREDeleteStringResources( curr, FALSE ) );
    }

    ok = (curr->info != NULL && curr->res != NULL && curr->lang != NULL);

    if( ok )  {
        if( curr->type->Info.TypeName.IsName ) {
            type = 0;
        } else {
            type = curr->type->Info.TypeName.ID.Num;
        }
        name = WREGetResName( curr->res, type );
        ok = (name != NULL);
    }

    if( ok && !force ) {
        ok = WREQueryDeleteName( name );
    }

    // nuke any edit sessions on this resource
    if( ok ) {
        lnode = curr->lang;
        switch( type ) {
        case RT_MENU:
            WREEndLangMenuSession( lnode );
            break;
        case RT_STRING:
            WREEndResStringSessions( curr->info );
            break;
        case RT_ACCELERATOR:
            WREEndLangAccelSession( lnode );
            break;
        case RT_DIALOG:
            WREEndLangDialogSession( lnode );
            break;
        case RT_GROUP_CURSOR:
        case RT_GROUP_ICON:
            ok = WREDeleteGroupImages( curr, (uint_16)type );
            /* fall through */
        case RT_BITMAP:
            if( ok ) {
                WREEndLangImageSession( lnode );
            }
            break;
        }
    }

    if( ok ) {
        ok = WRRemoveLangNodeFromDir( curr->info->info->dir, &curr->type,
                                      &curr->res, &curr->lang );
        curr->info->modified = true;
    }

    if( ok ) {
        if( !curr->type ) {
            curr->info->current_type = 0;
            ok = WREInitResourceWindow( curr->info, 0 );
        } else {
            res_lbox = GetDlgItem( curr->info->info_win, IDM_RNRES );
            index = SendMessage( res_lbox, LB_FINDSTRING, 0, (LPARAM)name );
            if( index == LB_ERR ) {
                index = 0;
            }
            ok = WRESetResNamesFromType( curr->info, curr->info->current_type,
                                         TRUE, NULL, index );
        }
    }

    if( ok ) {
        WRESetTotalText( curr->info );
    }

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

    return( ok );
}
示例#25
0
bool WdeSaveObjectInto( WdeResInfo *rinfo, WdeDialogBoxInfo *dbi,
                        WResID *name, void *data, uint_32 size,
                        WResLangType *lang )
{
    char                *fname;
    WdeGetFileStruct    gf;
    bool                dup;
    WRSaveIntoData      idata;
    WdeResDlgItem       ditem;
    bool                is_rc;
    bool                ok;

    idata.type = NULL;
    fname = NULL;
    dup = false;

    ok = (rinfo != NULL && dbi != NULL && name != NULL && data != NULL);

    if( ok ) {
        gf.file_name = NULL;
        gf.title = WdeDlgSaveIntoTitle;
        gf.filter = WdeResSaveFilter;
        fname = WdeGetOpenFileName( &gf );
        ok = (fname != NULL && *fname != '\0');
    }

    if( ok ) {
        is_rc = WdeIsFileAnRCFile( fname );
        if( !is_rc ) {
            ok = ((idata.type = WResIDFromNum( RESOURCE2INT( RT_DIALOG ) )) != NULL);
        }
    }

    if( ok ) {
        if( is_rc ) {
            memset( &ditem, 0, sizeof( WdeResDlgItem ) );
            ditem.dialog_info = dbi;
            ditem.dialog_name = name;
            ok = WdeSaveObjectToRC( fname, rinfo, &ditem, TRUE );
        } else {
            idata.next = NULL;
            idata.name = name;
            idata.data = data;
            idata.lang = *lang;
            idata.size = size;
            idata.MemFlags = dbi->MemoryFlags;
            ok = WRSaveObjectInto( fname, &idata, &dup ) && !dup;
        }
    }

    if( dup ) {
        WdeDisplayErrorMsg( WDE_DUPRESNAMEINFILE );
    }

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

    if( idata.type != NULL ) {
        WResIDFree( idata.type );
    }

    return( ok );
}
示例#26
0
bool WdeSaveObjectAs( WdeResInfo *rinfo, WdeDialogBoxInfo *dbi,
                      char **file_name, WResID *name, void *rdata, uint_32 size,
                      WResLangType *lang, bool get_name )
{
    char                *fname;
    WRFileType          ftype;
    WdeGetFileStruct    gf;
    WRSaveIntoData      idata;
    WdeResDlgItem       ditem;
    bool                is_rc;
    bool                ok;

    fname = NULL;
    idata.type = NULL;

    ok = (rinfo != NULL && dbi != NULL && file_name != NULL &&
          name != NULL && rdata != NULL);

    if( ok ) {
        if( get_name || *file_name == NULL ) {
            gf.file_name = *file_name;
            gf.title = WdeDlgSaveTitle;
            if( get_name ) {
                gf.title = WdeDlgSaveAsTitle;
            }
            gf.filter = WdeResSaveFilter;
            fname = WdeGetSaveFileName( &gf );
        } else {
            fname = WdeStrDup( *file_name );
        }
        ok = (fname != NULL && *fname != '\0');
    }

    if( ok ) {
        ftype = WdeSelectFileType( fname, rinfo->is32bit );
        ok = (ftype != WR_DONT_KNOW);
    }

    if( ok ) {
        is_rc = WdeIsFileAnRCFile( fname );
        ok = ((idata.type = WResIDFromNum( RESOURCE2INT( RT_DIALOG ) )) != NULL);
    }

    if( ok ) {
        memset( &ditem, 0, sizeof( WdeResDlgItem ) );
        ditem.dialog_info = dbi;
        ditem.dialog_name = name;
        if( is_rc ) {
            ok = WdeSaveObjectToRC( fname, rinfo, &ditem, FALSE );
        }
    }

    // if we are saving a .RES file then auto create a dlg script
    if( ok ) {
        if( ftype == WR_WIN16M_RES || ftype == WR_WIN16W_RES ||
            ftype == WR_WINNTM_RES || ftype == WR_WINNTW_RES ) {
            char        dlgName[_MAX_PATH];
            if( WdeCreateDLGName( fname, dlgName ) ) {
                ok = WdeSaveObjectToRC( dlgName, rinfo, &ditem, FALSE );
            }
        }
    }

    if( ok ) {
        idata.next = NULL;
        idata.name = name;
        idata.data = rdata;
        idata.lang = *lang;
        idata.size = size;
        idata.MemFlags = dbi->MemoryFlags;
        ok = WRSaveObjectAs( fname, ftype, &idata );
    }

    if( idata.type != NULL ) {
        WResIDFree( idata.type );
    }

    if( ok ) {
        if( fname != NULL ) {
            if( *file_name != NULL ) {
                WRMemFree( *file_name );
            }
            *file_name = fname;
        }
    } else {
        if( fname != NULL ) {
            WRMemFree( fname );
        }
    }

    return( ok );
}
示例#27
0
bool WREAddAccelToDir( WRECurrentResInfo *curr )
{
    WResLangType    lang;
    bool            dup;
    int             num_retries;
    WResID          *rname, *tname;
    bool            ok, tname_alloc;

    ok = true;
    tname_alloc = false;

    WREGetCurrentResource( curr );

    if( curr->info == NULL ) {
        curr->info = WRECreateNewResource( NULL );
        ok = (curr->info != NULL);
    }

    if( ok ) {
        if( curr->info->current_type == RESOURCE2INT( RT_ACCELERATOR ) ) {
            tname = &curr->type->Info.TypeName;
        } else {
            tname = WResIDFromNum( RESOURCE2INT( RT_ACCELERATOR ) );
            tname_alloc = true;
        }
        lang.lang = DEF_LANG;
        lang.sublang = DEF_SUBLANG;
    }

    if( ok ) {
        dup = true;
        num_retries = 0;
        rname = NULL;
        while( ok && dup && num_retries <= MAX_RETRIES ) {
            rname = WRECreateAccTitle();
            ok = (rname != NULL);
            if( ok ) {
                ok = WRENewResource( curr, tname, rname, DEF_MEMFLAGS, 0, 0,
                                     &lang, &dup, RESOURCE2INT( RT_ACCELERATOR ),
                                     tname_alloc );
                if( !ok && dup ) {
                    ok = true;
                }
                num_retries++;
            }
            if( rname != NULL ) {
                WRMemFree( rname );
            }
        }
        if( dup ) {
            WREDisplayErrorMsg( WRE_CANTFINDUNUSEDNAME );
        }
    }

    if( ok ) {
        curr->info->modified = true;
    }

    if( tname_alloc ) {
        WRMemFree( tname );
    }

    return( ok );
}
示例#28
0
bool WRAPI WRGetAndAddCursorImage( BYTE *data, WResDir dir, CURSORDIRENTRY *cd, int ord )
{
    BYTE                *cursor;
    bool                dup;
    uint_32             size;
    WResID              *tname;
    WResID              *rname;
    WResLangType        lang;
    CURSORHOTSPOT       hotspot;
    bool                ok;

    dup = false;
    lang.lang = DEF_LANG;
    lang.sublang = DEF_SUBLANG;
    tname = NULL;
    rname = NULL;

    ok = (data != NULL && dir != NULL && cd != NULL && cd->dwBytesInRes != 0);

    if( ok ) {
        cursor = (BYTE *)MemAlloc( cd->dwBytesInRes );
        ok = (cursor != NULL);
    }

    if( ok ) {
        memcpy( cursor, data + cd->dwImageOffset, cd->dwBytesInRes );
        hotspot.xHotspot = cd->wXHotspot;
        hotspot.yHotspot = cd->wYHotspot;
        size = cd->dwBytesInRes;
        ok = WRAddCursorHotspot( &cursor, &size, &hotspot );
    }

    if( ok ) {
        tname = WResIDFromNum( RESOURCE2INT( RT_CURSOR ) );
        ok = (tname != NULL);
    }

    if( ok ) {
        rname = WResIDFromNum( ord );
        ok = (rname != NULL);
    }

    if( ok ) {
        ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0, size, dir, &lang, &dup );
    }

    if( ok ) {
        ok = WRFindAndSetData( dir, tname, rname, &lang, cursor );
    }

    if( !ok ) {
        if( cursor != NULL ) {
            MemFree( cursor );
        }
    }

    if( tname != NULL ) {
        MemFree( tname );
    }

    if( rname != NULL ) {
        MemFree( rname );
    }

    return( ok );
}
示例#29
0
bool WRAPI 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;
    bool                ok;

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

    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 *)MemAlloc( *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, RESOURCE2INT( 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 ) {
            MemFree( *data );
            *data = NULL;
        }
        *size = 0;
    }

    return( ok );
}
示例#30
0
bool WRAPI 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;
    bool                ok;

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

    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 *)MemAlloc( *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, RESOURCE2INT( 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 ) {
            MemFree( *data );
            *data = NULL;
        }
        *size = 0;
    }

    return( ok );
}