[PATCH 2/4] comdlg32/fontdlg: Allow font sizes outside of defaults set
Nikolay Sivov
nsivov at codeweavers.com
Mon Dec 21 16:19:31 CST 2015
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
For https://bugs.winehq.org/show_bug.cgi?id=25104
dlls/comdlg32/cdlg.h | 1 +
dlls/comdlg32/comdlg32.rc | 1 +
dlls/comdlg32/fontdlg.c | 75 +++++++++++++++++++++++++++++++++++++----------
3 files changed, 61 insertions(+), 16 deletions(-)
diff --git a/dlls/comdlg32/cdlg.h b/dlls/comdlg32/cdlg.h
index 886804c..849b986 100644
--- a/dlls/comdlg32/cdlg.h
+++ b/dlls/comdlg32/cdlg.h
@@ -177,6 +177,7 @@ typedef struct {
#define IDS_SAVE_AS 1204
#define IDS_OPEN_FILE 1205
#define IDS_SELECT_FOLDER 1206
+#define IDS_FONT_SIZE_INPUT 1207
#define IDS_FAKEDOCTEXT 1300
diff --git a/dlls/comdlg32/comdlg32.rc b/dlls/comdlg32/comdlg32.rc
index 5113e80..7d0fbb5 100644
--- a/dlls/comdlg32/comdlg32.rc
+++ b/dlls/comdlg32/comdlg32.rc
@@ -144,6 +144,7 @@ STRINGTABLE
IDS_SAVE_AS "Save As"
IDS_OPEN_FILE "Open File"
IDS_SELECT_FOLDER "Select Folder"
+ IDS_FONT_SIZE_INPUT "Font size has to be a number."
}
/*
diff --git a/dlls/comdlg32/fontdlg.c b/dlls/comdlg32/fontdlg.c
index 8ba9c1e..245f150 100644
--- a/dlls/comdlg32/fontdlg.c
+++ b/dlls/comdlg32/fontdlg.c
@@ -32,6 +32,7 @@
#include "commdlg.h"
#include "dlgs.h"
#include "wine/debug.h"
+#include "wine/unicode.h"
#include "cderr.h"
#include "cdlg.h"
@@ -531,10 +532,12 @@ static INT AddFontStyle( const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *
return 1 ;
}
-static BOOL CFn_FitFontSize( HWND hDlg, int points)
+static void CFn_FitFontSize( HWND hDlg, int points)
{
+ static const WCHAR fmtW[] = {'%','d',0};
+ WCHAR buffW[16];
int i,n;
- BOOL ret = FALSE;
+
/* look for fitting font size in combobox3 */
n=SendDlgItemMessageW(hDlg, cmb3, CB_GETCOUNT, 0, 0);
for (i=0;i<n;i++)
@@ -546,11 +549,13 @@ static BOOL CFn_FitFontSize( HWND hDlg, int points)
SendMessageW(hDlg, WM_COMMAND,
MAKEWPARAM(cmb3, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb3));
- ret = TRUE;
- break;
+ return;
}
}
- return ret;
+
+ /* no default matching size, set text manually */
+ sprintfW(buffW, fmtW, points);
+ SetDlgItemTextW(hDlg, cmb3, buffW);
}
static BOOL CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
@@ -905,6 +910,31 @@ static LRESULT CFn_WMDrawItem(LPARAM lParam)
return TRUE;
}
+static INT get_dialog_font_point_size(HWND hDlg, CHOOSEFONTW *cf)
+{
+ BOOL invalid_size = FALSE;
+ INT i, size;
+
+ i = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
+ if (i != CB_ERR)
+ size = LOWORD(SendDlgItemMessageW(hDlg, cmb3, CB_GETITEMDATA , i, 0));
+ else
+ {
+ WCHAR buffW[8], *endptrW;
+
+ GetDlgItemTextW(hDlg, cmb3, buffW, sizeof(buffW)/sizeof(*buffW));
+ size = strtolW(buffW, &endptrW, 10);
+ invalid_size = size == 0 && *endptrW;
+
+ if (size == 0)
+ size = 10;
+ }
+
+ cf->iPointSize = 10 * size;
+ cf->lpLogFont->lfHeight = -MulDiv(cf->iPointSize, GetScreenDPI(), 720);
+ return invalid_size ? -1 : size;
+}
+
/***********************************************************************
* CFn_WMCommand [internal]
*/
@@ -978,6 +1008,8 @@ static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFO
LPLOGFONTW lpxx=lpcf->lpLogFont;
TRACE("WM_COMMAND/cmb2,3 =%08lX\n", lParam);
+
+ /* face name */
i=SendDlgItemMessageW(hDlg,cmb1,CB_GETCURSEL,0,0);
if (i==CB_ERR)
i=GetDlgItemTextW( hDlg, cmb1, str, 256 );
@@ -993,6 +1025,8 @@ static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFO
lpxx->lfPitchAndFamily = HIWORD(l) >> 8;
}
lstrcpynW(lpxx->lfFaceName, str, sizeof(lpxx->lfFaceName)/sizeof(lpxx->lfFaceName[0]));
+
+ /* style */
i=SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
if (i!=CB_ERR)
{
@@ -1002,14 +1036,11 @@ static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFO
if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
lpcf->nFontType |= BOLD_FONTTYPE;
}
- i=SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
- if( i != CB_ERR)
- lpcf->iPointSize = 10 * LOWORD(SendDlgItemMessageW(hDlg, cmb3,
- CB_GETITEMDATA , i, 0));
- else
- lpcf->iPointSize = 100;
- lpxx->lfHeight = - MulDiv( lpcf->iPointSize ,
- GetScreenDPI(), 720);
+
+ /* size */
+ get_dialog_font_point_size(hDlg, lpcf);
+
+ /* charset */
i=SendDlgItemMessageW(hDlg, cmb5, CB_GETCURSEL, 0, 0);
if (i!=CB_ERR)
lpxx->lfCharSet=SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
@@ -1056,6 +1087,18 @@ static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFO
break;
case IDOK:
+ {
+ WCHAR msgW[80];
+ INT pointsize;
+
+ pointsize = get_dialog_font_point_size(hDlg, lpcf);
+ if (pointsize == -1)
+ {
+ LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE_INPUT, msgW, sizeof(msgW)/sizeof(*msgW));
+ MessageBoxW(hDlg, msgW, NULL, MB_OK | MB_ICONINFORMATION);
+ return TRUE;
+ }
+
if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
( (lpcf->Flags & CF_LIMITSIZE) &&
(lpcf->iPointSize >= 10 * lpcf->nSizeMin) &&
@@ -1063,18 +1106,18 @@ static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFO
EndDialog(hDlg, TRUE);
else
{
- WCHAR buffer[80];
WCHAR format[80];
DWORD_PTR args[2];
LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE, format, sizeof(format)/sizeof(WCHAR));
args[0] = lpcf->nSizeMin;
args[1] = lpcf->nSizeMax;
FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
- format, 0, 0, buffer, sizeof(buffer)/sizeof(*buffer),
+ format, 0, 0, msgW, sizeof(msgW)/sizeof(*msgW),
(__ms_va_list*)args);
- MessageBoxW(hDlg, buffer, NULL, MB_OK);
+ MessageBoxW(hDlg, msgW, NULL, MB_OK);
}
return(TRUE);
+ }
case IDCANCEL:
EndDialog(hDlg, FALSE);
return(TRUE);
--
2.6.4
More information about the wine-patches
mailing list