Implemented the new font button stuff on Windows.
This commit is contained in:
parent
e6effa042d
commit
655e05463d
|
@ -57,7 +57,7 @@ struct uiDrawTextFont {
|
||||||
double size;
|
double size;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiDrawTextFont *mkTextFont(IDWriteFont *df, WCHAR *family, BOOL copyFamily, double size)
|
uiDrawTextFont *mkTextFont(IDWriteFont *df, BOOL addRef, WCHAR *family, BOOL copyFamily, double size)
|
||||||
{
|
{
|
||||||
uiDrawTextFont *font;
|
uiDrawTextFont *font;
|
||||||
WCHAR *copy;
|
WCHAR *copy;
|
||||||
|
@ -65,6 +65,8 @@ uiDrawTextFont *mkTextFont(IDWriteFont *df, WCHAR *family, BOOL copyFamily, doub
|
||||||
|
|
||||||
font = uiNew(uiDrawTextFont);
|
font = uiNew(uiDrawTextFont);
|
||||||
font->f = df;
|
font->f = df;
|
||||||
|
if (addRef)
|
||||||
|
font->f->AddRef();
|
||||||
if (copyFamily) {
|
if (copyFamily) {
|
||||||
copy = (WCHAR *) uiAlloc((wcslen(family) + 1) * sizeof (WCHAR), "WCHAR[]");
|
copy = (WCHAR *) uiAlloc((wcslen(family) + 1) * sizeof (WCHAR), "WCHAR[]");
|
||||||
wcscpy(copy, family);
|
wcscpy(copy, family);
|
||||||
|
@ -260,6 +262,7 @@ uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc)
|
||||||
logHRESULT("error loading font in uiDrawLoadClosestFont()", hr);
|
logHRESULT("error loading font in uiDrawLoadClosestFont()", hr);
|
||||||
|
|
||||||
font = mkTextFont(match,
|
font = mkTextFont(match,
|
||||||
|
FALSE, // we own the initial reference; no need to add another one
|
||||||
wfamily, FALSE, // will be freed with font
|
wfamily, FALSE, // will be freed with font
|
||||||
desc->Size);
|
desc->Size);
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ struct uiFontButton {
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
struct fontDialogParams params;
|
struct fontDialogParams params;
|
||||||
BOOL already;
|
BOOL already;
|
||||||
|
void (*onChanged)(uiFontButton *, void *);
|
||||||
|
void *onChangedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void onDestroy(uiFontButton *);
|
static void onDestroy(uiFontButton *);
|
||||||
|
@ -47,7 +49,7 @@ static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
|
||||||
parent = GetAncestor(b->hwnd, GA_ROOT); // TODO didn't we have a function for this
|
parent = GetAncestor(b->hwnd, GA_ROOT); // TODO didn't we have a function for this
|
||||||
if (showFontDialog(parent, &(b->params))) {
|
if (showFontDialog(parent, &(b->params))) {
|
||||||
updateFontButtonLabel(b);
|
updateFontButtonLabel(b);
|
||||||
// TODO event
|
(*(b->onChanged))(b, b->onChangedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
*lResult = 0;
|
*lResult = 0;
|
||||||
|
@ -78,25 +80,25 @@ static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width
|
||||||
*height = uiWindowsDlgUnitsToY(buttonHeight, d->BaseY);
|
*height = uiWindowsDlgUnitsToY(buttonHeight, d->BaseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
static void defaultOnChanged(uiFontButton *b, void *data)
|
||||||
TODO
|
|
||||||
static void defaultOnClicked(uiButton *b, void *data)
|
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO document that GetFont returns a NEW instance each time
|
uiDrawTextFont *uiFontButtonFont(uiFontButton *b)
|
||||||
|
{
|
||||||
|
// we don't own b->params.font; we have to add a reference
|
||||||
|
// we don't own b->params.familyName either; we have to copy it
|
||||||
|
return mkTextFont(b->params.font, TRUE, b->params.familyName, TRUE, b->params.size);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO document that the Handle of a Font may not be unique
|
// TODO document that the Handle of a Font may not be unique
|
||||||
|
|
||||||
#if 0
|
void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data)
|
||||||
TODO
|
|
||||||
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
|
|
||||||
{
|
{
|
||||||
b->onClicked = f;
|
b->onChanged = f;
|
||||||
b->onClickedData = data;
|
b->onChangedData = data;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
uiFontButton *uiNewFontButton(void)
|
uiFontButton *uiNewFontButton(void)
|
||||||
{
|
{
|
||||||
|
@ -114,7 +116,7 @@ uiFontButton *uiNewFontButton(void)
|
||||||
updateFontButtonLabel(b);
|
updateFontButtonLabel(b);
|
||||||
|
|
||||||
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
|
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
|
||||||
//TODO uiButtonOnClicked(b, defaultOnClicked, NULL);
|
uiFontButtonOnChanged(b, defaultOnChanged, NULL);
|
||||||
|
|
||||||
uiWindowsFinishNewControl(b, uiFontButton);
|
uiWindowsFinishNewControl(b, uiFontButton);
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,7 @@ extern WCHAR *fontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedSt
|
||||||
|
|
||||||
// drawtext.cpp
|
// drawtext.cpp
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern uiDrawTextFont *mkTextFont(IDWriteFont *df, WCHAR *family, BOOL copyFamily, double size);
|
extern uiDrawTextFont *mkTextFont(IDWriteFont *df, BOOL addRef, WCHAR *family, BOOL copyFamily, double size);
|
||||||
struct dwriteAttr {
|
struct dwriteAttr {
|
||||||
uiDrawTextWeight weight;
|
uiDrawTextWeight weight;
|
||||||
uiDrawTextItalic italic;
|
uiDrawTextItalic italic;
|
||||||
|
|
Loading…
Reference in New Issue