Example #1
0
void TooltipGetSize(PTOOLTIPWND pttwnd, SIZE *psize)
{
    HDC hdc = GetTooltipDC(pttwnd);
    GreGetTextExtentW(hdc, pttwnd->pstr, wcslen(pttwnd->pstr),
            psize, GGTE_WIN3_EXTENT);
    _ReleaseDC(hdc);
    psize->cx += SYSMET(CXEDGE) + 2 * SYSMET(CXBORDER) * TT_XOFFSET;
    psize->cy += SYSMET(CYEDGE) + 2 * SYSMET(CYBORDER) * TT_YOFFSET;
}
Example #2
0
File: font.c Project: GYGit/reactos
DWORD
FASTCALL
GreGetCharacterPlacementW(
    HDC hdc,
    LPCWSTR pwsz,
    INT nCount,
    INT nMaxExtent,
    LPGCP_RESULTSW pgcpw,
    DWORD dwFlags)
{
  GCP_RESULTSW gcpwSave;
  UINT i, nSet, cSet;
  INT *tmpDxCaretPos;
  LONG Cx;
  SIZE Size = {0,0};

  DPRINT1("GreGCPW Start\n");

   if (!pgcpw)
   {
      if (GreGetTextExtentW( hdc, pwsz, nCount, &Size, 1))
         return MAKELONG(Size.cx, Size.cy);
      return 0;
   }

  DPRINT1("GreGCPW 1\n");

  RtlCopyMemory(&gcpwSave, pgcpw, sizeof(GCP_RESULTSW));

  cSet = nSet = nCount;

  if ( nCount > gcpwSave.nGlyphs ) cSet = gcpwSave.nGlyphs;

  /* GCP_JUSTIFY may only be used in conjunction with GCP_MAXEXTENT. */
  if ( dwFlags & GCP_JUSTIFY) dwFlags |= GCP_MAXEXTENT;

  if ( !gcpwSave.lpDx && gcpwSave.lpCaretPos )
     tmpDxCaretPos = gcpwSave.lpCaretPos;
  else
     tmpDxCaretPos = gcpwSave.lpDx;

  if ( !GreGetTextExtentExW( hdc,
                             pwsz,
                             cSet,
                             nMaxExtent,
                            ((dwFlags & GCP_MAXEXTENT) ? (PULONG) &cSet : NULL),
                            (PULONG) tmpDxCaretPos,
                             &Size,
                             0) )
  {
     return 0;
  }

  DPRINT1("GreGCPW 2\n");

  nSet = cSet;

  if ( tmpDxCaretPos && nSet > 0)
  {
      for (i = (nSet - 1); i > 0; i--)
      {
          tmpDxCaretPos[i] -= tmpDxCaretPos[i - 1];
      }
  }

  if ( !(dwFlags & GCP_MAXEXTENT) || nSet )
  {
     if ( (dwFlags & GCP_USEKERNING) &&
           ( gcpwSave.lpDx ||
             gcpwSave.lpCaretPos ) &&
           nSet >= 2 )
     {
        DWORD Count;
        LPKERNINGPAIR pKP;

        Count = GreGetKerningPairs( hdc, 0, NULL);
        if (Count)
        {
           pKP = ExAllocatePoolWithTag(PagedPool, Count * sizeof(KERNINGPAIR), GDITAG_TEXT);
           if (pKP)
           {
              if ( GreGetKerningPairs( hdc, Count, pKP) != Count)
              {
                 ExFreePoolWithTag( pKP, GDITAG_TEXT);
                 return 0;
              }

              if ( (ULONG_PTR)(pKP) < ((ULONG_PTR)(pKP) + (ULONG_PTR)(Count * sizeof(KERNINGPAIR))) )
              {
                 DPRINT1("We Need to Do Something HERE!\n");
              }

              ExFreePoolWithTag( pKP, GDITAG_TEXT);

              if ( dwFlags & GCP_MAXEXTENT )
              {
                 if ( Size.cx > nMaxExtent )
                 {
                    for (Cx = Size.cx; nSet > 0; nSet--)
                    {
                        Cx -= tmpDxCaretPos[nSet - 1];
                        Size.cx = Cx;
                        if ( Cx <= nMaxExtent ) break;
                    }
                 }
                 if ( !nSet )
                 {
                    pgcpw->nGlyphs = 0;
                    pgcpw->nMaxFit = 0;
                    return 0;
                 }
              }
           }
        }
     }

     if ( (dwFlags & GCP_JUSTIFY) &&
           ( gcpwSave.lpDx ||
             gcpwSave.lpCaretPos ) &&
           nSet )
     {
         DPRINT1("We Need to Do Something HERE 2!\n");
     }

     if ( gcpwSave.lpDx && gcpwSave.lpCaretPos )
        RtlCopyMemory( gcpwSave.lpCaretPos, gcpwSave.lpDx, nSet * sizeof(LONG));

     if ( gcpwSave.lpCaretPos )
     {
        int pos = 0;
        i = 0;
        if ( nSet > 0 )
        {
           do
           {
              Cx = gcpwSave.lpCaretPos[i];
              gcpwSave.lpCaretPos[i] = pos;
              pos += Cx;
              ++i;
           }
           while ( i < nSet );
        }
     }

     if ( gcpwSave.lpOutString )
        RtlCopyMemory(gcpwSave.lpOutString, pwsz,  nSet * sizeof(WCHAR));

     if ( gcpwSave.lpClass )
        RtlFillMemory(gcpwSave.lpClass, nSet, GCPCLASS_LATIN);

     if ( gcpwSave.lpOrder )
     {
        for (i = 0; i < nSet; i++)
           gcpwSave.lpOrder[i] = i;
     }

     if ( gcpwSave.lpGlyphs )
     {
        if ( GreGetGlyphIndicesW( hdc, pwsz, nSet, gcpwSave.lpGlyphs, 0, 0) == GDI_ERROR )
        {
           nSet = 0;
           Size.cx = 0;
           Size.cy = 0;
        }
     }
     pgcpw->nGlyphs = nSet;
     pgcpw->nMaxFit = nSet;
  }
  DPRINT1("GreGCPW Exit\n");
  return MAKELONG(Size.cx, Size.cy);
}
Example #3
0
BOOL
xxxDesktopPaintCallback(
    PMONITOR        pMonitor,
    HDC             hdc,
    LPRECT          lprcMonitorClip,
    LPARAM          dwData)
{
    BOOL            f;
    PWND            pwnd;

    CheckLock(pMonitor);

    pwnd = (PWND)dwData;


    if (**((PULONG *)&InitSafeBootMode)) {
        FillRect(hdc, lprcMonitorClip, ghbrBlack );
        f = TRUE;
    } else {
        /*
         * if this is the disconnected desktop, skip the bitmap paint
         */
        if (!gbDesktopLocked) {

            /*
             * Paint the desktop with a color or the wallpaper.
             */
            if (ghbmWallpaper) {
                f = xxxDrawWallpaper(
                        pwnd,
                        hdc,
                        pMonitor,
                        lprcMonitorClip);
            } else {
                FillRect(hdc, lprcMonitorClip, SYSHBR(DESKTOP));
                f = TRUE;
            }
        }
    }

    if (**((PULONG *)&InitSafeBootMode)
            || gDrawVersionAlways
            || gdwCanPaintDesktop) {
        static BOOL fInit = TRUE;
        SIZE        size;
        int         imode;
        COLORREF    oldColor;
        HFONT       oldFont = NULL;


        /*
         * Grab the stuff from the registry
         */
        if (fInit) {
            if (**((PULONG *)&InitSafeBootMode)) {
                ServerLoadString( hModuleWin, STR_SAFEMODE, SafeModeStr, ARRAY_SIZE(SafeModeStr) );
                SafeModeStrLen = wcslen(SafeModeStr);
            }
            GetVersionInfo(**((PULONG *)&InitSafeBootMode) == 0);
            fInit = FALSE;
        }

        if (**((PULONG *)&InitSafeBootMode)) {
            if (gpsi != NULL && gpsi->hCaptionFont != NULL) {
                oldFont = GreSelectFont(hdc, gpsi->hCaptionFont);
            }
    
            GreGetTextExtentW(hdc, wszT, wcslen(wszT), &size, GGTE_WIN3_EXTENT);
            imode = GreSetBkMode(hdc, TRANSPARENT);

            oldColor = GreSetTextColor( hdc, RGB(255,255,255) );

            GreExtTextOutW(
                hdc,
                (pMonitor->rcWork.left + pMonitor->rcWork.right - size.cx) / 2,
                pMonitor->rcWork.top,
                0,
                (LPRECT)NULL,
                wszT,
                wcslen(wszT),
                (LPINT)NULL
                );

            GreGetTextExtentW(hdc, SafeModeStr, SafeModeStrLen, &size, GGTE_WIN3_EXTENT);

            GreExtTextOutW(
                hdc,
                pMonitor->rcWork.left,
                pMonitor->rcWork.top,
                0,
                (LPRECT)NULL,
                SafeModeStr,
                SafeModeStrLen,
                (LPINT)NULL
                );

            GreExtTextOutW(
                hdc,
                pMonitor->rcWork.right - size.cx,
                pMonitor->rcWork.top,
                0,
                (LPRECT)NULL,
                SafeModeStr,
                SafeModeStrLen,
                (LPINT)NULL
                );

            GreExtTextOutW(
                hdc,
                pMonitor->rcWork.right - size.cx,
                pMonitor->rcWork.bottom - gpsi->tmSysFont.tmHeight,
                0,
                (LPRECT)NULL,
                SafeModeStr,
                SafeModeStrLen,
                (LPINT)NULL
                );

            GreExtTextOutW(
                hdc,
                pMonitor->rcWork.left,
                pMonitor->rcWork.bottom - gpsi->tmSysFont.tmHeight,
                0,
                (LPRECT)NULL,
                SafeModeStr,
                SafeModeStrLen,
                (LPINT)NULL
                );

            GreSetBkMode(hdc, imode);
            GreSetTextColor(hdc, oldColor);
    
            if (oldFont) {
                GreSelectFont(hdc, oldFont);
            }
        } else {
            DesktopBuildPaint(hdc, pMonitor);
        }
    }

    return f;
}
Example #4
0
/***************************************************************************\
* DesktopBuildPaint
*
* Draw the build information onto the desktop
*
* History:
* 2/4/99    joejo - Bug 280256
\***************************************************************************/
void DesktopBuildPaint(
    HDC         hdc,
    PMONITOR    pMonitor)
{
    SIZE        size;
    int         imode;
    int         x;
    int         y;
    COLORREF    oldColor;
    RECT        rcText1 = {0,0,0,0};

    HFONT       oldFont = NULL;

    PWCHAR pwszT = wszProductName;

    /*
     * Set up DC
     */
    imode = GreSetBkMode(hdc, TRANSPARENT);

    if (GreGetBrushColor(SYSHBR(BACKGROUND)) != 0x00ffffff) {
        oldColor = GreSetTextColor( hdc, RGB(255,255,255) );
    } else {
        oldColor = GreSetTextColor( hdc, RGB(0,0,0) );
    }


    /*
     * Print Windows 2000 name
     */
    if (gpsi && gpsi->hCaptionFont) {
        oldFont = GreSelectFont(hdc, gpsi->hCaptionFont);
    }

    if (gDrawVersionAlways) {
        pwszT = (wcslen(wszProductName) > wcslen(USER_SHARED_DATA->NtSystemRoot))?wszProductName:USER_SHARED_DATA->NtSystemRoot;
    }

    GreGetTextExtentW(
        hdc,
        pwszT,
        wcslen(pwszT),
        &size,
        GGTE_WIN3_EXTENT);

    x = pMonitor->rcWork.right - size.cx - 5;
    y = pMonitor->rcWork.bottom -
            ((gDrawVersionAlways? 3: 2) * size.cy) - 5;

    rcText1.top = y;
    rcText1.bottom = rcText1.top + size.cy;
    rcText1.left = x;
    rcText1.right = rcText1.left + size.cx;

    GreSetTextAlign(hdc, TA_RIGHT | TA_BOTTOM);

    GreExtTextOutW(
        hdc,
        rcText1.right,
        rcText1.bottom,
        0,
        &rcText1,
        wszProductName,
        wcslen(wszProductName),
        (LPINT)NULL
        );


    /*
     * Print Build Number
     */
    if (oldFont != NULL && ghMenuFont != NULL ) {
        GreSelectFont(hdc, ghMenuFont);
    }

    rcText1.top = rcText1.bottom + 1;
    rcText1.bottom = rcText1.top + size.cy;

    GreExtTextOutW(
        hdc,
        rcText1.right,
        rcText1.bottom,
        0,
        &rcText1,
        wszProductBuild,
        wcslen(wszProductBuild),
        (LPINT)NULL
        );

    /*
     * If we are in CHK mode, draw the System Dir Path
     */
    if (gDrawVersionAlways) {
        rcText1.top = rcText1.bottom + 1;
        rcText1.bottom = rcText1.top + size.cy;

        GreExtTextOutW(
            hdc,
            rcText1.right,
            rcText1.bottom,
            0,
            &rcText1,
            USER_SHARED_DATA->NtSystemRoot,
            wcslen(USER_SHARED_DATA->NtSystemRoot),
            (LPINT)NULL
            );
    }

    if (oldFont) {
        GreSelectFont(hdc, oldFont);
    }

    GreSetBkMode(hdc, imode);
    GreSetTextColor(hdc, oldColor);
}
Example #5
0
DWORD MNRecalcTabStrings(
    HDC hdc,
    PMENU pMenu,
    UINT iBeg,
    UINT iEnd,
    DWORD xTab,
    DWORD hCount)
{
    UINT i;
    UINT    cOwnerDraw;
    int adx;
    int     maxWidth = 0;
    int     cx;
    PITEM pItem;
    CheckLock(pMenu);

    xTab += hCount;

    if ((iBeg >= pMenu->cItems) || (iBeg > iEnd))
        goto SeeYa;

    cOwnerDraw = 0;

    for (i = iBeg, pItem = pMenu->rgItems + iBeg; i < iEnd; pItem++, i++) {
        adx = 0;

        /*
         * Subtract hCount to make dxTab relative to start of column for
         * multi-column menus.
         */

        pItem->dxTab = xTab - hCount;

        // Skip non-string or empty string items
        if ((pItem->lpstr != NULL) && !TestMFT(pItem, MFT_OWNERDRAW)) {
            LPWSTR   lpString = TextPointer(pItem->lpstr);
            int     tp;
            SIZE size;

            // Are there any tabs?
            tp = FindCharPosition(lpString, TEXT('\t'));
            if (tp < (int) pItem->cch) {
                PTHREADINFO ptiCurrent = PtiCurrentShared();

                if (CALL_LPK(ptiCurrent)) {
                    xxxClientGetTextExtentPointW(hdc, lpString + tp + 1,
                          pItem->cch - tp - 1, &size);
                } else {
                    GreGetTextExtentW(hdc, lpString + tp + 1,
                          pItem->cch - tp - 1, &size, GGTE_WIN3_EXTENT);
                }
                adx = gcxMenuFontChar + size.cx;
            }
        } else if (TestMFT(pItem, MFT_OWNERDRAW))
            cOwnerDraw++;

        adx += xTab;

        if (adx > maxWidth)
            maxWidth = adx;

    }

    /*
     * Add on space for hierarchical arrow.  So basically, popup menu items
     * can have 4 columns:
     *      (1) Checkmark
     *      (2) Text
     *      (3) Tabbed text for accel
     *      (4) Hierarchical arrow
     *
     * But, we only do this if at least one item isn't ownerdraw
     *  and if there's at least one submenu in the popup.
     */
    if (cOwnerDraw != (iEnd - iBeg)) {
        maxWidth += gcxMenuFontChar + gpsi->oembmi[OBI_MENUCHECK].cx;
    }

    cx = maxWidth - hCount;

    for (i = iBeg, pItem = pMenu->rgItems + iBeg; i < iEnd; pItem++, i++)
        pItem->cxItem = cx;

SeeYa:
    return(maxWidth);
}
Example #6
0
/***************************************************************************\
*
*  DrawState()
*
*  Generic state drawing routine.  Does simple drawing into same DC if
*  normal state;  uses offscreen bitmap otherwise.
*
*  We do drawing for these simple types ourselves:
*      (1) Text
*          lData is string pointer.
*          wData is string length
*      (2) Icon
*          LOWORD(lData) is hIcon
*      (3) Bitmap
*          LOWORD(lData) is hBitmap
*      (4) Glyph (internal)
*          LOWORD(lData) is OBI_ value, one of
*              OBI_CHECKMARK
*              OBI_BULLET
*              OBI_MENUARROW
*          right now
*
*  Other types are required to draw via the callback function, and are
*  allowed to stick whatever they want in lData and wData.
*
*  We apply the following effects onto the image:
*      (1) Normal      (nothing)
*      (2) Default     (drop shadow)
*      (3) Union       (gray string dither)
*      (4) Disabled    (embossed)
*
*  Note that we do NOT stretch anything.  We just clip.
*
\***************************************************************************/
BOOL _DrawState(
    HDC           hdcDraw,
    HBRUSH        hbrFore,
    DRAWSTATEPROC qfnCallBack,
    LPARAM        lData,
    WPARAM        wData,
    int           x,
    int           y,
    int           cx,
    int           cy,
    UINT          uFlags)
{
    HFONT   hFont;
    HFONT   hFontSave = NULL;
    HDC     hdcT;
    HBITMAP hbmpT;
    POINT   ptOrg;
    BOOL    fResult;

    /*
     * These require monochrome conversion
     *
     * Enforce monochrome: embossed doesn't look great with 2 color displays
     */
    if ((uFlags & DSS_DISABLED) &&
        ((oemInfo.BitCount == 1) || SYSMET(SLOWMACHINE))) {

        uFlags &= ~DSS_DISABLED;
        uFlags |= DSS_UNION;
    }

    if (uFlags & (DSS_DISABLED | DSS_DEFAULT | DSS_UNION))
        uFlags |= DSS_MONO;

    /*
     * Get drawing sizes etc. AND VALIDATE.
     */
    switch (uFlags & DST_TYPEMASK) {

        case DST_GLYPH:

            /*
             * LOWORD(lData) is OBI_ value.
             */
            UserAssert(LOWORD(lData) < (WORD)OBI_COUNT);

            if (!cx)
                cx = oemInfo.bm[LOWORD(lData)].cx;

            if (!cy)
                cy = oemInfo.bm[LOWORD(lData)].cy;
            break;

        case DST_BITMAP:
            /*
             *  (lData) is hbmp.
             */
//            if (IsGDIObject((HBITMAP)LOWORD(lData)) != GDIOBJ_BITMAP)
//                return FALSE;

            if (!cx || !cy) {
                BITMAP bmp;

                try {

                    GreExtGetObjectW((HBITMAP)lData, sizeof(BITMAP), &bmp);

                    if (!cx)
                        cx = bmp.bmWidth;

                    if (!cy)
                        cy = bmp.bmHeight;

                } except (EXCEPTION_EXECUTE_HANDLER) {
                   return FALSE;
                }
            }
            break;

        case DST_ICON:

            /*
             * lData is picon.
             */
            if (!cx || !cy) {

                if (!cx)
                    cx = ((PICON)lData)->cx;

                if (!cy)
                    cy = ((PICON)lData)->cy / 2;  // Icons are double height in NT
            }
            break;

        case DST_TEXT:

            /*
             * lData is LPSTR
             * NOTE THAT WE DO NOT VALIDATE lData, DUE TO COMPATIBILITY
             * WITH GRAYSTRING().  THIS _SHOULD_ FAULT IF YOU PASS IN NULL.
             *
             * wData is cch.
             */
            if (!wData)
                wData = wcslen((LPWSTR)lData);

            if (!cx || !cy) {

                SIZE size;

                /*
                 * Make sure we use right dc w/ right font.
                 */
                GreGetTextExtentW(hdcDraw,
                                  (LPWSTR)lData,
                                  wData,
                                  &size,
                                  GGTE_WIN3_EXTENT);

                if (!cx)
                    cx = size.cx;
                if (!cy)
                    cy = size.cy;
            }

            /*
             * Now, pretend we're complex if qfnCallBack is supplied AND
             * we're supporting GrayString().
             */
//            if ((uFlags & DST_GRAYSTRING) && SELECTOROF(qfnCallBack)) {
//                uFlags &= ~DST_TYPEMASK;
//                uFlags |= DST_COMPLEX;
//            }
            break;

        case DST_PREFIXTEXT:

            if (lData==0) {
                RIPMSG0(RIP_ERROR, "DrawState: NULL DST_PREFIXTEXT string");
                return FALSE;
            }

            if (!wData)
                wData = wcslen((LPWSTR)lData);

            if (!cx || !cy) {

                SIZE size;

                PSMGetTextExtent(hdcDraw, (LPWSTR)lData, wData, &size);

                if (!cx)
                    cx = size.cx;
                if (!cy)
                    cy = size.cy;
            }

            /*
             * Add on height for prefix
             */
            cy += 2*SYSMET(CYBORDER);
            break;

        case DST_COMPLEX:
            if (qfnCallBack == NULL) {
                RIPMSG0(RIP_ERROR, "DrawState: invalid callback for DST_COMPLEX");
                return(FALSE);
            }
            break;

        default:
            RIPMSG0(RIP_ERROR, "DrawState: invalid DST_ type");
            return FALSE;
    }