/* * paintColors - paint the available colors on the color palette */ static void paintColors( HWND hwnd ) { WPI_PRES pres; WPI_PRES mempres; HDC hdc; PAINTSTRUCT ps; HBITMAP bitmap; HBITMAP oldbitmap; pres = _wpi_beginpaint( hwnd, NULL, &ps ); #ifdef __OS2_PM__ WinFillRect( pres, &ps, CLR_PALEGRAY ); #endif _wpi_torgbmode( pres ); if( numberOfColors == 2 ) { bitmap = hMonoBitmap; } else { bitmap = hColorBitmap; } mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectbitmap( mempres, bitmap ); _wpi_bitblt( pres, 0, 0, CUR_BMP_WIDTH, CUR_BMP_HEIGHT, mempres, 0, 0, SRCCOPY ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); _wpi_endpaint( hwnd, pres, &ps ); } /* paintColors */
/* * redrawViewWnd - process the WM_PAINT message for the view windows */ static void redrawViewWnd( HWND hwnd ) { WPI_PRES pres; WPI_PRES hps; WPI_PRES mempres; HDC memdc; HBITMAP bitmap; HBITMAP oldbitmap; img_node *node; PAINTSTRUCT ps; node = SelectFromViewHwnd( hwnd ); if( node == NULL ) { return; } hps = _wpi_beginpaint( hwnd, NULL, &ps ); drawBorder( node ); pres = _wpi_getpres( hwnd ); bitmap = CreateViewBitmap( node ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); oldbitmap = _wpi_selectbitmap( mempres, bitmap ); _wpi_bitblt( pres, BORDER_WIDTH, BORDER_WIDTH, node->width, node->height, mempres, 0, 0, SRCCOPY ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletebitmap( bitmap ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_releasepres( hwnd, pres ); _wpi_endpaint( hwnd, hps, &ps ); } /* redrawViewWnd */
/* * paintCurrent - paint the current window (process WM_PAINT) */ static void paintCurrent( HWND hwnd ) { WPI_PRES pres; WPI_PRES mempres; HDC hdc; PAINTSTRUCT ps; WPI_RECT rect; HBITMAP oldbitmap; int top; int bottom; pres = _wpi_beginpaint( hwnd, NULL, &ps ); #ifdef __OS2_PM__ WinFillRect( pres, &ps, CLR_PALEGRAY ); #endif mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( pres ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, lButton.bitmap ); _wpi_bitblt( pres, 0, 0, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, mempres, 0, 0, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, rButton.bitmap ); _wpi_bitblt( pres, CUR_RCOL_X - 1, 0, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, mempres, 0, 0, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); _wpi_setbackmode( pres, TRANSPARENT ); _wpi_settextcolor( pres, GetInverseColor( lButton.solid ) ); top = _wpi_cvth_y( CUR_COL_Y, currentHeight ); bottom = _wpi_cvth_y( CUR_COL_Y + CUR_SQR_SIZE, currentHeight ); _wpi_setintwrectvalues( &rect, CUR_LCOL_X, top, CUR_LCOL_X + CUR_SQR_SIZE, bottom ); _wpi_drawtext( pres, "L", 1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER ); _wpi_settextcolor( pres, GetInverseColor( rButton.solid ) ); _wpi_setintwrectvalues( &rect, CUR_RCOL_X, top, CUR_RCOL_X + CUR_SQR_SIZE, bottom ); _wpi_drawtext( pres, "R", 1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER ); _wpi_endpaint( hwnd, pres, &ps ); } /* paintCurrent */
/* * BlowupImage - stretch the view window into the window given by hwnd */ void BlowupImage( HWND hmdiwnd, WPI_PRES pres ) { HDC memdc; WPI_PRES mempres; WPI_RECT client; HBITMAP oldbitmap; HBITMAP newbitmap; HWND hwnd; img_node *node; BOOL new_pres; if( hmdiwnd != NULL ) { hwnd = hmdiwnd; } else { node = GetCurrentNode(); if( node == NULL ) { return; } hwnd = node->hwnd; } newbitmap = EnlargeImage( hwnd ); if( newbitmap == NULL ) { return; } new_pres = FALSE; if( pres == (WPI_PRES)NULL ) { pres = _wpi_getpres( hwnd ); new_pres = TRUE; } mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); oldbitmap = _wpi_selectobject( mempres, newbitmap ); if( ImgedConfigInfo.grid_on ) { showGrid( hwnd, mempres ); } else { GetClientRect( hwnd, &client ); _wpi_bitblt( pres, 0, 0, _wpi_getwidthrect( client ), _wpi_getheightrect( client ), mempres, 0, 0, SRCCOPY ); RedrawPrevClip( hwnd ); // Redraw if there was a clip region specified. } _wpi_selectobject( mempres, oldbitmap ); _wpi_deletebitmap( newbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); if( new_pres ) { _wpi_releasepres( hwnd, pres ); } } /* BlowupImage */
/* * 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 */
/* * CreateViewBitmap - create the bitmap on the screen (with the background * color as it should be, etc.) * - the 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 bkcolor; if( mdi_node != NULL ) { node = mdi_node; } else { node = GetCurrentNode(); if( node == NULL ) { 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 ); bkcolor = GetViewBkColor(); #ifdef __OS2_PM__ _wpi_preparemono( mempres, BLACK, bkcolor ); #endif oldbitmap = _wpi_selectobject( mempres, newbitmap ); brush = _wpi_createsolidbrush( bkcolor ); 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 */
/* * IEStretchBlt */ static 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 0 if( nWidthDest > 32 ) { /* 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 ); } #else /* use the version that rounds up to 32 bits */ linesize = BITS_TO_BYTES( (unsigned long)(nWidthDest * bitcount), 1 ); #endif 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 ); } /* IEStretchBlt */
/* * ChangeImageSize - changes the size of the current image being edited */ void ChangeImageSize( void ) { img_node *node; WPI_DLGPROC dlgproc; WPI_DLGRESULT button_type; img_node new_node; WPI_PRES pres; HDC srcdc; WPI_PRES srcpres; HDC destdc; WPI_PRES destpres; HBITMAP oldsrc; HBITMAP olddest; int retcode; WPI_PARAM2 lparam; WPI_RECT rc; short new_width; short new_height; int y_src; int y_dest; char *title; char *text; node = GetCurrentNode(); if( node == NULL ) { return; } if( node->imgtype != BITMAP_IMG ) { return; } imgHeight = node->height; imgWidth = node->width; dlgproc = _wpi_makedlgprocinstance( ChangeSizeDlgProc, Instance ); button_type = _wpi_dialogbox( HMainWindow, dlgproc, Instance, IMAGESIZE, 0L ); _wpi_freedlgprocinstance( dlgproc ); if( button_type == DLGID_CANCEL ) { return; } if( imgWidth == node->width && imgHeight == node->height ) { PrintHintTextByID( WIE_IMAGESIZEUNCHANGED, NULL ); return; } title = IEAllocRCString( WIE_INFORMATIONTEXT ); text = IEAllocRCString( WIE_RESETUNDOSTACKWARNING ); retcode = _wpi_messagebox( HMainWindow, text, title, MB_YESNO | MB_ICONINFORMATION ); if( text != NULL ) { IEFreeRCString( text ); } if( title != NULL ) { IEFreeRCString( title ); } if( retcode == WPI_IDNO ) { return; } new_node.width = (short)imgWidth; new_node.height = (short)imgHeight; new_node.bitcount = node->bitcount; new_node.imgtype = BITMAP_IMG; MakeBitmap( &new_node, TRUE ); pres = _wpi_getpres( HWND_DESKTOP ); srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc ); destpres = _wpi_createcompatiblepres( pres, Instance, &destdc ); _wpi_releasepres( HWND_DESKTOP, pres ); oldsrc = _wpi_selectbitmap( srcpres, node->hxorbitmap ); olddest = _wpi_selectbitmap( destpres, new_node.hxorbitmap ); if( stretchImage ) { _wpi_stretchblt( destpres, 0, 0, imgWidth, imgHeight, srcpres, 0, 0, node->width, node->height, SRCCOPY ); } else { #ifdef __OS2_PM__ y_src = node->height - imgHeight; if( y_src < 0 ) { y_src = 0; y_dest = imgHeight - node->height; } else { y_dest = 0; } #else y_src = 0; y_dest = 0; #endif _wpi_bitblt( destpres, 0, y_dest, node->width, node->height, srcpres, 0, y_src, SRCCOPY ); } _wpi_getoldbitmap( srcpres, oldsrc ); oldsrc = _wpi_selectbitmap( srcpres, node->handbitmap ); _wpi_getoldbitmap( destpres, olddest ); olddest = _wpi_selectbitmap( destpres, new_node.handbitmap ); if( stretchImage ) { _wpi_stretchblt( destpres, 0, 0, imgWidth, imgHeight, srcpres, 0, 0, node->width, node->height, SRCCOPY ); } else { _wpi_bitblt( destpres, 0, 0, node->width, node->height, srcpres, 0, 0, SRCCOPY ); } _wpi_getoldbitmap( srcpres, oldsrc ); _wpi_getoldbitmap( destpres, olddest ); _wpi_deletebitmap( node->hxorbitmap ); _wpi_deletebitmap( node->handbitmap ); _wpi_deletecompatiblepres( srcpres, srcdc ); _wpi_deletecompatiblepres( destpres, destdc ); node->hxorbitmap = new_node.hxorbitmap; node->handbitmap = new_node.handbitmap; node->width = (short)imgWidth; node->height = (short)imgHeight; SetIsSaved( node->hwnd, FALSE ); ResetUndoStack( node ); RePositionViewWnd( node ); _wpi_getclientrect( node->hwnd, &rc ); new_width = (short)_wpi_getwidthrect( rc ); new_height = (short)_wpi_getheightrect( rc ); lparam = WPI_MAKEP2( new_width, new_height ); ResizeChild( lparam, node->hwnd, false ); DisplayImageText( node ); WriteSetSizeText( WIE_NEWIMAGESIZE, imgWidth, imgHeight ); } /* ChangeImageSize */
/* * simpleRotate - simply rotate the image around the center of the given rectangle */ static void simpleRotate( img_node *node, WPI_RECT *rect, HBITMAP rotxorbmp, HBITMAP rotandbmp, BOOL rectexists ) { WPI_POINT topleft; WPI_POINT centre_pt; WPI_PRES pres; HDC xordc; WPI_PRES xorpres; HDC anddc; WPI_PRES andpres; HDC rotxordc; WPI_PRES rotxorpres; HDC rotanddc; WPI_PRES rotandpres; HBITMAP oldxor; HBITMAP oldand; HBITMAP oldxorrot; HBITMAP oldandrot; short width; short height; WPI_RECT new_rect; IMGED_DIM left; IMGED_DIM top; IMGED_DIM right; IMGED_DIM bottom; width = (short)_wpi_getwidthrect( *rect ); height = (short)_wpi_getheightrect( *rect ); /* * PM NOTE: The rectangle comes in with bottom = yTop and top = yBottom. * To use the same formula to calculate the center point and top left, we * use getwrectvalues. */ _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom ); centre_pt.x = (width / 2) + left; centre_pt.y = (height / 2) + top; topleft.x = centre_pt.x - centre_pt.y + top; topleft.y = centre_pt.y - centre_pt.x + left; pres = _wpi_getpres( HWND_DESKTOP ); xorpres = _wpi_createcompatiblepres( pres, Instance, &xordc ); andpres = _wpi_createcompatiblepres( pres, Instance, &anddc ); rotxorpres = _wpi_createcompatiblepres( pres, Instance, &rotxordc ); rotandpres = _wpi_createcompatiblepres( pres, Instance, &rotanddc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( xorpres ); _wpi_torgbmode( andpres ); _wpi_torgbmode( rotxorpres ); _wpi_torgbmode( rotandpres ); oldxor = _wpi_selectobject( xorpres, node->hxorbitmap ); oldand = _wpi_selectobject( andpres, node->handbitmap ); oldxorrot = _wpi_selectobject( rotxorpres, rotxorbmp ); oldandrot = _wpi_selectobject( rotandpres, rotandbmp ); _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom ); _wpi_patblt( xorpres, left, top, width, height, WHITENESS ); _wpi_patblt( andpres, left, top, width, height, BLACKNESS ); _wpi_bitblt( xorpres, topleft.x, topleft.y, height, width, rotxorpres, 0, 0, SRCCOPY ); _wpi_bitblt( andpres, topleft.x, topleft.y, height, width, rotandpres, 0, 0, SRCCOPY ); _wpi_selectobject( xorpres, oldxor ); _wpi_selectobject( andpres, oldand ); _wpi_selectobject( rotxorpres, oldxorrot ); _wpi_selectobject( rotandpres, oldandrot ); _wpi_deletecompatiblepres( xorpres, xordc ); _wpi_deletecompatiblepres( andpres, anddc ); _wpi_deletecompatiblepres( rotxorpres, rotxordc ); _wpi_deletecompatiblepres( rotandpres, rotanddc ); InvalidateRect( node->viewhwnd, NULL, TRUE ); RecordImage( node->hwnd ); if( DoKeepRect() ) { if( rectexists ) { _wpi_setwrectvalues( &new_rect, topleft.x, topleft.y, topleft.x+height, topleft.y + width ); SetDeviceClipRect( &new_rect ); } } else { rectexists = rectexists; new_rect = new_rect; SetRectExists( FALSE ); } BlowupImage( node->hwnd, NULL ); } /* simpleRotate */
/* * clipIntoArea - clip the bitmaps into the area when rotating */ static void clipIntoArea( img_node *node, WPI_RECT *rect, HBITMAP rotxorbmp, HBITMAP rotandbmp ) { WPI_PRES pres; WPI_PRES xorpres; HDC xordc; WPI_PRES andpres; HDC anddc; WPI_PRES rotxorpres; HDC rotxordc; WPI_PRES rotandpres; HDC rotanddc; HBITMAP oldxor; HBITMAP oldand; HBITMAP oldxorrot; HBITMAP oldandrot; short width; short height; WPI_POINT centre_pt; WPI_POINT topleft; short start_x; short start_y; short new_width; short new_height; IMGED_DIM left; IMGED_DIM right; IMGED_DIM top; IMGED_DIM bottom; width = (short)_wpi_getwidthrect( *rect ); height = (short)_wpi_getheightrect( *rect ); /* * PM NOTE: We use getwrectvalues so that 'topleft' can really be * replace with 'bottomleft' (which is our origin for blitting in PM). * Hence the value of 'top' is really the bottom of our rectangle. */ _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom ); centre_pt.x = (width / 2) + left; centre_pt.y = (height / 2) + top; topleft.x = __max( left, centre_pt.x - centre_pt.y + top ); topleft.y = __max( top, centre_pt.y - centre_pt.x + left ); if( topleft.x == left ) { start_x = (short)(left - (centre_pt.x - centre_pt.y + top)); new_width = width; } else { start_x = 0; new_width = height; } if( topleft.y == top ) { start_y = (short)(top - (centre_pt.y - centre_pt.x + left)); new_height = height; } else { start_y = 0; new_height = width; } pres = _wpi_getpres( HWND_DESKTOP ); xorpres = _wpi_createcompatiblepres( pres, Instance, &xordc ); andpres = _wpi_createcompatiblepres( pres, Instance, &anddc ); rotxorpres = _wpi_createcompatiblepres( pres, Instance, &rotxordc ); rotandpres = _wpi_createcompatiblepres( pres, Instance, &rotanddc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( xorpres ); _wpi_torgbmode( andpres ); _wpi_torgbmode( rotxorpres ); _wpi_torgbmode( rotandpres ); oldxor = _wpi_selectobject( xorpres, node->hxorbitmap ); oldand = _wpi_selectobject( andpres, node->handbitmap ); oldxorrot = _wpi_selectobject( rotxorpres, rotxorbmp ); oldandrot = _wpi_selectobject( rotandpres, rotandbmp ); _wpi_patblt( xorpres, left, top, width, height, WHITENESS ); _wpi_patblt( andpres, left, top, width, height, BLACKNESS ); _wpi_bitblt( xorpres, topleft.x, topleft.y, new_width, new_height, rotxorpres, start_x, start_y, SRCCOPY ); _wpi_bitblt( andpres, topleft.x, topleft.y, new_width, new_height, rotandpres, start_x, start_y, SRCCOPY ); _wpi_selectobject( xorpres, oldxor ); _wpi_selectobject( andpres, oldand ); _wpi_selectobject( rotxorpres, oldxorrot ); _wpi_selectobject( rotandpres, oldandrot ); _wpi_deletecompatiblepres( xorpres, xordc ); _wpi_deletecompatiblepres( andpres, anddc ); _wpi_deletecompatiblepres( rotxorpres, rotxordc ); _wpi_deletecompatiblepres( rotandpres, rotanddc ); InvalidateRect( node->viewhwnd, NULL, TRUE ); RecordImage( node->hwnd ); BlowupImage( node->hwnd, NULL ); } /* clipIntoArea */
void GUIDrawBitmap( int hot_spot, WPI_PRES hdc, int nDrawX, int nDrawY, WPI_COLOUR bkcolour) { WPI_POINT src_org; WPI_POINT dst_org; WPI_POINT size; WPI_PRES memDC; HBITMAP old_bmp; HBITMAP bitmap; HDC new_hdc; #ifdef __NT__ HDC new_hdc2; HBITMAP oldbmp2; HDC mem2; COLORREF cr; #endif bitmap = GUIHotSpots[hot_spot - 1].bitmap; size.x = GUIHotSpots[hot_spot - 1].size.x; size.y = GUIHotSpots[hot_spot - 1].size.y; src_org.x = 0; src_org.y = 0; dst_org.x = nDrawX; dst_org.y = nDrawY; _wpi_dptolp( hdc, &size, 1 ); _wpi_dptolp( hdc, &dst_org, 1 ); _wpi_dptolp( hdc, &src_org, 1 ); memDC = _wpi_createcompatiblepres( hdc, GUIMainHInst, &new_hdc ); old_bmp = _wpi_selectbitmap( memDC, bitmap ); #ifdef __NT__ /* Skip transparency for huge bitmaps, only splashes and such... */ if( size.x < 50 && size.y < 50) { /* New, on WIN32 platforms, use TB_TransparentBlt() */ mem2 = _wpi_createcompatiblepres( hdc, GUIMainHInst, &new_hdc2 ); if( bitmap2 == NULL) bitmap2 = CreateCompatibleBitmap( hdc, 50, 50 ); oldbmp2 = _wpi_selectbitmap( mem2, bitmap2 ); /* Get background color of bitmap */ /* Expects 0,0 pos in original to be in background/transp. color */ cr = GetPixel(memDC, 0, 0); /* IMPORTANT: must set required new background color for dest bmp */ // SetBkColor( mem2, GetSysColor(COLOR_BTNFACE) ); SetBkColor( mem2, bkcolour ); TB_TransparentBlt( mem2, src_org.x, src_org.y, size.x, size.y, memDC, cr ); _wpi_bitblt( hdc, dst_org.x, dst_org.y, size.x, size.y, mem2, src_org.x, src_org.y, SRCCOPY ); /* Clean up */ _wpi_selectbitmap( mem2, oldbmp2 ); _wpi_deletecompatiblepres( mem2, hdc ); } else { // Normal for large bitmaps... _wpi_bitblt( hdc, dst_org.x, dst_org.y, size.x, size.y, memDC, src_org.x, src_org.y, SRCCOPY ); } #else _wpi_bitblt( hdc, dst_org.x, dst_org.y, size.x, size.y, memDC, src_org.x, src_org.y, SRCCOPY ); #endif if( old_bmp != NULLHANDLE ) { _wpi_getoldbitmap( memDC, old_bmp ); } _wpi_deletecompatiblepres( memDC, new_hdc ); }
/* * copyImageToClipboard - copies the image to the clipboard */ static void copyImageToClipboard( short width, short height, img_node *node ) { HMENU hmenu; WPI_PRES pres; WPI_PRES mempres; HDC memdc; WPI_PRES clippres; HDC clipdc; HBITMAP hbitmap; HBITMAP oldbitmap; HBITMAP oldclipbitmap; HBITMAP viewbitmap; WPI_RECTDIM left; WPI_RECTDIM top; WPI_RECTDIM right; WPI_RECTDIM bottom; int clip_width, clip_height; CleanupClipboard(); pres = _wpi_getpres( node->viewhwnd ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); clippres = _wpi_createcompatiblepres( pres, Instance, &clipdc ); hbitmap = _wpi_createcompatiblebitmap( pres, width, height ); viewbitmap = CreateViewBitmap( node ); oldbitmap = _wpi_selectbitmap( mempres, viewbitmap ); oldclipbitmap = _wpi_selectbitmap( clippres, hbitmap ); clip_width = _wpi_getwidthrect( clipRect.rect ); clip_height = _wpi_getheightrect( clipRect.rect ); /* * use getwrectvalues because we want top and left to be our origins * (i.e. in PM the origin is the bottom) */ _wpi_getwrectvalues( clipRect.rect, &left, &top, &right, &bottom ); _wpi_bitblt( clippres, 0, 0, width, height, mempres, left, top, SRCCOPY ); _wpi_openclipboard( Instance, HMainWindow ); _wpi_emptyclipboard( Instance ); _wpi_setclipboarddata( Instance, CF_BITMAP, hbitmap, TRUE ); _wpi_closeclipboard( Instance ); _wpi_getoldbitmap( clippres, oldclipbitmap ); _wpi_deletecompatiblepres( clippres, clipdc ); clippres = _wpi_createcompatiblepres( pres, Instance, &clipdc ); hXorClipped = _wpi_createcompatiblebitmap( pres, width, height ); _wpi_getoldbitmap( mempres, oldbitmap ); oldbitmap = _wpi_selectbitmap( mempres, node->hxorbitmap ); oldclipbitmap = _wpi_selectbitmap( clippres, hXorClipped ); _wpi_bitblt( clippres, 0, 0, width, height, mempres, left, top, SRCCOPY ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_getoldbitmap( clippres, oldclipbitmap ); hAndClipped = _wpi_createcompatiblebitmap( pres, width, height ); oldbitmap = _wpi_selectbitmap( mempres, node->handbitmap ); oldclipbitmap = _wpi_selectbitmap( clippres, hAndClipped ); _wpi_bitblt( clippres, 0, 0, width, height, mempres, left, top, SRCCOPY ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_getoldbitmap( clippres, oldclipbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_deletecompatiblepres( clippres, clipdc ); _wpi_deletebitmap( viewbitmap ); _wpi_releasepres( node->viewhwnd, pres ); hmenu = GetMenu( _wpi_getframe( HMainWindow ) ); _wpi_enablemenuitem( hmenu, IMGED_PASTE, TRUE, FALSE ); } /* copyImageToClipboard */
/* * PasteImage - paste the image in the clipboard at the current point * - first check to see if the image was cut/copied from our program * - if it was, then we use the hXorClipped and hAndClipped bitmaps * we created in order to preserve the screen colors if ther were used * - otherwise, just copy from the clipboard */ void PasteImage( WPI_POINT *pt, WPI_POINT pointsize, HWND hwnd ) { HBITMAP hbitmap; HBITMAP hbitmapdup; HBITMAP holddup; HBITMAP oldbitmap; HBITMAP oldbitmap2; WPI_PRES pres; WPI_PRES mempres; HDC memdc; WPI_PRES clippres; HDC clipdc; WPI_RECT client; WPI_POINT truept; short width; short height; short clipwidth; short clipheight; img_node *node; int fstretchbmp; int bm_width, bm_height; WPI_RECTDIM left; WPI_RECTDIM right; WPI_RECTDIM top; WPI_RECTDIM bottom; WPI_RECTDIM client_l; WPI_RECTDIM client_r; WPI_RECTDIM client_t; WPI_RECTDIM client_b; #ifdef __OS2_PM__ int src_y, dest_y; #endif if( fEnableCutCopy ) { _wpi_getwrectvalues( clipRect.rect, &left, &top, &right, &bottom ); truept.x = left; truept.y = top; fstretchbmp = StretchPastedImage(); } else { truept.x = pt->x / pointsize.x; truept.y = pt->y / pointsize.y; fstretchbmp = -1; } node = SelectImage( hwnd ); pres = _wpi_getpres( node->viewhwnd ); if( _wpi_getclipboardowner( Instance ) == HMainWindow && node->imgtype != BITMAP_IMG ) { _wpi_getbitmapdim( hAndClipped, &bm_width, &bm_height ); GetClientRect( node->hwnd, &client ); if( fEnableCutCopy ) { width = (short)_wpi_getwidthrect( clipRect.rect ); height = (short)_wpi_getheightrect( clipRect.rect ); } else { _wpi_getrectvalues( client, &client_l, &client_t, &client_r, &client_b ); width = (short)( client_r / pointsize.x - truept.x ); if( width > (short)bm_width ) width = (short)bm_width; height = (short)( client_b / pointsize.y - truept.y ); if( height > (short)bm_height ) { height = (short)bm_height; } } mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_setstretchbltmode( mempres, COLORONCOLOR ); clippres = _wpi_createcompatiblepres( pres, Instance, &clipdc ); oldbitmap = _wpi_selectbitmap( mempres, node->handbitmap ); oldbitmap2 = _wpi_selectbitmap( clippres, hAndClipped ); if( fstretchbmp == FALSE ) { clipwidth = (short)bm_width; if( clipwidth > (short)width ) clipwidth = (short)width; clipheight = (short)bm_height; if( clipheight > (short)height ) clipheight = (short)height; _wpi_patblt( mempres, truept.x, truept.y, width, height, BLACKNESS ); _wpi_bitblt( mempres, truept.x, truept.y, clipwidth, clipheight, clippres, 0, 0, SRCCOPY ); } else if( fstretchbmp == TRUE ) { _wpi_stretchblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, bm_width, bm_height, SRCCOPY); } else { _wpi_bitblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, SRCCOPY ); } _wpi_getoldbitmap( mempres, oldbitmap ); oldbitmap = _wpi_selectbitmap( mempres, node->hxorbitmap ); hbitmapdup = DuplicateBitmap( hXorClipped ); _wpi_getoldbitmap( clippres, oldbitmap2 ); oldbitmap2 = _wpi_selectbitmap( clippres, hbitmapdup ); if( fstretchbmp == FALSE ) { clipwidth = (short)bm_width; if( clipwidth > (short)width ) clipwidth = (short)width; clipheight = (short)bm_height; if( clipheight > (short)height ) clipheight = (short)height; _wpi_patblt( mempres, truept.x, truept.y, width, height, WHITENESS ); #ifdef __OS2_PM__ if( bm_height > height ) { src_y = bm_height - height; dest_y = truept.y; } else { src_y = 0; dest_y = truept.y + (height - bm_height); } _wpi_bitblt( mempres, truept.x, dest_y, clipwidth, clipheight, clippres, 0, src_y, SRCCOPY ); #else _wpi_bitblt( mempres, truept.x, truept.y, clipwidth, clipheight, clippres, 0, 0, SRCCOPY ); #endif } else if( fstretchbmp == TRUE ) { _wpi_stretchblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, bm_width, bm_height, SRCCOPY ); } else { _wpi_bitblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, SRCCOPY ); } _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_getoldbitmap( clippres, oldbitmap2 ); _wpi_deletebitmap( hbitmapdup ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_deletecompatiblepres( clippres, clipdc ); } else { if( node->imgtype != BITMAP_IMG ) { CleanupClipboard(); } _wpi_openclipboard( Instance, HMainWindow ); hbitmap = _wpi_getclipboarddata( Instance, CF_BITMAP ); hbitmapdup = DuplicateBitmap( hbitmap ); _wpi_closeclipboard( Instance ); _wpi_getbitmapdim( hbitmapdup, &bm_width, &bm_height ); GetClientRect( node->hwnd, &client ); if( fEnableCutCopy ) { width = (short)_wpi_getwidthrect( clipRect.rect ); height = (short)_wpi_getheightrect( clipRect.rect ); } else { _wpi_getrectvalues( client, &client_l, &client_t, &client_r, &client_b ); width = (short)( client_r / pointsize.x - truept.x ); if( width > (short)bm_width ) width = (short)bm_width; height = (short)( client_b / pointsize.y - truept.y ); if( height > (short)bm_height ) { height = (short)bm_height; } } clippres = _wpi_createcompatiblepres( pres, Instance, &clipdc ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_setstretchbltmode( mempres, COLORONCOLOR ); holddup = _wpi_selectbitmap( clippres, hbitmapdup ); oldbitmap = _wpi_selectbitmap( mempres, node->hxorbitmap ); if( fstretchbmp == FALSE ) { clipwidth = (short)bm_width; if( clipwidth > (short)width ) clipwidth = (short)width; clipheight = (short)bm_height; if( clipheight > (short)height ) clipheight = (short)height; _wpi_patblt( mempres, truept.x, truept.y, width, height, WHITENESS ); #ifdef __OS2_PM__ if( bm_height > height ) { src_y = bm_height - height; dest_y = truept.y; } else { src_y = 0; dest_y = truept.y + (height - bm_height); } _wpi_bitblt( mempres, truept.x, dest_y, clipwidth, clipheight, clippres, 0, src_y, SRCCOPY ); #else _wpi_bitblt( mempres, truept.x, truept.y, clipwidth, clipheight, clippres, 0, 0, SRCCOPY ); #endif } else if( fstretchbmp == TRUE ) { _wpi_stretchblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, bm_width, bm_height, SRCCOPY ); } else { _wpi_bitblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, SRCCOPY ); } _wpi_getoldbitmap( clippres, holddup ); _wpi_deletebitmap( hbitmapdup ); _wpi_deletecompatiblepres( clippres, clipdc ); _wpi_getoldbitmap( mempres, oldbitmap ); oldbitmap = _wpi_selectbitmap( mempres, node->handbitmap ); _wpi_patblt( mempres, truept.x, truept.y, width, height, BLACKNESS ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); } ReleaseCapture(); _wpi_releasepres( node->viewhwnd, pres ); InvalidateRect( node->viewhwnd, NULL, TRUE ); if( !fEnableCutCopy ) { _wpi_setcursor( prevCursor ); _wpi_destroycursor( pointCursor ); SetToolType( prevToolType ); } fEnableCutCopy = FALSE; RecordImage( hwnd ); BlowupImage( NULL, NULL ); PrintHintTextByID( WIE_BITMAPPASTED, NULL ); } /* PasteImage */
WPI_MRESULT CALLBACK GraphWndProc( HWND Wnd, WPI_MSG message, WPI_PARAM1 wParam, WPI_PARAM2 lParam ) //============================================================= { WPI_PRES Win_dc; PAINTSTRUCT ps; int width, height; int x, y, t; int h_minpos, h_maxpos, h_currpos; int v_minpos, v_maxpos, v_currpos; WPI_RECTDIM left, top, right, bottom; WPI_RECT rect; struct ScrollStruct scroll_info; LPWDATA w; HWND frame; #if defined( __OS2__ ) int wheight; WPI_RECT wrect; #endif w = _GetWindowData( Wnd ); if( w == NULL ) { return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); } #if defined( __OS2__ ) frame = w->frame; #else frame = Wnd; #endif switch( message ) { #if defined( __WINDOWS__ ) case WM_SETFOCUS: SetFocus( _MainWindow ); case WM_SYSCOMMAND: case WM_MOUSEACTIVATE: _MakeWindowActive( w ); return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); case WM_KILLFOCUS: if( ( wParam != NULL) && ( wParam != _MainWindow ) ) { _ShowWindowActive( NULL, w ); } return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); #else case WM_FOCUSCHANGE: case WM_SYSCOMMAND: _MakeWindowActive( w ); return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); #endif case WM_PAINT: // Setup Win_dc = _wpi_beginpaint( Wnd, NULLHANDLE, &ps ); _wpi_torgbmode( Win_dc ); _wpi_getpaintrect( &ps, &rect ); _wpi_getwrectvalues( rect, &left, &top, &right, &bottom ); width = _wpi_getwidthrect( rect ); height = _wpi_getheightrect( rect ); // Copy from the memory dc to the screen #if defined( __OS2__ ) GetClientRect( Wnd, &wrect ); wheight = _wpi_getheightrect( wrect ); y = _GetPresHeight() - wheight - _BitBlt_Coord.ycoord + top; #else y = _BitBlt_Coord.ycoord + top; #endif _wpi_bitblt( Win_dc, left, top, width, height, _Mem_dc, _BitBlt_Coord.xcoord + left, y, SRCCOPY ); //Cleanup _wpi_endpaint( Wnd, Win_dc, &ps ); break; #if defined( __OS2__ ) case WM_CLOSE: WinDestroyWindow( w->frame ); return( 0 ); #endif case WM_DESTROY: // free the system resources allocated if( _Mem_dc ){ _wpi_deletecliprgn( _Mem_dc, _ClipRgn ); _wpi_deletecompatiblepres( _Mem_dc, _Hdc ); if( _Mem_bmp ){ _wpi_deletebitmap( _Mem_bmp ); if( !_IsStockFont() ){ _wpi_f_deletefont( _CurFnt ); } } #if defined( __OS2__ ) WinSendMsg( _GetWinMenuHandle(), ( ULONG )MM_DELETEITEM, MPFROM2SHORT( ( w->handles[0] + DID_WIND_STDIO ), FALSE ), 0 ); #endif _DestroyAWindow( w ); } break; case WM_VSCROLL: scroll_info = getscrolldata( frame, SB_VERT ); CalPos( &scroll_info, wParam, lParam, &v_currpos, &y ); // Make sure we have to refresh first if( _BitBlt_Coord.ycoord != y ) { _BitBlt_Coord.ycoord = y; _wpi_setscrollpos( frame, SB_VERT, v_currpos, TRUE ); _wpi_invalidaterect( Wnd, NULL, 0 ); _wpi_updatewindow( Wnd ); } return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); case WM_HSCROLL: scroll_info = getscrolldata( frame, SB_HORZ ); CalPos( &scroll_info, wParam, lParam, &h_currpos, &x ); // make sure we need to refresh first if( _BitBlt_Coord.xcoord != x ) { _BitBlt_Coord.xcoord = x; _wpi_setscrollpos( frame, SB_HORZ, h_currpos, TRUE ); _wpi_invalidaterect( Wnd, NULL, 0 ); _wpi_updatewindow( Wnd ); } return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); case WM_SIZE: x = _wpi_getsystemmetrics( SM_CXSCREEN ); y = _wpi_getsystemmetrics( SM_CYSCREEN ); _wpi_getscrollrange( frame, SB_VERT, &v_minpos, &v_maxpos ); _wpi_getscrollrange( frame, SB_HORZ, &h_minpos, &h_maxpos ); _wpi_getclientrect( Wnd, &rect ); _wpi_getrectvalues( rect, &left, &top, &right, &bottom ); height = bottom - top + 1; width = right - left + 1; if( width >= x ) { // hide the scroll bar #if defined( __OS2__ ) WinShowWindow( WinWindowFromID( frame, FID_HORZSCROLL ), FALSE ); #else ShowScrollBar( Wnd, SB_HORZ, FALSE ); #endif _BitBlt_Coord.xcoord = 0; h_currpos = 0; } else { // if the window isn't as big as the device context // show the scroll bar t = x - width + 1; if( x - _BitBlt_Coord.xcoord + 1 < width ) { _BitBlt_Coord.xcoord = x - width + 1; } if( _BitBlt_Coord.xcoord == t ) { h_currpos = h_maxpos; } else { h_currpos = CalScrollAmt( h_maxpos, h_minpos, _BitBlt_Coord.xcoord, x, width ); } #if defined( __OS2__ ) WinShowWindow( WinWindowFromID( frame, FID_HORZSCROLL ), TRUE ); #else ShowScrollBar( Wnd, SB_HORZ, 1 ); #endif } if( height >= y ) { // hide the scroll bar #if defined( __OS2__ ) WinShowWindow( WinWindowFromID( frame, FID_VERTSCROLL ), FALSE ); #else ShowScrollBar( Wnd, SB_VERT, 0 ); #endif _BitBlt_Coord.ycoord = 0; v_currpos = 0; } else { // if the the window isn't as big as the device context // then show the scroll bar t = y - height + 1; if( y - _BitBlt_Coord.ycoord + 1 < height ) { _BitBlt_Coord.ycoord = t; } if( _BitBlt_Coord.ycoord == t ) { v_currpos = v_maxpos; } else { v_currpos = CalScrollAmt( v_maxpos, v_minpos, _BitBlt_Coord.ycoord, y, height ); } #if defined( __OS2__ ) WinShowWindow( WinWindowFromID( frame, FID_VERTSCROLL ), TRUE ); #else ShowScrollBar( Wnd, SB_VERT, 1 ); #endif } // Adjust the scroll bar thumbs' positions _wpi_setscrollpos( frame, SB_HORZ, h_currpos, TRUE ); _wpi_setscrollpos( frame, SB_VERT, v_currpos, TRUE ); #if defined( __OS2__ ) Win_dc = WinBeginPaint( Wnd, NULL, &rect ); WinFillRect( Win_dc, &rect, CLR_BLACK ); WinEndPaint( Win_dc ); #endif _wpi_invalidaterect( Wnd, NULL, 0 ); break; default: return( _wpi_defwindowproc( Wnd, message, wParam, lParam ) ); } return( NULL ); }
/* * showGrid - Display the grid on the draw area. */ static void showGrid( HWND hwnd, WPI_PRES mempres ) { short i; short psx; short psy; WPI_RECT rcclient; HPEN hblackpen; HPEN holdpen; img_node *node; short width; short height; IMGED_DIM left; IMGED_DIM right; IMGED_DIM top; IMGED_DIM bottom; WPI_PRES pres; WPI_POINT startpt; WPI_POINT endpt; node = SelectImage( hwnd ); _wpi_torgbmode( mempres ); GetClientRect( hwnd, &rcclient ); width = (short)( _wpi_getwidthrect(rcclient) ); height = (short)( _wpi_getheightrect(rcclient) ); if (((width / node->width) < POINTSIZE_MIN) || ((height / node->height) < POINTSIZE_MIN)) { psx = 0; psy = 0; } else { psx = width / node->width; psy = height / node->height; hblackpen = _wpi_createpen( PS_SOLID, 0, BLACK ); holdpen = _wpi_selectobject( mempres, hblackpen ); _wpi_getrectvalues( rcclient, &left, &top, &right, &bottom ); for (i=0; i < width; i = i + psx) { _wpi_setpoint( &startpt, i, top ); _wpi_setpoint( &endpt, i, bottom ); _wpi_movetoex( mempres, &startpt, NULL ); _wpi_lineto( mempres, &endpt ); } for (i=0; i <= height; i = i + psy) { _wpi_setpoint( &startpt, left, i ); _wpi_setpoint( &endpt, right, i ); _wpi_movetoex( mempres, &startpt, NULL ); _wpi_lineto( mempres, &endpt ); } _wpi_selectobject( mempres, holdpen ); _wpi_deleteobject( hblackpen ); } pres = _wpi_getpres( hwnd ); _wpi_bitblt( pres, 0, 0, width, height, mempres, 0, 0, SRCCOPY ); _wpi_releasepres( hwnd, pres ); RedrawPrevClip(hwnd); // Redraws if there was a clip region specified. } /* showGrid */
void GUIPaint( gui_window *wnd, HWND hwnd, bool isdlg ) { HDC prev_hdc; PAINTSTRUCT *prev_ps; gui_row_num row_num; PAINTSTRUCT ps; WPI_RECT fill_area; #ifdef __OS2_PM__ ULONG flags; RECTL client; #endif isdlg=isdlg; /* save old state */ prev_hdc = wnd->hdc; prev_ps = wnd->ps; /* Setup Paint */ wnd->ps = &ps; wnd->hdc = _wpi_beginpaint( hwnd, NULLHANDLE, wnd->ps ); _wpi_torgbmode( wnd->hdc ); _wpi_getpaintrect( wnd->ps, &fill_area ); #ifdef __OS2_PM__ fill_area = *(wnd->ps); if( isdlg ) { _wpi_inflaterect( GUIMainHInst, &fill_area, 10, 10); } WinFillRect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ) ); #endif #if defined( __NT__ ) if( isdlg ) { _wpi_fillrect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ), wnd->bk_brush ); } #endif if( wnd->font != NULL ) { wnd->prev_font = _wpi_selectfont( wnd->hdc, wnd->font ); } else { wnd->prev_font = NULL; } /* send paint to app */ GUIGetUpdateRows( wnd, hwnd, &row_num.start, &row_num.num ); if( row_num.num > 0 ) { GUIEVENTWND( wnd, GUI_PAINT, &row_num ); } /* finish painting */ if( wnd->prev_font != NULL ) { _wpi_getoldfont( wnd->hdc, wnd->prev_font ); wnd->prev_font = NULL; } #ifdef __OS2_PM__ if( isdlg ) { flags = DB_AREAATTRS | DB_DLGBORDER; #ifdef _M_I86 if( WinQueryActiveWindow( HWND_DESKTOP, FALSE ) != hwnd ) { #else if( WinQueryActiveWindow( HWND_DESKTOP ) != hwnd ) { #endif //if( _wpi_getfocus() != hwnd ) { flags |= DB_PATINVERT; } WinQueryWindowRect( hwnd, &client ); WinDrawBorder( wnd->hdc, &client, 1, 1, 0, 0, flags ); } #endif _wpi_endpaint( hwnd, wnd->hdc, wnd->ps ); /* restore old state */ wnd->hdc = prev_hdc; wnd->ps = prev_ps; } #else // this is some experimental PM stuff void GUIPaint( gui_window *wnd, HWND hwnd, bool isdlg ) { HDC prev_hdc; PAINTSTRUCT *prev_ps; gui_row_num row_num; PAINTSTRUCT ps; PAINTSTRUCT fill_area; // experimenal stuff HPS hps; RECTL client; LONG width, height; ULONG flags; int compat_created; gui_paint_info *pinfo; // figure out which paint info to use if( !isdlg && wnd->root == hwnd ) { pinfo = &wnd->root_pinfo; } else { pinfo = &wnd->hwnd_pinfo; } pinfo->in_use++; compat_created = FALSE; /* save old state */ prev_hdc = wnd->hdc; prev_ps = wnd->ps; if( isdlg ) { _wpi_getclientrect( hwnd, &client ); } else { WinQueryWindowRect( hwnd, &client ); } width = client.xRight - client.xLeft; height = client.yTop - client.yBottom; wnd->ps = &ps; //hps = _wpi_beginpaint( hwnd, pinfo->normal_pres, wnd->ps ); hps = _wpi_beginpaint( hwnd, NULL, wnd->ps ); if( pinfo->compatible_pres == (WPI_PRES)NULL ) { compat_created = TRUE; pinfo->compatible_pres = _wpi_createcompatiblepres( hps, GUIMainHInst, &pinfo->compatible_hdc ); pinfo->draw_bmp = _wpi_createcompatiblebitmap( hps, width, height ); pinfo->old_bmp = _wpi_selectbitmap( pinfo->compatible_pres, pinfo->draw_bmp ); } // the condition is here VERY conservative!! // its gains have to analyzed if( compat_created || pinfo->force_count ) { wnd->hdc = pinfo->compatible_pres; //wnd->hdc = hps; _wpi_torgbmode( wnd->hdc ); fill_area = *(wnd->ps); if( isdlg ) { _wpi_inflaterect( GUIMainHInst, &fill_area, 10, 10); } WinFillRect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ) ); wnd->prev_font = NULL; if( wnd->font != NULL ) { wnd->prev_font = _wpi_selectfont( wnd->hdc, wnd->font ); } /* send paint to app */ GUIGetUpdateRows( wnd, hwnd, &row_num.start, &row_num.num ); if( row_num.num > 0 ) { GUIEVENTWND( wnd, GUI_PAINT, &row_num ); } /* finish painting */ if( wnd->prev_font != NULL ) { _wpi_getoldfont( wnd->hdc, wnd->prev_font ); wnd->prev_font = NULL; } if( pinfo->force_count ) { //pinfo->force_count--; } } //_wpi_bitblt( hps, client.xLeft, client.yBottom, width, height, // wnd->hdc, 0, 0, SRCCOPY ); if( pinfo->in_use == 1 ) { //_wpi_bitblt( hps, client.xLeft, client.yBottom, width, height, // wnd->hdc, 0, 0, SRCCOPY ); _wpi_bitblt( hps, ps.xLeft, ps.yBottom, ps.xRight - ps.xLeft, ps.yTop - ps.yBottom, wnd->hdc, ps.xLeft, ps.yBottom, SRCCOPY ); if( pinfo->delete_when_done ) { GUIFreePaintHandles( pinfo, TRUE ); } } if( isdlg ) { flags = DB_AREAATTRS | DB_DLGBORDER; #ifdef _M_I86 if( WinQueryActiveWindow( HWND_DESKTOP, FALSE ) != hwnd ) { #else if( WinQueryActiveWindow( HWND_DESKTOP ) != hwnd ) { #endif //if( _wpi_getfocus() != hwnd ) { flags |= DB_PATINVERT; } WinQueryWindowRect( hwnd, &client ); WinDrawBorder( hps, &client, 1, 1, 0, 0, flags ); } _wpi_endpaint( hwnd, hps, wnd->ps ); /* restore old state */ wnd->hdc = prev_hdc; wnd->ps = prev_ps; if( pinfo->in_use ) { pinfo->in_use--; } } #endif void GUIInvalidatePaintHandles( gui_window *wnd ) { GUIFreeWndPaintHandles( wnd, FALSE ); }
/* * FlipImage - flip the image along either the x-axis or the y-axis */ void FlipImage( WORD whichway ) { img_node *node; short width; short height; short destwidth; short destheight; short new_left; short new_top; WPI_RECT dims; HBITMAP xorflip; HBITMAP oldflip; HBITMAP oldbitmap; HBITMAP andflip; WPI_PRES pres; WPI_PRES mempres; HDC memdc; WPI_PRES flippres; HDC flipdc; HCURSOR prevcursor; IMGED_DIM bottom; IMGED_DIM left; IMGED_DIM right; IMGED_DIM top; node = GetCurrentNode(); if( node == NULL ) { return; } PrintHintTextByID( WIE_FLIPPINGIMAGE, NULL ); prevcursor = _wpi_setcursor( _wpi_getsyscursor( IDC_WAIT ) ); if( !DoesRectExist( &dims ) ) { _wpi_setwrectvalues( &dims, 0, 0, (IMGED_DIM)node->width, (IMGED_DIM)node->height ); } width = (short)_wpi_getwidthrect( dims ); height = (short)_wpi_getheightrect( dims ); pres = _wpi_getpres( HWND_DESKTOP ); if( node->bitcount == 1 ) { xorflip = _wpi_createbitmap( width, height, 1, 1, NULL ); } else { #if 1 xorflip = _wpi_createcompatiblebitmap( pres, width, height ); #else xorflip = _wpi_createbitmap( width, height, ColorPlanes, BitsPerPixel, NULL ); #endif } andflip = _wpi_createbitmap( width, height, 1, 1, NULL ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); flippres = _wpi_createcompatiblepres( pres, Instance, &flipdc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_getrectvalues( dims, &left, &top, &right, &bottom ); _wpi_preparemono( flippres, BLACK, WHITE ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); oldflip = _wpi_selectobject( flippres, xorflip ); _wpi_bitblt( flippres, 0, 0, width, height, mempres, left, top, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( flippres, oldflip ); oldbitmap = _wpi_selectobject( mempres, node->handbitmap ); oldflip = _wpi_selectobject( flippres, andflip ); _wpi_bitblt( flippres, 0, 0, width, height, mempres, left, top, SRCCOPY ); if( whichway == IMGED_FLIPVERT ) { destwidth = -1 * width; new_left = right - 1; new_top = top; destheight = height; } else { destwidth = width; new_left = left; new_top = bottom - 1; destheight = -1 * height; } _wpi_stretchblt( mempres, new_left, new_top, destwidth, destheight, flippres, 0, 0, width, height, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); _wpi_selectobject( flippres, oldflip ); oldflip = _wpi_selectobject( flippres, xorflip ); _wpi_stretchblt( mempres, new_left, new_top, destwidth, destheight, flippres, 0, 0, width, height, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( flippres, oldflip ); _wpi_deleteobject( xorflip ); _wpi_deleteobject( andflip ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_deletecompatiblepres( flippres, flipdc ); InvalidateRect( node->viewhwnd, NULL, TRUE ); if( !DoKeepRect() ) { SetRectExists( FALSE ); } RecordImage( node->hwnd ); BlowupImage( node->hwnd, NULL ); if( whichway == IMGED_FLIPHORZ ) { PrintHintTextByID( WIE_IMAGEREFLECTEDH, NULL ); } else { PrintHintTextByID( WIE_IMAGEREFLECTEDV, NULL ); } _wpi_setcursor( prevcursor ); } /* FlipImage */
void _L1GetPic( short x1, short y1, short x2, short y2, /*===============================*/ struct picture _WCI86HUGE *image ) /* Copy that portion of the screen inside the viewport to the buffer pointed by 'image'. */ { short dx; /* width of rectangle in pixels */ short dy; /* height of rectangle in pixels */ short t; #if defined( _DEFAULT_WINDOWS ) WPI_PRES dc; short srcy; #else short line_len; /* length of each line in bytes */ #if !defined( __386__ ) unsigned short new_off; #endif char *tmp; gr_device _FARD *dev_ptr; /* pointer to _CurrState->deviceptr */ char _WCI86HUGE *pic; /* buffer to store image */ copy_fn *copy; /* pointer to copy routine */ setup_fn *setup; #endif if( x1 > x2 ) { // ensure x1 < x2 t = x1; x1 = x2; x2 = t; } if( y1 > y2 ) { // ensure y1 < y2 t = y1; y1 = y2; y2 = t; } if( _L0BlockClip( &x1, &y1, &x2, &y2 ) != 0 ) { /* clip image to */ image->picwidth = 0; /* active viewport */ image->picheight = 0; _ErrorStatus = _GRNOOUTPUT; return; } dx = x2 - x1 + 1; /* row width in pixels */ dy = y2 - y1 + 1; /* height in pixel rows */ image->picwidth = dx; /* save width in image picture */ image->picheight = dy; /* save height in image picture */ #if defined( _DEFAULT_WINDOWS ) dc = _Mem_dc; // Create a memory DC to put the image in image->buffer = _wpi_createcompatiblepres( dc, _GetInst(), &( image->pdc ) ); image->bmp = _wpi_createcompatiblebitmap( dc, dx, dy ); if( ( image->buffer == NULL ) || ( image->bmp == NULL ) ) { _ErrorStatus = _GRINSUFFICIENTMEMORY; return; } _wpi_selectbitmap( image->buffer, image->bmp ); // Transfer the image to a memory DC #if defined( __OS2__ ) srcy = _wpi_cvth_y( y2, _GetPresHeight() ); #else srcy = y1; #endif _wpi_bitblt( image->buffer, 0, 0, dx, dy, dc, x1, srcy, SRCCOPY ); #else image->bpp = _CurrState->vc.bitsperpixel; /* save bpp - never used ? */ line_len = _RowLen( dx ); /* width of row in bytes */ _StartDevice(); dev_ptr = _CurrState->deviceptr; copy = dev_ptr->readrow; pic = &image->buffer; tmp = NULL; setup = dev_ptr->setup; for( ; y1 <= y2; ++y1 ) { /* copy screen image to buffer */ ( *setup )( x1, y1, 0 ); #if !defined( __386__ ) // check whether the entire row will fit in the buffer new_off = FP_OFF( pic ) + line_len - 1; if( new_off < FP_OFF( pic ) ) { if( tmp == NULL ) { // may have been already allocated if( _stackavail() - line_len > 0x100 ) { tmp = __alloca( _RoundUp( line_len ) ); } } if( tmp != NULL ) { ( *copy )( tmp, _Screen.mem, dx, _Screen.bit_pos, 0 ); for( t = 0; t < line_len; ++t ) { *pic = tmp[ t ]; ++pic; // the PIA function will handle this properly } } else { _ErrorStatus = _GRINSUFFICIENTMEMORY; pic += line_len; } } else { #endif ( *copy )( pic, _Screen.mem, dx, _Screen.bit_pos, 0 ); pic += line_len; #if !defined( __386__ ) } #endif } _ResetDevice(); #endif }
/* * ShiftImage - shift the image in the given direction */ void ShiftImage( WORD shiftdirection ) { HBITMAP dup_and; HBITMAP dup_xor; HBITMAP oldbitmap; HBITMAP oldsrcbitmap; WPI_PRES pres; HDC memdc; WPI_PRES mempres; HDC srcdc; WPI_PRES srcpres; short x_src; short y_src; short x_dest; short y_dest; short width; short height; short min_width; short min_height; short rgn_width; short rgn_height; img_node *node; WPI_RECT rect; IMGED_DIM left; IMGED_DIM right; IMGED_DIM top; IMGED_DIM bottom; DWORD message; node = GetCurrentNode(); if( node == NULL ) { return; } dup_and = DuplicateBitmap( node->handbitmap ); dup_xor = DuplicateBitmap( node->hxorbitmap ); pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); _wpi_torgbmode( srcpres ); if( DoesRectExist( &rect ) ) { width = (short)_wpi_getwidthrect( rect ); height = (short)_wpi_getheightrect( rect ); } else { _wpi_setwrectvalues( &rect, 0, 0, node->width, node->height ); width = node->width; height = node->height; } _wpi_getwrectvalues( rect, &left, &top, &right, &bottom ); oldbitmap = _wpi_selectobject( mempres, node->handbitmap ); _wpi_patblt( mempres, left, top, width, height, BLACKNESS ); _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); _wpi_patblt( mempres, left, top, width, height, WHITENESS ); oldsrcbitmap = _wpi_selectobject( srcpres, dup_xor ); x_src = (short)left; y_src = (short)top; x_dest =(short)left; y_dest = (short)top; min_width = (short)min( ImgedConfigInfo.shift, width ); min_height = (short)min( ImgedConfigInfo.shift, height ); rgn_width = width; rgn_height = height; switch( shiftdirection ) { case IMGED_LEFT: width -= min_width; x_src = x_src + min_width; message = WIE_IMAGESHIFTEDLEFT; break; case IMGED_RIGHT: width -= min_width; x_dest = x_dest + min_width; message = WIE_IMAGESHIFTEDRIGHT; break; case IMGED_UP: #ifndef __OS2_PM__ height -= min_height; y_src = y_src + min_height; #else height += min_height; y_src = y_src - min_height; #endif message = WIE_IMAGESHIFTEDUP; break; case IMGED_DOWN: #ifndef __OS2_PM__ height -= min_height; y_dest = y_dest + min_height; #else height += min_height; y_dest = y_dest - min_height; #endif message = WIE_IMAGESHIFTEDDOWN; break; default: break; } _wpi_bitblt( mempres, x_dest, y_dest, width, height, srcpres, x_src, y_src, SRCCOPY ); _wpi_selectobject( srcpres, oldsrcbitmap ); oldsrcbitmap = _wpi_selectobject( srcpres, dup_and ); _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, node->handbitmap ); _wpi_bitblt( mempres, x_dest, y_dest, width, height, srcpres, x_src, y_src, SRCCOPY ); if( IsShiftWrap() ) { switch( shiftdirection ) { case IMGED_LEFT: width = min_width; x_src = (short)left; x_dest = (short)(right - width); break; case IMGED_RIGHT: width = min_width; x_dest = (short)left; x_src = (short)(right - width); break; case SHIFT_UP: height = min_height; y_src = (short)top; y_dest = (short)(bottom - height); break; case SHIFT_DOWN: height = min_height; y_dest = (short)top; y_src = (short)(bottom - height); break; default: break; } _wpi_bitblt( mempres, x_dest, y_dest, width, height, srcpres, x_src, y_src, SRCCOPY ); _wpi_selectobject( srcpres, oldsrcbitmap ); _wpi_selectobject( mempres, oldbitmap ); oldsrcbitmap = _wpi_selectobject( srcpres, dup_xor ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); _wpi_bitblt( mempres, x_dest, y_dest, width, height, srcpres, x_src, y_src, SRCCOPY ); } _wpi_selectobject( srcpres, oldsrcbitmap ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( srcpres, srcdc ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_deleteobject( dup_xor ); _wpi_deleteobject( dup_and ); RecordImage( node->hwnd ); BlowupImage( node->hwnd, NULL ); InvalidateRect( node->viewhwnd, NULL, FALSE ); IEPrintAmtText( message, ImgedConfigInfo.shift ); } /* ShiftImage */