/* * CutImage - cuts the current clipping rectangle to the clipboard */ void CutImage( void ) { WPI_PRES pres; WPI_PRES mempres; HDC memdc; HBITMAP oldbitmap; short width; short height; img_node *node; WPI_RECTDIM left; WPI_RECTDIM right; WPI_RECTDIM top; WPI_RECTDIM bottom; node = GetCurrentNode(); if( node == NULL ) { return; } if( !fEnableCutCopy ) { _wpi_setwrectvalues( &clipRect.rect, 0, 0, node->width, node->height ); width = node->width; height = node->height; } else { width = (short)_wpi_getwidthrect( clipRect.rect ); height = (short)_wpi_getheightrect( clipRect.rect ); } copyImageToClipboard( width, height, node ); pres = _wpi_getpres( node->viewhwnd ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_releasepres( node->viewhwnd, pres ); oldbitmap = _wpi_selectbitmap( mempres, node->hxorbitmap ); _wpi_getrectvalues( clipRect.rect, &left, &top, &right, &bottom ); _wpi_patblt( mempres, left, top, width, height, WHITENESS ); _wpi_getoldbitmap( mempres, oldbitmap ); oldbitmap = _wpi_selectbitmap( mempres, node->handbitmap ); _wpi_patblt( mempres, left, top, width, height, BLACKNESS ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); InvalidateRect( node->viewhwnd, NULL, FALSE ); RecordImage( node->hwnd ); if( !fEnableCutCopy ) { PrintHintTextByID( WIE_ENTIREIMAGECUT, NULL ); } else { PrintHintTextByID( WIE_AREACUT, NULL ); fEnableCutCopy = FALSE; } BlowupImage( node->hwnd, NULL ); } /* CutImage */
/* * 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 */
/* * 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 */
/* * ShowNewColor - replace the color of the color box and redisplay the boxes */ void ShowNewColor( int index, COLORREF newcolor, BOOL repaint ) { WPI_POINT topleft; WPI_POINT bottomright; WPI_PRES pres; WPI_PRES mempres; HDC hdc; HBITMAP oldbitmap; HBRUSH brush; HBRUSH oldbrush; HPEN blackpen; HPEN oldpen; pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); paletteBox[index].color = newcolor; paletteBox[index].solid_color = _wpi_getnearestcolor( pres, newcolor ); _wpi_releasepres( HWND_DESKTOP, pres ); if( numberOfColors != 2 ) { topleft.x = (index / 2) * SQR_SIZE; bottomright.x = topleft.x + SQR_SIZE + 1; if( index / 2 == (index + 1) / 2 ) { topleft.y = 0; bottomright.y = SQR_SIZE + 1; } else { topleft.y = SQR_SIZE; bottomright.y = 2 * SQR_SIZE + 1; } pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); brush = _wpi_createsolidbrush( newcolor ); oldbrush = _wpi_selectobject( mempres, brush ); blackpen = _wpi_createpen( PS_SOLID, 0, BLACK ); oldpen = _wpi_selectobject( mempres, blackpen ); oldbitmap = _wpi_selectbitmap( mempres, hColorBitmap ); _wpi_cvth_pt( &topleft, colorsHeight ); _wpi_cvth_pt( &bottomright, colorsHeight ); _wpi_rectangle( mempres, topleft.x, topleft.y, bottomright.x, bottomright.y ); _wpi_selectobject( mempres, oldpen ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( blackpen ); _wpi_deleteobject( brush ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); } if( repaint ) { _wpi_invalidaterect( hColorsWnd, NULL, FALSE ); } } /* ShowNewColor */
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 }
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 ); }
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 */
/* * 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 */