/* internal version of DrawText, passed flags for text data type*/ static int MwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect, UINT uFormat, int flags) { MWCOORD x, y, width, height, baseline; if(nCount == -1) nCount = strlen(lpString); if(uFormat & (DT_CALCRECT|DT_CENTER|DT_RIGHT)) { if(!hdc) return 0; GdGetTextSize(hdc->font->pfont, lpString, nCount, &width, &height, &baseline, MWTF_ASCII); } x = lpRect->left; y = lpRect->top; if(uFormat & DT_CALCRECT) { lpRect->right = x + width; lpRect->bottom = y + height; return height; } if(uFormat & DT_CENTER) x = (lpRect->left + lpRect->right - width) / 2; else if(uFormat & DT_RIGHT) x += lpRect->right - width; /* draw text at DT_TOP using current fg, bg and bkmode*/ MwExtTextOut(hdc, x, y, 0, NULL, lpString, nCount, NULL, flags); return height; }
/* * MwDrawText Support routine: given a position, a string and length, * process underline, ampersands and tabs, and output * using mwExtTextOut ormwTabbedTextOut */ static void mwDrawTextOut(HDC hDC, int x, int y, LPSTR str, int len, UINT uFormat, int flags) { int i, j, k, dx, dy, x1; MWCOORD baseline; if(!hDC) return; for (i = 0, j = 0, k = 0, x1 = 0; i < len; i++) { if (str[i] == '&') { if (i) { if (uFormat & DT_EXPANDTABS) { mwTabbedTextOut(hDC, x, y, &str[j], i, 0, 0, x, FALSE, flags); x += LOWORD(mwTabbedTextOut(hDC, x, y, &str[j], i, 0, 0, 0, TRUE, flags)); } else { MwExtTextOut(hDC, x, y, 0, NULL, &str[j], i - j, NULL, flags); GdGetTextSize(hDC->font->pfont, &str[j], i - j, &dx, &dy, &baseline, flags); x += dx; } } if (str[i + 1] == '&') { TextOut(hDC, x, y, "&", 1); GdGetTextSize(hDC->font->pfont, "&", 1, &dx, &dy, &baseline, flags); x += dx; i++; } else { x1 = x; k = i + 1; } j = i + 1; } } if (i > j) { if (uFormat & DT_EXPANDTABS) mwTabbedTextOut(hDC, x, y, &str[j], i - j, 0, 0, x, FALSE, flags); else MwExtTextOut(hDC, x, y, 0, NULL, &str[j], i - j, NULL, flags); if (k && str[k] != ' ') { GdGetTextSize(hDC->font->pfont, &str[k], 1, &dx, &dy, &baseline, flags); dy -= dy / 18 + 1; /* underline position */ MoveToEx(hDC, x1, y + dy, NULL); LineTo(hDC, x1 + dx, y + dy); } } }
BOOL WINAPI GetTextExtentPoint( HDC hdc, /* handle to DC*/ LPCTSTR lpszStr, /* character string*/ int cchString, /* number of characters*/ LPSIZE lpSize) /* string dimensions*/ { int width = 1, height = 1, baseline = 0; if (lpSize) { lpSize->cx = 0; lpSize->cy = 0; } if (!hdc || !lpszStr || !cchString || !lpSize) return FALSE; GdGetTextSize(hdc->font->pfont, lpszStr, cchString, &width, &height, &baseline, MWTF_UTF8); lpSize->cx = width; lpSize->cy = height; /*printf("<MWIN>: lpszStr=\"%s\", cchString=%d, lpsize->cx=%d, lpSize->cy=%d\n", lpszStr, cchString, lpSize->cx, lpSize->cy);*/ return TRUE; }
static void lstCalcHeight(HWND hwnd) { int xw, xh, xb; PLISTBOXDATA pData = (PLISTBOXDATA) hwnd->userdata; BOOL other = FALSE; if (ISOWNERDRAW(GetWindowLong(hwnd, GWL_STYLE))) other = lbAskMeasureItem(hwnd, -1, &pData->itemHeight); if (!other || pData->itemHeight == 0) { HDC hdc = GetDC(hwnd); #if MWCLIENT /* nanox client */ GrSetGCFont(hdc->gc, hdc->font->fontid); GrGetGCTextSize(hdc->gc, "X", 1, MWTF_ASCII, &xw, &xh, &xb); #else SelectObject(hdc, GET_WND_FONT(hwnd)); GdGetTextSize(hdc->font->pfont, "X", 1, &xw, &xh, &xb, MWTF_ASCII); #endif ReleaseDC(hwnd, hdc); pData->itemHeight = xh + 1; } else pData->dwFlags |= LBF_USERMEASURE; }
/* internal version of DrawText, passed flags for text data type*/ static int MwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect, UINT uFormat, int flags) { MWCOORD x, y, width, height, baseline; LPCSTR lpStrDup = NULL; RECT rcUline; if(!hdc) return 0; if(nCount == -1) nCount = strlen(lpString); if (!(uFormat & DT_NOPREFIX) && (lpStrDup = MwCheckUnderlineChar(hdc, lpString, &nCount, &rcUline))) lpString = lpStrDup; if(uFormat & (DT_CALCRECT|DT_CENTER|DT_RIGHT)) { GdGetTextSize(hdc->font->pfont, lpString, nCount, &width, &height, &baseline, flags); } x = lpRect->left; y = lpRect->top; if(uFormat & DT_CALCRECT) { #if 0 if (!(uFormat & DT_SINGLELINE)) { char *p=(char*)lpString, *pLast=p, *pMax=p; int iLenCur, iLenMax = 0, iLines = 0; long lMaxWidth = lpRect->right - lpRect->left; /* Determine line with maximum width */ for (pLast=p, pMax=p; ; p++) { if (*p=='\n' || !*p) { if (lMaxWidth) { do { iLenCur = p - pLast; GdGetTextSize(hdc->font->pfont, pLast, iLenCur, &width, &height, &baseline, flags); if (width <= lMaxWidth) break; while (p>(char*)lpString && (*p==' ' || *p=='\t')) p--; while (p>(char*)lpString && !(*p==' ' || *p=='\t')) p--; } while (width > lMaxWidth && p>(char*)lpString); } if ((iLenCur = p - pLast) > iLenMax) { iLenMax = iLenCur; pMax = pLast; } pLast = p+1; iLines++; } if (!*p) break; } GdGetTextSize(hdc->font->pfont, pMax, iLenMax, &width, &height, &baseline, flags); height *= iLines; } #endif lpRect->right = x + width; lpRect->bottom = y + height; if (lpStrDup) free(lpStrDup); return height; } if(uFormat & DT_CENTER) x = (lpRect->left + lpRect->right - width) / 2; else if(uFormat & DT_RIGHT) x = lpRect->right - width; if(uFormat & DT_VCENTER) y = lpRect->bottom / 2 - (height / 2); if(uFormat & DT_BOTTOM) { flags |= MWTF_BOTTOM; y = lpRect->bottom; } /* draw text at DT_TOP using current fg, bg and bkmode*/ MwExtTextOut(hdc, x, y, 0, NULL, lpString, nCount, NULL, flags); if (lpStrDup) { OffsetRect(&rcUline, x, y); SelectObject(hdc, GetStockObject(BLACK_PEN)); MoveToEx(hdc, rcUline.left, rcUline.bottom, NULL); LineTo(hdc, rcUline.right, rcUline.bottom); free(lpStrDup); } return height; }
/* internal version of ExtTextOut, passed flags for text data type*/ static BOOL MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc, LPCVOID lpszString, UINT cbCount, CONST INT *lpDx, int flags) { HWND hwnd; POINT pt; RECT rc; hwnd = MwPrepareDC(hdc); if(!hwnd) return FALSE; pt.x = x; pt.y = y; if(MwIsClientDC(hdc)) ClientToScreen(hwnd, &pt); /* optionally fill passed rectangle*/ if(lprc && (fuOptions&ETO_OPAQUE)) { rc = *lprc; if(MwIsClientDC(hdc)) MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2); /* fill rectangle with current background color*/ GdSetForegroundColor(hdc->psd, hdc->bkcolor); GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); GdSetUseBackground(FALSE); } else { /* use current background mode for text background draw*/ GdSetUseBackground(hdc->bkmode == OPAQUE? TRUE: FALSE); /* always set background color in case GdArea is * used to draw, which compares gr_foreground != gr_background * if gr_usebg is false... */ /*if(hdc->bkmode == OPAQUE)*/ GdSetBackgroundColor(hdc->psd, hdc->bkcolor); } if (cbCount == 0) { /* Special case - no text. Used to fill rectangle. */ return TRUE; } /* nyi: lpDx*/ /* draw text in current text foreground and background color*/ GdSetForegroundColor(hdc->psd, hdc->textcolor); //GdSetFont(hdc->font->pfont); /* this whole text alignment thing needs rewriting*/ if((hdc->textalign & TA_BASELINE) == TA_BASELINE) { /* this is not right... changed for kaffe port flags |= MWTF_TOP; */ flags |= MWTF_BASELINE; } else if(hdc->textalign & TA_BOTTOM) { MWCOORD ph, pw, pb; if(lprc) pt.y += lprc->bottom - lprc->top; else { GdGetTextSize(hdc->font->pfont, lpszString, cbCount, &pw, &ph, &pb, flags); pt.y += ph; } flags |= MWTF_BOTTOM; } else flags |= MWTF_TOP; if((hdc->textalign & TA_CENTER) == TA_CENTER) { MWCOORD ph, pw, pb; GdGetTextSize(hdc->font->pfont, lpszString, cbCount, &pw, &ph, &pb, flags); pt.x -= pw/2; } else if(hdc->textalign & TA_RIGHT) { MWCOORD ph, pw, pb; GdGetTextSize(hdc->font->pfont, lpszString, cbCount, &pw, &ph, &pb, flags); pt.x -= pw; } GdText(hdc->psd, hdc->font->pfont, pt.x, pt.y, lpszString, cbCount, flags); return TRUE; }