📄 fontdlg.c
字号:
((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
{
wsprintfW(buffer, strFormat, h);
j=SendMessageW(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
if (j==CB_ERR)
{
j=SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
if (j!=CB_ERR) j = SendMessageW(hwnd, CB_SETITEMDATA, j, h);
if (j==CB_ERR) return 1;
}
}
return 0;
}
/*************************************************************************
* SetFontSizesToCombo3 [internal]
*/
static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTW lpcf)
{
static const BYTE sizes[]={6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
int i;
for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
return 0;
}
/*************************************************************************
* CFn_GetDC [internal]
*/
static inline HDC CFn_GetDC(LPCHOOSEFONTW lpcf)
{
HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ?
lpcf->hDC :
GetDC(0);
if(!ret) ERR("HDC failure!!!\n");
return ret;
}
/*************************************************************************
* CFn_ReleaseDC [internal]
*/
static inline void CFn_ReleaseDC(LPCHOOSEFONTW lpcf, HDC hdc)
{
if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
ReleaseDC(0, hdc);
}
/***********************************************************************
* AddFontStyle [internal]
*/
INT AddFontStyle( const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
UINT nFontType, LPCHOOSEFONTW lpcf, HWND hcmb2, HWND hcmb3,
HWND hDlg, BOOL iswin16)
{
int i;
const LOGFONTW *lplf = &(lpElfex->elfLogFont);
HWND hcmb5;
HDC hdc;
TRACE("(nFontType=%d)\n",nFontType);
TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
" ch=%d op=%d cp=%d q=%d pf=%xh\n",
debugstr_w(lplf->lfFaceName),lplf->lfHeight,lplf->lfWidth,
lplf->lfEscapement,lplf->lfOrientation,
lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
if (nFontType & RASTER_FONTTYPE)
{
INT points;
if(!(hdc = CFn_GetDC(lpcf))) return 0;
points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.tmInternalLeading,
72, GetDeviceCaps(hdc, LOGPIXELSY));
CFn_ReleaseDC(lpcf, hdc);
i = AddFontSizeToCombo3(hcmb3, points, lpcf);
if(i) return 0;
} else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
if (!SendMessageW(hcmb2, CB_GETCOUNT, 0, 0))
{
if(!(hdc = CFn_GetDC(lpcf))) return 0;
i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
CFn_ReleaseDC(lpcf, hdc);
if (i)
return 0;
}
if( iswin16 || !( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
i = SendMessageW( hcmb5, CB_FINDSTRINGEXACT, 0,
(LPARAM)lpElfex->elfScript);
if( i == CB_ERR) {
i = SendMessageW( hcmb5, CB_ADDSTRING, 0,
(LPARAM)lpElfex->elfScript);
if( i != CB_ERR)
SendMessageW( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
}
return 1 ;
}
static INT CFn_FitFontSize( HWND hDlg, int points)
{
int i,n;
int ret = 0;
/* look for fitting font size in combobox3 */
n=SendDlgItemMessageW(hDlg, cmb3, CB_GETCOUNT, 0, 0);
for (i=0;i<n;i++)
{
if (points == (int)SendDlgItemMessageW
(hDlg,cmb3, CB_GETITEMDATA,i,0))
{
SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,i,0);
SendMessageW(hDlg, WM_COMMAND,
MAKEWPARAM(cmb3, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb3));
ret = 1;
break;
}
}
return ret;
}
static INT CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
{
LONG id;
int i, ret = 0;
/* look for fitting font style in combobox2 */
for (i=0;i<TEXT_EXTRAS;i++)
{
id = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
if (packedstyle == id)
{
SendDlgItemMessageW(hDlg, cmb2, CB_SETCURSEL, i, 0);
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb2));
ret = 1;
break;
}
}
return ret;
}
static INT CFn_FitCharSet( HWND hDlg, int charset )
{
int i,n,cs;
/* look for fitting char set in combobox5 */
n=SendDlgItemMessageW(hDlg, cmb5, CB_GETCOUNT, 0, 0);
for (i=0;i<n;i++)
{
cs =SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
if (charset == cs)
{
SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, i, 0);
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb2));
return 1;
}
}
/* no charset fits: select the first one in the list */
SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, 0, 0);
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb2));
return 0;
}
/***********************************************************************
* FontStyleEnumProc32 [internal]
*/
static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXW *lpElfex,
const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam )
{
LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
HWND hcmb2=s->hWnd1;
HWND hcmb3=s->hWnd2;
HWND hDlg=GetParent(hcmb3);
return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
dwFontType, s->lpcf32w, hcmb2, hcmb3, hDlg, FALSE);
}
/***********************************************************************
* CFn_WMInitDialog [internal]
*/
LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
LPCHOOSEFONTW lpcf)
{
HDC hdc;
int i,j,init=0;
long pstyle;
CFn_ENUMSTRUCT s;
LPLOGFONTW lpxx;
HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
static const WCHAR strColorName[] = {'[','c','o','l','o','r',' ','n','a','m','e',']',0};
SetPropW(hDlg, strWineFontData, (HANDLE)lpcf);
lpxx=lpcf->lpLogFont;
TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
if (lpcf->lStructSize != sizeof(CHOOSEFONTW))
{
ERR("structure size failure !!!\n");
EndDialog (hDlg, 0);
return FALSE;
}
if (!himlTT)
himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
if (!(lpcf->Flags & CF_APPLY))
ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
if (lpcf->Flags & CF_EFFECTS)
{
for (i=0;i<TEXT_COLORS;i++)
{
WCHAR name[30];
if( LoadStringW(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name,
sizeof(name)/sizeof(*name) )==0 )
{
memcpy(name, strColorName, sizeof(strColorName));
}
j=SendDlgItemMessageW(hDlg, cmb4, CB_ADDSTRING, 0, (LPARAM)name);
SendDlgItemMessageW(hDlg, cmb4, CB_SETITEMDATA, j, textcolors[i]);
/* look for a fitting value in color combobox */
if (textcolors[i]==lpcf->rgbColors)
SendDlgItemMessageW(hDlg,cmb4, CB_SETCURSEL,j,0);
}
}
else
{
ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
}
if(!(hdc = CFn_GetDC(lpcf)))
{
EndDialog (hDlg, 0);
return FALSE;
}
s.hWnd1=GetDlgItem(hDlg,cmb1);
s.lpcf32w=lpcf;
do {
LOGFONTW elf;
s.added = 0;
elf.lfCharSet = DEFAULT_CHARSET; /* enum all charsets */
elf.lfPitchAndFamily = 0;
elf.lfFaceName[0] = '\0'; /* enum all fonts */
if (!EnumFontFamiliesExW(hdc, &elf, (FONTENUMPROCW)FontFamilyEnumProc, (LPARAM)&s, 0))
{
TRACE("EnumFontFamiliesEx returns 0\n");
break;
}
if (s.added) break;
if (lpcf->Flags & CF_FIXEDPITCHONLY) {
FIXME("No font found with fixed pitch only, dropping flag.\n");
lpcf->Flags &= ~CF_FIXEDPITCHONLY;
continue;
}
if (lpcf->Flags & CF_TTONLY) {
FIXME("No font found with truetype only, dropping flag.\n");
lpcf->Flags &= ~CF_TTONLY;
continue;
}
break;
} while (1);
if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
{
/* look for fitting font name in combobox1 */
j=SendDlgItemMessageW(hDlg,cmb1,CB_FINDSTRING,-1,(LPARAM)lpxx->lfFaceName);
if (j!=CB_ERR)
{
INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
lpxx->lfHeight;
INT points;
int charset = lpxx->lfCharSet;
points = MulDiv( height, 72, GetDeviceCaps(hdc, LOGPIXELSY));
pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
FW_NORMAL,lpxx->lfItalic !=0);
SendDlgItemMessageW(hDlg, cmb1, CB_SETCURSEL, j, 0);
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb1));
init=1;
/* look for fitting font style in combobox2 */
CFn_FitFontStyle(hDlg, pstyle);
/* look for fitting font size in combobox3 */
CFn_FitFontSize(hDlg, points);
CFn_FitCharSet( hDlg, charset );
}
}
if (!init)
{
SendDlgItemMessageW(hDlg,cmb1,CB_SETCURSEL,0,0);
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb1));
}
if ((lpcf->Flags & CF_USESTYLE) && lpcf->lpszStyle)
{
j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LPARAM)lpcf->lpszStyle);
if (j!=CB_ERR)
{
j=SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,j,0);
SendMessageW(hDlg,WM_COMMAND,cmb2,
MAKELONG(HWND_16(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
}
}
CFn_ReleaseDC(lpcf, hdc);
SetCursor(hcursor);
return TRUE;
}
/***********************************************************************
* CFn_WMMeasureItem [internal]
*/
LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
HFONT hfontprev;
TEXTMETRICW tm;
LPMEASUREITEMSTRUCT lpmi=(LPMEASUREITEMSTRUCT)lParam;
INT height = 0;
if (!himlTT)
himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
ImageList_GetIconSize( himlTT, 0, &height);
lpmi->itemHeight = height + 2;
/* use MAX of bitmap height and tm.tmHeight .*/
hdc=GetDC(hDlg);
if(!hdc) return 0;
hfontprev = SelectObject( hdc, GetStockObject( SYSTEM_FONT));
GetTextMetricsW(hdc, &tm);
if( tm.tmHeight > lpmi->itemHeight) lpmi->itemHeight = tm.tmHeight;
SelectObject(hdc, hfontprev);
ReleaseDC(hDlg, hdc);
return 0;
}
/***********************************************************************
* CFn_WMDrawItem [internal]
*/
LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
HBRUSH hBrush;
WCHAR buffer[40];
COLORREF cr, oldText=0, oldBk=0;
RECT rect;
int nFontType;
int idx;
LPDRAWITEMSTRUCT lpdi = (LPDRAWITEMSTRUCT)lParam;
if (lpdi->itemID == (UINT)-1) /* got no items */
DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
else
{
if (lpdi->CtlType == ODT_COMBOBOX)
{
if (lpdi->itemState & ODS_SELECTED)
{
hBrush=GetSysColorBrush(COLOR_HIGHLIGHT);
oldText=SetTextColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
oldBk=SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
} else
{
hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
SelectObject(lpdi->hDC, hBrush);
}
FillRect(lpdi->hDC, &lpdi->rcItem, hBrush);
}
else
return TRUE; /* this should never happen */
rect=lpdi->rcItem;
switch (lpdi->CtlID)
{
case cmb1:
/* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
(LPARAM)buffer);
TextOutW(lpdi->hDC, lpdi->rcItem.left + TTBITMAP_XSIZE + 10,
lpdi->rcItem.top, buffer, lstrlenW(buffer));
nFontType = SendMessageW(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
idx = -1;
if (nFontType & TRUETYPE_FONTTYPE) {
idx = 0; /* picture: TT */
if( nFontType & NTM_TT_OPENTYPE)
idx = 2; /* picture: O */
} else if( nFontType & NTM_PS_OPENTYPE)
idx = 3; /* picture: O+ps */
else if( nFontType & NTM_TYPE1)
idx = 4; /* picture: a */
else if( nFontType & DEVICE_FONTTYPE)
idx = 1; /* picture: printer */
if( idx >= 0)
ImageList_Draw( himlTT, idx, lpdi->hDC, lpdi->rcItem.left,
lpdi->rcItem.top, ILD_TRANSPARENT);
break;
case cmb2:
case cmb3:
/* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
case cmb5:
SendMessageW(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
(LPARAM)buffer);
TextOutW(lpdi->hDC, lpdi->rcItem.left,
lpdi->rcItem.top, buffer, lstrlenW(buffer));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -