📄 wptoolbr.c
字号:
bitmap = _wpi_createcompatiblebitmap( pres, bar->button_size.x,
bar->button_size.y );
oldbmp = _wpi_selectbitmap( mempres, bitmap );
#if defined(__NT__) || defined(__WINDOWS__)
mem2 = CreateCompatibleDC( pres );
bitmap2 = CreateCompatibleBitmap( pres,
bar->button_size.x, bar->button_size.y );
oldbmp2 = SelectObject( mem2, bitmap2 );
#endif
brush = btnFaceBrush;
if( selected && bar->bgbrush != HNULL ) {
brush = bar->bgbrush;
}
/* Does this do anything ??? */
/* _wpi_fillrect( mempres, &tool->area, btnColour, brush ); */
dst_size = bar->button_size;
dst_size.x -= 4 * BORDER_WIDTH( bar );
dst_size.y -= 4 * BORDER_WIDTH( bar );
dst_org.x = (1 * BORDER_WIDTH( bar ))+shift;
dst_org.y = (1 * BORDER_WIDTH( bar ))+shift;
#ifdef __OS2_PM__
dst_org.y = _wpi_cvth_y( dst_org.y, (bar->button_size.y) );
dst_org.y = dst_org.y - dst_size.y + 1;
#endif
used_bmp = tool->u.bitmap;
if( selected ) {
// if the button is selected and it has the ITEM_DOWNBMP flag
// then we draw the alternate bitmap instead.
if( tool->flags & ITEM_DOWNBMP ) {
used_bmp = tool->depressed;
}
}
toolBarDrawBitmap( mempres, dst_size, dst_org, used_bmp );
#if defined(__NT__) || defined(__WINDOWS__)
/* New, on WIN32 platforms, use WPTB_TransparentBlt() */
/* Get background color of button bitmap */
bmptmp = SelectObject(mem2, used_bmp);
/* Expects 0,0 pix in original to be in background color */
cr = GetPixel(mem2, 0, 0);
bmptmp = SelectObject(mem2, bmptmp);
/* IMPORTANT: must set required new background color for dest bmp */
SetBkColor(mem2, GetSysColor(COLOR_BTNFACE));
WPTB_TransparentBlt( mem2, dst_org.x, dst_org.y,
dst_size.x, dst_size.y,
mempres, cr);
if( oldbmp != HNULL ) {
SelectObject( mempres, oldbmp );
DeleteObject(bitmap);
}
if( delete_mempres ) {
DeleteDC(mempres);
}
/* Switch new bitmap into vars expected by code below */
mempres = mem2;
delete_mempres = TRUE;
bitmap = bitmap2;
oldbmp = oldbmp2;
#endif
drawBorder( mempres, bar->button_size, BORDER_WIDTH( bar ) );
if( selected ) {
drawTopLeftCorner( mempres, bar->button_size, BORDER_WIDTH( bar ),
btnShadowPen );
drawTopLeftInsideCorner( mempres, bar->button_size,
BORDER_WIDTH( bar ), btnFacePen );
} else {
drawTopLeftCorner( mempres, bar->button_size, BORDER_WIDTH( bar ),
btnHighlightPen );
drawBottomRightCorner( mempres, bar->button_size, BORDER_WIDTH( bar ),
btnShadowPen );
drawBottomRightInsideCorner( mempres, bar->button_size,
BORDER_WIDTH( bar ), btnShadowPen );
}
_wpi_getrectvalues( (tool->area), &left, &top, &right, &bottom );
_wpi_bitblt( pres, left, top, bar->button_size.x, bar->button_size.y,
mempres, 0, 0, SRCCOPY ); /* copy it to screen */
_wpi_getoldbitmap( mempres, oldbmp );
if( delete_pres ) {
_wpi_releasepres( hwnd, pres );
}
_wpi_deletebitmap( bitmap );
if( delete_mempres ) {
_wpi_deletecompatiblepres( mempres, mem );
}
} /* drawButton */
/*
* isPointInToolbar - is the point in the mousemove message in the toolbar
*/
BOOL isPointInToolbar( HWND hwnd, WPI_PARAM1 wparam, WPI_PARAM2 lparam )
{
WPI_POINT p;
WPI_RECT r;
lparam = lparam; // to suppress compiler warnings for PM
wparam = wparam; // to suppress compiler warnings for Win
WPI_MAKEPOINT( wparam, lparam, p );
_wpi_getclientrect( hwnd, &r );
if( _wpi_ptinrect( &r, p ) ) {
return( TRUE );
}
return( FALSE );
} /* isPointInToolbar */
/*
* findToolAtPoint - find a tool at a given point
*/
static tool *findToolAtPoint( toolbar *bar, WPI_PARAM1 wparam, WPI_PARAM2 lparam )
{
WPI_POINT p;
tool *tool;
lparam = lparam; // to suppress compiler warnings for PM
wparam = wparam; // to suppress compiler warnings for Win
WPI_MAKEPOINT( wparam, lparam, p );
for( tool = bar->tool_list; tool != NULL; tool = tool->next ) {
if( _wpi_ptinrect( &tool->area, p ) ) {
if( tool->flags & ITEM_BLANK ) {
return( NULL );
} else {
return( tool );
}
}
}
return( NULL );
} /* findToolAtPoint */
/*
* HasToolAtPoint - return TRUE if tool exists at a given point
*/
BOOL HasToolAtPoint( struct toolbar *bar, WPI_PARAM1 wparam, WPI_PARAM2 lparam )
{
return( findToolAtPoint( bar, wparam, lparam ) != NULL );
} /* HasToolAtPoint */
/*
* ToolBarWndProc - callback routine for the tool bar
*/
MRESULT CALLBACK ToolBarWndProc( HWND hwnd, WPI_MSG msg, WPI_PARAM1 wparam,
WPI_PARAM2 lparam )
{
CREATESTRUCT __FAR *cs;
toolbar *bar;
tool *tool;
WPI_RECT inter;
WPI_PRES pres;
WPI_PRES mempres;
HDC memdc;
PAINTSTRUCT ps;
BOOL posted;
bar = GET_INFO( hwnd );
if( msg == WM_CREATE ) {
#ifndef __OS2_PM__
cs = MAKEPTR( lparam );
bar = (toolbar *)cs->lpCreateParams;
#ifdef __WINDOWS_386__
bar = MapAliasToFlat( (DWORD) bar );
#endif
#else
cs = PVOIDFROMMP( wparam );
bar = (toolbar *)cs;
WinSetPresParam( hwnd, PP_BACKGROUNDCOLORINDEX,
(ULONG)sizeof(LONG)+1, (PVOID)&btnColour );
#endif
bar->hwnd = hwnd;
SET_INFO( hwnd, bar );
}
if( bar != NULL && bar->hook != NULL ) {
if( bar->hook( hwnd, msg, wparam, lparam ) && msg != WM_DESTROY ) {
return( 0L );
}
}
switch( msg ) {
case WM_SIZE:
if( bar && bar->tool_list && !bar->is_fixed ) {
createButtonList( hwnd, bar, bar->tool_list );
_wpi_invalidaterect( hwnd, NULL, TRUE );
_wpi_updatewindow( hwnd );
}
break;
case WM_LBUTTONDOWN:
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDOWN:
case WM_RBUTTONDBLCLK:
if( bar && bar->tool_list ) {
currTool = NULL;
tool = findToolAtPoint( bar, wparam, lparam );
if( tool ) {
if( bar->hook != NULL ) {
bar->hook( hwnd, WM_USER, MPFROMSHORT(tool->id),
(WPI_PARAM2)0 );
}
currTool = tool;
drawButton( hwnd, tool, TRUE, NULL, NULL, NULL );
mouse_captured = TRUE;
_wpi_setcapture( hwnd );
currIsDown = TRUE;
if( bar->helphook != NULL ) {
bar->helphook( hwnd, MPFROMSHORT(currTool->id), TRUE );
}
}
}
break;
case WM_LBUTTONUP:
case WM_RBUTTONUP:
if( bar && bar->tool_list ) {
tool = findToolAtPoint( bar, wparam, lparam );
posted = FALSE;
if( tool != NULL ) {
if( tool == currTool ) {
_wpi_postmessage( bar->owner, WM_COMMAND, tool->id, CMDSRC_MENU );
posted = TRUE;
drawButton( hwnd, tool, FALSE, NULL, NULL, NULL );
}
}
if( !posted && bar->hook != NULL ) {
if( currTool != NULL ) {
bar->hook( hwnd, WM_USER, MPFROMSHORT(currTool->id),
(WPI_PARAM2)1 );
}
}
if( currTool != NULL ) {
mouse_captured = FALSE;
ignore_mousemove = TRUE; // release_capture generates a
// WM_MOUSEMOVE
_wpi_releasecapture();
if( bar->helphook != NULL ) {
bar->helphook( hwnd, MPFROMSHORT(currTool->id), FALSE );
}
currTool = NULL;
}
}
break;
case WM_MOUSEMOVE:
if( ignore_mousemove ) {
ignore_mousemove = FALSE;
break;
}
tool = findToolAtPoint( bar, wparam, lparam );
if( currTool ) {
if( tool == currTool ) {
if( !currIsDown ) {
currIsDown = TRUE;
drawButton( hwnd, currTool, TRUE, NULL, NULL, NULL );
if( bar->helphook != NULL ) {
bar->helphook( hwnd, MPFROMSHORT(currTool->id), TRUE );
}
}
} else {
if( currIsDown ) {
drawButton( hwnd, currTool, FALSE, NULL, NULL, NULL );
currIsDown = FALSE;
if( bar->helphook != NULL ) {
bar->helphook( hwnd, MPFROMSHORT(currTool->id), FALSE );
}
}
}
} else {
if( bar->helphook != NULL ) {
if( tool ) {
bar->helphook( hwnd, MPFROMSHORT(tool->id), TRUE );
lastID = tool->id;
} else if( lastID != (WORD)-1 ) {
bar->helphook( hwnd, MPFROMSHORT(lastID), FALSE );
lastID = -1;
}
}
}
break;
#if defined(__NT__) || defined(__WINDOWS__)
case WM_SYSCOLORCHANGE: {
COLORREF clr_btnface;
COLORREF clr_btnshadow;
COLORREF clr_btnhighlight;
COLORREF clr_black;
if( gdiObjectsCreated ) {
_wpi_deleteobject( blackPen );
_wpi_deleteobject( btnShadowPen );
_wpi_deleteobject( btnHighlightPen );
_wpi_deleteobject( btnFacePen );
_wpi_deleteobject( blackBrush );
_wpi_deleteobject( btnFaceBrush );
gdiObjectsCreated = FALSE;
}
clr_btnshadow = GetSysColor( COLOR_BTNSHADOW );
clr_btnhighlight = GetSysColor( COLOR_BTNHIGHLIGHT );
btnColour = GetSysColor( COLOR_BTNFACE );
clr_btnface = btnColour;
clr_black = GetSysColor(COLOR_BTNTEXT);
if( !gdiObjectsCreated ) {
blackPen = _wpi_createpen( PS_SOLID, BORDER_WIDTH(bar), clr_black );
btnShadowPen = _wpi_createpen( PS_SOLID, BORDER_WIDTH(bar), clr_btnshadow );
btnHighlightPen = _wpi_createpen( PS_SOLID, BORDER_WIDTH(bar), clr_btnhighlight );
btnFacePen = _wpi_createpen( PS_SOLID, BORDER_WIDTH(bar), clr_btnface );
blackBrush = _wpi_createsolidbrush( clr_black );
btnFaceBrush = _wpi_createsolidbrush( clr_btnface );
gdiObjectsCreated = TRUE;
}
}
break;
#endif
case WM_PAINT:
pres = _wpi_beginpaint( hwnd, NULL, &ps );
mempres = _wpi_createcompatiblepres( pres, appInst, &memdc );
#ifdef __OS2_PM__
WinFillRect( pres, &ps, CLR_PALEGRAY );
for( tool = bar->tool_list; tool != NULL; tool = tool->next ) {
if( _wpi_intersectrect( appInst, &inter, &ps, &tool->area ) ) {
#else
/* First non comment line below inserted as test by RR 2003.10.26 */
/* Ref PM implementation above, and WM_PAINT: handler in toolbr.c */
_wpi_fillrect( pres, &ps.rcPaint, clr_btnface, btnFaceBrush );
for( tool = bar->tool_list; tool != NULL; tool = tool->next ) {
if( _wpi_intersectrect( appInst, &inter, &ps.rcPaint, &tool->area ) ) {
#endif
drawButton( hwnd, tool, FALSE, pres, mempres, memdc );
}
}
_wpi_deletecompatiblepres( mempres, memdc );
_wpi_endpaint( hwnd, NULL, &ps );
break;
#ifndef __OS2_PM__
case WM_ERASEBKGND:
InvalidateRect( hwnd, NULL, FALSE );
/* Resulting WM_PAINT will fill entire area, */
/* so avoid default handler kicking in. */
return 1;
#endif
case WM_DESTROY:
bar->hwnd = HNULL;
break;
}
return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
} /* ToolBarWndPproc */
/*
* ChangeToolButtonBitmap - change a bitmap for a toolbar item
*/
void ChangeToolButtonBitmap( toolbar *bar, WORD id, HBITMAP newbmp )
{
tool *t;
t = findTool( bar->tool_list, id );
if( t != NULL ) {
t->u.bitmap = newbmp;
_wpi_invalidaterect( bar->hwnd, &t->area, TRUE );
_wpi_updatewindow( bar->hwnd );
}
} /* ChangeToolButtonBitmap */
/********** Below - new inserted 2003.10.31 ********************/
#if defined(__NT__) || defined(__WINDOWS__)
/*
* WPTB_TransparentBlt
*
* Purpose: Given two DC's and a color to assume as transparent in
* the source, BitBlts the bitmap to the dest DC letting the existing
* background show in place of the transparent color.
* Adapted from an old MS SDK sample.
*
* NOTE: make sure BkColor is set in dest hDC.
*
* Parameters: hDC HDC destination, on which to draw.
* x, y UINT location at which to draw the bitmap
* width UINT width to draw
* height UINT height to draw
* hDCIn HDC source, to copy from
* cr COLORREF to consider as transparent in source.
*
* Return Value: None
*/
#define ROP_DSPDxax 0x00E20746
void WPTB_TransparentBlt (HDC hDC, UINT x, UINT y, UINT width, UINT height,
HDC hDCIn, COLORREF cr)
{
HDC hDCMid, hMemDC;
HBITMAP hBmpMono, hBmpT;
HBRUSH hBr, hBrT;
COLORREF crBack, crText;
if (NULL == hDCIn)
return;
/* Make two intermediate DC's */
hDCMid = CreateCompatibleDC (hDC);
hMemDC = CreateCompatibleDC (hDC);
/* Create a monochrome bitmap for masking */
hBmpMono = CreateCompatibleBitmap (hDCMid, x + width, y + height);
SelectObject (hDCMid, hBmpMono);
/* Create a mid-stage bitmap */
hBmpT = CreateCompatibleBitmap (hDC, x + width, y + height);
SelectObject (hMemDC, hBmpT);
/* Create a monochrome mask where we have 0's in the image, 1's elsewhere. */
crBack = SetBkColor (hDCIn, cr);
BitBlt (hDCMid, x, y, width, height, hDCIn, x, y, SRCCOPY);
SetBkColor (hDCIn, crBack);
/* Put the unmodified image in the temporary bitmap */
BitBlt (hMemDC, x, y, width, height, hDCIn, x, y, SRCCOPY);
/* Create an select a brush of the background color */
hBr = CreateSolidBrush (GetBkColor (hDC));
hBrT = SelectObject (hMemDC, hBr);
/* Force conversion of the monochrome to stay black and white. */
crText = SetTextColor (hMemDC, 0L);
crBack = SetBkColor (hMemDC, RGB (255, 255, 255));
/*
* Where the monochrome mask is 1, Blt the brush; where the mono
* mask is 0, leave the destination untouched. This results in
* painting around the image with the background brush. We do this
* first in the temporary bitmap, then put the whole thing to the
* screen (avoids flicker).
*/
BitBlt (hMemDC, x, y, width, height, hDCMid, x, y, ROP_DSPDxax);
BitBlt (hDC, x, y, width, height, hMemDC, x, y, SRCCOPY);
SetTextColor (hMemDC, crText);
SetBkColor (hMemDC, crBack);
SelectObject (hMemDC, hBrT);
DeleteObject (hBr);
DeleteDC (hMemDC);
DeleteDC (hDCMid);
DeleteObject (hBmpT);
DeleteObject (hBmpMono);
} /* TansparentBlt () */
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -