comparison win/dw.c @ 2254:48daaf050e82

Win: Experimental change to use CHARFORMAT2 to set the Rich Edit MLE font size. Remove EM_SETFONTSIZE message since it did not seem to function at all. This needs testing and cleanup, but it seems mostly functional on Win 10.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 25 Jan 2021 20:39:52 +0000
parents a691de150bef
children 66d0f1df4b34
comparison
equal deleted inserted replaced
2253:08369a79850f 2254:48daaf050e82
40 #endif 40 #endif
41 #include <richedit.h> 41 #include <richedit.h>
42 42
43 #ifdef RICHEDIT 43 #ifdef RICHEDIT
44 int _DW_MLE_RICH_EDIT = DW_FEATURE_UNSUPPORTED; 44 int _DW_MLE_RICH_EDIT = DW_FEATURE_UNSUPPORTED;
45 static CHARFORMAT _dw_default_charformat = {0}; 45 static CHARFORMAT2 _dw_default_charformat = {0};
46 #endif 46 #endif
47 47
48 #define STATICCLASSNAME TEXT("STATIC") 48 #define STATICCLASSNAME TEXT("STATIC")
49 #define COMBOBOXCLASSNAME TEXT("COMBOBOX") 49 #define COMBOBOXCLASSNAME TEXT("COMBOBOX")
50 #define LISTBOXCLASSNAME TEXT("LISTBOX") 50 #define LISTBOXCLASSNAME TEXT("LISTBOX")
5689 if (_tcsnicmp(tmpbuf, RICHEDIT_CLASS, _tcslen(RICHEDIT_CLASS)+1) == 0 || 5689 if (_tcsnicmp(tmpbuf, RICHEDIT_CLASS, _tcslen(RICHEDIT_CLASS)+1) == 0 ||
5690 _tcsnicmp(tmpbuf, MSFTEDIT_CLASS, _tcslen(MSFTEDIT_CLASS)+1) == 0) 5690 _tcsnicmp(tmpbuf, MSFTEDIT_CLASS, _tcslen(MSFTEDIT_CLASS)+1) == 0)
5691 { 5691 {
5692 if(fontname) 5692 if(fontname)
5693 { 5693 {
5694 CHARFORMAT cf = {0}; 5694 CHARFORMAT2 cf = {0};
5695 char *Italic, *Bold, *myFontName = strchr(fontname, '.'); 5695 char *Italic, *Bold, *myFontName = strchr(fontname, '.');
5696 int size = atoi(fontname); 5696 int size = atoi(fontname);
5697 5697
5698 /* If we found a '.' use the location after the . */ 5698 /* If we found a '.' use the location after the . */
5699 if(myFontName) 5699 if(myFontName)
5706 if((Bold = strstr(myFontName, " Bold"))) 5706 if((Bold = strstr(myFontName, " Bold")))
5707 *Bold = 0; 5707 *Bold = 0;
5708 5708
5709 cf.cbSize = sizeof(cf); 5709 cf.cbSize = sizeof(cf);
5710 SendMessage(handle, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf); 5710 SendMessage(handle, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf);
5711 cf.dwMask = CFM_FACE | CFM_ITALIC | CFM_BOLD; 5711 cf.dwMask = CFM_FACE | CFM_SIZE | CFM_ITALIC | CFM_BOLD;
5712 cf.dwEffects = (Italic ? CFE_ITALIC : 0) | (Bold ? CFE_BOLD : 0); 5712 cf.dwEffects = (Italic ? CFE_ITALIC : 0) | (Bold ? CFE_BOLD : 0);
5713 _tcsncpy(cf.szFaceName, UTF8toWide(myFontName), (sizeof(cf.szFaceName)/sizeof(TCHAR))-1); 5713 _tcsncpy(cf.szFaceName, UTF8toWide(myFontName), (sizeof(cf.szFaceName)/sizeof(TCHAR))-1);
5714 cf.yHeight = (size > 0) ? (size * 20) : 180;
5714 SendMessage(handle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf); 5715 SendMessage(handle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf);
5715
5716 SendMessage(handle, EM_SETFONTSIZE , (WPARAM)(size ? size : 9), 0);
5717 free(myFontName);
5718 } 5716 }
5719 else 5717 else
5720 {
5721 SendMessage(handle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&_dw_default_charformat); 5718 SendMessage(handle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&_dw_default_charformat);
5722 SendMessage(handle, EM_SETFONTSIZE , (WPARAM)9, 0);
5723 }
5724 } 5719 }
5725 else 5720 else
5726 #endif 5721 #endif
5727 { 5722 {
5728 /* This needs to be after we get the correct handle */ 5723 /* This needs to be after we get the correct handle */
5900 else if (_tcsnicmp(tmpbuf, RICHEDIT_CLASS, _tcslen(RICHEDIT_CLASS)+1) == 0 || 5895 else if (_tcsnicmp(tmpbuf, RICHEDIT_CLASS, _tcslen(RICHEDIT_CLASS)+1) == 0 ||
5901 _tcsnicmp(tmpbuf, MSFTEDIT_CLASS, _tcslen(MSFTEDIT_CLASS)+1) == 0) 5896 _tcsnicmp(tmpbuf, MSFTEDIT_CLASS, _tcslen(MSFTEDIT_CLASS)+1) == 0)
5902 { 5897 {
5903 ULONG _fore = _internal_color(fore); 5898 ULONG _fore = _internal_color(fore);
5904 ULONG _back = _internal_color(back); 5899 ULONG _back = _internal_color(back);
5905 CHARFORMAT cf; 5900 CHARFORMAT2 cf;
5906 5901
5907 SendMessage(handle, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf); 5902 SendMessage(handle, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf);
5908 cf.cbSize = sizeof(cf); 5903 cf.cbSize = sizeof(cf);
5909 cf.dwMask = CFM_COLOR; 5904 cf.dwMask = CFM_COLOR;
5910 cf.dwEffects = 0; 5905 cf.dwEffects = 0;
7043 #ifdef RICHEDIT 7038 #ifdef RICHEDIT
7044 if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit)) 7039 if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit))
7045 { 7040 {
7046 cinfo->cinfo.pOldProc = SubclassWindow(tmp, _richeditwndproc); 7041 cinfo->cinfo.pOldProc = SubclassWindow(tmp, _richeditwndproc);
7047 /* Save the default RichEdit font for later use */ 7042 /* Save the default RichEdit font for later use */
7048 _dw_default_charformat.cbSize = sizeof(CHARFORMAT); 7043 _dw_default_charformat.cbSize = sizeof(_dw_default_charformat);
7049 SendMessage(tmp, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&_dw_default_charformat); 7044 SendMessage(tmp, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&_dw_default_charformat);
7050 /* Make sure we set the mask we will use for reseting the MLE later */ 7045 /* Make sure we set the mask we will use for reseting the MLE later */
7051 _dw_default_charformat.dwMask = CFM_FACE | CFM_ITALIC | CFM_BOLD; 7046 _dw_default_charformat.dwMask = CFM_FACE | CFM_SIZE | CFM_ITALIC | CFM_BOLD;
7047 dw_debug("Default CHARFORMAT szFaceName \"%s\" dwMask %x yHeight %d\n", WideToUTF8(_dw_default_charformat.szFaceName),
7048 (int)_dw_default_charformat.dwMask, (int)_dw_default_charformat.yHeight);
7049 if(_dw_default_charformat.yHeight < 1)
7050 _dw_default_charformat.yHeight = 180;
7052 } 7051 }
7053 else 7052 else
7054 #endif 7053 #endif
7055 cinfo->cinfo.pOldProc = SubclassWindow(tmp, _simplewndproc); 7054 cinfo->cinfo.pOldProc = SubclassWindow(tmp, _simplewndproc);
7056 cinfo->cinfo.fore = cinfo->cinfo.back = -1; 7055 cinfo->cinfo.fore = cinfo->cinfo.back = -1;