richedit: Respect manually added links when autourldetect is disabled.

Dylan Smith dylan.ah.smith at gmail.com
Mon Mar 9 02:01:00 CDT 2009


EM_SETCHARFORMAT can be used to make text links.  Automatic URL
detection being enable would cause these links to be removed if the text
is not a URL, so this must be prevented.

Previously checks were made for AutoURLDetect_bEnable before calling
ME_UpdateSelectionLinkAttribute, or ME_UpdateLinkAttribute.  This is
more error prone than checking for this within the function, so one call
was missing this check.

ME_SetCursor also didn't respect this behaviour, since it wouldn't set
the cursor to the hand when hovering over a link without automatic URL
detection disabled.
---
 dlls/riched20/editor.c |   50 +++++++++++++++++++++--------------------------
 1 files changed, 22 insertions(+), 28 deletions(-)
-------------- next part --------------
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 93d0c34..c9cb244 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -2040,6 +2040,8 @@ static void ME_UpdateSelectionLinkAttribute(ME_TextEditor *editor)
   ME_DisplayItem *prev_para;
   int from, to;
 
+  if (!editor->AutoURLDetect_bEnable) return;
+
   ME_GetSelection(editor, &from, &to);
 
   /* Find paragraph previous to the one that contains start cursor */
@@ -2235,9 +2237,7 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
           ME_CommitCoalescingUndo(editor);
           SetCursor(NULL);
 
-          if (editor->AutoURLDetect_bEnable)
-            ME_UpdateSelectionLinkAttribute(editor);
-
+          ME_UpdateSelectionLinkAttribute(editor);
           ME_UpdateRepaint(editor);
         }
         return TRUE;
@@ -2396,8 +2396,7 @@ static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode,
       ITextHost_TxSetCursor(editor->texthost, NULL, FALSE);
     }
 
-    if (editor->AutoURLDetect_bEnable) ME_UpdateSelectionLinkAttribute(editor);
-
+    ME_UpdateSelectionLinkAttribute(editor);
     ME_UpdateRepaint(editor);
   }
   return 0;
@@ -2518,22 +2517,20 @@ static BOOL ME_SetCursor(ME_TextEditor *editor)
   offset = ME_CharFromPos(editor, pt.x, pt.y, &isExact);
   if (isExact)
   {
-      if (editor->AutoURLDetect_bEnable)
+      ME_Cursor cursor;
+      ME_Run *run;
+
+      ME_CursorFromCharOfs(editor, offset, &cursor);
+      run = &cursor.pRun->member.run;
+      if (run->style->fmt.dwMask & CFM_LINK &&
+          run->style->fmt.dwEffects & CFE_LINK)
       {
-          ME_Cursor cursor;
-          ME_Run *run;
-          ME_CursorFromCharOfs(editor, offset, &cursor);
-          run = &cursor.pRun->member.run;
-          if (editor->AutoURLDetect_bEnable &&
-              run->style->fmt.dwMask & CFM_LINK &&
-              run->style->fmt.dwEffects & CFE_LINK)
-          {
-              ITextHost_TxSetCursor(editor->texthost,
-                                    LoadCursorW(NULL, (WCHAR*)IDC_HAND),
-                                    FALSE);
-              return TRUE;
-          }
+          ITextHost_TxSetCursor(editor->texthost,
+                                LoadCursorW(NULL, (WCHAR*)IDC_HAND),
+                                FALSE);
+          return TRUE;
       }
+
       if (ME_IsSelection(editor))
       {
           int selStart, selEnd;
@@ -3234,12 +3231,10 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
 
     if (bSelection) {
       ME_ReleaseStyle(style);
-      if (editor->AutoURLDetect_bEnable)
-        ME_UpdateSelectionLinkAttribute(editor);
+      ME_UpdateSelectionLinkAttribute(editor);
     } else {
       len = 1;
-      if (editor->AutoURLDetect_bEnable)
-        ME_UpdateLinkAttribute(editor, 0, -1);
+      ME_UpdateLinkAttribute(editor, 0, -1);
     }
     ME_CommitUndo(editor);
     if (!(pStruct->flags & ST_KEEPUNDO))
@@ -3433,7 +3428,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
       ME_ClearTempStyle(editor);
     ME_EndToUnicode(unicode, wszText);
     ME_CommitUndo(editor);
-    if (editor->AutoURLDetect_bEnable) ME_UpdateSelectionLinkAttribute(editor);
+    ME_UpdateSelectionLinkAttribute(editor);
     if (!wParam)
       ME_EmptyUndoStack(editor);
     ME_UpdateRepaint(editor);
@@ -3501,10 +3496,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     }
     else
       TRACE("WM_SETTEXT - NULL\n");
-    if (editor->AutoURLDetect_bEnable)
-    {
-      ME_UpdateLinkAttribute(editor, 0, -1);
-    }
+    ME_UpdateLinkAttribute(editor, 0, -1);
     ME_SetSelection(editor, 0, 0);
     editor->nModifyStep = 0;
     ME_CommitUndo(editor);
@@ -4850,6 +4842,8 @@ static BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, int sel_min, int sel_m
   BOOL modified = FALSE;
   int cMin, cMax;
 
+  if (!editor->AutoURLDetect_bEnable) return FALSE;
+
   if (sel_max == -1) sel_max = ME_GetTextLength(editor);
   do
   {


More information about the wine-patches mailing list