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

📄 ieutil.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include "imgedit.h"
#include "iconinfo.h"
#include "iemem.h"

static WPI_POINT        *windowCoords;
static int              windowIndex;    // used to figure out window coordinates
#ifdef __OS2_PM__
static int              imageMax;
#endif
/*
 * CreateViewBitmap - creates the bitmap on the screen (with the background
 *                      colour as it should be etc...).  Function caller is
 *                      responsible for deleting the bitmap.
 */
HBITMAP CreateViewBitmap( img_node *mdi_node )
{
    WPI_PRES    pres;
    WPI_PRES    xorandpres;
    WPI_PRES    mempres;
    WPI_PRES    freehandpres;
    HDC         xoranddc;
    HDC         memdc;
    HBITMAP     newbitmap;
    HBITMAP     oldxorandbitmap;
    HBITMAP     oldbitmap;
    HBRUSH      brush;
    HBRUSH      oldbrush;
    img_node    *node;
    COLORREF    bkcolour;

    if (mdi_node) {
        node = mdi_node;
    } else {
        node = GetCurrentNode();
        if (!node) return(NULL);
    }

    pres = _wpi_getpres( HWND_DESKTOP );
    xorandpres = _wpi_createcompatiblepres( pres, Instance, &xoranddc );
    mempres = _wpi_createcompatiblepres( pres, Instance, &memdc );
    newbitmap = _wpi_createcompatiblebitmap(pres, node->width, node->height );
    _wpi_releasepres( HWND_DESKTOP, pres );

    _wpi_torgbmode( mempres );
    _wpi_torgbmode( xorandpres );
    bkcolour = GetBkColour();

#ifdef __OS2_PM__
    _wpi_preparemono( mempres, BLACK, bkcolour );
#endif
    oldbitmap = _wpi_selectobject( mempres, newbitmap );

    brush = _wpi_createsolidbrush( bkcolour );
    oldbrush = _wpi_selectobject( mempres, brush );

    _wpi_patblt( mempres, 0, 0, node->width, node->height, PATCOPY );
    _wpi_selectobject( mempres, oldbrush );
    _wpi_deletebrush( brush );

    GetFreeHandPresentationSpaces( NULL, &freehandpres, NULL );
    if( freehandpres == (WPI_PRES)NULL ) {
        oldxorandbitmap = _wpi_selectobject( xorandpres, node->handbitmap );
        _wpi_bitblt( mempres, 0, 0, node->width, node->height,
                     xorandpres, 0, 0, SRCAND);
        _wpi_selectobject( xorandpres, oldxorandbitmap );
    } else {
        _wpi_bitblt( mempres, 0, 0, node->width, node->height,
                     freehandpres, 0, 0, SRCAND);
    }

    GetFreeHandPresentationSpaces( NULL, NULL, &freehandpres );
    if( freehandpres == (WPI_PRES)NULL ) {
        oldxorandbitmap = _wpi_selectobject( xorandpres, node->hxorbitmap );
        _wpi_bitblt( mempres, 0, 0, node->width, node->height,
                     xorandpres, 0, 0, SRCINVERT);
        _wpi_selectobject( xorandpres, oldxorandbitmap );
    } else {
        _wpi_bitblt( mempres, 0, 0, node->width, node->height,
                     freehandpres, 0, 0, SRCINVERT);
    }

    _wpi_deletecompatiblepres( xorandpres, xoranddc );
    _wpi_selectobject( mempres, oldbitmap );
    _wpi_deletecompatiblepres( mempres, memdc );

    return( newbitmap );
} /* CreateViewBitmap */

/*
 * DuplicateBitmap - produces a duplicate of the bitmap.
 */
HBITMAP DuplicateBitmap( HBITMAP hbitmap)
{
    HDC         srcdc;
    WPI_PRES    srcpres;
    HDC         destdc;
    WPI_PRES    destpres;
    WPI_PRES    pres;
    int         width;
    int         height;
    int         planes;
    int         bitspixel;
    HBITMAP     newbitmap;
    HBITMAP     oldbitmap;
    HBITMAP     oldnewbitmap;

    _wpi_getbitmapparms( hbitmap, &width, &height, &planes, NULL, &bitspixel );
    pres = _wpi_getpres( HWND_DESKTOP );
    srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc );
    destpres = _wpi_createcompatiblepres( pres, Instance, &destdc );
    _wpi_releasepres( HWND_DESKTOP, pres );

    newbitmap = _wpi_createbitmap(width, height, planes, bitspixel, NULL );

    oldbitmap = _wpi_selectobject( srcpres, hbitmap );
    oldnewbitmap = _wpi_selectobject( destpres, newbitmap );

    _wpi_bitblt(destpres, 0, 0, width, height, srcpres, 0, 0, SRCCOPY);

    _wpi_selectobject( srcpres, oldbitmap );
    _wpi_selectobject( destpres, oldnewbitmap );

    _wpi_deletecompatiblepres( srcpres, srcdc );
    _wpi_deletecompatiblepres( destpres, destdc );
    return( newbitmap );
} /* DuplicateBitmap */

BOOL IEStretchBlt( WPI_PRES hdcDest, int nXOriginDest, int nYOriginDest,
                                     int nWidthDest, int nHeightDest,
                   WPI_PRES hdcSrc, int nXOriginSrc, int nYOriginSrc,
                                    int nWidthSrc, int nHeightSrc,
                   DWORD fdwRop, int bitcount )
{
    POINT               slines;
    POINT               dlines;
    POINT               num_strips;
    unsigned long       linesize;
    int                 x, y;
    int                 sw, sh, dw, dh;
    WPI_PRES            srcpres;
    HDC                 srcdc;
    HBITMAP             oldbitmap;
    HBITMAP             newbitmap;

    num_strips.x = nWidthDest / 256;
    num_strips.x++;
    if (nWidthDest > 32 && FALSE) {
        /* use the version that returns exact bytes needed for bits */
        linesize = BITS_INTO_BYTES( (unsigned long)( nWidthDest * bitcount), 1 );
    } else {
        /* use the version that rounds up to 32 bits */
        linesize = BITS_TO_BYTES( (unsigned long)( nWidthDest * bitcount), 1 );
    }
    num_strips.y = ( (unsigned long)nHeightDest * linesize ) / ( 16 * 1024 );
    num_strips.y++;

    if( num_strips.x > nWidthSrc ) {
        num_strips.x = nWidthSrc;
    } else if( num_strips.x < nWidthSrc ) {
        num_strips.x += ( num_strips.x % 2 );
    }

    if( num_strips.y > nHeightSrc ) {
        num_strips.y = nHeightSrc;
    } else if( num_strips.y < nHeightSrc ) {
        num_strips.y += ( num_strips.y % 2 );
    }

    slines.x = nWidthSrc / num_strips.x;
    dlines.x = ( (unsigned long)slines.x * (unsigned long)nWidthDest ) /
                   (unsigned long)nWidthSrc;

    slines.y = nHeightSrc / num_strips.y;
    dlines.y = ( (unsigned long)slines.y * (unsigned long)nHeightDest ) /
                   (unsigned long)nHeightSrc;

    srcpres = _wpi_createcompatiblepres( hdcDest, Instance, &srcdc );
    newbitmap = _wpi_createcompatiblebitmap( hdcDest, dlines.x, dlines.y );
    oldbitmap = _wpi_selectobject( srcpres, newbitmap );

    sw = slines.x;
    dw = dlines.x;
    for( x=0; slines.x * x <= nWidthSrc; x++ ) {
        if( ( slines.x * x + sw ) > nWidthSrc ) {
            sw = nWidthSrc - x * slines.x;
            dw = nWidthDest - x * dlines.x;
        }
        sh = slines.y;
        dh = dlines.y;
        for( y=0; slines.y * y <= nHeightSrc; y++ ) {
            if( ( slines.y * y + sh ) > nHeightSrc ) {
                sh = nHeightSrc - y * slines.y;
                dh = nHeightDest - y * dlines.y;
            }
            _wpi_stretchblt( srcpres, 0, 0, dw, dh, hdcSrc,
                             nXOriginSrc + slines.x*x, nYOriginSrc + slines.y*y,
                             sw, sh, fdwRop );
            _wpi_bitblt( hdcDest, nXOriginDest + dlines.x*x,
                         nYOriginDest + dlines.y*y, dw, dh, srcpres, 0, 0,
                         SRCCOPY );
        }
    }

    _wpi_selectobject( srcpres, oldbitmap );
    _wpi_deleteobject( newbitmap );
    _wpi_deletecompatiblepres( srcpres, srcdc );

    return( TRUE );
}

/*
 * EnlargeImage - takes an mdi window handle and enlarges the view bitmap
 *                that goes with it.  It returns a handle to the bitmap.
 *                The bitmap must be deleted by the calling routine.
 */
HBITMAP EnlargeImage( HWND hwnd )
{
    WPI_PRES    pres;
    WPI_PRES    srcpres;
    WPI_PRES    destpres;
    HDC         srcdc;
    HDC         destdc;
    HBITMAP     oldbitmap;
    HBITMAP     newbitmap;
    HBITMAP     olddestbitmap;
    HBITMAP     viewbitmap;
    img_node    *node;
    WPI_RECT    rc;
    short       width;
    short       height;
    int         window_width;
    int         window_height;
    BITMAP      bm;

    node = SelectImage( hwnd );
    if (!node) return (NULL);

    viewbitmap = CreateViewBitmap( node );
    _wpi_getclientrect( hwnd, &rc );
    /*
     * I add this so that if the window's client rect doesn't fit on the
     * screen, it will still enlarge to the right size.
     */
    window_width = _wpi_getwidthrect( rc );
    window_height = _wpi_getheightrect( rc );
    if( window_width < node->width ) {
        window_width = node->width;
    }
    if( window_height < node->height ) {
        window_height = node->height;
    }

    pres = _wpi_getpres( HWND_DESKTOP );
    srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc );
    destpres = _wpi_createcompatiblepres( pres, Instance, &destdc );
    newbitmap = _wpi_createcompatiblebitmap( pres, _wpi_getwidthrect(rc),
                                                        _wpi_getheightrect(rc));
    _wpi_releasepres( HWND_DESKTOP, pres );
    GetObject( newbitmap, sizeof(BITMAP), &bm );

    _wpi_torgbmode( destpres );
    _wpi_torgbmode( srcpres );
    olddestbitmap = _wpi_selectobject( destpres, newbitmap );
    oldbitmap = _wpi_selectobject( srcpres, viewbitmap );
    height = node->height;
    width = node->width;

    IEStretchBlt( destpres, 0, 0, _wpi_getwidthrect(rc),
            _wpi_getheightrect(rc), srcpres, 0, 0, width, height,
            SRCCOPY, bm.bmBitsPixel );

    _wpi_selectobject( srcpres, oldbitmap );
    _wpi_deletecompatiblepres( srcpres, srcdc );
    _wpi_deleteobject( viewbitmap );

    _wpi_selectobject( destpres, olddestbitmap );
    _wpi_deletecompatiblepres( destpres, destdc );

    return( newbitmap );
} /* EnlargeImage */

/*
 * SetIsSaved - Sets whether the given mdi child has been saved.
 */
void SetIsSaved( HWND hwnd, BOOL fissaved )
{
    img_node    *node;
    img_node    *next_icon;
    char        fname[ _MAX_FNAME ];
    char        dir[ _MAX_DIR ];
    char        ext[ _MAX_EXT ];
    char        drive[ _MAX_DRIVE ];
    char        title[ _MAX_EXT + _MAX_FNAME + 2];
    char        *main_title;

    node = GetImageNode( hwnd );
    if (!node) return;

    // We do not check whether or not the image needs to have its
    // title bars updated here because sometimes we will save images
    // that are not modified to different files.
    #if 0
    if (fissaved == node->issaved) {
        return;
    }
    #endif

    next_icon = node;
    while (next_icon) {
        next_icon->issaved = fissaved;
        next_icon = next_icon->nexticon;
    }

    if( fissaved ) {
        _wpi_getwindowtext( _wpi_getframe(node->hwnd), title, 14 );
        if( ( strnicmp( title, IEImageUntitled, strlen( IEImageUntitled ) ) == 0 ) &&
            ( strnicmp( node->fname, IEImageUntitled, strlen( IEImageUntitled ) ) == 0 ) ) {
            return;
        }
        _splitpath( node->fname, drive, dir, fname, ext );

        strcpy( title, strupr(fname) );
        strcat( title, strupr(ext) );
        _wpi_setwindowtext( _wpi_getframe(node->hwnd), (LPSTR)title );

        main_title = (char *)

⌨️ 快捷键说明

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