wpi_os2.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 2,017 行 · 第 1/5 页

C
2,017
字号
    bih.cbFix = sizeof( BITMAPINFOHEADER );
    GpiQueryBitmapParameters( obj->bitmap, &bih );
    *pwidth = bih.cx;
    *pheight = bih.cy;
} /* _wpi_getbitmapdim */

BOOL _wpi_getclassinfo( WPI_INST inst, PSZ name, WPI_WNDCLASS *info )
/*******************************************************************/
/* Since there is no WNDCLASS structure in OS/2, we made one. But this
   function must then be defined */
{
    CLASSINFO           ci;
    BOOL                ret;

    ret = WinQueryClassInfo( inst.hab, name, &ci );
    if( ret ) {
        info->style = ci.flClassStyle;
        info->lpfnWndProc = ci.pfnWindowProc;
        info->cbWndExtra = ci.cbWindowData;
    }

    return( ret );
}

#ifdef __FLAT__
WPI_TASK _wpi_getcurrenttask( void )
/**********************************************************************/
{
    PTIB                pt;
    PPIB                ppib;

    DosGetInfoBlocks( &pt, &ppib );
    return( pt->tib_ptib2->tib2_ultid );
} /* _wpi_getcurrenttask */
#endif

int _wpi_getdlgitemint( HWND hwnd, int item, BOOL *retcode, BOOL issigned )
/**********************************************************************/
{
    char                buffer[20];
    char                dummy[2];
    int                 result = 0;

    issigned = issigned;                // PM doesn't use this

    *retcode = TRUE;
    if( WinQueryDlgItemText( hwnd, (ULONG)item, 20, buffer ) != 0 ) {
        if( sscanf( buffer, "%d%1s", &result, dummy ) != 1) {
            result = 0;
            *retcode = FALSE;
        }
    } else {
        *retcode = FALSE;
    }

    return( result );
} /* _wpi_getdlgitemint */

void _wpi_getpaintrect( PAINTSTRUCT *ps, WPI_RECT *rect )
/**********************************************************************/
{
    rect->xLeft = ps->xLeft;
    rect->xRight =  ps->xRight;
    rect->yBottom =  ps->yTop;
    rect->yTop =  ps->yBottom;
} /* _wpi_getpaintrect */

WPI_COLOUR _wpi_getpixel( WPI_PRES hps, int x, int y )
/**********************************************************************/
{
    POINTL      pt;

    pt.x = x;
    pt.y = y;
    return( GpiQueryPel(hps, &pt) );
}

WPI_PRES _wpi_getpres( HWND hwnd )
/**********************************************************************/
{
    HDC         wpi_hdc;
    WPI_PRES    pres;

    pres = WinGetPS( hwnd );
    wpi_hdc = GpiQueryDevice( pres );
    GpiAssociate( pres, wpi_hdc );
    return( pres );
} /* _wpi_getpres */

void _wpi_getwindowrect( HWND hwnd, WPI_RECT *rect )
/**********************************************************************/
{
    GetWindowRect( hwnd, rect );
} /* _wpi_getwindowrect */

void _wpi_hitrect( int xc, int yc, int ytop, int ybottom, int xleft,
                                            int xright, int mxp, int myp )
/**********************************************************************/
{
    long               y_fract = 0;
    long               x_fract = 0;

    y_fract = ((long)abs( myp - yc ) << 16) / ( ytop - ybottom );
    x_fract = ((long)abs( mxp - xc ) << 16) / ( xright - xleft );

    if( y_fract >= x_fract ) {
        if( myp > yc ) {
            mxp += ( ytop - yc ) / ( myp - yc ) * ( xc - mxp );
            myp = ytop;
        } else if( myp < yc ) {
            mxp += ( yc - ybottom ) / ( yc - myp ) * ( xc - mxp );
            myp = ybottom;
        }
    } else {
        if( mxp > xc ) {
            myp += ( xright - xc ) / ( mxp - xc ) * ( myp - yc );
            mxp = xright;
        } else if( mxp < xc ) {
            myp += ( xc - xright ) / ( xc - mxp ) * ( myp - yc );
            mxp = xleft;
        }
    }
} /* _wpi_hitrect */

BOOL _wpi_iszoomed( HWND hwnd )
/***********************************************************************/
{
    SWP         swp;

    WinQueryWindowPos( hwnd, &swp );

    if (PM1632SWP_FLAG( swp ) & SWP_MAXIMIZE) {
        return( TRUE );
    } else {
        return( FALSE );
    }
}

BOOL _wpi_isiconic( HWND hwnd )
/***********************************************************************/
{
    SWP         swp;

    WinQueryWindowPos( hwnd, &swp );

    if (PM1632SWP_FLAG( swp ) & SWP_MINIMIZE) {
        return( TRUE );
    } else {
        return( FALSE );
    }
 } /* _wpi_isiconic */

void _wpi_patblt( WPI_PRES dest, int x_pos, int y_pos, int cx, int cy, LONG format )
/***********************************************************************/
/* NOTE: for PM version, y_pos is taken to be the lower left corner,   */
/* not the upper left as it would be for the windows version.          */
{
    HPS         hps;
    POINTL      pts[3];

    hps = WinGetScreenPS( HWND_DESKTOP );
    _wpi_torgbmode( hps );
    pts[0].x = x_pos;
    pts[0].y = y_pos;
    pts[1].x = x_pos + cx;
    pts[1].y = y_pos + cy;
    pts[2].x = 0;
    pts[2].y = 0;

    GpiBitBlt( dest, hps, 3, pts, format, BBO_IGNORE );
    WinReleasePS( hps );
} /* _wpi_patblt */

#ifdef __FLAT__
BOOL _wpi_polygon( WPI_PRES pres, WPI_POINT *pts, int num_pts )
/**********************************************************************/
{
    POLYGON             poly[1];
    BOOL                ret;

    poly[0].aPointl = pts;
    poly[0].ulPoints = num_pts;

    GpiSetCurrentPosition( pres, &pts[0] );
    ret = ( GpiPolygons(pres, 1, poly, POLYGON_BOUNDARY, POLYGON_INCL) ==
                                                                    GPI_OK );
    return( ret );
} /* _wpi_polygon */
#endif

void _wpi_preparemono( WPI_PRES hps, WPI_COLOUR colour, WPI_COLOUR back_colour )
/**********************************************************************/
/* This is necessary for bltting a monochrome bitmap.  The colour     */
/* parameter should be the colour of the 1's on the bitmap (normally  */
/* white).  The back_colour parameter should be the colour of the 0's */
/* on the bitmap (normally black) Also, hps needs to be in RGB mode.  */
{
    IMAGEBUNDLE         imb;

    GpiQueryAttrs( hps, PRIM_IMAGE, IBB_BACK_COLOR | IBB_COLOR, &imb );
    imb.lBackColor = colour;
    imb.lColor = back_colour;
    GpiSetAttrs(hps, PRIM_IMAGE, IBB_COLOR | IBB_BACK_COLOR, 0, &imb);
} /* _wpi_preparemono */

BOOL _wpi_rectangle( WPI_PRES pres, int left, int top, int right, int bottom )
/**********************************************************************/
/* The coordinates are assumed to be in the order of the parameter    */
/* list.  The right and bottom are adjusted to be consisten with Win  */
{
    POINTL              pt;
    BOOL                ret;

    ret = TRUE;

    pt.x = (LONG)left;
    pt.y = (LONG)top;
    if ( !GpiSetCurrentPosition(pres, &pt) ) ret = FALSE;

    pt.x = right - 1;
    pt.y = bottom + 1;
    if ( !GpiBox(pres, DRO_OUTLINEFILL, &pt, 0L, 0L) ) ret = FALSE;

    return( ret );
} /* _wpi_rectangle */

void _wpi_releasepres( HWND hwnd, WPI_PRES pres )
/**********************************************************************/
{
    hwnd = hwnd;
    GpiAssociate( pres, NULLHANDLE );
    WinReleasePS( pres );
} /* _wpi_releasepres */

WPI_HANDLE _wpi_selectbitmap( WPI_PRES pres, WPI_HANDLE bitmap )
/**********************************************************************/
{
    WPI_OBJECT  *obj;
    WPI_OBJECT  *old_obj;

    obj = (WPI_OBJECT *)bitmap;

    if( obj != NULL ) {
        old_obj = _wpi_malloc( sizeof(WPI_OBJECT) );
        old_obj->type = WPI_BITMAP_OBJ;
        old_obj->bitmap = GpiSetBitmap( pres, obj->bitmap );
    }

    return( (WPI_HANDLE)old_obj );
} /* _wpi_selectbitmap */

void _wpi_getoldbitmap( WPI_PRES pres, WPI_HANDLE oldobj )
/********************************************************/
{
    WPI_OBJECT  *oldbitmap;

    oldbitmap = (WPI_OBJECT *)oldobj;

    if( oldbitmap && oldbitmap->type == WPI_BITMAP_OBJ ) {
        GpiSetBitmap( pres, oldbitmap->bitmap );
        _wpi_free( oldbitmap );
    }
} /* _wpi_getoldbitmap */


void _wpi_deletebitmap( WPI_HANDLE bmp )
/**********************************************************************/
{
    WPI_OBJECT  *obj;

    obj = (WPI_OBJECT *)bmp;

    if( obj != NULL ) {
        if( obj->bitmap != (HBITMAP)NULL ) {
            GpiDeleteBitmap( obj->bitmap );
        }
        _wpi_free( obj );
    }
} /* _wpi_deletebitmap */

#ifdef __FLAT__
void _wpi_setmodhandle( char *name, WPI_INST *inst )
/**********************************************************************/
{
    if( DosQueryModuleHandle( name, &(inst->mod_handle) ) != 0 ) {
        inst->mod_handle = NULLHANDLE;
    }
} /* _wpi_setmodhandle */
#endif

WPI_COLOUR _wpi_setpixel( WPI_PRES hps, int x, int y, WPI_COLOUR clr )
/**********************************************************************/
{
    LONG        oldclr;
    WPI_COLOUR  setclr;
    POINTL      pt;

    setclr = GpiQueryNearestColor( hps, 0L, clr );
    oldclr = GpiQueryColor( hps );
    if ( !oldclr ) setclr = -1;
    if ( !GpiSetColor(hps, clr) ) setclr = -1;

    pt.x = (LONG)x;
    pt.y = (LONG)y;
    if ( !GpiSetPel(hps, &pt) ) setclr = -1;
    if ( !GpiSetColor(hps, oldclr) ) setclr = -1;
    return( setclr );
} /* _wpi_setpixel */

void _wpi_setpoint( WPI_POINT *pt, int x, int y )
/**********************************************************************/
{
    pt->x = (LONG)x;
    pt->y = (LONG)y;
} /* _wpi_setpoint */

void _wpi_stretchblt( WPI_PRES dest, int x_dest, int y_dest, int cx_dest,
    int cy_dest, WPI_PRES src, int x_src, int y_src, int cx_src, int cy_src, LONG rop )
/**********************************************************************/
/* NOTE:  the coordinates to this function must be in PM units AND    */
/* in PM convention.                                                  */
{
    POINTL              pts[4];

    pts[0].x = x_dest;
    pts[0].y = y_dest;
    pts[1].x = x_dest + cx_dest;
    pts[1].y = y_dest + cy_dest;
    pts[2].x = x_src;
    pts[2].y = y_src;
    pts[3].x = x_src + cx_src;
    pts[3].y = y_src + cy_src;
    GpiBitBlt(dest, src, 4L, pts, rop, BBO_IGNORE);
} /* _wpi_stretchblt */


BOOL _wpi_ptinrect( WPI_RECT *prect, WPI_POINT pt )
{
    return( ( pt.x >= prect->xLeft ) && ( pt.x < prect->xRight ) &&
            ( pt.y <= prect->yTop ) && ( pt.y > prect->yBottom ) );
}

BOOL _wpi_insertmenu( HMENU hmenu, unsigned pos, unsigned menu_flags,
                      unsigned attr_flags, unsigned id,
                      HMENU popup, char *text, BOOL by_position )
{
    MENUITEM    mi;
    MRESULT     result;
    char        *new_text;
    char        *t;
    HMENU       parent;
    unsigned    pos_in_parent;

    if( hmenu == NULLHANDLE ) {
        return( FALSE );
    }

    if( by_position ) {
        if( pos == -1 ) {
            pos = MIT_END;
        }
        parent = hmenu;
        pos_in_parent = pos;
    } else {
        if( !_wpi_getmenuparentoffset( hmenu, pos, &parent, &pos_in_parent ) ) {
            return( FALSE );
        }
    }

    mi.iPosition   = pos_in_parent;
    mi.afStyle     = menu_flags;
    mi.afAttribute = attr_flags;
    mi.id          = id;
    mi.hwndSubMenu = popup;
    mi.hItem       = NULL;

    new_text = _wpi_menutext2pm( text );

    t = NULL;
    if( new_text && *new_text ) {
        t = new_text;
    }
    result = WinSendMsg( parent, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(t) );

    if( new_text ) {
        _wpi_free( new_text );
    }

    return( ( result != (MRESULT)MIT_MEMERROR ) &&
            ( result != (MRESULT)MIT_ERROR ) );
}

BOOL _wpi_appendmenu( HMENU hmenu, unsigned menu_flags,
                      unsigned attr_flags, unsigned id,
                      HMENU popup, char *text )
{
    return( _wpi_insertmenu( hmenu, -1, menu_flags, attr_flags, id, popup, text, TRUE ) );
}

BOOL _wpi_getmenustate( HMENU hmenu, unsigned id, WPI_MENUSTATE *state,
                        BOOL by_position )
{
    if( !hmenu || !state ) {
        return( FALSE );

⌨️ 快捷键说明

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