📄 clip.c
字号:
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)min(client_r/pointsize.x - truept.x, bm_width);
height = (short)min(client_b/pointsize.y - truept.y, 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)min( bm_width, width );
clipheight = (short)min( bm_height, 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)min( bm_width, width );
clipheight = (short)min( bm_height, height );
_wpi_patblt( mempres, truept.x, truept.y, width, height, WHITENESS );
#ifdef __OS2_PM__
{
int src_y, dest_y;
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)min( client_r/pointsize.x - truept.x, bm_width );
height = (short)min( client_b/pointsize.y - truept.y, 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)min( bm_width, width );
clipheight = (short)min( bm_height, height );
_wpi_patblt( mempres, truept.x, truept.y, width, height, WHITENESS );
#ifdef __OS2_PM__
{
int src_y, dest_y;
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 */
/*
* CutImage - Cuts the current clipRect to the clipboard.
*/
void CutImage( void )
{
WPI_PRES pres;
WPI_PRES mempres;
HDC memdc;
HBITMAP oldbitmap;
short width;
short height;
img_node *node;
IMGED_DIM left;
IMGED_DIM right;
IMGED_DIM top;
IMGED_DIM bottom;
node = GetCurrentNode();
if ( !node ) return;
if (!fEnableCutCopy) {
_wpi_setwrectvalues(&(clipRect.rect), 0, 0, (IMGED_DIM)node->width,
(IMGED_DIM)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 */
/*
* DragClipBitmap - routine to show the clipped bitmap
*/
void DragClipBitmap( HWND hwnd, WPI_POINT *newpt, WPI_POINT pointsize )
{
int prevROP2;
HBRUSH hbrush;
HBRUSH holdbrush;
HPEN hwhitepen;
HPEN holdpen;
WPI_PRES pres;
pres = _wpi_getpres( hwnd );
if( pres == (HDC)NULL ) {
return;
}
prevROP2 = _wpi_setrop2( pres, R2_XORPEN );
hbrush = _wpi_createsolidbrush( CLR_BLACK );
holdbrush = _wpi_selectobject( pres, hbrush );
hwhitepen = _wpi_createpen( PS_SOLID, 0, CLR_WHITE );
holdpen = _wpi_selectobject( pres, hwhitepen );
if (!firstTime) {
_wpi_rectangle( pres, prevPoint.x*pointsize.x,
prevPoint.y*pointsize.y,
prevPoint.x*pointsize.x + dragWidth,
prevPoint.y*pointsize.y + dragHeight);
}
_wpi_rectangle( pres, newpt->x*pointsize.x, newpt->y*pointsize.y,
newpt->x*pointsize.x + dragWidth,
newpt->y*pointsize.y + dragHeight);
_wpi_selectobject( pres, holdpen );
_wpi_selectobject( pres, holdbrush );
_wpi_deleteobject( hwhitepen );
_wpi_deleteobject( hbrush );
_wpi_setrop2( pres, prevROP2 );
_wpi_releasepres( hwnd, pres );
memcpy( &prevPoint, newpt, sizeof(WPI_POINT) );
firstTime = FALSE;
} /* DragClipBitmap */
/*
* CheckForClipboard - checks to see if the CUT, COPY or PASTE menu items
* can be enabled.
*/
void CheckForClipboard( HMENU hmenu )
{
unsigned long format;
format = 0;
if ((_wpi_isclipboardformatavailable(Instance, CF_BITMAP, &format)) &&
DoImagesExist()) {
_wpi_enablemenuitem( hmenu, IMGED_PASTE, TRUE, FALSE );
} else {
_wpi_enablemenuitem( hmenu, IMGED_PASTE, FALSE, FALSE );
}
} /* CheckForClipboard */
/*
* SetRectExists - Sets whether or not there is a clipping rectangle on the
* screen. (indicated by fEnableCutCopy flag)
*/
void SetRectExists( BOOL does_rect_exist )
{
fEnableCutCopy = does_rect_exist;
} /* SetRectExists */
/*
* CleanupClipboard - Cleans up the hAndClipped and hXorClipped bitmaps if
* they were created by a cut or copy.
*/
void CleanupClipboard( void )
{
if (hXorClipped) {
_wpi_deletebitmap( hXorClipped );
_wpi_deletebitmap( hAndClipped );
hXorClipped = NULL;
hAndClipped = NULL;
}
} /* CleanupClipboard */
/*
* DontPaste - when escape is hit while dragging the image to paste.
*/
void DontPaste( HWND hwnd, WPI_POINT *topleft, WPI_POINT pointsize )
{
firstTime = TRUE;
DragClipBitmap( hwnd, topleft, pointsize );
_wpi_setcursor( prevCursor );
_wpi_destroycursor( pointCursor );
ReleaseCapture();
SetToolType( prevToolType );
PrintHintTextByID( WIE_PASTECANCELLED, NULL );
} /* DontPaste */
/*
* DoesRectExist - returns whether or not a rectangle exists.
*/
BOOL DoesRectExist( WPI_RECT *rc )
{
if (fEnableCutCopy) {
*rc = clipRect.rect;
} else {
_wpi_setrectvalues( rc, 0, 0, 0, 0 );
}
return( fEnableCutCopy );
} /* DoesRectExist */
/*
* SetDeviceClipRect - sets the new clip rect with device units of image
*/
void SetDeviceClipRect( WPI_RECT *rect )
{
clipRect.rect = *rect;
fEnableCutCopy = TRUE;
} /* SetDeviceClipRect */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -