changeset 2255:66d0f1df4b34

Win: Cleanup after testing the last commit... Remove _dw_default_charformat. After testing on many versions of Windows, CHARFORMAT2 szFaceName is empty and yHeight is 180 (9 point) so don't bother saving it during MLE creation... Also the MLE Word Wrap feature test was broken, it always reported unsupported. Now it will report enabled when Rich Edit MLE is enabled, otherwise unsupported. Word Wrap feature is not configurable, but Rich Edit MLE is, so use that if needed.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 25 Jan 2021 21:14:13 +0000
parents 48daaf050e82
children b7467bceb2cd
files win/dw.c
diffstat 1 files changed, 32 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/win/dw.c	Mon Jan 25 20:39:52 2021 +0000
+++ b/win/dw.c	Mon Jan 25 21:14:13 2021 +0000
@@ -42,7 +42,6 @@
 
 #ifdef RICHEDIT
 int _DW_MLE_RICH_EDIT = DW_FEATURE_UNSUPPORTED;
-static CHARFORMAT2 _dw_default_charformat = {0};
 #endif
 
 #define STATICCLASSNAME TEXT("STATIC")
@@ -5711,11 +5710,21 @@
             cf.dwMask = CFM_FACE | CFM_SIZE | CFM_ITALIC | CFM_BOLD;
             cf.dwEffects = (Italic ? CFE_ITALIC : 0) | (Bold ? CFE_BOLD : 0);
             _tcsncpy(cf.szFaceName, UTF8toWide(myFontName), (sizeof(cf.szFaceName)/sizeof(TCHAR))-1);
+            /* yHeight is apparently the point size * 20, defaulting to 9 (180) */
             cf.yHeight = (size > 0) ? (size * 20) : 180;
             SendMessage(handle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf);
        }
        else
-           SendMessage(handle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&_dw_default_charformat);
+       {
+           /* On testing what the default is, the szFaceName is empty,
+            * yHeight is 180 (9 point). So use that to reset to default.
+            */
+           CHARFORMAT2 cf = {0};
+           cf.cbSize = sizeof(cf);
+           cf.yHeight = 180;
+           cf.dwMask = CFM_FACE | CFM_SIZE | CFM_ITALIC | CFM_BOLD;
+           SendMessage(handle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf);
+       }
     }
     else
 #endif
@@ -7037,18 +7046,7 @@
 
 #ifdef RICHEDIT
    if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit))
-   {
       cinfo->cinfo.pOldProc = SubclassWindow(tmp, _richeditwndproc);
-      /* Save the default RichEdit font for later use */
-      _dw_default_charformat.cbSize = sizeof(_dw_default_charformat);
-      SendMessage(tmp, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&_dw_default_charformat);
-      /* Make sure we set the mask we will use for reseting the MLE later */
-      _dw_default_charformat.dwMask = CFM_FACE | CFM_SIZE | CFM_ITALIC | CFM_BOLD;
-      dw_debug("Default CHARFORMAT szFaceName \"%s\" dwMask %x yHeight %d\n", WideToUTF8(_dw_default_charformat.szFaceName), 
-                (int)_dw_default_charformat.dwMask, (int)_dw_default_charformat.yHeight);
-      if(_dw_default_charformat.yHeight < 1)
-         _dw_default_charformat.yHeight = 180;
-   }
    else
 #endif
    cinfo->cinfo.pOldProc = SubclassWindow(tmp, _simplewndproc);
@@ -13874,6 +13872,16 @@
         }
 #endif
 #ifdef RICHEDIT
+        /* Word wrap support on Windows is tied to Rich Edit,
+         * if Rich Edit MLE is unsupported or disabled...
+         * Word Wrap will return Unsupported.
+         */
+        case DW_FEATURE_MLE_WORD_WRAP:
+        {
+            if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit))
+                return DW_FEATURE_ENABLED;
+            return DW_FEATURE_UNSUPPORTED;
+        }
         case DW_FEATURE_MLE_RICH_EDIT:
         {
             if(hmsftedit || hrichedit)
@@ -13938,6 +13946,17 @@
         }
 #endif
 #ifdef RICHEDIT
+        /* Word wrap support on Windows is tied to Rich Edit,
+         * if Rich Edit MLE is unsupported or disabled...
+         * Word Wrap will return Unsupported. If supported, 
+         * it is not configurable, configure Rich Edit instead.
+         */
+        case DW_FEATURE_MLE_WORD_WRAP:
+        {
+            if(_DW_MLE_RICH_EDIT == DW_FEATURE_ENABLED && (hrichedit || hmsftedit))
+                return DW_ERROR_GENERAL;
+            return DW_FEATURE_UNSUPPORTED;
+        }
         case DW_FEATURE_MLE_RICH_EDIT:
         {
             if(state >= DW_FEATURE_DISABLED && state <= DW_FEATURE_ENABLED)