#include <WinTen.h>
#include <Windows.h>
#include <ClipApi.h>

#define FW_MEASURE  WM_USER+1031
#define FW_DRAW     WM_USER+1032

void DrawBitmap( HDC, HBITMAP, WORD, WORD, WORD, WORD, DWORD );

//----------------------------------------------------------------------------//

CLIPPER CtrlDraw()
{
   DRAWITEMSTRUCT * pDraw = ( DRAWITEMSTRUCT * ) _parnl( 1 );

   _retni( SendMessage( pDraw->hwndItem, FW_DRAW, 0, ( LONG ) pDraw ) );
}

//----------------------------------------------------------------------------//

CLIPPER LbxMeasure()
{
   LPMEASUREITEMSTRUCT pMeasure = ( LPMEASUREITEMSTRUCT ) _parnl( 1 );

   pMeasure->itemHeight = _parni( 2 );
   _retl( TRUE );
}

//----------------------------------------------------------------------------//

CLIPPER LbxDrawIte()  // m()      // LPDRAWITEMSTRUCT, aItems
{
   LPDRAWITEMSTRUCT pDraw = ( LPDRAWITEMSTRUCT ) _parnl( 1 );

   DrawBitmap( pDraw->hDC, _parni( 2, pDraw->itemID + 1 ),
               pDraw->rcItem.top, pDraw->rcItem.left, 0, 0, 0 );

   _retl( TRUE );
}

//----------------------------------------------------------------------------//

CLIPPER CTRLDRAWFO()  // CUS()      hWnd, nOriginRow, nOriginCol
{
   HWND hWnd = _parni( 1 );
   WORD wRow = _parni( 2 );
   WORD wCol = _parni( 3 );
   HWND hWndParent = GetParent( hWnd );
   HDC hDC   = GetDC( hWndParent );
   RECT rct;
   POINT pt;

   GetWindowRect( hWnd, &rct );

   rct.bottom += wRow + 1;
   rct.right  += wCol + 1;
   rct.top    += wRow;
   rct.left   += wCol;

   pt.x = rct.left;
   pt.y = rct.top;

   ScreenToClient( hWndParent, &pt );
   rct.left = pt.x - 1;
   rct.top  = pt.y - 1;
   pt.x     = rct.right;
   pt.y     = rct.bottom;

   ScreenToClient( hWndParent, &pt );
   rct.right  = pt.x;
   rct.bottom = pt.y;

   DrawFocusRect( hDC, &rct );
   ReleaseDC( hWndParent, hDC );
}

//----------------------------------------------------------------------------//
