Okay, I made a mistake: we want uiFontButton to return uiDrawFonts, not uiDrawFontDescriptors. Started the work to change the Windows one likewise.

This commit is contained in:
Pietro Gagliardi 2016-04-18 15:31:52 -04:00
parent ccfa3d41a3
commit b19a8c9c46
3 changed files with 24 additions and 13 deletions

View File

@ -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 += \

View File

@ -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)

View File

@ -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);