diff --git a/windows/GNUfiles.mk b/windows/GNUfiles.mk index 48fe7da3..b0387a52 100644 --- a/windows/GNUfiles.mk +++ b/windows/GNUfiles.mk @@ -20,7 +20,6 @@ CFILES += \ windows/draw.c \ windows/entry.c \ windows/events.c \ - windows/fontbutton.c \ windows/group.c \ windows/init.c \ windows/label.c \ @@ -45,6 +44,7 @@ CFILES += \ CXXFILES += \ windows/drawtext.cpp \ windows/dwrite.cpp \ + windows/fontbutton.cpp \ windows/fontdialog.cpp HFILES += \ diff --git a/windows/fontbutton.c b/windows/fontbutton.cpp similarity index 85% rename from windows/fontbutton.c rename to windows/fontbutton.cpp index 472cbcb6..25940e0f 100644 --- a/windows/fontbutton.c +++ b/windows/fontbutton.cpp @@ -1,8 +1,6 @@ // 14 april 2016 #include "uipriv_windows.h" -// TODO implement a custom font dialog that uses DirectWrite? - struct uiFontButton { uiWindowsControl c; HWND hwnd; @@ -10,24 +8,28 @@ struct uiFontButton { BOOL already; }; +static void onDestroy(uiFontButton *); + uiWindowsDefineControlWithOnDestroy( uiFontButton, // type name uiFontButtonType, // type function - uiWindowsUnregisterWM_COMMANDHandler(this->hwnd); // on destroy + onDestroy(this); // on destroy ) +static void onDestroy(uiFontButton *b) +{ + uiWindowsUnregisterWM_COMMANDHandler(b->hwnd); + destroyFontDialogParams(&(b->params)); +} + static void updateFontButtonLabel(uiFontButton *b) { - // TODO make this dynamically sized - // TODO also include the style, but from where? libui or DirectWrite? - WCHAR text[1024]; - WCHAR *family; + WCHAR *text; - family = toUTF16(b->params.desc.Family); - _snwprintf(text, 1024, L"%s %s %g", family, b->params.outStyleName, b->params.desc.Size); - uiFree(family); + text = fontDialogParamsToString(&(b->params)); // TODO error check SendMessageW(b->hwnd, WM_SETTEXT, 0, (LPARAM) text); + uiFree(text); // changing the text might necessitate a change in the button's size uiWindowsControlQueueRelayout(uiWindowsControl(b)); @@ -83,6 +85,9 @@ static void defaultOnClicked(uiButton *b, void *data) } #endif +// TODO document that GetFont returns a NEW instance each time +// TODO document that the Handle of a Font may not be unique + #if 0 TODO void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data) diff --git a/windows/uipriv_windows.h b/windows/uipriv_windows.h index af2854eb..49014873 100644 --- a/windows/uipriv_windows.h +++ b/windows/uipriv_windows.h @@ -170,12 +170,18 @@ extern void dwriteAttrToAttr(struct dwriteAttr *attr); extern void doDrawText(ID2D1RenderTarget *rt, ID2D1Brush *black, double x, double y, uiDrawTextLayout *layout); // fontdialog.cpp +#ifdef __cplusplus struct fontDialogParams { - uiDrawTextFontDescriptor desc; - WCHAR *outStyleName; + IDWriteFont *font; + double size; + WCHAR *familyName; + WCHAR *styleName; }; extern BOOL showFontDialog(HWND parent, struct fontDialogParams *params); extern void loadInitialFontDialogParams(struct fontDialogParams *params); +extern void destroyFontDialogParams(struct fontDialogParams *params); +extern WCHAR fontDialogParamsToString(struct fontDialogParams *params); +#endif // d2dscratch.c extern ATOM registerD2DScratchClass(HICON, HCURSOR);