/// @cond ignore //------------------------------------------------------------------------ static CCoord getFontCapHeight (CFontRef font) { CCoord c = font->getSize (); IPlatformFont* pf = font->getPlatformFont (); if (pf) { CCoord capHeight = pf->getCapHeight (); if (capHeight <= 0) capHeight = pf->getAscent (); if (capHeight > 0) c = capHeight; } return c; }
//----------------------------------------------------------------------------- void CDrawContext::setFont (const CFontRef newFont, const CCoord& size, const int32_t& style) { if (newFont == 0) return; if ((size > 0 && newFont->getSize () != size) || (style != -1 && newFont->getStyle () != style)) { OwningPointer<CFontDesc> font = (CFontRef)newFont->newCopy (); currentState.font = font; if (size > 0) currentState.font->setSize (size); if (style != -1) currentState.font->setStyle (style); } else { currentState.font = newFont; } }
//----------------------------------------------------------------------------- void CDrawContext::setFont (const CFontRef newFont, const CCoord& size, const int32_t& style) { if (newFont == 0) return; if (currentState.font) currentState.font->forget (); if ((size > 0 && newFont->getSize () != size) || (style != -1 && newFont->getStyle () != style)) { currentState.font = (CFontRef)newFont->newCopy (); if (size > 0) currentState.font->setSize (size); if (style != -1) currentState.font->setStyle (style); } else { currentState.font = newFont; currentState.font->remember (); } }
//----------------------------------------------------------------------------- Win32TextEdit::Win32TextEdit (HWND parent, IPlatformTextEditCallback* textEdit) : IPlatformTextEdit (textEdit) , platformControl (0) , platformFont (0) , platformBackColor (0) , oldWndProcEdit (0) { CRect rect = textEdit->platformGetSize (); CFontRef fontID = textEdit->platformGetFont (); CHoriTxtAlign horiTxtAlign = textEdit->platformGetHoriTxtAlign (); int wstyle = 0; if (horiTxtAlign == kLeftText) wstyle |= ES_LEFT; else if (horiTxtAlign == kRightText) wstyle |= ES_RIGHT; else wstyle |= ES_CENTER; CPoint textInset = textEdit->platformGetTextInset (); rect.offset (textInset.x, textInset.y); rect.right -= textInset.x*2; rect.bottom -= textInset.y*2; // get/set the current font LOGFONT logfont = {0}; CCoord fontH = fontID->getSize (); if (fontH > rect.getHeight ()) fontH = rect.getHeight () - 3; if (fontH < rect.getHeight ()) { CCoord adjust = (rect.getHeight () - (fontH + 3)) / (CCoord)2; rect.top += adjust; rect.bottom -= adjust; } UTF8StringHelper stringHelper (textEdit->platformGetText ()); text = stringHelper; DWORD wxStyle = 0; if (getD2DFactory () == 0 && getSystemVersion ().dwMajorVersion >= 6) // Vista and above wxStyle = WS_EX_COMPOSITED; wstyle |= WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL; platformControl = CreateWindowEx (wxStyle, TEXT("EDIT"), stringHelper, wstyle, (int)rect.left, (int)rect.top, (int)rect.getWidth (), (int)rect.getHeight (), parent, NULL, GetInstance (), 0); logfont.lfWeight = FW_NORMAL; logfont.lfHeight = (LONG)-fontH; logfont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS; UTF8StringHelper fontNameHelper (fontID->getName ()); VSTGUI_STRCPY (logfont.lfFaceName, fontNameHelper); logfont.lfClipPrecision = CLIP_STROKE_PRECIS; logfont.lfOutPrecision = OUT_STRING_PRECIS; logfont.lfQuality = DEFAULT_QUALITY; logfont.lfCharSet = ANSI_CHARSET; platformFont = CreateFontIndirect (&logfont); SetWindowLongPtr (platformControl, GWLP_USERDATA, (__int3264)(LONG_PTR)this); SendMessage (platformControl, WM_SETFONT, (WPARAM)platformFont, true); SendMessage (platformControl, EM_SETMARGINS, EC_LEFTMARGIN|EC_RIGHTMARGIN, MAKELONG (0, 0)); SendMessage (platformControl, EM_SETSEL, 0, -1); SendMessage (platformControl, EM_LIMITTEXT, 255, 0); SetFocus (platformControl); oldWndProcEdit = (WINDOWSPROC)(LONG_PTR)SetWindowLongPtr (platformControl, GWLP_WNDPROC, (__int3264)(LONG_PTR)procEdit); CColor backColor = textEdit->platformGetBackColor (); platformBackColor = CreateSolidBrush (RGB (backColor.red, backColor.green, backColor.blue)); }