1
1
/*
2
- * Edit control
2
+ * Edit control
3
3
*
4
- * Copyright David W. Metcalfe, 1994
5
- * Copyright William Magro, 1995, 1996
6
- * Copyright Frans van Dorsselaer, 1996, 1997
4
+ * Copyright David W. Metcalfe, 1994
5
+ * Copyright William Magro, 1995, 1996
6
+ * Copyright Frans van Dorsselaer, 1996, 1997
7
7
*
8
8
*
9
9
* This library is free software; you can redistribute it and/or
@@ -2904,30 +2904,30 @@ static void EDIT_EM_SetLimitText(EDITSTATE *es, UINT limit)
2904
2904
2905
2905
/*********************************************************************
2906
2906
*
2907
- * EM_SETMARGINS
2907
+ * EM_SETMARGINS
2908
2908
*
2909
2909
* EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2910
2910
* action wParam despite what the docs say. EC_USEFONTINFO calculates the
2911
2911
* margin according to the textmetrics of the current font.
2912
2912
*
2913
- * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
2914
- * of the char's width as the margin, but this is not how Windows handles this.
2915
- * For all other fonts Windows sets the margins to zero.
2916
- *
2917
- * FIXME - When EC_USEFONTINFO is used the margins only change if the
2918
- * edit control is equal to or larger than a certain size.
2919
- * Interestingly if one subtracts both the left and right margins from
2920
- * this size one always seems to get an even number. The extents of
2921
- * the (four character) string "'**'" match this quite closely, so
2922
- * we'll use this until we come up with a better idea.
2913
+ * When EC_USEFONTINFO is used in the non_cjk case the margins only
2914
+ * change if the edit control is equal to or larger than a certain
2915
+ * size. Though there is an exception for the empty client rect case
2916
+ * with small font sizes.
2923
2917
*/
2924
- static int calc_min_set_margin_size ( HDC dc , INT left , INT right )
2918
+ static BOOL is_cjk ( UINT charset )
2925
2919
{
2926
- static const WCHAR magic_string [] = {'\'' ,'*' ,'*' ,'\'' , 0 };
2927
- SIZE sz ;
2928
-
2929
- GetTextExtentPointW (dc , magic_string , sizeof (magic_string )/sizeof (WCHAR ) - 1 , & sz );
2930
- return sz .cx + left + right ;
2920
+ switch (charset )
2921
+ {
2922
+ case SHIFTJIS_CHARSET :
2923
+ case HANGUL_CHARSET :
2924
+ case GB2312_CHARSET :
2925
+ case CHINESEBIG5_CHARSET :
2926
+ return TRUE;
2927
+ }
2928
+ /* HANGUL_CHARSET is strange, though treated as CJK by Win 8, it is
2929
+ * not by other versions including Win 10. */
2930
+ return FALSE;
2931
2931
}
2932
2932
2933
2933
static void EDIT_EM_SetMargins (EDITSTATE * es , INT action ,
@@ -2941,19 +2941,25 @@ static void EDIT_EM_SetMargins(EDITSTATE *es, INT action,
2941
2941
if (es -> font && (left == EC_USEFONTINFO || right == EC_USEFONTINFO )) {
2942
2942
HDC dc = GetDC (es -> hwndSelf );
2943
2943
HFONT old_font = SelectObject (dc , es -> font );
2944
- GetTextMetricsW (dc , & tm );
2944
+ LONG width = GdiGetCharDimensions (dc , & tm , NULL );
2945
+ RECT rc ;
2946
+
2945
2947
/* The default margins are only non zero for TrueType or Vector fonts */
2946
2948
if (tm .tmPitchAndFamily & ( TMPF_VECTOR | TMPF_TRUETYPE )) {
2947
- int min_size ;
2948
- RECT rc ;
2949
- /* This must be calculated more exactly! But how? */
2950
- default_left_margin = tm .tmAveCharWidth / 2 ;
2951
- default_right_margin = tm .tmAveCharWidth / 2 ;
2952
- min_size = calc_min_set_margin_size (dc , default_left_margin , default_right_margin );
2953
- GetClientRect (es -> hwndSelf , & rc );
2954
- if (!IsRectEmpty (& rc ) && (rc .right - rc .left < min_size )) {
2955
- default_left_margin = es -> left_margin ;
2956
- default_right_margin = es -> right_margin ;
2949
+ if (!is_cjk (tm .tmCharSet )) {
2950
+ default_left_margin = width / 2 ;
2951
+ default_right_margin = width / 2 ;
2952
+
2953
+ GetClientRect (es -> hwndSelf , & rc );
2954
+ if (rc .right - rc .left < (width / 2 + width ) * 2 &&
2955
+ (width >= 28 || !IsRectEmpty (& rc )) ) {
2956
+ default_left_margin = es -> left_margin ;
2957
+ default_right_margin = es -> right_margin ;
2958
+ }
2959
+ } else {
2960
+ /* FIXME: figure out the CJK values. They are not affected by the client rect. */
2961
+ default_left_margin = width / 2 ;
2962
+ default_right_margin = width / 2 ;
2957
2963
}
2958
2964
}
2959
2965
SelectObject (dc , old_font );
0 commit comments