Changeset 407 for trunk/src


Ignore:
Timestamp:
Aug 3, 1999, 11:22:34 PM (26 years ago)
Author:
sandervl
Message:

DrawState & DrawTextEx ported by Rene Pronk

Location:
trunk/src/user32
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/new/uitools.cpp

    r300 r407  
    1 /* $Id: uitools.cpp,v 1.1 1999-07-14 08:35:36 sandervl Exp $ */
     1/* $Id: uitools.cpp,v 1.2 1999-08-03 21:22:34 sandervl Exp $ */
    22/*
    33 * User Interface Functions
     
    77 * Copyright 1999 Achim Hasenmueller
    88 * Copyright 1999 Christoph Bratschi
     9 * Copyright 1999 Rene Pronk
    910 */
    1011
     
    13741375    return FALSE;
    13751376}
     1377
     1378
     1379/*****************************************************************************
     1380 * Name      : int WIN32API DrawTextExA
     1381 * Purpose   : The DrawTextEx function draw the text in the rectangle
     1382 * Parameters:
     1383 * Variables :
     1384 * Result    : If the function succeeds, the return value is the height of the
     1385 *             text, otherwise zero.
     1386 * Remark    : TODO: Returned number of characters is always the entire string
     1387 *             since there is no way to know the real answer this way.
     1388 * Status    : PARTIALLY IMPLEMENTED AND TESTED
     1389 *
     1390 * Author    : Rene Pronk [Thu, 1999/07/29 15:03]
     1391 *****************************************************************************/
     1392
     1393int WIN32API DrawTextExA (HDC hdc, LPTSTR lpchText, int cchText, LPRECT lprc,
     1394                          UINT dwDTFormat, LPDRAWTEXTPARAMS lpDTParams) {
     1395
     1396   int result;
     1397
     1398   dprintf(("USER32:DrawTextExA (%08xh,%s,%08xh,%08xh,%08xh,%08xh).\n",
     1399            hdc, lpchText, cchText, lprc, dwDTFormat, lpDTParams));
     1400
     1401   if (lpDTParams != NULL) {
     1402           // 'create' margins
     1403           lprc->left += lpDTParams->iLeftMargin;
     1404           lprc->right -= lpDTParams->iRightMargin;
     1405
     1406           // just assume all the text has been drawn
     1407           if (cchText != -1)
     1408                   lpDTParams->uiLengthDrawn = cchText;
     1409           else {
     1410                   // determine string length
     1411                   int size = 0;
     1412                   while ((BYTE) *(lpchText + size) != 0)
     1413                           size ++;
     1414                   lpDTParams->uiLengthDrawn = size;
     1415           }
     1416   }
     1417
     1418   result = DrawTextA (hdc, lpchText, cchText, lprc, dwDTFormat);
     1419
     1420   if (lpDTParams != NULL) {
     1421           // don't forget to restore the margins
     1422           lprc->left -= lpDTParams->iLeftMargin;
     1423           lprc->right += lpDTParams->iRightMargin;
     1424   }
     1425
     1426   return result;
     1427}
     1428
     1429
     1430
     1431/*****************************************************************************
     1432 * Name      : int WIN32API DrawTextExW
     1433 * Purpose   : The DrawTextEx function draw the text in the rectangle
     1434 * Parameters:
     1435 * Variables :
     1436 * Result    : If the function succeeds, the return value is the height of the
     1437 *             text, otherwise zero.
     1438 * Remark    : TODO: Returned number of characters is always the entire string
     1439 *             since there is no way to know the real answer this way.
     1440 * Status    : PARTIALLY IMPLEMENTED AND TESTED
     1441 *
     1442 * Author    : Rene Pronk [Thu, 1999/07/29 15:03]
     1443 *****************************************************************************/
     1444
     1445int WIN32API DrawTextExW (HDC hdc, LPTSTR lpchText, int cchText, LPRECT lprc,
     1446                          UINT dwDTFormat, LPDRAWTEXTPARAMS lpDTParams) {
     1447
     1448   char *astring = UnicodeToAsciiString((LPWSTR)lpchText);
     1449   int   rc;
     1450
     1451   dprintf(("USER32:DrawTextExW (%08xh,%s,%08xh,%08xh,%08xh,%08xh).\n",
     1452            hdc, astring, cchText, lprc, dwDTFormat, lpDTParams));
     1453
     1454   rc = DrawTextExA (hdc, astring, cchText, lprc, dwDTFormat, lpDTParams);
     1455   FreeAsciiString(astring);
     1456   return(rc);
     1457}
     1458
     1459
     1460/******************************************************************************
     1461 *
     1462 * This function is used by Paint_DrawState which is inturn used by both
     1463 * DrawStateA and DrawStateW. The code is directly borrowed from Wine.
     1464 *
     1465 ******************************************************************************/
     1466
     1467static BOOL Paint_DrawStateJam(HDC hdc, UINT opcode,
     1468                               DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
     1469                               LPRECT rc, UINT dtflags, BOOL unicode)
     1470{
     1471    HDC memdc;
     1472    HBITMAP hbmsave;
     1473    BOOL retval;
     1474    INT cx = rc->right - rc->left;
     1475    INT cy = rc->bottom - rc->top;
     1476
     1477    switch(opcode)
     1478    {
     1479    case DST_TEXT:
     1480    case DST_PREFIXTEXT:
     1481        if(unicode)
     1482            return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
     1483        else
     1484            return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
     1485
     1486    case DST_ICON:
     1487        return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
     1488
     1489    case DST_BITMAP:
     1490        memdc = CreateCompatibleDC(hdc);
     1491        if(!memdc) return FALSE;
     1492        hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
     1493        if(!hbmsave)
     1494        {
     1495            DeleteDC(memdc);
     1496            return FALSE;
     1497        }
     1498        retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
     1499        SelectObject(memdc, hbmsave);
     1500        DeleteDC(memdc);
     1501        return retval;
     1502
     1503    case DST_COMPLEX:
     1504        if(func)
     1505            return func(hdc, lp, wp, cx, cy);
     1506        else
     1507            return FALSE;
     1508    }
     1509    return FALSE;
     1510}
     1511
     1512
     1513/******************************************************************************
     1514 *
     1515 * This function is used by both DrawStateA and DrawStateW. The code is directly
     1516 * borrowed from Wine
     1517 *
     1518 ******************************************************************************/
     1519BOOL Paint_DrawState (HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
     1520                      INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode)
     1521{
     1522    HBITMAP hbm, hbmsave;
     1523    HFONT hfsave;
     1524    HBRUSH hbsave;
     1525    HDC memdc;
     1526    RECT rc;
     1527    UINT dtflags = DT_NOCLIP;
     1528    COLORREF fg, bg;
     1529    UINT opcode = flags & 0xf;
     1530    INT len = wp;
     1531    BOOL retval, tmp;
     1532
     1533    if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len)    /* The string is '\0' terminated */
     1534    {
     1535        if(unicode)
     1536            len = lstrlenW((LPWSTR)lp);
     1537        else
     1538            len = lstrlenA((LPSTR)lp);
     1539   }
     1540
     1541    /* Find out what size the image has if not given by caller */
     1542    if(!cx || !cy)
     1543    {
     1544        SIZE s;
     1545        BITMAP bmp;
     1546
     1547        switch(opcode)
     1548        {
     1549        case DST_TEXT:
     1550        case DST_PREFIXTEXT:
     1551            if(unicode)
     1552                retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
     1553            else
     1554                retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
     1555            if(!retval) return FALSE;
     1556            break;
     1557
     1558        case DST_ICON:
     1559            /* Just assume the icon has the size given by GetSystemMetrics. This should be
     1560               valid since both CreateIcon and LoadIcon can't create icons with different
     1561               sizes. I wouldn't how else to get the size of the icon. RP
     1562            */
     1563            s.cx = GetSystemMetrics (SM_CXICON);
     1564            s.cy = GetSystemMetrics (SM_CYICON);
     1565            break;
     1566
     1567        case DST_BITMAP:
     1568            retval = GetObjectA ((HBITMAP) lp, sizeof (BITMAP), &bmp);
     1569            if(retval == 0) return FALSE;
     1570            s.cx = bmp.bmWidth;
     1571            s.cy = bmp.bmHeight;
     1572            break;
     1573
     1574        case DST_COMPLEX: /* cx and cy must be set in this mode */
     1575            return FALSE;
     1576        }
     1577
     1578        if(!cx) cx = s.cx;
     1579        if(!cy) cy = s.cy;
     1580    }
     1581
     1582    rc.left   = x;
     1583    rc.top    = y;
     1584    rc.right  = x + cx;
     1585    rc.bottom = y + cy;
     1586
     1587    if(flags & DSS_RIGHT)    /* This one is not documented in the win32.hlp file */
     1588        dtflags |= DT_RIGHT;
     1589    if(opcode == DST_TEXT)
     1590        dtflags |= DT_NOPREFIX;
     1591
     1592    /* For DSS_NORMAL we just jam in the image and return */
     1593    if((flags & 0x7ff0) == DSS_NORMAL)
     1594    {
     1595        return Paint_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
     1596    }
     1597
     1598    /* For all other states we need to convert the image to B/W in a local bitmap */
     1599    /* before it is displayed */
     1600    fg = SetTextColor(hdc, RGB(0, 0, 0));
     1601    bg = SetBkColor(hdc, RGB(255, 255, 255));
     1602    hbm = (HBITMAP)NULL; hbmsave = (HBITMAP)NULL;
     1603    memdc = (HDC)NULL; hbsave = (HBRUSH)NULL;
     1604    retval = FALSE; /* assume failure */
     1605
     1606    /* From here on we must use "goto cleanup" when something goes wrong */
     1607    hbm     = CreateBitmap(cx, cy, 1, 1, NULL);
     1608    if(!hbm) goto cleanup;
     1609    memdc   = CreateCompatibleDC(hdc);
     1610    if(!memdc) goto cleanup;
     1611    hbmsave = (HBITMAP)SelectObject(memdc, hbm);
     1612    if(!hbmsave) goto cleanup;
     1613    rc.left = rc.top = 0;
     1614    rc.right = cx;
     1615    rc.bottom = cy;
     1616    if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
     1617    SetBkColor(memdc, RGB(255, 255, 255));
     1618    SetTextColor(memdc, RGB(0, 0, 0));
     1619    hfsave  = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
     1620    if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
     1621    tmp = Paint_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
     1622    if(hfsave) SelectObject(memdc, hfsave);
     1623    if(!tmp) goto cleanup;
     1624
     1625    /* These states cause the image to be dithered */
     1626    if(flags & (DSS_UNION|DSS_DISABLED))
     1627    {
     1628        WORD wPattern55AA[] = { 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa };
     1629        HBITMAP hPattern55AABitmap = CreateBitmap( 8, 8, 1, 1, wPattern55AA );
     1630        HBRUSH hPattern55AABrush = CreatePatternBrush(hPattern55AABitmap);
     1631
     1632        hbsave = (HBRUSH)SelectObject(memdc, hPattern55AABrush);
     1633        if(!hbsave) goto cleanup;
     1634        tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
     1635        if(hbsave) SelectObject(memdc, hbsave);
     1636        if(!tmp) goto cleanup;
     1637    }
     1638
     1639    hbsave = (HBRUSH)SelectObject(hdc, hbr ? hbr : GetStockObject(WHITE_BRUSH));
     1640    if(!hbsave) goto cleanup;
     1641
     1642    if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
     1643
     1644    /* DSS_DEFAULT makes the image boldface */
     1645    if(flags & DSS_DEFAULT)
     1646    {
     1647        if(!BitBlt(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
     1648    }
     1649
     1650    retval = TRUE; /* We succeeded */
     1651
     1652cleanup:
     1653    SetTextColor(hdc, fg);
     1654    SetBkColor(hdc, bg);
     1655
     1656    if(hbsave)  SelectObject(hdc, hbsave);
     1657    if(hbmsave) SelectObject(memdc, hbmsave);
     1658    if(hbm)     DeleteObject(hbm);
     1659    if(memdc)   DeleteDC(memdc);
     1660
     1661    return retval;
     1662}
     1663
     1664
     1665
     1666/*****************************************************************************
     1667 * Name      : BOOL WIN32API DrawStateA
     1668 * Purpose   : Draws a bitmap, icon, text or complex object in one of the following
     1669 *             states: normal, disabled, union or mono
     1670 * Parameters:
     1671 * Variables :
     1672 * Result    : If the function succeeds, the return value is a handle of the
     1673 *               window station associated with the calling process.
     1674 *             If the function fails, the return value is NULL. This can occur
     1675 *               if the calling process is not an application written for Windows
     1676 *               NT. To get extended error information, call GetLastError.
     1677 * Remark    : Disabled doesn't look like the Windows implementation, but it does
     1678 *             look disabled.
     1679 * Status    : PARTIALLY IMPLEMENTED
     1680 *
     1681 * Author    : Rene Pronk [Sun, 1999/07/25 21:27]
     1682 *****************************************************************************/
     1683
     1684BOOL WIN32API DrawStateA(HDC hdc, HBRUSH hbc, DRAWSTATEPROC lpOutputFunc, LPARAM lData,
     1685                         WPARAM wData, int x, int y, int cx, int cy, UINT fuFlags)
     1686{
     1687  dprintf(("USER32:DrawStateA (%08xh,%08xh,%08xh,%08xh,%08xh,%d,%d,%d,%d,%08x).\n",
     1688         hdc, hbc, lpOutputFunc, lData, wData, x, y, cx, cy, fuFlags));
     1689
     1690  return Paint_DrawState (hdc, hbc, lpOutputFunc, lData, wData, x, y ,cx, cy, fuFlags, FALSE);
     1691}
     1692
     1693
     1694
     1695/*****************************************************************************
     1696 * Name      : BOOL WIN32API DrawStateW
     1697 * Purpose   : Draws a bitmap, icon, text or complex object in one of the following
     1698 *             states: normal, disabled, union or mono
     1699 * Parameters:
     1700 * Variables :
     1701 * Result    : If the function succeeds, the return value is a handle of the
     1702 *               window station associated with the calling process.
     1703 *             If the function fails, the return value is NULL. This can occur
     1704 *               if the calling process is not an application written for Windows
     1705 *               NT. To get extended error information, call GetLastError.
     1706 * Remark    : Disabled doesn't look like the Windows implementation, but it does
     1707 *             look disabled.
     1708 * Status    : PARTIALLY IMPLEMENTED
     1709 *
     1710 * Author    : Rene Pronk [Sun, 1999/07/25 21:27]
     1711 *****************************************************************************/
     1712
     1713BOOL WIN32API DrawStateW(HDC hdc, HBRUSH hbc, DRAWSTATEPROC lpOutputFunc, LPARAM lData,
     1714                         WPARAM wData, int x, int y, int cx, int cy, UINT fuFlags)
     1715{
     1716  dprintf(("USER32:DrawStateW (%08xh,%08xh,%08xh,%08xh,%08xh,%d,%d,%d,%d,%08x).\n",
     1717         hdc, hbc, lpOutputFunc, lData, wData, x, y, cx, cy, fuFlags));
     1718
     1719  return Paint_DrawState (hdc, hbc, lpOutputFunc, lData, wData, x, y ,cx, cy, fuFlags, TRUE);
     1720}
    13761721//******************************************************************************
    13771722//******************************************************************************
     
    14281773//******************************************************************************
    14291774//******************************************************************************
    1430 int WIN32API DrawTextExW(HDC arg1, LPCWSTR arg2, int arg3, PRECT arg4, UINT arg5, LPDRAWTEXTPARAMS lpDTParams)
    1431 {
    1432  char *astring = UnicodeToAsciiString((LPWSTR)arg2);
    1433  int   rc;
    1434 
    1435 #ifdef DEBUG
    1436     WriteLog("USER32:  DrawTextExW (not completely supported) %s\n", astring);
    1437 #endif
    1438     rc = O32_DrawText(arg1, astring, arg3, arg4, arg5);
    1439     FreeAsciiString(astring);
    1440     return(rc);
    1441 }
    1442 //******************************************************************************
    1443 //******************************************************************************
    14441775int WIN32API DrawTextA(HDC arg1, LPCSTR arg2, int arg3, PRECT arg4, UINT arg5)
    14451776{
     
    14481779#endif
    14491780    return O32_DrawText(arg1, arg2, arg3, arg4, arg5);
    1450 }
    1451 //******************************************************************************
    1452 //******************************************************************************
    1453 int WIN32API DrawTextExA(HDC arg1, LPCSTR arg2, int arg3, PRECT arg4, UINT arg5, LPDRAWTEXTPARAMS lpDTParams)
    1454 {
    1455 #ifdef DEBUG
    1456     WriteLog("USER32:  DrawTextExA (not completely implemented) %s", arg2);
    1457 #endif
    1458     return O32_DrawText(arg1, arg2, arg3, arg4, arg5);
    1459 }
    1460 //******************************************************************************
    1461 //******************************************************************************
    1462 BOOL WIN32API DrawStateA(HDC hdc, HBRUSH hbc, DRAWSTATEPROC lpOutputFunc,
    1463                 LPARAM lData, WPARAM wData, int x, int y, int cx,
    1464                 int cy, UINT fuFlags)
    1465 {
    1466 #ifdef DEBUG
    1467   WriteLog("USER32:  DrawStateA, not implemented\n");
    1468 #endif
    1469   return(TRUE);
    14701781}
    14711782/*****************************************************************************
     
    15321843  return FALSE;
    15331844}
    1534 
    1535 
    1536 /*****************************************************************************
    1537  * Name      :
    1538  * Purpose   :
    1539  * Parameters:
    1540  * Variables :
    1541  * Result    :
    1542  * Remark    :
    1543  * Status    : UNTESTED STUB
    1544  *
    1545  * Author    : Patrick Haller [Thu, 1998/02/26 11:55]
    1546  *****************************************************************************/
    1547 
    1548 BOOL WIN32API DrawStateW(HDC           hdc,
    1549                          HBRUSH        hBrush,
    1550                          DRAWSTATEPROC lpOutputFunc,
    1551                          LPARAM        lParam,
    1552                          WPARAM        wParam,
    1553                          int           x,
    1554                          int           y,
    1555                          int           cx,
    1556                          int           cy,
    1557                          UINT          fuFlags)
    1558 {
    1559   dprintf(("USER32:DrawStateW (%08xh,%08xh,%08xh,%08xh,%08xh,%d,%d,%d,%d,%08x) not implemented.\n",
    1560          hdc,
    1561          hBrush,
    1562          lpOutputFunc,
    1563          lParam,
    1564          wParam,
    1565          x,
    1566          y,
    1567          cx,
    1568          cy,
    1569          fuFlags));
    1570 
    1571   return(DrawStateA(hdc,
    1572                     hBrush,
    1573                     lpOutputFunc,
    1574                     lParam,
    1575                     wParam,
    1576                     x,
    1577                     y,
    1578                     cx,
    1579                     cy,
    1580                     fuFlags));
    1581 }
    15821845/***********************************************************************
    15831846 * DrawCaptionTemp32A [USER32.599]
  • trunk/src/user32/uitools.cpp

    r221 r407  
    1 /* $Id: uitools.cpp,v 1.3 1999-06-26 15:29:11 achimha Exp $ */
     1/* $Id: uitools.cpp,v 1.4 1999-08-03 21:22:33 sandervl Exp $ */
    22/*
    33 * User Interface Functions
     
    77 * Copyright 1999 Achim Hasenmueller
    88 * Copyright 1999 Christoph Bratschi
     9 * Copyright 1999 Rene Pronk
    910 */
    1011
     
    13741375    return FALSE;
    13751376}
     1377
     1378
     1379/*****************************************************************************
     1380 * Name      : int WIN32API DrawTextExA
     1381 * Purpose   : The DrawTextEx function draw the text in the rectangle
     1382 * Parameters:
     1383 * Variables :
     1384 * Result    : If the function succeeds, the return value is the height of the
     1385 *             text, otherwise zero.
     1386 * Remark    : TODO: Returned number of characters is always the entire string
     1387 *             since there is no way to know the real answer this way.
     1388 * Status    : PARTIALLY IMPLEMENTED AND TESTED
     1389 *
     1390 * Author    : Rene Pronk [Thu, 1999/07/29 15:03]
     1391 *****************************************************************************/
     1392
     1393int WIN32API DrawTextExA (HDC hdc, LPTSTR lpchText, int cchText, LPRECT lprc,
     1394                          UINT dwDTFormat, LPDRAWTEXTPARAMS lpDTParams) {
     1395
     1396   int result;
     1397
     1398   dprintf(("USER32:DrawTextExA (%08xh,%s,%08xh,%08xh,%08xh,%08xh).\n",
     1399            hdc, lpchText, cchText, lprc, dwDTFormat, lpDTParams));
     1400
     1401   if (lpDTParams != NULL) {
     1402           // 'create' margins
     1403           lprc->left += lpDTParams->iLeftMargin;
     1404           lprc->right -= lpDTParams->iRightMargin;
     1405
     1406           // just assume all the text has been drawn
     1407           if (cchText != -1)
     1408                   lpDTParams->uiLengthDrawn = cchText;
     1409           else {
     1410                   // determine string length
     1411                   int size = 0;
     1412                   while ((BYTE) *(lpchText + size) != 0)
     1413                           size ++;
     1414                   lpDTParams->uiLengthDrawn = size;
     1415           }
     1416   }
     1417
     1418   result = DrawTextA (hdc, lpchText, cchText, lprc, dwDTFormat);
     1419
     1420   if (lpDTParams != NULL) {
     1421           // don't forget to restore the margins
     1422           lprc->left -= lpDTParams->iLeftMargin;
     1423           lprc->right += lpDTParams->iRightMargin;
     1424   }
     1425
     1426   return result;
     1427}
     1428
     1429
     1430
     1431/*****************************************************************************
     1432 * Name      : int WIN32API DrawTextExW
     1433 * Purpose   : The DrawTextEx function draw the text in the rectangle
     1434 * Parameters:
     1435 * Variables :
     1436 * Result    : If the function succeeds, the return value is the height of the
     1437 *             text, otherwise zero.
     1438 * Remark    : TODO: Returned number of characters is always the entire string
     1439 *             since there is no way to know the real answer this way.
     1440 * Status    : PARTIALLY IMPLEMENTED AND TESTED
     1441 *
     1442 * Author    : Rene Pronk [Thu, 1999/07/29 15:03]
     1443 *****************************************************************************/
     1444
     1445int WIN32API DrawTextExW (HDC hdc, LPTSTR lpchText, int cchText, LPRECT lprc,
     1446                          UINT dwDTFormat, LPDRAWTEXTPARAMS lpDTParams) {
     1447
     1448   char *astring = UnicodeToAsciiString((LPWSTR)lpchText);
     1449   int   rc;
     1450
     1451   dprintf(("USER32:DrawTextExW (%08xh,%s,%08xh,%08xh,%08xh,%08xh).\n",
     1452            hdc, astring, cchText, lprc, dwDTFormat, lpDTParams));
     1453
     1454   rc = DrawTextExA (hdc, astring, cchText, lprc, dwDTFormat, lpDTParams);
     1455   FreeAsciiString(astring);
     1456   return(rc);
     1457}
     1458
     1459
     1460/******************************************************************************
     1461 *
     1462 * This function is used by Paint_DrawState which is inturn used by both
     1463 * DrawStateA and DrawStateW. The code is directly borrowed from Wine.
     1464 *
     1465 ******************************************************************************/
     1466
     1467static BOOL Paint_DrawStateJam(HDC hdc, UINT opcode,
     1468                               DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
     1469                               LPRECT rc, UINT dtflags, BOOL unicode)
     1470{
     1471    HDC memdc;
     1472    HBITMAP hbmsave;
     1473    BOOL retval;
     1474    INT cx = rc->right - rc->left;
     1475    INT cy = rc->bottom - rc->top;
     1476
     1477    switch(opcode)
     1478    {
     1479    case DST_TEXT:
     1480    case DST_PREFIXTEXT:
     1481        if(unicode)
     1482            return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
     1483        else
     1484            return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
     1485
     1486    case DST_ICON:
     1487        return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
     1488
     1489    case DST_BITMAP:
     1490        memdc = CreateCompatibleDC(hdc);
     1491        if(!memdc) return FALSE;
     1492        hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
     1493        if(!hbmsave)
     1494        {
     1495            DeleteDC(memdc);
     1496            return FALSE;
     1497        }
     1498        retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
     1499        SelectObject(memdc, hbmsave);
     1500        DeleteDC(memdc);
     1501        return retval;
     1502
     1503    case DST_COMPLEX:
     1504        if(func)
     1505            return func(hdc, lp, wp, cx, cy);
     1506        else
     1507            return FALSE;
     1508    }
     1509    return FALSE;
     1510}
     1511
     1512
     1513/******************************************************************************
     1514 *
     1515 * This function is used by both DrawStateA and DrawStateW. The code is directly
     1516 * borrowed from Wine
     1517 *
     1518 ******************************************************************************/
     1519BOOL Paint_DrawState (HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
     1520                      INT x, INT y, INT cx, INT cy, UINT flags, BOOL unicode)
     1521{
     1522    HBITMAP hbm, hbmsave;
     1523    HFONT hfsave;
     1524    HBRUSH hbsave;
     1525    HDC memdc;
     1526    RECT rc;
     1527    UINT dtflags = DT_NOCLIP;
     1528    COLORREF fg, bg;
     1529    UINT opcode = flags & 0xf;
     1530    INT len = wp;
     1531    BOOL retval, tmp;
     1532
     1533    if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len)    /* The string is '\0' terminated */
     1534    {
     1535        if(unicode)
     1536            len = lstrlenW((LPWSTR)lp);
     1537        else
     1538            len = lstrlenA((LPSTR)lp);
     1539   }
     1540
     1541    /* Find out what size the image has if not given by caller */
     1542    if(!cx || !cy)
     1543    {
     1544        SIZE s;
     1545        BITMAP bmp;
     1546
     1547        switch(opcode)
     1548        {
     1549        case DST_TEXT:
     1550        case DST_PREFIXTEXT:
     1551            if(unicode)
     1552                retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
     1553            else
     1554                retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
     1555            if(!retval) return FALSE;
     1556            break;
     1557
     1558        case DST_ICON:
     1559            /* Just assume the icon has the size given by GetSystemMetrics. This should be
     1560               valid since both CreateIcon and LoadIcon can't create icons with different
     1561               sizes. I wouldn't how else to get the size of the icon. RP
     1562            */
     1563            s.cx = GetSystemMetrics (SM_CXICON);
     1564            s.cy = GetSystemMetrics (SM_CYICON);
     1565            break;
     1566
     1567        case DST_BITMAP:
     1568            retval = GetObjectA ((HBITMAP) lp, sizeof (BITMAP), &bmp);
     1569            if(retval == 0) return FALSE;
     1570            s.cx = bmp.bmWidth;
     1571            s.cy = bmp.bmHeight;
     1572            break;
     1573
     1574        case DST_COMPLEX: /* cx and cy must be set in this mode */
     1575            return FALSE;
     1576        }
     1577
     1578        if(!cx) cx = s.cx;
     1579        if(!cy) cy = s.cy;
     1580    }
     1581
     1582    rc.left   = x;
     1583    rc.top    = y;
     1584    rc.right  = x + cx;
     1585    rc.bottom = y + cy;
     1586
     1587    if(flags & DSS_RIGHT)    /* This one is not documented in the win32.hlp file */
     1588        dtflags |= DT_RIGHT;
     1589    if(opcode == DST_TEXT)
     1590        dtflags |= DT_NOPREFIX;
     1591
     1592    /* For DSS_NORMAL we just jam in the image and return */
     1593    if((flags & 0x7ff0) == DSS_NORMAL)
     1594    {
     1595        return Paint_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode);
     1596    }
     1597
     1598    /* For all other states we need to convert the image to B/W in a local bitmap */
     1599    /* before it is displayed */
     1600    fg = SetTextColor(hdc, RGB(0, 0, 0));
     1601    bg = SetBkColor(hdc, RGB(255, 255, 255));
     1602    hbm = (HBITMAP)NULL; hbmsave = (HBITMAP)NULL;
     1603    memdc = (HDC)NULL; hbsave = (HBRUSH)NULL;
     1604    retval = FALSE; /* assume failure */
     1605
     1606    /* From here on we must use "goto cleanup" when something goes wrong */
     1607    hbm     = CreateBitmap(cx, cy, 1, 1, NULL);
     1608    if(!hbm) goto cleanup;
     1609    memdc   = CreateCompatibleDC(hdc);
     1610    if(!memdc) goto cleanup;
     1611    hbmsave = (HBITMAP)SelectObject(memdc, hbm);
     1612    if(!hbmsave) goto cleanup;
     1613    rc.left = rc.top = 0;
     1614    rc.right = cx;
     1615    rc.bottom = cy;
     1616    if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
     1617    SetBkColor(memdc, RGB(255, 255, 255));
     1618    SetTextColor(memdc, RGB(0, 0, 0));
     1619    hfsave  = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
     1620    if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
     1621    tmp = Paint_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode);
     1622    if(hfsave) SelectObject(memdc, hfsave);
     1623    if(!tmp) goto cleanup;
     1624
     1625    /* These states cause the image to be dithered */
     1626    if(flags & (DSS_UNION|DSS_DISABLED))
     1627    {
     1628        WORD wPattern55AA[] = { 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa };
     1629        HBITMAP hPattern55AABitmap = CreateBitmap( 8, 8, 1, 1, wPattern55AA );
     1630        HBRUSH hPattern55AABrush = CreatePatternBrush(hPattern55AABitmap);
     1631
     1632        hbsave = (HBRUSH)SelectObject(memdc, hPattern55AABrush);
     1633        if(!hbsave) goto cleanup;
     1634        tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
     1635        if(hbsave) SelectObject(memdc, hbsave);
     1636        if(!tmp) goto cleanup;
     1637    }
     1638
     1639    hbsave = (HBRUSH)SelectObject(hdc, hbr ? hbr : GetStockObject(WHITE_BRUSH));
     1640    if(!hbsave) goto cleanup;
     1641
     1642    if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
     1643
     1644    /* DSS_DEFAULT makes the image boldface */
     1645    if(flags & DSS_DEFAULT)
     1646    {
     1647        if(!BitBlt(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
     1648    }
     1649
     1650    retval = TRUE; /* We succeeded */
     1651
     1652cleanup:
     1653    SetTextColor(hdc, fg);
     1654    SetBkColor(hdc, bg);
     1655
     1656    if(hbsave)  SelectObject(hdc, hbsave);
     1657    if(hbmsave) SelectObject(memdc, hbmsave);
     1658    if(hbm)     DeleteObject(hbm);
     1659    if(memdc)   DeleteDC(memdc);
     1660
     1661    return retval;
     1662}
     1663
     1664
     1665
     1666/*****************************************************************************
     1667 * Name      : BOOL WIN32API DrawStateA
     1668 * Purpose   : Draws a bitmap, icon, text or complex object in one of the following
     1669 *             states: normal, disabled, union or mono
     1670 * Parameters:
     1671 * Variables :
     1672 * Result    : If the function succeeds, the return value is a handle of the
     1673 *               window station associated with the calling process.
     1674 *             If the function fails, the return value is NULL. This can occur
     1675 *               if the calling process is not an application written for Windows
     1676 *               NT. To get extended error information, call GetLastError.
     1677 * Remark    : Disabled doesn't look like the Windows implementation, but it does
     1678 *             look disabled.
     1679 * Status    : PARTIALLY IMPLEMENTED
     1680 *
     1681 * Author    : Rene Pronk [Sun, 1999/07/25 21:27]
     1682 *****************************************************************************/
     1683
     1684BOOL WIN32API DrawStateA(HDC hdc, HBRUSH hbc, DRAWSTATEPROC lpOutputFunc, LPARAM lData,
     1685                         WPARAM wData, int x, int y, int cx, int cy, UINT fuFlags)
     1686{
     1687  dprintf(("USER32:DrawStateA (%08xh,%08xh,%08xh,%08xh,%08xh,%d,%d,%d,%d,%08x).\n",
     1688         hdc, hbc, lpOutputFunc, lData, wData, x, y, cx, cy, fuFlags));
     1689
     1690  return Paint_DrawState (hdc, hbc, lpOutputFunc, lData, wData, x, y ,cx, cy, fuFlags, FALSE);
     1691}
     1692
     1693
     1694
     1695/*****************************************************************************
     1696 * Name      : BOOL WIN32API DrawStateW
     1697 * Purpose   : Draws a bitmap, icon, text or complex object in one of the following
     1698 *             states: normal, disabled, union or mono
     1699 * Parameters:
     1700 * Variables :
     1701 * Result    : If the function succeeds, the return value is a handle of the
     1702 *               window station associated with the calling process.
     1703 *             If the function fails, the return value is NULL. This can occur
     1704 *               if the calling process is not an application written for Windows
     1705 *               NT. To get extended error information, call GetLastError.
     1706 * Remark    : Disabled doesn't look like the Windows implementation, but it does
     1707 *             look disabled.
     1708 * Status    : PARTIALLY IMPLEMENTED
     1709 *
     1710 * Author    : Rene Pronk [Sun, 1999/07/25 21:27]
     1711 *****************************************************************************/
     1712
     1713BOOL WIN32API DrawStateW(HDC hdc, HBRUSH hbc, DRAWSTATEPROC lpOutputFunc, LPARAM lData,
     1714                         WPARAM wData, int x, int y, int cx, int cy, UINT fuFlags)
     1715{
     1716  dprintf(("USER32:DrawStateW (%08xh,%08xh,%08xh,%08xh,%08xh,%d,%d,%d,%d,%08x).\n",
     1717         hdc, hbc, lpOutputFunc, lData, wData, x, y, cx, cy, fuFlags));
     1718
     1719  return Paint_DrawState (hdc, hbc, lpOutputFunc, lData, wData, x, y ,cx, cy, fuFlags, TRUE);
     1720}
  • trunk/src/user32/user32.cpp

    r289 r407  
    1 /* $Id: user32.cpp,v 1.19 1999-07-11 21:11:57 sandervl Exp $ */
     1/* $Id: user32.cpp,v 1.20 1999-08-03 21:22:33 sandervl Exp $ */
    22
    33/*
     
    480480//******************************************************************************
    481481//******************************************************************************
    482 BOOL WIN32API GetClientRect( HWND arg1, PRECT  arg2)
    483 {
    484 #ifdef DEBUG
    485     WriteLog("USER32:  GetClientRect of %X\n", arg1);
    486 #endif
    487 
    488     return O32_GetClientRect(arg1, arg2);
     482BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
     483{
     484 BOOL rc;
     485
     486    rc = O32_GetClientRect(hwnd, pRect);
     487    dprintf(("USER32:  GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
     488    return rc;
    489489}
    490490//******************************************************************************
     
    678678#ifdef DEBUG
    679679    WriteLog("USER32: DrawTextA %s", arg2);
    680 #endif
    681     return O32_DrawText(arg1, arg2, arg3, arg4, arg5);
    682 }
    683 //******************************************************************************
    684 //******************************************************************************
    685 int WIN32API DrawTextExA(HDC arg1, LPCSTR arg2, int arg3, PRECT arg4, UINT arg5, LPDRAWTEXTPARAMS lpDTParams)
    686 {
    687 #ifdef DEBUG
    688     WriteLog("USER32:  DrawTextExA (not completely implemented) %s", arg2);
    689680#endif
    690681    return O32_DrawText(arg1, arg2, arg3, arg4, arg5);
     
    791782        break;
    792783    }
    793 #ifdef DEBUG
    794     WriteLog("USER32:  GetSystemMetrics %d returned %d\n", arg1, rc);
    795 #endif
     784    dprintf(("USER32:  GetSystemMetrics %d returned %d\n", arg1, rc));
    796785    return(rc);
    797786}
     
    17211710#ifdef DEBUG
    17221711    WriteLog("USER32:  DrawTextW %s\n", astring);
    1723 #endif
    1724     rc = O32_DrawText(arg1, astring, arg3, arg4, arg5);
    1725     FreeAsciiString(astring);
    1726     return(rc);
    1727 }
    1728 //******************************************************************************
    1729 //******************************************************************************
    1730 int WIN32API DrawTextExW(HDC arg1, LPCWSTR arg2, int arg3, PRECT arg4, UINT arg5, LPDRAWTEXTPARAMS lpDTParams)
    1731 {
    1732  char *astring = UnicodeToAsciiString((LPWSTR)arg2);
    1733  int   rc;
    1734 
    1735 #ifdef DEBUG
    1736     WriteLog("USER32:  DrawTextExW (not completely supported) %s\n", astring);
    17371712#endif
    17381713    rc = O32_DrawText(arg1, astring, arg3, arg4, arg5);
     
    35243499//******************************************************************************
    35253500//******************************************************************************
    3526 BOOL WIN32API DrawStateA(HDC hdc, HBRUSH hbc, DRAWSTATEPROC lpOutputFunc,
    3527                 LPARAM lData, WPARAM wData, int x, int y, int cx,
    3528                 int cy, UINT fuFlags)
    3529 {
    3530 #ifdef DEBUG
    3531   WriteLog("USER32:  DrawStateA, not implemented\n");
    3532 #endif
    3533   return(TRUE);
    3534 }
    3535 //******************************************************************************
    3536 //******************************************************************************
    35373501//******************************************************************************
    35383502//******************************************************************************
     
    41074071 *****************************************************************************/
    41084072
    4109 BOOL WIN32API DrawStateW(HDC           hdc,
    4110                          HBRUSH        hBrush,
    4111                          DRAWSTATEPROC lpOutputFunc,
    4112                          LPARAM        lParam,
    4113                          WPARAM        wParam,
    4114                          int           x,
    4115                          int           y,
    4116                          int           cx,
    4117                          int           cy,
    4118                          UINT          fuFlags)
    4119 {
    4120   dprintf(("USER32:DrawStateW (%08xh,%08xh,%08xh,%08xh,%08xh,%d,%d,%d,%d,%08x) not implemented.\n",
    4121          hdc,
    4122          hBrush,
    4123          lpOutputFunc,
    4124          lParam,
    4125          wParam,
    4126          x,
    4127          y,
    4128          cx,
    4129          cy,
    4130          fuFlags));
    4131 
    4132   return(DrawStateA(hdc,
    4133                     hBrush,
    4134                     lpOutputFunc,
    4135                     lParam,
    4136                     wParam,
    4137                     x,
    4138                     y,
    4139                     cx,
    4140                     cy,
    4141                     fuFlags));
    4142 }
    4143 
    4144 
    41454073/*****************************************************************************
    41464074 * Name      : BOOL WIN32API EnumDesktopWindows
Note: See TracChangeset for help on using the changeset viewer.