コード例 #1
0
ファイル: ieopen.c プロジェクト: ABratovic/open-watcom-v2
/*
 * ReadCursorFromData - read the cursor data and set up structures
 */
BOOL ReadCursorFromData( void *data, char *fname, WRInfo *info,
                         WResLangNode *lnode )
{
    unsigned            pos;
    an_img_file         *cursorfile;
    an_img              *cursor;
    BOOL                ret;

    pos = 0;
    cursorfile = ImageOpenData( (BYTE *)data, &pos );
    if( cursorfile == NULL ) {
        WImgEditError( WIE_ERR_BAD_CURSOR_DATA, fname );
        return( FALSE );
    }
    cursor = ImgResourceToImgData( (BYTE *)data, &pos, cursorfile, 0 );

    ret = doReadCursor( fname, cursorfile, cursor, info, lnode );

    if( ret ) {
        SetupMenuAfterOpen();
    }

    return( ret );

} /* ReadCursorFromData */
コード例 #2
0
ファイル: ieopen.c プロジェクト: ABratovic/open-watcom-v2
/*
 * OpenImage - get the filename of the file to open
 *           - depending on the extension, set the type (.ico, .bmp, .cur) and call the
 *             appropriate function to open it
 */
int OpenImage( HANDLE hDrop )
{
    char                fname[_MAX_PATH];
    int                 rv = FALSE;

    if( NULL == hDrop ) {
        /*
         * Not doing a drag-drop
         */
        if( !getOpenFName( fname ) ) {
            if( CommDlgExtendedError() == FNERR_INVALIDFILENAME ) {
                WImgEditError( WIE_ERR_BAD_FILENAME, fname );
                return( FALSE );
            }
            return( FALSE );
        }
        rv = reallyOpenImage( fname );
    } else {
        /*
         * hDrop is only ever !NULL when we're dealing with a WM_DROPFILES
         * message, and that only happens with __NT__
         */
#ifdef __NT__
        int     nFiles = DragQueryFile( hDrop, 0xFFFFFFFF, NULL, 0 );
        int     i;
        
        for( i = 0, rv = TRUE; rv && i < nFiles; i++ ) {
            DragQueryFile( hDrop, i, fname, _MAX_PATH - 1 );
            imgType = getImageTypeFromFilename( fname );
            rv = reallyOpenImage( fname );
        }
#endif
    }
    
    if( rv ) {
        SetupMenuAfterOpen();
    }

    return( rv );

} /* OpenImage */
コード例 #3
0
ファイル: ieopen.c プロジェクト: ABratovic/open-watcom-v2
/*
 * OpenFileOnStart - open a file on program startup
 */
void OpenFileOnStart( char *fname )
{
    int         namelen;
    char        ext[_MAX_EXT];
    FILE        *fp;

    fp = fopen( fname, "r" );
    if( fp == NULL ) {
        if( OpenNewFiles ) {
            if( NewImage( UNDEF_IMG, fname ) ) {
                return;
            }
        }
        WImgEditError( WIE_ERR_STARTUP_FNO, fname );
        return;
    }
    fclose( fp );

    namelen = strlen( fname );
    strcpy( ext, &fname[namelen - 3] );

    if( stricmp( ext, "bmp" ) == 0 ) {
        if( !readInBitmapFile( fname ) ) {
            return;
        }
    } else if( stricmp( ext, "ico" ) == 0 ) {
        if( !readInIconFile( fname ) ) {
            return;
        }
    } else if( stricmp( ext, "cur" ) == 0 ) {
        if( !readInCursorFile( fname ) ) {
            return;
        }
    } else {
        return;
    }

    SetupMenuAfterOpen();

} /* OpenFileOnStart */
コード例 #4
0
ファイル: ieopen.c プロジェクト: ABratovic/open-watcom-v2
/*
 * ReadBitmapFromData
 */
BOOL ReadBitmapFromData( void *data, char *fullname, WRInfo *info, WResLangNode *lnode )
{
    bitmap_info         bmi;
    HBITMAP             hbitmap;
    HCURSOR             prevcursor;
    BOOL                ret;

    prevcursor = SetCursor( LoadCursor( NULL, IDC_WAIT ) );
    hbitmap = BitmapFromData( data, &bmi );
    SetCursor( prevcursor );
    if( hbitmap == (HBITMAP)NULL ) {
        WImgEditError( WIE_ERR_BAD_BITMAP_DATA, fullname );
        return( FALSE );
    }

    ret = doReadInBitmapFile( hbitmap, &bmi, fullname, info, lnode );

    if( ret ) {
        SetupMenuAfterOpen();
    }

    return( ret );

} /* ReadBitmapFromData */
コード例 #5
0
ファイル: ieopen.c プロジェクト: ABratovic/open-watcom-v2
/*
 * ReadIconFromData - read the icon data and set up structures
 */
BOOL ReadIconFromData( void *data, char *fname, WRInfo *info, WResLangNode *lnode )
{
    unsigned            pos;
    an_img_file         *iconfile;
    img_node            *node;
    int                 num_of_images;
    HDC                 hdc;
    int                 i;
    an_img              *icon;
    char                filename[_MAX_FNAME + _MAX_EXT];

    pos = 0;
    GetFnameFromPath( fname, filename );
    iconfile = ImageOpenData( (BYTE *)data, &pos );
    if( iconfile == NULL ) {
        WImgEditError( WIE_ERR_BAD_ICON_DATA, filename );
        return( FALSE );
    }
    num_of_images = iconfile->count;

#if 0
    /* See biBitCount test below... */
    for( i = 0; i < num_of_images; i++ ) {
        if( iconfile->resources[i].color_count != 2 &&
            iconfile->resources[i].color_count != 8 &&
            iconfile->resources[i].color_count != 16 &&
            iconfile->resources[i].color_count != 0 ) {
            WImgEditError( WIE_ERR_BAD_ICON_CLR, filename );
            ImageClose( iconfile );
            return( FALSE );
        }
    }
#endif
    
    node = MemAlloc( sizeof( img_node ) * num_of_images );

    hdc = GetDC( NULL );
    for( i = 0; i < num_of_images; i++ ) {
        icon = ImgResourceToImgData( (BYTE *)data, &pos, iconfile, i );
        if( icon->bm->bmiHeader.biBitCount != 4 &&
            icon->bm->bmiHeader.biBitCount != 1 &&
            icon->bm->bmiHeader.biBitCount != 8 ) {
            WImgEditError( WIE_ERR_BAD_ICON_CLR, filename );
            ReleaseDC( NULL, hdc );
            ImageFini( icon );
            ImageClose( iconfile );
            MemFree( node );
            return( FALSE );
        }

        node[i].imgtype = ICON_IMG;
        node[i].bitcount = icon->bm->bmiHeader.biBitCount;
        node[i].width = icon->bm->bmiHeader.biWidth;
        node[i].height = icon->bm->bmiHeader.biHeight;
        node[i].hotspot.x = 0;
        node[i].hotspot.y = 0;
        node[i].handbitmap = ImgToAndBitmap( hdc, icon );
        node[i].hxorbitmap = ImgToXorBitmap( hdc, icon );
        node[i].num_of_images = num_of_images;
        node[i].viewhwnd = NULL;
        if( i > 0 ) {
            node[i - 1].nexticon = &node[i];
        }
        node[i].wrinfo = NULL;
        node[i].lnode = NULL;
        if( i == 0 ) {
            node[i].wrinfo = info;
            node[i].lnode = lnode;
        }
        node[i].issaved = TRUE;
        node[i].next = NULL;
        strcpy( node[i].fname, strupr( fname ) );
        ImageFini( icon );
    }
    node[i - 1].nexticon = NULL;

    ReleaseDC( NULL, hdc );
    ImageClose( iconfile );

    WriteIconLoadedText( filename, node->num_of_images );
    CreateNewDrawPad( node );

    MemFree( node );

    SetupMenuAfterOpen();

    return( TRUE );

} /* ReadIconFromData */
コード例 #6
0
/*
 * NewImage - create a new image and return the image type (bitmap, icon, or cursor)
 */
int NewImage( int img_type, const char *filename )
{
    WPI_DLGPROC         dlgproc;
    INT_PTR             button_type;
    short               width;
    short               height;
    short               bcount;
    img_node            node;
    char                ext[_MAX_EXT];

    // If filename is not NULL and we don't know the image type,
    // then guess based on the file extesion.
    if( filename != NULL && img_type == UNDEF_IMG ) {
        _splitpath( filename, NULL, NULL, NULL, ext );
        if( stricmp( ext, ".bmp" ) == 0 ) {
            img_type = BITMAP_IMG;
        } else if( stricmp( ext, ".ico" ) == 0 ) {
            img_type = ICON_IMG;
        } else if( stricmp( ext, ".cur" ) == 0 ) {
            img_type = CURSOR_IMG;
        }
    }

    if( img_type == UNDEF_IMG ) {
        dlgproc = _wpi_makedlgprocinstance( SelImgDlgProc, Instance );
        button_type = _wpi_dialogbox( HMainWindow, dlgproc, Instance, SELECTIMAGE, 0L );
        _wpi_freedlgprocinstance( dlgproc );

        if( button_type == DLGID_CANCEL ) {
            return( FALSE );
        }
    } else {
        imgType = img_type;
    }

    imageCount++;

    switch( imgType ) {
    case BITMAP_IMG:
        dlgproc = _wpi_makedlgprocinstance( SelBitmapDlgProc, Instance );
        button_type = _wpi_dialogbox( HMainWindow, dlgproc, Instance, BITMAPTYPE, 0L );
        _wpi_freedlgprocinstance( dlgproc );
        if( button_type == DLGID_CANCEL ) {
            imgType = UNDEF_IMG;
            imageCount--;
            return( imgType );
        } else if( button_type == SEL_SELECT ) {
#ifdef __OS2_PM__
            IEDisplayErrorMsg( WIE_NOTE, WIE_NOTIMPLEMENTED, MB_OK | MB_ICONINFORMATION );
            return( FALSE );
#else
            if( !SelectDynamicBitmap( &node, imageCount, filename ) ) {
                return( FALSE );
            }
#endif
        } else {
            initializeImage( &node, filename );
        }
        break;

    case ICON_IMG:
        if( !CreateNewIcon( &width, &height, &bcount, TRUE ) ) {
            imgType = UNDEF_IMG;
            return( imgType );
        }
        imgWidth = width;
        imgHeight = height;
        bitCount = bcount;
        initializeImage( &node, filename );
        break;

    case CURSOR_IMG:
#ifdef __OS2_PM__
        if( !CreateNewIcon( &width, &height, &bcount, FALSE ) ) {
            imgType = UNDEF_IMG;
            return( imgType );
        }
        imgWidth = width;
        imgHeight = height;
        bitCount = bcount;
#else
        dlgproc = MakeProcInstance_DLG( SelCursorDlgProc, Instance );
        button_type = JDialogBox( Instance, "CURSORTYPE", HMainWindow, dlgproc );
        FreeProcInstance_DLG( dlgproc );
        if( button_type == IDCANCEL ) {
            imgType = UNDEF_IMG;
            return( imgType );
        }
#endif
        initializeImage( &node, filename );
        break;

    default:
        return( FALSE );
    }

    node.wrinfo = NULL;
    node.lnode = NULL;

    CreateNewDrawPad( &node );

    SetupMenuAfterOpen();

    return( imgType );

} /* NewImage */