Hooked the Windows font button and font dialog together at last. More TODOs. Now we just need to actually convert everything to DirectWrite and implement the label.

This commit is contained in:
Pietro Gagliardi 2016-04-17 22:09:18 -04:00
parent 40d673fb01
commit 7cf8420682
4 changed files with 30 additions and 40 deletions

1
ui.h
View File

@ -472,7 +472,6 @@ typedef enum uiDrawTextWeight {
uiDrawTextWeightUltraHeavy, uiDrawTextWeightUltraHeavy,
} uiDrawTextWeight; } uiDrawTextWeight;
// TODO drop Oblique?
typedef enum uiDrawTextItalic { typedef enum uiDrawTextItalic {
uiDrawTextItalicNormal, uiDrawTextItalicNormal,
uiDrawTextItalicOblique, uiDrawTextItalicOblique,

View File

@ -6,8 +6,7 @@
struct uiFontButton { struct uiFontButton {
uiWindowsControl c; uiWindowsControl c;
HWND hwnd; HWND hwnd;
LOGFONTW font; uiDrawTextFontDescriptor desc;
INT pointSize;
BOOL already; BOOL already;
}; };
@ -20,7 +19,6 @@ uiWindowsDefineControlWithOnDestroy(
static void updateFontButtonLabel(uiFontButton *b) static void updateFontButtonLabel(uiFontButton *b)
{ {
// TODO // TODO
SetWindowTextW(b->hwnd, b->font.lfFaceName);
// changing the text might necessitate a change in the button's size // changing the text might necessitate a change in the button's size
uiWindowsControlQueueRelayout(uiWindowsControl(b)); uiWindowsControlQueueRelayout(uiWindowsControl(b));
} }
@ -28,38 +26,20 @@ static void updateFontButtonLabel(uiFontButton *b)
static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
{ {
uiFontButton *b = uiFontButton(c); uiFontButton *b = uiFontButton(c);
CHOOSEFONTW cf; HWND parent;
char *oldFamily;
if (code != BN_CLICKED) if (code != BN_CLICKED)
return FALSE; return FALSE;
ZeroMemory(&cf, sizeof (CHOOSEFONTW)); parent = GetAncestor(b->hwnd, GA_ROOT); // TODO didn't we have a function for this
cf.lStructSize = sizeof (CHOOSEFONTW); oldFamily = (char *) (b->desc.Family);
cf.hwndOwner = GetAncestor(b->hwnd, GA_ROOT); // TODO didn't we have a function for this if (showFontDialog(parent, &(b->desc))) {
showFontDialog(cf.hwndOwner); if (b->already) // don't free the static Arial string
cf.lpLogFont = &(b->font); uiFree(oldFamily);
ZeroMemory(&(b->font), sizeof(LOGFONTW));
b->font.lfFaceName[0]='A';
b->font.lfFaceName[1]='r';
b->font.lfFaceName[2]='i';
b->font.lfFaceName[3]='a';
b->font.lfFaceName[4]='l';
b->font.lfFaceName[5]=0;
b->font.lfHeight=-15*96/72;
// TODO CF_FORCEFONTEXIST? CF_INACTIVEFONTS? CF_NOSCRIPTSEL? CF_USESTYLE?
// if (b->already)
cf.Flags = CF_INITTOLOGFONTSTRUCT;
if (ChooseFontW(&cf) != FALSE) {
b->already = TRUE; b->already = TRUE;
updateFontButtonLabel(b); updateFontButtonLabel(b);
// TODO event // TODO event
} else {
DWORD err;
err = CommDlgExtendedError();
if (err != 0)
// TODO
logLastError("TODO help");
} }
*lResult = 0; *lResult = 0;
@ -120,6 +100,13 @@ uiFontButton *uiNewFontButton(void)
hInstance, NULL, hInstance, NULL,
TRUE); TRUE);
// arbitrary defaults that will do
b->desc.Family = "Arial";
b->desc.Size = 10; // from the real font dialog
b->desc.Weight = uiDrawTextWeightNormal;
b->desc.Italic = uiDrawTextItalicNormal;
b->desc.Stretch = uiDrawTextStretchNormal;
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b)); uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
//TODO uiButtonOnClicked(b, defaultOnClicked, NULL); //TODO uiButtonOnClicked(b, defaultOnClicked, NULL);

View File

@ -2,7 +2,9 @@
#include "uipriv_windows.h" #include "uipriv_windows.h"
// TODOs // TODOs
// - quote the Choose Font sample here for reference
// - the Choose Font sample defaults to Regular/Italic/Bold/Bold Italic in some case (no styles?); do we? find out what the case is // - the Choose Font sample defaults to Regular/Italic/Bold/Bold Italic in some case (no styles?); do we? find out what the case is
// - do we set initial family and style topmost as well?
struct fontDialog { struct fontDialog {
HWND hwnd; HWND hwnd;
@ -10,7 +12,7 @@ struct fontDialog {
HWND styleCombobox; HWND styleCombobox;
HWND sizeCombobox; HWND sizeCombobox;
// TODO desc; uiDrawTextFontDescriptor *desc;
fontCollection *fc; fontCollection *fc;
@ -433,6 +435,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam)
f = uiNew(struct fontDialog); f = uiNew(struct fontDialog);
f->hwnd = hwnd; f->hwnd = hwnd;
f->desc = (uiDrawTextFontDescriptor *) lParam;
f->familyCombobox = GetDlgItem(f->hwnd, rcFontFamilyCombobox); f->familyCombobox = GetDlgItem(f->hwnd, rcFontFamilyCombobox);
if (f->familyCombobox == NULL) if (f->familyCombobox == NULL)
@ -516,8 +519,9 @@ static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam)
return TRUE; return TRUE;
} }
// TODO // OK
// TODO fill f->desc here
f->desc->Size = f->curSize;
endFontDialog(f, 2); endFontDialog(f, 2);
return TRUE; return TRUE;
} }
@ -581,16 +585,16 @@ static INT_PTR CALLBACK fontDialogDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, L
return FALSE; return FALSE;
} }
void showFontDialog(HWND parent) BOOL showFontDialog(HWND parent, uiDrawTextFontDescriptor *desc)
{ {
switch (DialogBoxParamW(hInstance, MAKEINTRESOURCE(rcFontDialog), parent, fontDialogDlgProc, (LPARAM) NULL)) { switch (DialogBoxParamW(hInstance, MAKEINTRESOURCE(rcFontDialog), parent, fontDialogDlgProc, (LPARAM) desc)) {
case 1: case 1: // cancel
// TODO cancel return FALSE;
break; case 2: // ok
case 2: // make the compiler happy by putting the return after the switch
// TODO OK
break; break;
default: default:
logLastError("error running font dialog in showFontDialog()"); logLastError("error running font dialog in showFontDialog()");
} }
return TRUE;
} }

View File

@ -158,7 +158,7 @@ extern WCHAR *fontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedSt
extern void doDrawText(ID2D1RenderTarget *rt, ID2D1Brush *black, double x, double y, uiDrawTextLayout *layout); extern void doDrawText(ID2D1RenderTarget *rt, ID2D1Brush *black, double x, double y, uiDrawTextLayout *layout);
// fontdialog.cpp // fontdialog.cpp
extern void showFontDialog(HWND parent); extern BOOL showFontDialog(HWND parent, uiDrawTextFontDescriptor *desc);
// d2dscratch.c // d2dscratch.c
extern ATOM registerD2DScratchClass(HICON, HCURSOR); extern ATOM registerD2DScratchClass(HICON, HCURSOR);