Started writing a replacement for the standard ChooseFont() dialog that uses DirectWrite instead of GDI.
This commit is contained in:
parent
88e797e2be
commit
97d35571c1
|
@ -43,7 +43,8 @@ CFILES += \
|
|||
|
||||
CXXFILES += \
|
||||
windows/drawtext.cpp \
|
||||
windows/dwrite.cpp
|
||||
windows/dwrite.cpp \
|
||||
windows/fontdialog.cpp
|
||||
|
||||
HFILES += \
|
||||
windows/area.h \
|
||||
|
|
|
@ -36,6 +36,7 @@ static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
|
|||
ZeroMemory(&cf, sizeof (CHOOSEFONTW));
|
||||
cf.lStructSize = sizeof (CHOOSEFONTW);
|
||||
cf.hwndOwner = GetAncestor(b->hwnd, GA_ROOT); // TODO didn't we have a function for this
|
||||
showFontDialog(cf.hwndOwner);
|
||||
cf.lpLogFont = &(b->font);
|
||||
// TODO CF_FORCEFONTEXIST? CF_INACTIVEFONTS? CF_NOSCRIPTSEL? CF_USESTYLE?
|
||||
if (b->already)
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
// 14 april 2016
|
||||
#include "uipriv_windows.h"
|
||||
|
||||
struct fontDialog {
|
||||
HWND hwnd;
|
||||
HWND familyCombobox;
|
||||
HWND styleCombobox;
|
||||
HWND sizeCombobox;
|
||||
HWND smallCapsCheckbox;
|
||||
// TODO desc;
|
||||
fontCollection *fc;
|
||||
};
|
||||
|
||||
static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam)
|
||||
{
|
||||
struct fontDialog *f;
|
||||
|
||||
f = uiNew(struct fontDialog);
|
||||
f->hwnd = hwnd;
|
||||
|
||||
f->familyCombobox = GetDlgItem(f->hwnd, rcFontFamilyCombobox);
|
||||
if (f->familyCombobox == NULL)
|
||||
logLastError("error getting font family combobox handle in beginFontDialog()");
|
||||
f->styleCombobox = GetDlgItem(f->hwnd, rcFontStyleCombobox);
|
||||
if (f->styleCombobox == NULL)
|
||||
logLastError("error getting font style combobox handle in beginFontDialog()");
|
||||
f->sizeCombobox = GetDlgItem(f->hwnd, rcFontSizeCombobox);
|
||||
if (f->sizeCombobox == NULL)
|
||||
logLastError("error getting font size combobox handle in beginFontDialog()");
|
||||
f->smallCapsCheckbox = GetDlgItem(f->hwnd, rcFontSmallCapsCheckbox);
|
||||
if (f->smallCapsCheckbox == NULL)
|
||||
logLastError("error getting small caps checkbox handle in beginFontDialog()");
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static void endFontDialog(struct fontDialog *f, INT_PTR code)
|
||||
{
|
||||
if (EndDialog(f->hwnd, code) == 0)
|
||||
logLastError("error ending font dialog in endFontDialog()");
|
||||
uiFree(f);
|
||||
}
|
||||
|
||||
static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam)
|
||||
{
|
||||
// cancelling
|
||||
if (LOWORD(wParam) != IDOK) {
|
||||
endFontDialog(f, 1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
endFontDialog(f, 2);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static INT_PTR CALLBACK fontDialogDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
struct fontDialog *f;
|
||||
|
||||
f = (struct fontDialog *) GetWindowLongPtrW(hwnd, DWLP_USER);
|
||||
if (f == NULL) {
|
||||
if (uMsg == WM_INITDIALOG) {
|
||||
f = beginFontDialog(hwnd, lParam);
|
||||
SetWindowLongPtrW(hwnd, DWLP_USER, (LONG_PTR) f);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
switch (uMsg) {
|
||||
case WM_COMMAND:
|
||||
if (HIWORD(wParam) != BN_CLICKED)
|
||||
return FALSE;
|
||||
return tryFinishDialog(f, wParam);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void showFontDialog(HWND parent)
|
||||
{
|
||||
switch (DialogBoxParamW(hInstance, MAKEINTRESOURCE(rcFontDialog), parent, fontDialogDlgProc, (LPARAM) NULL)) {
|
||||
case 1:
|
||||
// TODO cancel
|
||||
break;
|
||||
case 2:
|
||||
// TODO OK
|
||||
break;
|
||||
default:
|
||||
logLastError("error running font dialog in showFontDialog()");
|
||||
}
|
||||
}
|
|
@ -1,3 +1,9 @@
|
|||
// 30 may 2015
|
||||
|
||||
#define rcTabPageDialog 100
|
||||
#define rcFontDialog 101
|
||||
|
||||
#define rcFontFamilyCombobox 1000
|
||||
#define rcFontStyleCombobox 1001
|
||||
#define rcFontSizeCombobox 1002
|
||||
#define rcFontSmallCapsCheckbox 1003
|
||||
|
|
|
@ -16,3 +16,35 @@ EXSTYLE WS_EX_CONTROLPARENT
|
|||
BEGIN
|
||||
// nothing
|
||||
END
|
||||
|
||||
// this is for our custom DirectWrite-based font dialog (see fontdialog.cpp)
|
||||
// this is based on the "New Font Dialog with Syslink" in Microsoft's font.dlg
|
||||
// TODO look at localization
|
||||
rcFontDialog DIALOGEX 13, 54, 243, 234
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_3DLOOK
|
||||
CAPTION "Font"
|
||||
FONT 9, "Segoe UI"
|
||||
BEGIN
|
||||
LTEXT "&Font:", -1, 7, 7, 98, 9
|
||||
COMBOBOX rcFontFamilyCombobox, 7, 16, 98, 76,
|
||||
CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL |
|
||||
CBS_SORT | WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS
|
||||
|
||||
LTEXT "Font st&yle:", -1, 114, 7, 74, 9
|
||||
COMBOBOX rcFontStyleCombobox, 114, 16, 74, 76,
|
||||
CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL |
|
||||
WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS
|
||||
|
||||
LTEXT "&Size:", -1, 198, 7, 36, 9
|
||||
COMBOBOX rcFontSizeCombobox, 198, 16, 36, 76,
|
||||
CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL |
|
||||
CBS_SORT | WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS
|
||||
|
||||
AUTOCHECKBOX "S&mall caps", rcFontSmallCapsCheckbox,
|
||||
13, 111, 90, 10, WS_TABSTOP
|
||||
|
||||
GROUPBOX "Sample", -1, 114, 97, 120, 43, WS_GROUP
|
||||
|
||||
DEFPUSHBUTTON "OK", IDOK, 141, 215, 45, 14, WS_GROUP
|
||||
PUSHBUTTON "Cancel", IDCANCEL, 190, 215, 45, 14, WS_GROUP
|
||||
END
|
||||
|
|
|
@ -155,6 +155,9 @@ extern void fontCollectionFree(fontCollection *fc);
|
|||
// drawtext.cpp
|
||||
extern void doDrawText(ID2D1RenderTarget *rt, ID2D1Brush *black, double x, double y, uiDrawTextLayout *layout);
|
||||
|
||||
// fontdialog.cpp
|
||||
extern void showFontDialog(HWND parent);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue