/* * ClearImage - clear the XOR and the AND bitmaps */ void ClearImage( void ) { WPI_PRES pres; WPI_PRES xorpres; WPI_PRES andpres; HDC xormemdc; HDC andmemdc; HBITMAP oldxor; HBITMAP oldand; img_node *node; WPI_RECT clear_area; IMGED_DIM left; IMGED_DIM top; IMGED_DIM right; IMGED_DIM bottom; int width; int height; node = GetCurrentNode(); if( node == NULL ) { return; } if( DoesRectExist( &clear_area ) ) { SetRectExists( FALSE ); } else { _wpi_setwrectvalues( &clear_area, 0, 0, node->width, node->height ); } pres = _wpi_getpres( HWND_DESKTOP ); xorpres = _wpi_createcompatiblepres( pres, Instance, &xormemdc ); andpres = _wpi_createcompatiblepres( pres, Instance, &andmemdc ); _wpi_releasepres( HWND_DESKTOP, pres ); oldxor = _wpi_selectobject( xorpres, node->hxorbitmap ); oldand = _wpi_selectobject( andpres, node->handbitmap ); _wpi_getwrectvalues( clear_area, &left, &top, &right, &bottom ); width = _wpi_getwidthrect( clear_area ); height = _wpi_getheightrect( clear_area ); _wpi_patblt( xorpres, left, top, width, height, WHITENESS ); _wpi_patblt( andpres, left, top, width, height, BLACKNESS ); _wpi_selectobject( xorpres, oldxor ); _wpi_selectobject( andpres, oldand ); _wpi_deletecompatiblepres( xorpres, xormemdc ); _wpi_deletecompatiblepres( andpres, andmemdc ); InvalidateRect( node->viewhwnd, NULL, TRUE ); RecordImage( node->hwnd ); BlowupImage( node->hwnd, NULL ); PrintHintTextByID( WIE_AREACLEARED, NULL ); } /* ClearImage */
/* * 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 */
/* * rotateTheImage - create the rotated bitmaps */ static void rotateTheImage( img_node *node, int whichway, WPI_RECT *rect, HBITMAP rotxorbmp, HBITMAP rotandbmp ) { WPI_PRES pres; WPI_PRES rotxorpres; HDC rotxordc; WPI_PRES xorpres; HDC xordc; WPI_PRES rotandpres; HDC rotanddc; HBITMAP oldandrot; HBITMAP oldxorrot; HBITMAP oldxor; short new_height; short new_width; long i; long amt_done; long prev_amt; long total_amt; long temp; IMGED_DIM left; IMGED_DIM top; IMGED_DIM right; IMGED_DIM bottom; int x; int y; COLORREF color; bitmap_bits *xorbits; bitmap_bits *andbits; bitmap_bits *rotxorbits; bitmap_bits *rotandbits; new_height = (short)_wpi_getwidthrect( *rect ); new_width = (short)_wpi_getheightrect( *rect ); oldxor = NULL; amt_done = prev_amt = 0L; total_amt = (long)new_height * (long)new_width; i = 0L; _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom ); if( node->imgtype == BITMAP_IMG ) { pres = _wpi_getpres( HWND_DESKTOP ); xorpres = _wpi_createcompatiblepres( pres, Instance, &xordc ); rotxorpres = _wpi_createcompatiblepres( pres, Instance, &rotxordc ); rotandpres = _wpi_createcompatiblepres( pres, Instance, &rotanddc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( rotxorpres ); _wpi_torgbmode( rotandpres ); oldxorrot = _wpi_selectobject( rotxorpres, rotxorbmp ); oldandrot = _wpi_selectobject( rotandpres, rotandbmp ); _wpi_patblt( rotxorpres, 0, 0, new_width, new_height, WHITENESS ); _wpi_patblt( rotandpres, 0, 0, new_width, new_height, BLACKNESS ); _wpi_selectobject( rotxorpres, oldxorrot ); _wpi_selectobject( rotandpres, oldandrot ); _wpi_deletecompatiblepres( rotandpres, rotanddc ); _imged_getthebits( xorbits, xorpres, node->hxorbitmap, oldxor ); _imged_getthebits( rotxorbits, rotxorpres, rotxorbmp, oldxorrot ); if( whichway == ROTATE_COUNTERCLOCKWISE ) { for( y = 0; y < new_height; y++ ) { for( x = 0; x < new_width; x++ ) { color = _imged_getpixel( xorbits, xorpres, right - y - 1, top + x ); _imged_setpixel( rotxorbits, rotxorpres, x, y, color ); i++; temp = i * 100; amt_done = temp / total_amt; if( amt_done - prev_amt >= 2 ) { IEPrintRotateAmt( amt_done ); prev_amt = amt_done; } } } } else { for( y = 0; y < new_height; y++ ) { for( x = 0; x < new_width; x++ ) { color = _imged_getpixel( xorbits, xorpres, left + y, bottom - x - 1 ); _imged_setpixel( rotxorbits, rotxorpres, x, y, color ); i++; temp = i * 100; amt_done = temp / total_amt; if( amt_done - prev_amt >= 2 ) { IEPrintRotateAmt( amt_done ); prev_amt = amt_done; } } } } _imged_freethebits( xorbits, xorpres, node->hxorbitmap, FALSE, oldxor ); _imged_freethebits( rotxorbits, rotxorpres, rotxorbmp, TRUE, oldxorrot ); _wpi_deletecompatiblepres( xorpres, xordc ); _wpi_deletecompatiblepres( rotxorpres, rotxordc ); } else { // We can use the bits.c routines for icons and cursors. xorbits = GetTheBits( node->hxorbitmap ); andbits = GetTheBits( node->handbitmap ); rotxorbits = GetTheBits( rotxorbmp ); rotandbits = GetTheBits( rotandbmp ); if( whichway != IMGED_ROTATECC ) { for( y = 0; y < new_height; y++ ) { for( x = 0; x < new_width; x++ ) { color = MyGetPixel( xorbits, right - y - 1, top + x ); MySetPixel( rotxorbits, x, y, color ); color = MyGetPixel( andbits, right - y - 1, top + x ); MySetPixel( rotandbits, x, y, color ); i++; temp = i * 100; amt_done = temp / total_amt; if( amt_done - prev_amt >= 2 ) { IEPrintRotateAmt( amt_done ); prev_amt = amt_done; } } } } else { for( y = 0; y < new_height; y++ ) { for( x = 0; x < new_width; x++ ) { color = MyGetPixel( xorbits, left + y, bottom - x - 1 ); MySetPixel( rotxorbits, x, y, color ); color = MyGetPixel( andbits, left + y, bottom - x - 1 ); MySetPixel( rotandbits, x, y, color ); i++; temp = i * 100; amt_done = temp / total_amt; if( amt_done - prev_amt >= 2 ) { IEPrintRotateAmt( amt_done ); prev_amt = amt_done; } } } } FreeTheBits( xorbits, node->hxorbitmap, FALSE ); FreeTheBits( andbits, node->handbitmap, FALSE ); FreeTheBits( rotxorbits, rotxorbmp, TRUE ); FreeTheBits( rotandbits, rotandbmp, TRUE ); } } /* rotateTheImage */
/* * stretchIntoArea - stretch the rotated image into the area specified */ static void stretchIntoArea( 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; IMGED_DIM left; IMGED_DIM right; IMGED_DIM bottom; IMGED_DIM top; width = (short)_wpi_getwidthrect( *rect ); height = (short)_wpi_getheightrect( *rect ); _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom ); 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_setstretchbltmode( xorpres, STRETCH_COLOR ); _wpi_stretchblt( xorpres, left, top, width, height, rotxorpres, 0, 0, height, width, SRCCOPY ); _wpi_setstretchbltmode( andpres, STRETCH_COLOR ); _wpi_stretchblt( andpres, left, top, width, height, rotandpres, 0, 0, height, width, 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 ); } /* stretchIntoArea */
/* * 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 GUIDrawTextBitmapRGB( gui_window *wnd, const char *text, size_t length, int height, gui_coord *pos, WPI_COLOUR fore, WPI_COLOUR back, gui_ord extentx, bool draw_extent, int bitmap ) { int nDrawX, nDrawY; UINT lenx; HBRUSH brush; HBRUSH old_brush; HPEN pen; HPEN old_pen; int old_rop; size_t num_chars; WPI_RECT rect; gui_coord indent; int hscroll_pos; gui_coord extent; WPI_COLOUR colour; GUI_RECTDIM left, top, right, bottom; GUI_RECTDIM paint_left, paint_top, paint_right, paint_bottom; WPI_RECT paint_rect; WPI_RECT draw_rect; //draw_cache dcache; if( ( wnd->hdc == NULLHANDLE ) || ( wnd->ps == NULL ) || ( ( text == NULL ) && ( bitmap == 0 ) ) || ( ( bitmap != 0 ) && ( height == 0 ) ) ) { return; } old_rop = 0; old_brush = (HBRUSH)NULL; brush = (HBRUSH)NULL; old_pen = (HPEN)NULL; pen = (HPEN)NULL; GUIGetMetrics( wnd ); if( !bitmap ) { height = AVGYCHAR(GUItm); } rect = wnd->hwnd_client; _wpi_getrectvalues( rect, &left, &top, &right, &bottom); _wpi_getpaintrect( wnd->ps, &paint_rect ); _wpi_getwrectvalues( paint_rect, &paint_left, &paint_top, &paint_right, &paint_bottom ); top = paint_top / height * height; bottom = ( paint_bottom + height - 1) / height * height; if( GUI_DO_HSCROLL( wnd ) ) { hscroll_pos = GUIGetScrollPos( wnd, SB_HORZ ); } else { hscroll_pos = 0; } if( bitmap == 0 ) { num_chars = strlen( text ); if( num_chars > length ) { num_chars = length; } } indent.x = pos->x; indent.y = pos->y; GUIScaleToScreenR( &indent ); nDrawY = indent.y; if( GUI_DO_VSCROLL( wnd ) ) { nDrawY -= GUIGetScrollPos( wnd, SB_VERT ); } nDrawX = left; nDrawX += ( indent.x - hscroll_pos ); if( bitmap > 0 ) { lenx = length ; } else { lenx = GUIGetTextExtentX( wnd, text, num_chars ); } if( draw_extent ) { /* blanks out some portion of rest of the line */ if( extentx != GUI_NO_COLUMN ) { extent.x = extentx; GUIScaleToScreen( &extent ); right = nDrawX + extent.x; } } else { right = nDrawX + lenx; } nDrawY = _wpi_cvth_y_size( nDrawY, _wpi_getheightrect(wnd->hwnd_client), height ); _wpi_setrectvalues( &draw_rect, nDrawX, nDrawY, right, nDrawY+height ); if( GUIIsRectInUpdateRect( wnd, &draw_rect ) ) { colour = _wpi_getnearestcolor( wnd->hdc, back ); brush = _wpi_createsolidbrush( colour ); pen = _wpi_createpen( PS_SOLID, 1, colour ); if( pen == NULLHANDLE ) { GUIError(LIT( Pen_Failed )); } old_brush = _wpi_selectbrush( wnd->hdc, brush ); old_pen = _wpi_selectpen( wnd->hdc, pen ); #ifdef __OS2_PM__ _wpi_rectangle( wnd->hdc, nDrawX, nDrawY+1, right, nDrawY + height - 1 ); #else _wpi_rectangle( wnd->hdc, nDrawX, nDrawY, right, nDrawY + height); #endif /* if visible even with scrolling */ if( nDrawX < ( paint_right + hscroll_pos ) ) { if( bitmap > 0 ) { GUIDrawBitmap( bitmap, wnd->hdc, nDrawX, nDrawY, colour); } else { #ifdef __OS2_PM__ nDrawY += _wpi_metricdescent( GUItm ); #endif old_rop = _wpi_setrop2( wnd->hdc, R2_COPYPEN ); SetText( wnd, fore, back ); _wpi_textout( wnd->hdc, nDrawX, nDrawY, text, num_chars ); } } /* restore old resources */ if( old_rop != 0 ) { _wpi_setrop2( wnd->hdc, old_rop ); } if( old_brush != (HBRUSH)NULL ) { _wpi_getoldbrush( wnd->hdc, old_brush ); } if( brush != (HBRUSH)NULL ) { _wpi_deletebrush( brush ); } if( old_pen != (HPEN)NULL ) { _wpi_getoldpen( wnd->hdc, old_pen ); } if( pen != (HPEN)NULL ) { _wpi_deletepen( pen ); } } }
/* * 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 ); }