📄 wptoolbr.c
字号:
BOOL ToolBarDeleteItem( toolbar *bar, WORD id )
{
tool *t, *next;
t = findTool( bar->tool_list, id );
if( t != NULL ) {
// need to destroy the window on the tool bar and recreate
// all the other tools after this one
next = t->next;
deleteTool( &bar->tool_list, t );
createButtonList( bar->hwnd, bar, next );
return( TRUE );
}
return( FALSE );
} /* ToolBarDeleteItem */
#ifdef __OS2_PM__
static WPI_PROC oldFrameProc;
WPI_MRESULT CALLBACK FrameProc( HWND hwnd, WPI_MSG msg, WPI_PARAM1 wparam,
WPI_PARAM2 lparam )
{
HWND client;
switch( msg ) {
case WM_RBUTTONDBLCLK:
case WM_LBUTTONDBLCLK:
client = WinWindowFromID( hwnd, FID_CLIENT );
if( client != NULLHANDLE ) {
#ifndef __OS2_PM__
_wpi_sendmessage( client, msg, 0, (WPI_PARAM2)0xfffffff );
#else
_wpi_sendmessage( client, msg, (WPI_PARAM1)0xfffffff, 0 );
#endif
}
break;
case WM_SYSCOMMAND:
if( SHORT1FROMMP(wparam) != SC_CLOSE ) {
client = WinWindowFromID( hwnd, FID_CLIENT );
if( client != NULLHANDLE ) {
_wpi_sendmessage( client, msg, wparam, lparam );
}
break;
}
// fall through!!
case WM_CLOSE:
client = WinWindowFromID( hwnd, FID_CLIENT );
if( client != NULLHANDLE ) {
_wpi_sendmessage( client, WM_CLOSE, 0, 0 );
}
_wpi_destroywindow( hwnd );
return( NULL );
}
return( _wpi_callwindowproc( oldFrameProc, hwnd, msg, wparam, lparam ) );
}
#endif
/*
* ToolBarDisplay - create and show the tool bar
*/
void ToolBarDisplay( toolbar *bar, TOOLDISPLAYINFO *disp )
{
int height, width;
currTool = NULL;
currIsDown = FALSE;
lastID = -1;
mouse_captured = FALSE;
if( bar->bgbrush != NULL ) {
_wpi_deleteobject( bar->bgbrush );
bar->bgbrush = NULL;
}
if( disp->background != NULL ) {
bar->bgbrush = _wpi_createpatternbrush( disp->background );
}
if( bar->hwnd != HNULL ) {
if( _wpi_getcapture() == bar->hwnd ) {
_wpi_releasecapture();
}
toolbardestroywindow( bar->hwnd );
}
bar->button_size = disp->button_size;
bar->hook = disp->hook;
bar->helphook = disp->helphook;
bar->border = disp->border_size;
bar->background = disp->background;
bar->foreground = disp->foreground;
bar->is_fixed = disp->is_fixed;
width = _wpi_getwidthrect( (disp->area) );
height = _wpi_getheightrect( (disp->area) );
#ifndef __OS2_PM__
#if defined(__NT__)
if ( LOBYTE(LOWORD(GetVersion())) >= 4 && (bar->is_fixed) ) {
CreateWindow( className, NULL, WS_CHILD, //( disp->style ),
disp->area.left, disp->area.top, width, height,
bar->owner, (HMENU) HNULL, GET_HINSTANCE( bar->owner ), bar );
}
else {
if( LOBYTE(LOWORD(GetVersion())) >= 4 && ( !bar->is_fixed ) ) {
CreateWindowEx( WS_EX_TOOLWINDOW, className, NULL, disp->style,
disp->area.left, disp->area.top, width, height,
bar->owner, (HMENU) HNULL, GET_HINSTANCE( bar->owner ), bar );
} else {
CreateWindow( className, NULL, disp->style,
disp->area.left, disp->area.top, width, height,
bar->owner, (HMENU) HNULL, GET_HINSTANCE( bar->owner ), bar );
}
}
#else
CreateWindow( className, NULL, disp->style,
disp->area.left, disp->area.top, width, height,
bar->owner, (HMENU) HNULL, GET_HINSTANCE( bar->owner ), bar );
#endif
/*
* Windows ignores the GETMINMAXINFO before the WM_CREATE or
* something so we kluge it.
*/
MoveWindow( bar->hwnd, disp->area.left, disp->area.top,
width, height, TRUE );
#else // It is __OS2_PM__
{
HWND frame;
HWND parent;
if ( disp->is_fixed ) {
parent = bar->owner;
} else {
parent = HWND_DESKTOP;
}
frame = WinCreateStdWindow( parent, 0L, &(disp->style), NULL, "",
0L, (HMODULE)0, 0, NULL);
WinSetOwner( frame, bar->owner );
oldFrameProc = _wpi_subclasswindow( frame, (WPI_PROC)FrameProc );
WinSetPresParam( frame, PP_BACKGROUNDCOLORINDEX,
(ULONG)sizeof(LONG)+1, (PVOID)&btnColour );
WinCreateWindow( frame, className, "", WS_VISIBLE, 0, 0, 0, 0, frame,
HWND_TOP, FID_CLIENT, (PVOID)bar, NULL);
WinSetWindowPos(frame, HWND_TOP, disp->area.xLeft,
disp->area.yBottom, width, height,
SWP_MOVE | SWP_SIZE | SWP_HIDE );
}
#endif
} /* ToolBarDisplay */
/*
* ToolBarWindow - return a handle to the toolbar window ... for PM this
* is a handle to the frame window
*/
HWND ToolBarWindow( toolbar *bar )
{
if( bar == NULL ) {
return( HNULL );
}
return( _wpi_getframe(bar->hwnd) );
} /* ToolBarWindow */
/*
* UpdateToolBar - update our tool bar
*/
void UpdateToolBar( toolbar *bar )
{
_wpi_invalidaterect( bar->hwnd, NULL, TRUE );
_wpi_updatewindow( bar->hwnd );
} /* UpdateToolBar */
/*
* drawTopLeftCorner - draws the top left corner of a button
*/
static void drawTopLeftCorner( WPI_PRES pres, WPI_POINT size, int border,
HPEN pen )
{
HPEN old_pen;
WPI_POINT pt;
old_pen = _wpi_selectobject( pres, pen );
_wpi_setpoint( &pt, border, size.y - 2*border );
_wpi_cvth_pt( &pt, size.y );
_wpi_movetoex( pres, &pt, NULL );
_wpi_setpoint( &pt, border, border );
_wpi_cvth_pt( &pt, size.y );
_wpi_lineto( pres, &pt );
_wpi_setpoint( &pt, size.x - border, border );
_wpi_cvth_pt( &pt, size.y );
_wpi_lineto( pres, &pt );
_wpi_selectobject( pres, old_pen );
} /* drawTopLeftCorner */
/*
* drawTopLeftInsideCorner - draws the top left corner of a button
*/
static void drawTopLeftInsideCorner( WPI_PRES pres, WPI_POINT size,
int border, HPEN pen )
{
HPEN old_pen;
WPI_POINT pt;
old_pen = _wpi_selectobject( pres, pen );
_wpi_setpoint( &pt, border*2, size.y - 2*border );
_wpi_cvth_pt( &pt, size.y );
_wpi_movetoex( pres, &pt, NULL );
_wpi_setpoint( &pt, border*2, border*2 );
_wpi_cvth_pt( &pt, size.y );
_wpi_lineto( pres, &pt );
pt.x = size.x - border;
_wpi_lineto( pres, &pt );
_wpi_selectobject( pres, old_pen );
} /* drawTopLeftCorner */
/*
* drawBottomRightCorner - draws the bottom right corner of a button
*/
static void drawBottomRightCorner( WPI_PRES pres, WPI_POINT size, int border,
HPEN pen )
{
HPEN old_pen;
WPI_POINT pt;
int height;
height = size.y;
size.x -= 2*border;
size.y -= 2*border;
old_pen = _wpi_selectobject( pres, pen );
_wpi_setpoint( &pt, size.x, border );
_wpi_cvth_pt( &pt, height );
_wpi_movetoex( pres, &pt, NULL );
_wpi_setpoint( &pt, size.x, size.y );
_wpi_cvth_pt( &pt, height );
_wpi_lineto( pres, &pt );
_wpi_setpoint( &pt, border-1, size.y );
_wpi_cvth_pt( &pt, height );
_wpi_lineto( pres, &pt );
_wpi_selectobject( pres, old_pen );
} /* drawBottomRightCorner */
/*
* drawBottomRightInsideCorner - draw the inside corner of a button
*/
static void drawBottomRightInsideCorner( WPI_PRES pres, WPI_POINT size,
int border, HPEN pen )
{
HPEN old_pen;
WPI_POINT pt;
int height;
height = size.y;
size.x -= 3*border;
size.y -= 3*border;
old_pen = _wpi_selectobject( pres, pen );
_wpi_setpoint( &pt, 2*border, size.y );
_wpi_cvth_pt( &pt, height );
_wpi_movetoex( pres, &pt, NULL );
_wpi_setpoint( &pt, size.x, size.y );
_wpi_cvth_pt( &pt, height );
_wpi_lineto( pres, &pt );
_wpi_setpoint( &pt, size.x, border );
_wpi_cvth_pt( &pt, height );
_wpi_lineto( pres, &pt );
_wpi_selectobject( pres, old_pen );
} /* drawBottomRightInsideCorner */
/*
* drawBorder - draw to border of a button
*/
static void drawBorder( WPI_PRES pres, WPI_POINT size, int border )
{
HPEN old_pen;
int x,y;
WPI_POINT pt;
y = _wpi_cvth_y( size.y-1, size.y );
x = size.x-1;
old_pen = _wpi_selectobject( pres, blackPen );
_wpi_setpoint( &pt, 0, _wpi_cvth_y(0, size.y) );
_wpi_movetoex( pres, &pt, NULL );
pt.x = x;
_wpi_lineto( pres, &pt );
pt.y = y;
_wpi_lineto( pres, &pt );
pt.x = 0;
_wpi_lineto( pres, &pt );
pt.y = _wpi_cvth_y(0, size.y);
_wpi_lineto( pres, &pt );
_wpi_selectobject( pres, btnFacePen );
_wpi_setpoint( &pt, 0, _wpi_cvth_y(0, size.y) );
_wpi_movetoex( pres, &pt, NULL );
pt.x = border;
if (!round_corners) {
pt.x -= 1;
}
_wpi_lineto( pres, &pt );
pt.x = x;
_wpi_movetoex( pres, &pt, NULL );
pt.y = _wpi_cvth_y( border, size.y );
if (!round_corners) {
pt.y += 1;
}
_wpi_lineto( pres, &pt );
pt.y = y;
_wpi_movetoex( pres, &pt, NULL );
pt.x = x - border;
if (!round_corners) {
pt.x += 1;
}
_wpi_lineto( pres, &pt );
pt.x = 0;
_wpi_movetoex( pres, &pt, NULL );
pt.y = _wpi_cvth_y( _wpi_cvth_y(y, size.y) - border, size.y );
if (!round_corners) {
pt.y -= 1;
}
_wpi_lineto( pres, &pt );
_wpi_selectobject( pres, old_pen );
} /* drawBorder */
/*
* toolBarDrawBitmap - draw the bitmap on a button
*/
static void toolBarDrawBitmap( WPI_PRES pres, WPI_POINT dst_size,
WPI_POINT dst_org, HBITMAP bitmap )
{
WPI_BITMAP bm;
WPI_PRES mempres;
HDC memdc;
WPI_POINT src_org, src_size;
HBRUSH old_brush;
HBITMAP old_bmp;
DPtoLP( pres, &dst_size, 1 );
DPtoLP( pres, &dst_org, 1 );
mempres = _wpi_createcompatiblepres( pres, appInst, &memdc );
old_bmp = _wpi_selectbitmap( mempres, bitmap );
_wpi_getbitmapstruct( bitmap, &bm );
src_size.x = _wpi_bitmapwidth( &bm );
src_size.y = _wpi_bitmapheight( &bm );
DPtoLP( pres, &src_size, 1 );
src_org.x = 0;
src_org.y = 0;
DPtoLP( pres, &src_org, 1 );
#if defined(__NT__) || defined(__WINDOWS__)
SetStretchBltMode( pres, COLORONCOLOR );
#else
SetStretchBltMode( pres, STRETCH_DELETESCANS );
#endif
/*
* If it's a monochrome bitmap try and do the right thing - I can see
* this pissing off some users, but oh well.
*/
if( _wpi_bitmapbitcount( &bm ) == 1 && _wpi_bitmapplanes( &bm ) == 1 ) {
old_brush = _wpi_selectobject( pres, blackBrush );
_wpi_stretchblt( pres, dst_org.x, dst_org.y, dst_size.x, dst_size.y,
mempres, src_org.x, src_org.y, src_size.x, src_size.y, 0xb8074a );
_wpi_getoldbitmap( mempres, old_bmp );
_wpi_selectobject( pres, old_brush );
} else {
_wpi_stretchblt( pres, dst_org.x, dst_org.y, dst_size.x, dst_size.y,
mempres, src_org.x, src_org.y, src_size.x, src_size.y, SRCCOPY );
_wpi_getoldbitmap( mempres, old_bmp );
}
_wpi_deletecompatiblepres( mempres, memdc );
} /* toolBarDrawBitmap */
/*
* drawButton - draw a button on the toolbar
*/
static void drawButton( HWND hwnd, tool *tool, BOOL down,
WPI_PRES pres, WPI_PRES mempres, HDC mem )
{
toolbar *bar;
HBRUSH brush;
HBITMAP bitmap, oldbmp;
int shift;
BOOL selected;
WPI_POINT dst_size;
WPI_POINT dst_org;
HBITMAP used_bmp;
TOOLBR_DIM left;
TOOLBR_DIM right;
TOOLBR_DIM top;
TOOLBR_DIM bottom;
BOOL delete_pres;
BOOL delete_mempres;
#if defined(__NT__) || defined(__WINDOWS__)
HBITMAP bitmap2, oldbmp2 , bmptmp;
HDC mem2;
COLORREF cr;
#endif
if( tool->flags & ITEM_BLANK ) {
return;
}
/* draw the button */
bar = GET_INFO( hwnd );
if( tool->flags & ITEM_STICKY ) {
selected = (tool->state == BUTTON_DOWN);
} else {
selected = down;
}
shift = 0;
if( selected ) {
shift = 2*BORDER_WIDTH( bar );
}
delete_pres = FALSE;
delete_mempres = FALSE;
if( pres == NULLHANDLE ) {
pres = _wpi_getpres( hwnd );
mempres = NULLHANDLE;
delete_pres = TRUE;
}
if( ( mempres == NULLHANDLE ) || ( mem == NULLHANDLE ) ) {
mempres = _wpi_createcompatiblepres( pres, appInst, &mem );
delete_mempres = TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -