From 4d025172fe4d15ab520468bceac249dbe809e066 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 18 Apr 2016 01:12:25 -0400 Subject: [PATCH] And brought the new font out of the font dialog and into the font button. We should be good now... --- windows/fontbutton.c | 16 +++++++++++++--- windows/fontdialog.cpp | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/windows/fontbutton.c b/windows/fontbutton.c index bd5316af..fec97666 100644 --- a/windows/fontbutton.c +++ b/windows/fontbutton.c @@ -18,7 +18,17 @@ uiWindowsDefineControlWithOnDestroy( static void updateFontButtonLabel(uiFontButton *b) { - // TODO + // TODO make this dynamically sized + // TODO also include the style, but from where? libui or DirectWrite? + WCHAR text[1024]; + WCHAR *family; + + family = toUTF16(b->desc.Family); + _snwprintf(text, 1024, L"%s %g", family, b->desc.Size); + uiFree(family); + // TODO error check + SendMessageW(b->hwnd, WM_SETTEXT, 0, (LPARAM) text); + // changing the text might necessitate a change in the button's size uiWindowsControlQueueRelayout(uiWindowsControl(b)); } @@ -94,8 +104,7 @@ uiFontButton *uiNewFontButton(void) b = (uiFontButton *) uiNewControl(uiFontButtonType()); b->hwnd = uiWindowsEnsureCreateControlHWND(0, - // TODO - L"button", L"Arial 10", + L"button", L"you should not be seeing this", BS_PUSHBUTTON | WS_TABSTOP, hInstance, NULL, TRUE); @@ -106,6 +115,7 @@ uiFontButton *uiNewFontButton(void) b->desc.Weight = uiDrawTextWeightNormal; b->desc.Italic = uiDrawTextItalicNormal; b->desc.Stretch = uiDrawTextStretchNormal; + updateFontButtonLabel(b); uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b)); //TODO uiButtonOnClicked(b, defaultOnClicked, NULL); diff --git a/windows/fontdialog.cpp b/windows/fontdialog.cpp index 1d0c8826..009001a0 100644 --- a/windows/fontdialog.cpp +++ b/windows/fontdialog.cpp @@ -528,6 +528,10 @@ static void endFontDialog(struct fontDialog *f, INT_PTR code) static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam) { + WCHAR *wfamily; + IDWriteFont *font; + struct dwriteAttr attr; + // cancelling if (LOWORD(wParam) != IDOK) { endFontDialog(f, 1); @@ -535,8 +539,18 @@ static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam) } // OK - // TODO fill f->desc here + wfamily = cbGetItemText(f->familyCombobox, f->curFamily); + f->desc->Family = toUTF8(wfamily); + uiFree(wfamily); f->desc->Size = f->curSize; + font = (IDWriteFont *) cbGetItemData(f->styleCombobox, f->curStyle); + attr.dweight = font->GetWeight(); + attr.ditalic = font->GetStyle(); + attr.dstretch = font->GetStretch(); + dwriteAttrToAttr(&attr); + f->desc->Weight = attr.weight; + f->desc->Italic = attr.italic; + f->desc->Stretch = attr.stretch; endFontDialog(f, 2); return TRUE; }