Ejemplo n.º 1
0
/*
 * doReadCursor
 */
BOOL doReadCursor( char *fname, an_img_file *cursorfile, an_img *cursor,
                   WRInfo *info, WResLangNode *lnode )
{
    img_node            node;
    HDC                 hdc;
    char                filename[_MAX_FNAME + _MAX_EXT];

    if( cursorfile == NULL || cursor == NULL ) {
        return( FALSE );
    }

    GetFnameFromPath( fname, filename );

    node.imgtype = CURSOR_IMG;
    node.width = cursor->bm->bmiHeader.biWidth;
    node.height = cursor->bm->bmiHeader.biHeight;
    if( node.height == 0 ) {
        node.height = node.width;
    }
    node.bitcount = cursor->bm->bmiHeader.biBitCount;
    node.hotspot.x = cursorfile->resources->xhotspot;
    node.hotspot.y = cursorfile->resources->yhotspot;
    node.issaved = TRUE;
    node.num_of_images = 1;
    node.next = NULL;
    node.nexticon = NULL;
    node.wrinfo = info;
    node.lnode = lnode;

    hdc = GetDC( NULL );
    node.handbitmap = ImgToAndBitmap( hdc, cursor );
    node.hxorbitmap = ImgToXorBitmap( hdc, cursor );
    ReleaseDC( NULL, hdc );

    strcpy( node.fname, strupr( fname ) );
    ImageFini( cursor );
    ImageClose( cursorfile );

    PrintHintTextByID( WIE_OPENEDTEXT, filename );
    MakeIcon( &node, FALSE );           // also makes cursors
    CreateNewDrawPad( &node );

    return( TRUE );

} /* doReadCursor */
Ejemplo n.º 2
0
/*
 * doReadInBitmapFile
 */
static BOOL doReadInBitmapFile( HBITMAP hbitmap, bitmap_info *bmi, char *fullname,
                                WRInfo *info, WResLangNode *lnode )
{
    HBITMAP             oldbmp1;
    HBITMAP             oldbmp2;
    img_node            node;
    char                filename[_MAX_FNAME + _MAX_EXT];
    BITMAPINFOHEADER    *h;
    HDC                 hdc;
    HDC                 srcdc;
    HDC                 destdc;

    GetFnameFromPath( fullname, filename );

    if( hbitmap != NULL ) {
        h = &bmi->u.bm_info->bmiHeader;

        if( h->biWidth > MAX_DIM || h->biHeight > MAX_DIM ) {
            WImgEditError( WIE_ERR_BITMAP_TOO_BIG, filename );
            MemFree( bmi->u.bm_info );
            DeleteObject( hbitmap );
            return( FALSE );
        }

#if 0
        /* Should not be an error... */
        else if( h->biBitCount > 8 ) {
            WImgEditError( WIE_ERR_TOO_MANY_COLOURS, filename );
            MemFree( bmi->u.bm_info );
            DeleteObject( hbitmap );
            return( FALSE );
        }
#endif
        node.imgtype = BITMAP_IMG;
        node.width = bmi->u.bm_info->bmiHeader.biWidth;
        node.height = bmi->u.bm_info->bmiHeader.biHeight;
        node.bitcount = bmi->u.bm_info->bmiHeader.biBitCount;
        node.hotspot.x = 0;
        node.hotspot.y = 0;
        node.num_of_images = 1;
        node.nexticon = NULL;
        node.issaved = TRUE;
        if( node.bitcount == 1 ) {
            hdc = GetDC( NULL );
            srcdc = CreateCompatibleDC( hdc );
            destdc = CreateCompatibleDC( hdc );
            ReleaseDC( NULL, hdc );

            node.hxorbitmap = CreateCompatibleBitmap( destdc, node.width, node.height );
            oldbmp1 = SelectObject( srcdc, hbitmap );
            oldbmp2 = SelectObject( destdc, node.hxorbitmap );
            BitBlt( destdc, 0, 0, node.width, node.height, srcdc, 0, 0, SRCCOPY );
            SelectObject( srcdc, oldbmp1 );
            SelectObject( destdc, oldbmp2 );
            DeleteDC( srcdc );
            DeleteDC( destdc );
            DeleteObject( hbitmap );
        } else {
            node.hxorbitmap = hbitmap;
        }

        strcpy( node.fname, fullname );
        PrintHintTextByID( WIE_OPENEDTEXT, filename );

        node.wrinfo = info;
        node.lnode = lnode;

        MakeBitmap( &node, FALSE );
        CreateNewDrawPad( &node );

        MemFree( bmi->u.bm_info );
        return( TRUE );
    }
    return( FALSE );

} /* doReadInBitmapFile */
Ejemplo n.º 3
0
/*
 * readInIconFile - read the icon file and set up structures
 */
static BOOL readInIconFile( char *fname )
{
    FILE                *fp;
    an_img_file         *iconfile;
    img_node            *node;
    int                 num_of_images;
    HDC                 hdc;
    int                 i;
    an_img              *icon;
    char                filename[_MAX_FNAME + _MAX_EXT];

    fp = fopen( fname, "rb" );
    if( fp == NULL ) {
        WImgEditError( WIE_ERR_FILE_NOT_OPENED, fname );
        return( FALSE );
    }

    GetFnameFromPath( fname, filename );
#ifdef JAMIE
    {
        char msg[80];
        sprintf( msg, "Jamie: IconHeader size = %d", sizeof( an_img_file ) );
        MessageBox( HMainWindow, msg, "FYI", MB_OK );
    }
#endif
    iconfile = ImageOpen( fp );
    if( iconfile == NULL ) {
        fclose( fp );
        WImgEditError( WIE_ERR_BAD_ICON_FILE, 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 );
            fclose( fp );
            return( FALSE );
        }
    }
#endif

    node = MemAlloc( sizeof( img_node ) * num_of_images );

    hdc = GetDC( NULL );
    for( i = 0; i < num_of_images; i++ ) {
        icon = ImgResourceToImg( fp, 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 );
            fclose( fp );
            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;
        node[i].wrinfo = NULL;
        node[i].lnode = NULL;
        if( i > 0 ) {
            node[i - 1].nexticon = &node[i];
        }
        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 );
    fclose( fp );

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

    MemFree( node );
    return( TRUE );

} /* readInIconFile */
Ejemplo n.º 4
0
/*
 * 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 */
Ejemplo n.º 5
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 */