richedit: Store mouse captured state rather than calling GetCapture.

Dylan Smith dylan.ah.smith at gmail.com
Sun Jan 11 01:59:20 CST 2009


Windowless richedit control will not be able to call GetCapture without
a handle to the host window (and there is no ITextHost_TxGetCapture
method), but there is a ITextHost_TxSetCapture method available for
setting and releasing the capture on the mouse.  This means that the
richedit control will need to keep track of whether it has captured the
mouse or not to implement windowless richedit controls.
---
 dlls/riched20/editor.c  |   12 ++++++++----
 dlls/riched20/editstr.h |    2 ++
 2 files changed, 10 insertions(+), 4 deletions(-)
-------------- next part --------------
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 563e12e..47511e3 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -2493,7 +2493,7 @@ static BOOL ME_SetCursor(ME_TextEditor *editor)
   }
   ScreenToClient(editor->hWnd, &pt);
 
-  if (editor->nSelectionType == stLine && GetCapture() == editor->hWnd) {
+  if (editor->nSelectionType == stLine && editor->bMouseCaptured) {
       SetCursor(hLeft);
       return TRUE;
   }
@@ -2629,6 +2629,7 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd) {
   ed->mode = TM_RICHTEXT | TM_MULTILEVELUNDO | TM_MULTICODEPAGE;
   ed->AutoURLDetect_bEnable = FALSE;
   ed->bHaveFocus = FALSE;
+  ed->bMouseCaptured = FALSE;
   for (i=0; i<HFONT_CACHE_SIZE; i++)
   {
     ed->pFontCache[i].nRefs = 0;
@@ -3833,6 +3834,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam),
                    ME_CalculateClickCount(editor, msg, wParam, lParam));
     SetCapture(editor->hWnd);
+    editor->bMouseCaptured = TRUE;
     ME_LinkNotify(editor,msg,wParam,lParam);
     if (!ME_SetCursor(editor)) goto do_default;
     break;
@@ -3841,16 +3843,18 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
         !ME_FilterEvent(editor, msg, &wParam, &lParam))
       return 0;
-    if (GetCapture() == editor->hWnd)
+    if (editor->bMouseCaptured)
       ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
     ME_LinkNotify(editor,msg,wParam,lParam);
     /* Set cursor if mouse is captured, since WM_SETCURSOR won't be received. */
-    if (GetCapture() == editor->hWnd)
+    if (editor->bMouseCaptured)
         ME_SetCursor(editor);
     break;
   case WM_LBUTTONUP:
-    if (GetCapture() == editor->hWnd)
+    if (editor->bMouseCaptured) {
       ReleaseCapture();
+      editor->bMouseCaptured = FALSE;
+    }
     if (editor->nSelectionType == stDocument)
       editor->nSelectionType = stPosition;
     if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h
index cde05f9..6850ca7 100644
--- a/dlls/riched20/editstr.h
+++ b/dlls/riched20/editstr.h
@@ -376,6 +376,8 @@ typedef struct tagME_TextEditor
 
   /* Cache previously set vertical scrollbar info */
   SCROLLINFO vert_si;
+
+  BOOL bMouseCaptured;
 } ME_TextEditor;
 
 typedef struct tagME_Context


More information about the wine-patches mailing list