Example #1
0
/*
 * CloseCurrentImage - Gets the current image the user is editing and deletes
 *                     the node from the linked list and sends a message to
 *                     destroy the mdi child (this will activate another
 *                     child then).
 */
void CloseCurrentImage( HWND hwnd )
{
    img_node    *node;
    char        file_name[ _MAX_PATH ];
    BOOL        ret;

    node = SelectImage( hwnd );
    if (!node) return;
    ret = DestroyWindow( _wpi_getframe(node->viewhwnd) );
    GetFnameFromPath( node->fname, file_name );
    DeleteUndoStack( hwnd );
    if ( !DeleteNode(hwnd) ) {
        WImgEditError( WIE_ERR_BAD_HWND, WIE_INTERNAL_002 );
        return;
    }
    DeleteActiveImage();
    ClearImageText();

    GrayEditOptions();
    PrintHintTextByID( WIE_FILEHASBEENCLOSED, file_name );
    SetWindowText( _wpi_getframe(HMainWindow), IEAppTitle );

#ifdef __OS2_PM__
    ret = DestroyWindow( _wpi_getframe(hwnd) );
#else
    SendMessage(ClientWindow, WM_MDIDESTROY, (WPARAM)hwnd, 0L);
#endif
} /* CloseCurrentImage */
Example #2
0
/*
 * reallyOpenImage
 */
static int reallyOpenImage( char *fname )
{
    char                filename[_MAX_FNAME + _MAX_EXT];
    
    switch( imgType ) {
    case BITMAP_IMG:
        if( !readInBitmapFile( fname ) ) {
            return( FALSE );
        }
        break;
    case ICON_IMG:
        if( !readInIconFile( fname ) ) {
            return( FALSE );
        }
        break;
    case CURSOR_IMG:
        if( !readInCursorFile( fname ) ) {
            return( FALSE );
        }
        break;
    case RESOURCE_IMG:
        if( !readInResourceFile( fname ) ) {
            return( FALSE );
        }
        break;
    default:
        GetFnameFromPath( fname, filename );
        WImgEditError( WIE_ERR_BAD_FILE_EXT, filename );
        imgType = BITMAP_IMG;
        return( FALSE );
    }

    return( imgType );

} /* reallyOpenImage */
Example #3
0
/*
 * closeTheImage - get the current image the user is editing, delete
 *                 the node from the linked list, and send a message to
 *                 destroy the MDI child (this will activate another child)
 */
static void closeTheImage( img_node *node )
{
    char        file_name[_MAX_PATH];
    BOOL        ret;
    HWND        hwnd;

    if( node == NULL ) {
        return;
    }

    ret = _wpi_destroywindow( _wpi_getframe( node->viewhwnd ) );
    GetFnameFromPath( node->fname, file_name );
    hwnd = node->hwnd;
    DeleteUndoStack( hwnd );
    if( !DeleteNode( hwnd ) ) {
        WImgEditError( WIE_ERR_BAD_HWND, WIE_INTERNAL_002 );
        return;
    }
#ifdef __OS2_PM__
    ret = DestroyWindow( _wpi_getframe( hwnd ) );
#else
    SendMessage( ClientWindow, WM_MDIDESTROY, (WPARAM)hwnd, 0L );
#endif

} /* closeTheImage */
Example #4
0
/*
 * saveBitmapFile - gets the bitmap data and saves it in fname.
 */
static bool saveBitmapFile( img_node *node )
{
    BITMAPARRAYFILEHEADER2      new_file;
    BITMAPINFO2                 *bmi;
    long                        clrtable_size;
    RGB2                        *colours;
    FILE                        *fp;
    char                        text[ HINT_TEXT_LEN ];
    char                        filename[ _MAX_FNAME ];
    bool                        ok;

    ok = false;
    bmi = GetXorBitmapInfo(node);
    if( bmi != NULL ) {
        clrtable_size = sizeof( RGB2 ) * ( 1 << ( node->bitcount ) );

        new_file.usType = BFT_BITMAPARRAY;
        new_file.cbSize = sizeof( BITMAPARRAYFILEHEADER2 );
        new_file.offNext = 0;
        new_file.cxDisplay = 0;
        new_file.cyDisplay = 0;

        new_file.bfh2.usType = BFT_BMAP;
        new_file.bfh2.cbSize = sizeof( BITMAPFILEHEADER2 );
        new_file.bfh2.xHotspot = 0;
        new_file.bfh2.yHotspot = 0;
        new_file.bfh2.offBits = new_file.cbSize + clrtable_size;
        memcpy( &(new_file.bfh2.bmp2), bmi, sizeof( BITMAPINFOHEADER2 ) );

        colours = (void *)&(bmi->argbColor[0]);

        fp = fopen( node->fname, "wb" );
        if( fp != NULL ) {
            if( fseek( fp, 0L, SEEK_SET ) == 0 ) {
                if( fwrite( &new_file, sizeof( BITMAPARRAYFILEHEADER2 ), 1, fp ) == 1 ) {
                    if( fwrite( colours, clrtable_size, 1, fp ) == 1 ) {
                        if( writeDataInPieces( bmi, fp, node ) ) {
                            ok = true;
                        } else {
                            MessageBox( HMainWindow, "Error writing file!", "Error", MB_OK | MB_ICONEXCLAMATION );
                            SetHintText( "Error saving file" );
                        }
                    }
                }
            }
            fclose( fp );
        }
        FreeDIBitmapInfo( bmi );
        if( ok ) {
            AllowRestoreOption( node );
            SetIsSaved( node->hwnd, TRUE );
            GetFnameFromPath( node->fname, filename );
            sprintf( text, "Bitmap saved to '%s'", filename );
            SetHintText( text );
        }
    }
    return( ok );
} /* saveBitmapFile */
Example #5
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 */
Example #6
0
/*
 * LoadColorPalette - load a palette
 */
BOOL LoadColorPalette( void )
{
    char                fname[_MAX_PATH];
    char                filename[_MAX_FNAME + _MAX_EXT];
    a_pal_file          *pal_file;
    FILE                *fp;
    WORD                file_type;

    if( !getOpenPalName( fname ) ) {
        if( CommDlgExtendedError() == FNERR_INVALIDFILENAME ) {
            WImgEditError( WIE_ERR_BAD_FILENAME, fname );
            return( FALSE );
        }
        return( TRUE );
    }

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

    GetFnameFromPath( fname, filename );

    fseek( fp, 0L, SEEK_SET );
    fread( &file_type, sizeof( WORD ), 1, fp );
    if( file_type != PALETTE_FILE ) {
        WImgEditError( WIE_ERR_BAD_PALFILE, filename );
        fclose( fp );
        return( FALSE );
    }

    fseek( fp, 0L, SEEK_SET );
    fread( pal_file, sizeof( a_pal_file ), 1, fp );

    fclose( fp );
    SetNewPalette( pal_file );
    PrintHintTextByID( WIE_PALETTELOADEDFROM, filename );

    MemFree( pal_file );
    return( TRUE );

} /* LoadColorPalette */
Example #7
0
/*
 * SaveColourPalette - saves the current colour palette.
 */
bool SaveColourPalette( void )
{
    a_pal_file          pal_file;
    FILE                *fp;
    char                fname[ _MAX_PATH ];
    char                filename[ _MAX_FNAME + _MAX_EXT ];
    char                text[ HINT_TEXT_LEN ];
    bool                ok;

    if( !getSavePalName( fname ) ) {
        if( CommDlgExtendedError() != 0 ) {
            sprintf( text, "Error saving '%s'", fname );
            SetHintText( text );
            return( false );
        } else {
            return( true );
        }
    }
    checkForPalExt( fname );
    if( !GetPaletteFile( &pal_file ) ) {
        sprintf( text, "Current palette not 16 colours!", fname );
        SetHintText( text );
        return( true );                   // Just return ... no error
    }

    ok = false;
    sprintf( text, "Error saving '%s'", fname );
    fp = fopen( fname, "wb" );
    if( fp != NULL ) {
        if( fseek( fp, 0L, SEEK_SET ) == 0 ) {
            if( fwrite( &pal_file, sizeof( a_pal_file ), 1, fp ) == 1 ) {
                ok = true;
            }
        }
        fclose( fp );
    }
    if( ok ) {
        GetFnameFromPath( fname, filename );
        sprintf( text, "Palette saved to '%s'", filename );
    }
    SetHintText( text );
    return( ok );

} /* SaveColourPalette */
Example #8
0
/*
 * FocusOnImage - Selects one of the mdi children.
 */
void FocusOnImage( HWND hwnd )
{
    char        current_file[ _MAX_PATH ];
    char        *text;

    if (activeImage) {
        RedrawPrevClip(activeImage->hwnd);
        SetRectExists( FALSE );
    }

    activeImage = SelectImage( hwnd );
    if (!activeImage) {
        WImgEditError( WIE_ERR_BAD_HWND, WIE_INTERNAL_001 );
        return;
    }
    ResetViewWindow( activeImage->viewhwnd );
    CreateDrawnImage( activeImage );

    SetMenus( activeImage );
    SetNumColours( 1<<(activeImage->bitcount) );

    SetHotSpot( activeImage );
    DisplayImageText( activeImage );
    CheckForUndo( activeImage );

    GetFnameFromPath( activeImage->fname, current_file );

    text = (char *)
        MemAlloc( strlen( IEAppTitle ) + strlen( current_file ) + 3 + 1 );
    if( text ) {
        strcpy( text, IEAppTitle );
        strcat( text, " - " );
        strcat( text, current_file );
        _wpi_setwindowtext( _wpi_getframe(HMainWindow), text );
        MemFree( text );
    }

#ifndef __OS2_PM__
    RedrawWindow( hwnd, NULL, NULL, RDW_UPDATENOW );
#endif
} /* FocusOnImage */
Example #9
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 */
Example #10
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 */
Example #11
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 */
Example #12
0
/*
 * lastChanceSave - is called when the user quits and the current image
 *                  is not yet saved.  Returns FALSE if CANCEL
 *                  is selected, otherwise, it returns TRUE.
 */
static BOOL lastChanceSave( img_node *node )
{
    int         retcode;
    int         how;
    HMENU       hmenu;
    char        *title;
    char        *text;
    char        *msg_text;
    char        filename[ _MAX_PATH ];

    if( !node ) return( TRUE );

    IECheckIfActiveWindow();
    if( strnicmp( node->fname, IEImageUntitled, strlen( IEImageUntitled ) ) != 0 ) {
        GetFnameFromPath( node->fname, filename );
        how = SB_SAVE;
    } else {
        strcpy( filename, node->fname );
        how = SB_SAVE_AS;
    }

    retcode = IDCANCEL;
    title = IEAllocRCString( WIE_EXITTITLE );
    if( ImgedIsDDE ) {
        text = IEAllocRCString( WIE_QUERYIMAGEUPDATE );
    } else {
        text = IEAllocRCString( WIE_QUERYIMAGESAVE );
    }
    if( text ) {
        msg_text = (char *)MemAlloc( strlen( text ) + strlen( filename ) + 1 );
        if( msg_text ) {
            sprintf( msg_text, text, filename );
            retcode = _wpi_messagebox( HMainWindow, msg_text, title,
                                       MB_YESNOCANCEL | MB_ICONQUESTION );
            MemFree( msg_text );
        }
        IEFreeRCString( text );
    }
    if( title ) {
        IEFreeRCString( title );
    }

    if (retcode == IDYES) {
        if( ImgedIsDDE ) {
#ifndef __OS2_PM__
            if( IEUpdateDDEEditSession() ) {
                SetIsSaved( node->hwnd, TRUE );
            } else {
                PrintHintTextByID( WIE_FILENOTSAVED, NULL );
                return( FALSE );
            }
#else
            PrintHintTextByID( WIE_FILENOTSAVED, NULL );
            return( FALSE );
#endif
        } else {
            if (!SaveFile( how )) {
                PrintHintTextByID( WIE_FILENOTSAVED, NULL );
                return( FALSE );
            } else {
                hmenu = _wpi_getmenu( HMainWindow );
                _wpi_enablemenuitem( hmenu, IMGED_SAVE, FALSE, FALSE );
                SetIsSaved( node->hwnd, TRUE );
            }
        }
    } else if (retcode == IDCANCEL) {
        return (FALSE);
    }
    return (TRUE);
} /* lastChanceSave */
Example #13
0
/*
 * WinNewDrawPad - create a new drawing pad for Windows version
 */
HWND WinNewDrawPad( img_node *node )
{
    MDICREATESTRUCT     mdicreate;
    short               y_adjustment;
    short               x_adjustment;
    short               pad_x;
    short               pad_y;
    int                 i;
    img_node            *temp;
    POINT               origin;
    char                filename[_MAX_PATH];
    HWND                drawarea;
    HMENU               sys_menu;

    node->viewhwnd = CreateViewWin( node->width, node->height );
    pad_x = 0;
    pad_y = 0;

    temp = node->nexticon;

    for( i = 1; i < node->num_of_images; i++ ) {
        temp->viewhwnd = node->viewhwnd;
        temp = temp->nexticon;
    }

    if( node->imgtype == BITMAP_IMG ) {
        mdicreate.szClass = DrawAreaClassB;
    } else if( node->imgtype == ICON_IMG ) {
        mdicreate.szClass = DrawAreaClassI;
    } else {
        mdicreate.szClass = DrawAreaClassC;
    }

    GetFnameFromPath( node->fname, filename );
    mdicreate.szTitle = filename;
    mdicreate.hOwner = Instance;

    x_adjustment = (short)(2 * GetSystemMetrics( SM_CXFRAME ));
    y_adjustment = (short)(2 * GetSystemMetrics( SM_CYFRAME ) +
                           GetSystemMetrics( SM_CYCAPTION ) - 1);

    origin.x = 0;
    origin.y = 0;
    FindOrigin( &origin );
    CalculateDims( node->width, node->height, &pad_x, &pad_y );

    mdicreate.cx = x_adjustment + pad_x;
    mdicreate.cy = y_adjustment + pad_y;
    mdicreate.x = origin.x;
    mdicreate.y = origin.y;
    mdicreate.style = WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_VISIBLE |
                      WS_CLIPSIBLINGS | WS_DLGFRAME | WS_MINIMIZEBOX |
                      WS_THICKFRAME;
    mdicreate.lParam = (LPARAM)(LPVOID)node;

    drawarea = (HWND)SendMessage( ClientWindow, WM_MDICREATE, 0,
                                  (LPARAM)(LPVOID)&mdicreate );

    if( drawarea != (HWND)NULL ) {
        RECT    rect;
        int     w, h;
        _wpi_getclientrect( drawarea, &rect );
        w = _wpi_getwidthrect( rect );
        h = _wpi_getheightrect( rect );
        if( w != pad_x || h != pad_y ) {
            GetWindowRect( drawarea, &rect );
            w = _wpi_getwidthrect( rect ) + (pad_x - w);
            h = _wpi_getheightrect( rect ) + (pad_y - h);
            SetWindowPos( drawarea, HWND_TOP, 0, 0, w, h,
                          SWP_SIZE | SWP_NOZORDER | SWP_NOMOVE );
        }
    }

    if( ImgedIsDDE ) {
        sys_menu = GetSystemMenu( drawarea, FALSE );
        if( sys_menu != (HMENU)NULL ) {
            EnableMenuItem( sys_menu, SC_CLOSE, MF_GRAYED );
        }
    }

    BlowupImage( NULL, NULL );
    return( drawarea );

} /* WinNewDrawPad */
Example #14
0
/*
 * lastChanceSave - called when the user quits and the current image
 *                  is not yet saved
 *                - return FALSE if CANCEL is selected
 *                - otherwise, it return TRUE
 */
static BOOL lastChanceSave( HWND hwnd )
{
    int         retcode;
    int         how;
    HMENU       hmenu;
    img_node    *node;
    img_node    *icon;
    char        *title;
    char        *text;
    char        *msg_text;
    char        filename[_MAX_PATH];

    if( !DoImagesExist() ) {
        return( TRUE );
    }

    node = SelectImage( hwnd );
    if( node == NULL ) {
        return( TRUE );
    }

    icon = GetImageNode( hwnd );
    while( icon != NULL ) {
        if( icon->issaved ) {
            return( TRUE );
        }
        icon = icon->nexticon;
    }

    if( strnicmp( node->fname, IEImageUntitled, strlen( IEImageUntitled ) ) != 0 ) {
        GetFnameFromPath( node->fname, filename );
        how = SB_SAVE;
    } else {
        strcpy( filename, node->fname );
        how = SB_SAVE_AS;
    }

    retcode = WPI_IDCANCEL;
    title = IEAllocRCString( WIE_CLOSETITLE );
    text = IEAllocRCString( WIE_QUERYIMAGESAVE );
    if( text != NULL ) {
        msg_text = (char *)MemAlloc( strlen( text ) + strlen( filename ) + 1 );
        if( msg_text != NULL ) {
            sprintf( msg_text, text, filename );
            retcode = _wpi_messagebox( HMainWindow, msg_text, title,
                                       MB_YESNOCANCEL | MB_ICONQUESTION );
            MemFree( msg_text );
        }
        IEFreeRCString( text );
    }
    if( title != NULL ) {
        IEFreeRCString( title );
    }

    if( retcode == WPI_IDYES ) {
        if( !SaveFile( how ) ) {
            PrintHintTextByID( WIE_FILENOTSAVED, NULL );
            return( FALSE );
        } else {
            hmenu = _wpi_getmenu( _wpi_getframe( HMainWindow ) );
            _wpi_enablemenuitem( hmenu, IMGED_SAVE, FALSE, FALSE );
            SetIsSaved( hwnd, TRUE );
        }
    } else if( retcode == WPI_IDCANCEL ) {
        return( FALSE );
    }
    return( TRUE );

} /* lastChanceSave */
Example #15
0
/*
 * saveImageFile - saves a cursor or icon file
 */
static bool saveImageFile( img_node *node )
{
    BITMAPARRAYFILEHEADER2      new_file;
    BITMAPFILEHEADER2           *and_part;
    BITMAPFILEHEADER2           *xor_part;
    BITMAPINFO2                 *andbmi;
    BITMAPINFO2                 *xorbmi;
    long                        clrtable_size;
    long                        and_size;
    ULONG                       nextoff;
    RGB2                        *colours;
    FILE                        *fp;
    char                        text[ HINT_TEXT_LEN ];
    char                        filename[ _MAX_FNAME ];
    img_node                    *new_image;
    bool                        ok;

    ok = false;
    fp = fopen( node->fname, "wb" );
    if( fp != NULL ) {
        if( fseek( fp, 0L, SEEK_SET ) == 0 ) {
            ok = true;
            nextoff = 0;
            for( new_image = node; new_image != NULL; new_image = new_image->nexticon ) {
                new_file.usType = BFT_BITMAPARRAY;
                new_file.cbSize = sizeof( BITMAPARRAYFILEHEADER2 );
                new_file.offNext = nextoff;
                new_file.cxDisplay = 0;
                new_file.cyDisplay = 0;

                and_part = fillFileHeader( new_image );
                memcpy( &(new_file.bfh2), and_part, sizeof( BITMAPFILEHEADER2 ) );
                /*
                 * First the info for the AND mask
                 */
                andbmi = GetAndBitmapInfo( new_image );
                if( andbmi == NULL ) {
                    ok = false;
                } else {
                    clrtable_size = sizeof( RGB2 ) * ( 1 << new_image->bitcount );
                    and_size = sizeof( RGB2 ) * 2;

                    new_file.bfh2.offBits = new_file.offNext + new_file.cbSize +
                                            and_size + clrtable_size +
                                            sizeof( BITMAPFILEHEADER2 );
                    memcpy( &(new_file.bfh2.bmp2), andbmi, sizeof( BITMAPINFOHEADER2 ) );
                    colours = (void *)&(andbmi->argbColor[0]);

                    if( fwrite( &new_file, sizeof( BITMAPARRAYFILEHEADER2 ), 1, fp ) != 1 ) {
                        ok = false;
                    } else if( fwrite( colours, and_size, 1, fp ) != 1 ) {
                        ok = false;
                    }
                    FreeDIBitmapInfo( andbmi );
                }
                MemFree( and_part );

                if( ok ) {
                    /*
                     * Now we write the XOR part
                     */
                    xor_part = fillFileHeader( new_image );
                    xorbmi = GetXorBitmapInfo( new_image );
                    if( xorbmi == NULL ) {
                        ok = false;
                    } else {
                        xor_part->offBits = new_file.bfh2.offBits + BITS_TO_BYTES( new_image->width, 2 * new_image->height );
                        memcpy( &(xor_part->bmp2), xorbmi, sizeof( BITMAPINFOHEADER2 ) );
                        colours = (void *)&(xorbmi->argbColor[0]);
                        if( fwrite( xor_part, sizeof( BITMAPFILEHEADER2 ), 1, fp ) != 1 ) {
                            ok = false;
                        } else if( fwrite( colours, clrtable_size, 1, fp ) != 1 ) {
                            ok = false;
                        }
                        FreeDIBitmapInfo( xorbmi );
                    }
                    MemFree( xor_part );
                    nextoff = nextoff + sizeof( BITMAPARRAYFILEHEADER2 ) + and_size + sizeof( BITMAPFILEHEADER2 ) + clrtable_size;
                }
                if( !rc ) {
                    break;
                }
            }
        }
        fclose( fp );
    }
    if( ok ) {
        /*
         * Now we write the bits for all the images in the file.
         */
        if( !writeImageBits( fp, node ) ) {
            return( false );
        }
        AllowRestoreOption( node );
        SetIsSaved( node->hwnd, TRUE );
        GetFnameFromPath( node->fname, filename );
        if( node->imgtype == ICON_IMG ) {
            sprintf( text, "Icon saved to '%s'", filename );
        } else {
            sprintf( text, "Pointer saved to '%s'", filename );
        }
        SetHintText( text );
    }
    return( ok );
} /* saveImageFile */