Migrated fontbutton.cpp back.

This commit is contained in:
Pietro Gagliardi 2018-03-16 20:06:23 -04:00
parent 1b1d609c88
commit 1d1b6c3162
3 changed files with 19 additions and 17 deletions

View File

@ -12,14 +12,3 @@ extern WCHAR *fontCollectionFamilyName(fontCollection *fc, IDWriteFontFamily *fa
extern void fontCollectionFree(fontCollection *fc); extern void fontCollectionFree(fontCollection *fc);
extern WCHAR *fontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStrings *names); extern WCHAR *fontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStrings *names);
// fontdialog.cpp
struct fontDialogParams {
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);

View File

@ -59,3 +59,15 @@ struct drawTextBackgroundParams {
double b; double b;
double a; double a;
}; };
// fontdialog.cpp
struct fontDialogParams {
IDWriteFont *font;
double size;
WCHAR *familyName;
WCHAR *styleName;
};
extern BOOL uiprivShowFontDialog(HWND parent, struct fontDialogParams *params);
extern void uiprivLoadInitialFontDialogParams(struct fontDialogParams *params);
extern void uiprivDestroyFontDialogParams(struct fontDialogParams *params);
extern WCHAR *uiprivFontDialogParamsToString(struct fontDialogParams *params);

View File

@ -1,5 +1,6 @@
// 14 april 2016 // 14 april 2016
#include "uipriv_windows.hpp" #include "uipriv_windows.hpp"
#include "attrstr.hpp"
struct uiFontButton { struct uiFontButton {
uiWindowsControl c; uiWindowsControl c;
@ -15,7 +16,7 @@ static void uiFontButtonDestroy(uiControl *c)
uiFontButton *b = uiFontButton(c); uiFontButton *b = uiFontButton(c);
uiWindowsUnregisterWM_COMMANDHandler(b->hwnd); uiWindowsUnregisterWM_COMMANDHandler(b->hwnd);
destroyFontDialogParams(&(b->params)); uiprivDestroyFontDialogParams(&(b->params));
uiWindowsEnsureDestroyWindow(b->hwnd); uiWindowsEnsureDestroyWindow(b->hwnd);
uiFreeControl(uiControl(b)); uiFreeControl(uiControl(b));
} }
@ -24,9 +25,9 @@ static void updateFontButtonLabel(uiFontButton *b)
{ {
WCHAR *text; WCHAR *text;
text = fontDialogParamsToString(&(b->params)); text = uiprivFontDialogParamsToString(&(b->params));
setWindowText(b->hwnd, text); setWindowText(b->hwnd, text);
uiFree(text); uiprivFree(text);
// changing the text might necessitate a change in the button's size // changing the text might necessitate a change in the button's size
uiWindowsControlMinimumSizeChanged(uiWindowsControl(b)); uiWindowsControlMinimumSizeChanged(uiWindowsControl(b));
@ -41,7 +42,7 @@ static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
return FALSE; return FALSE;
parent = parentToplevel(b->hwnd); parent = parentToplevel(b->hwnd);
if (showFontDialog(parent, &(b->params))) { if (uiprivShowFontDialog(parent, &(b->params))) {
updateFontButtonLabel(b); updateFontButtonLabel(b);
(*(b->onChanged))(b, b->onChangedData); (*(b->onChanged))(b, b->onChangedData);
} }
@ -88,7 +89,7 @@ static void defaultOnChanged(uiFontButton *b, void *data)
void uiFontButtonFont(uiFontButton *b, uiDrawFontDescriptor *desc) void uiFontButtonFont(uiFontButton *b, uiDrawFontDescriptor *desc)
{ {
fontdescFromIDWriteFont(b->params.font, desc); uiprivFontDescriptorFromIDWriteFont(b->params.font, desc);
desc->Family = toUTF8(b->params.familyName); desc->Family = toUTF8(b->params.familyName);
desc->Size = b->params.size; desc->Size = b->params.size;
} }
@ -111,7 +112,7 @@ uiFontButton *uiNewFontButton(void)
hInstance, NULL, hInstance, NULL,
TRUE); TRUE);
loadInitialFontDialogParams(&(b->params)); uiprivLoadInitialFontDialogParams(&(b->params));
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b)); uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
uiFontButtonOnChanged(b, defaultOnChanged, NULL); uiFontButtonOnChanged(b, defaultOnChanged, NULL);