[2/5] richedit: Used ITextHost methods to avoid using window handle directly.

Dylan Smith dylan.ah.smith at gmail.com
Tue Jan 20 00:41:32 CST 2009


The methods in ITextHost are mostly thin wrappers around functions that
take a handle to a window as their first parameter.  This patch just
uses the wrapper functions provided by ITextHost instead of using the
functions that require a handle to a window that the editor might now
have (for windowless richedit controls).
---
 dlls/riched20/caret.c   |   22 ++++++------
 dlls/riched20/context.c |    4 +-
 dlls/riched20/editor.c  |   79 +++++++++++++++++++++++++----------------------
 dlls/riched20/editor.h  |    2 +-
 dlls/riched20/paint.c   |   47 ++++++++++++++++------------
 dlls/riched20/para.c    |    4 +-
 dlls/riched20/run.c     |   12 +++---
 dlls/riched20/table.c   |    2 +-
 dlls/riched20/wrap.c    |   19 +++++------
 9 files changed, 100 insertions(+), 91 deletions(-)
-------------- next part --------------
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 461ad00..bd0b149 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -173,7 +173,7 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor,
     ME_DisplayItem *row = ME_FindItemBack(pCursorRun, diStartRowOrParagraph);
 
     if (row) {
-      HDC hDC = GetDC(editor->hWnd);
+      HDC hDC = ITextHost_TxGetDC(editor->texthost);
       ME_Context c;
       ME_DisplayItem *run = pCursorRun;
       ME_DisplayItem *para = NULL;
@@ -217,7 +217,7 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor,
       *x = c.rcView.left + run->member.run.pt.x + sz.cx - editor->horz_si.nPos;
       *y = c.rcView.top + para->member.para.pt.y + row->member.row.nBaseline
            + run->member.run.pt.y - pSizeRun->member.run.nAscent - editor->vert_si.nPos;
-      ME_DestroyContext(&c, editor->hWnd);
+      ME_DestroyContext(&c);
       return;
     }
   }
@@ -238,8 +238,8 @@ ME_MoveCaret(ME_TextEditor *editor)
   if(editor->bHaveFocus && !ME_IsSelection(editor))
   {
     x = min(x, editor->rcFormat.right-1);
-    CreateCaret(editor->hWnd, NULL, 0, height);
-    SetCaretPos(x, y);
+    ITextHost_TxCreateCaret(editor->texthost, NULL, 0, height);
+    ITextHost_TxSetCaretPos(editor->texthost, x, y);
   }
 }
 
@@ -248,14 +248,14 @@ void ME_ShowCaret(ME_TextEditor *ed)
 {
   ME_MoveCaret(ed);
   if(ed->bHaveFocus && !ME_IsSelection(ed))
-    ShowCaret(ed->hWnd);
+    ITextHost_TxShowCaret(ed->texthost, TRUE);
 }
 
 void ME_HideCaret(ME_TextEditor *ed)
 {
   if(!ed->bHaveFocus || ME_IsSelection(ed))
   {
-    HideCaret(ed->hWnd);
+    ITextHost_TxShowCaret(ed->texthost, FALSE);
     DestroyCaret();
   }
 }
@@ -1020,7 +1020,7 @@ int ME_CharFromPos(ME_TextEditor *editor, int x, int y, BOOL *isExact)
   RECT rc;
   BOOL bResult;
 
-  GetClientRect(editor->hWnd, &rc);
+  ITextHost_TxGetClientRect(editor->texthost, &rc);
   if (x < 0 || y < 0 || x >= rc.right || y >= rc.bottom) {
     if (isExact) *isExact = FALSE;
     return -1;
@@ -1154,7 +1154,7 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
     }
   }
   ME_InvalidateSelection(editor);
-  HideCaret(editor->hWnd);
+  ITextHost_TxShowCaret(editor->texthost, FALSE);
   ME_ShowCaret(editor);
   ME_ClearTempStyle(editor);
   ME_SendSelChange(editor);
@@ -1188,7 +1188,7 @@ void ME_MouseMove(ME_TextEditor *editor, int x, int y)
   }
 
   ME_InvalidateSelection(editor);
-  HideCaret(editor->hWnd);
+  ITextHost_TxShowCaret(editor->texthost, FALSE);
   ME_ShowCaret(editor);
   ME_SendSelChange(editor);
 }
@@ -1574,7 +1574,7 @@ void ME_SendSelChange(ME_TextEditor *editor)
     ME_ClearTempStyle(editor);
 
     editor->notified_cr = sc.chrg;
-    SendMessageW(GetParent(editor->hWnd), WM_NOTIFY, sc.nmhdr.idFrom, (LPARAM)&sc);
+    ITextHost_TxNotify(editor->texthost, sc.nmhdr.code, &sc);
   }
 }
 
@@ -1636,7 +1636,7 @@ ME_ArrowKey(ME_TextEditor *editor, int nVKey, BOOL extend, BOOL ctrl)
 
   ME_InvalidateSelection(editor);
   ME_Repaint(editor);
-  HideCaret(editor->hWnd);
+  ITextHost_TxShowCaret(editor->texthost, FALSE);
   ME_EnsureVisible(editor, &tmp_curs);
   ME_ShowCaret(editor);
   ME_SendSelChange(editor);
diff --git a/dlls/riched20/context.c b/dlls/riched20/context.c
index 161a64a..80e808e 100644
--- a/dlls/riched20/context.c
+++ b/dlls/riched20/context.c
@@ -33,8 +33,8 @@ void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC)
   c->dpi.cy = GetDeviceCaps(hDC, LOGPIXELSY);
 }
 
-void ME_DestroyContext(ME_Context *c, HWND hWnd)
+void ME_DestroyContext(ME_Context *c)
 {
-  if (hWnd) ReleaseDC(hWnd, c->hDC);
+  if (c->hDC) ITextHost_TxReleaseDC(c->editor->texthost, c->hDC);
   DeleteObject(c->hbrMargin);
 }
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index f69c185..ce47c8d 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1393,7 +1393,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
   ME_InStream inStream;
   BOOL invalidRTF = FALSE;
 
-  TRACE("stream==%p hWnd==%p format==0x%X\n", stream, editor->hWnd, format);
+  TRACE("stream==%p editor==%p format==0x%X\n", stream, editor, format);
   editor->nEventMask = 0;
 
   ME_GetSelection(editor, &from, &to);
@@ -1580,9 +1580,9 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
   if (!(format & SFF_SELECTION)) {
     ME_ClearTempStyle(editor);
   }
-  HideCaret(editor->hWnd);
+  ITextHost_TxShowCaret(editor->texthost, FALSE);
   ME_MoveCaret(editor);
-  ShowCaret(editor->hWnd);
+  ITextHost_TxShowCaret(editor->texthost, TRUE);
   ME_SendSelChange(editor);
   ME_SendRequestResize(editor, FALSE);
 
@@ -2100,14 +2100,11 @@ ME_FilterEvent(ME_TextEditor *editor, UINT msg, WPARAM* wParam, LPARAM* lParam)
 {
     MSGFILTER msgf;
 
-    msgf.nmhdr.hwndFrom = editor->hWnd;
-    msgf.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
     msgf.nmhdr.code = EN_MSGFILTER;
     msgf.msg = msg;
-
     msgf.wParam = *wParam;
     msgf.lParam = *lParam;
-    if (SendMessageW(GetParent(editor->hWnd), WM_NOTIFY, msgf.nmhdr.idFrom, (LPARAM)&msgf))
+    if (ITextHost_TxNotify(editor->texthost, msgf.nmhdr.code, &msgf) == S_OK)
         return FALSE;
     *wParam = msgf.wParam;
     *lParam = msgf.lParam;
@@ -2476,7 +2473,7 @@ static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode,
       ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
       ME_ReleaseStyle(style);
       ME_CommitCoalescingUndo(editor);
-      SetCursor(NULL);
+      ITextHost_TxSetCursor(editor->texthost, NULL, FALSE);
     }
 
     if (editor->AutoURLDetect_bEnable) ME_UpdateSelectionLinkAttribute(editor);
@@ -2554,7 +2551,8 @@ static BOOL ME_SetCursor(ME_TextEditor *editor)
   if (!(sbi.rgstate[0] & (STATE_SYSTEM_INVISIBLE|STATE_SYSTEM_OFFSCREEN)) &&
       PtInRect(&sbi.rcScrollBar, pt))
   {
-      SetCursor(LoadCursorW(NULL, (WCHAR*)IDC_ARROW));
+      ITextHost_TxSetCursor(editor->texthost,
+                            LoadCursorW(NULL, (WCHAR*)IDC_ARROW), FALSE);
       return TRUE;
   }
   sbi.cbSize = sizeof(sbi);
@@ -2562,33 +2560,36 @@ static BOOL ME_SetCursor(ME_TextEditor *editor)
   if (!(sbi.rgstate[0] & (STATE_SYSTEM_INVISIBLE|STATE_SYSTEM_OFFSCREEN)) &&
       PtInRect(&sbi.rcScrollBar, pt))
   {
-      SetCursor(LoadCursorW(NULL, (WCHAR*)IDC_ARROW));
+      ITextHost_TxSetCursor(editor->texthost,
+                            LoadCursorW(NULL, (WCHAR*)IDC_ARROW), FALSE);
       return TRUE;
   }
-  ScreenToClient(editor->hWnd, &pt);
+  ITextHost_TxScreenToClient(editor->texthost, &pt);
 
   if (editor->nSelectionType == stLine && editor->bMouseCaptured) {
-      SetCursor(hLeft);
+      ITextHost_TxSetCursor(editor->texthost, hLeft, FALSE);
       return TRUE;
   }
   if (!editor->bEmulateVersion10 /* v4.1 */ &&
       pt.y < editor->rcFormat.top &&
       pt.x < editor->rcFormat.left)
   {
-      SetCursor(hLeft);
+      ITextHost_TxSetCursor(editor->texthost, hLeft, FALSE);
       return TRUE;
   }
   if (pt.y < editor->rcFormat.top || pt.y > editor->rcFormat.bottom)
   {
       if (editor->bEmulateVersion10) /* v1.0 - 3.0 */
-          SetCursor(LoadCursorW(NULL, (WCHAR*)IDC_ARROW));
+          ITextHost_TxSetCursor(editor->texthost,
+                                LoadCursorW(NULL, (WCHAR*)IDC_ARROW), FALSE);
       else /* v4.1 */
-          SetCursor(LoadCursorW(NULL, (WCHAR*)IDC_IBEAM));
+          ITextHost_TxSetCursor(editor->texthost,
+                                LoadCursorW(NULL, (WCHAR*)IDC_IBEAM), TRUE);
       return TRUE;
   }
   if (pt.x < editor->rcFormat.left)
   {
-      SetCursor(hLeft);
+      ITextHost_TxSetCursor(editor->texthost, hLeft, FALSE);
       return TRUE;
   }
   offset = ME_CharFromPos(editor, pt.x, pt.y, &isExact);
@@ -2604,7 +2605,9 @@ static BOOL ME_SetCursor(ME_TextEditor *editor)
               run->style->fmt.dwMask & CFM_LINK &&
               run->style->fmt.dwEffects & CFE_LINK)
           {
-              SetCursor(LoadCursorW(NULL, (WCHAR*)IDC_HAND));
+              ITextHost_TxSetCursor(editor->texthost,
+                                    LoadCursorW(NULL, (WCHAR*)IDC_HAND),
+                                    FALSE);
               return TRUE;
           }
       }
@@ -2613,12 +2616,15 @@ static BOOL ME_SetCursor(ME_TextEditor *editor)
           int selStart, selEnd;
           ME_GetSelection(editor, &selStart, &selEnd);
           if (selStart <= offset && selEnd >= offset) {
-              SetCursor(LoadCursorW(NULL, (WCHAR*)IDC_ARROW));
+              ITextHost_TxSetCursor(editor->texthost,
+                                    LoadCursorW(NULL, (WCHAR*)IDC_ARROW),
+                                    FALSE);
               return TRUE;
           }
       }
   }
-  SetCursor(LoadCursorW(NULL, (WCHAR*)IDC_IBEAM));
+  ITextHost_TxSetCursor(editor->texthost,
+                        LoadCursorW(NULL, (WCHAR*)IDC_IBEAM), TRUE);
   return TRUE;
 }
 
@@ -2626,7 +2632,7 @@ static void ME_SetDefaultFormatRect(ME_TextEditor *editor)
 {
   DWORD exstyle = GetWindowLongW(editor->hWnd, GWL_EXSTYLE);
 
-  GetClientRect(editor->hWnd, &editor->rcFormat);
+  ITextHost_TxGetClientRect(editor->texthost, &editor->rcFormat);
   editor->rcFormat.top += (exstyle & WS_EX_CLIENTEDGE ? 1 : 0);
   editor->rcFormat.left += 1 + editor->selofs;
   editor->rcFormat.right -= 1;
@@ -3182,7 +3188,7 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     ME_InvalidateSelection(editor);
     ME_SetSelection(editor, wParam, lParam);
     ME_InvalidateSelection(editor);
-    HideCaret(editor->hWnd);
+    ITextHost_TxShowCaret(editor->texthost, FALSE);
     ME_ShowCaret(editor);
     ME_SendSelChange(editor);
     return 0;
@@ -3216,7 +3222,7 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     ME_InvalidateSelection(editor);
     end = ME_SetSelection(editor, range.cpMin, range.cpMax);
     ME_InvalidateSelection(editor);
-    HideCaret(editor->hWnd);
+    ITextHost_TxShowCaret(editor->texthost, FALSE);
     ME_ShowCaret(editor);
     ME_SendSelChange(editor);
 
@@ -3224,7 +3230,7 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
   }
   case EM_SHOWSCROLLBAR:
   {
-    ShowScrollBar(editor->hWnd, wParam, lParam);
+    ITextHost_TxShowScrollBar(editor->texthost, wParam, lParam);
     return 0;
   }
   case EM_SETTEXTEX:
@@ -3298,7 +3304,7 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
       DeleteObject(editor->hbrBackground);
       lColor = editor->rgbBackColor;
     }
-    else lColor = GetSysColor(COLOR_WINDOW);
+    else lColor = ITextHost_TxGetSysColor(editor->texthost, COLOR_WINDOW);
 
     if (wParam)
     {
@@ -3310,8 +3316,8 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
       editor->rgbBackColor = lParam;
       editor->hbrBackground = CreateSolidBrush(editor->rgbBackColor);
     }
-    InvalidateRect(editor->hWnd, NULL, TRUE);
-    UpdateWindow(editor->hWnd);
+    ITextHost_TxInvalidateRect(editor->texthost, NULL, TRUE);
+    ITextHost_TxViewChange(editor->texthost, TRUE);
     return lColor;
   }
   case EM_GETMODIFY:
@@ -3496,9 +3502,9 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     if (!wParam)
       wParam = (WPARAM)GetStockObject(SYSTEM_FONT); 
     GetObjectW((HGDIOBJ)wParam, sizeof(LOGFONTW), &lf);
-    hDC = GetDC(editor->hWnd);
+    hDC = ITextHost_TxGetDC(editor->texthost);
     ME_CharFormatFromLogFont(hDC, &lf, &fmt); 
-    ReleaseDC(editor->hWnd, hDC);
+    ITextHost_TxReleaseDC(editor->texthost, hDC);
     ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), &fmt);
     ME_SetDefaultCharFormat(editor, &fmt);
 
@@ -3947,10 +3953,10 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
         !ME_FilterEvent(editor, msg, &wParam, &lParam))
       return 0;
-    SetFocus(editor->hWnd);
+    ITextHost_TxSetFocus(editor->texthost);
     ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam),
                    ME_CalculateClickCount(editor, msg, wParam, lParam));
-    SetCapture(editor->hWnd);
+    ITextHost_TxSetCapture(editor->texthost, TRUE);
     editor->bMouseCaptured = TRUE;
     ME_LinkNotify(editor,msg,wParam,lParam);
     if (!ME_SetCursor(editor)) goto do_default;
@@ -3969,7 +3975,7 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     break;
   case WM_LBUTTONUP:
     if (editor->bMouseCaptured) {
-      ReleaseCapture();
+      ITextHost_TxSetCapture(editor->texthost, FALSE);
       editor->bMouseCaptured = FALSE;
     }
     if (editor->nSelectionType == stDocument)
@@ -4241,7 +4247,7 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
       RECT clientRect;
       RECT *rc = (RECT *)lParam;
 
-      GetClientRect(editor->hWnd, &clientRect);
+      ITextHost_TxGetClientRect(editor->texthost, &clientRect);
       if (wParam == 0)
       {
         editor->rcFormat.top = max(0, rc->top - border);
@@ -4280,7 +4286,7 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
   {
     RECT clientRect;
 
-    GetClientRect(editor->hWnd, &clientRect);
+    ITextHost_TxGetClientRect(editor->texthost, &clientRect);
     if (editor->bDefaultFormatRect) {
       ME_SetDefaultFormatRect(editor);
     } else {
@@ -4310,7 +4316,7 @@ static LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     HIMC hIMC;
 
     ME_Style *style = ME_GetInsertStyle(editor, 0);
-    hIMC = ImmGetContext(editor->hWnd);
+    hIMC = ITextHost_TxImmGetContext(editor->texthost);
     ME_DeleteSelection(editor);
     ME_CommitUndo(editor);
     ME_SaveTempStyle(editor);
@@ -4437,7 +4443,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
 {
   ME_TextEditor *editor;
   HRESULT hresult;
-  LRESULT lresult;
+  LRESULT lresult = 0;
 
   TRACE("enter hwnd %p msg %04x (%s) %lx %lx, unicode %d\n",
         hWnd, msg, get_msg_name(msg), wParam, lParam, unicode);
@@ -4515,8 +4521,7 @@ LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM
 
 void ME_SendOldNotify(ME_TextEditor *editor, int nCode)
 {
-  HWND hWnd = editor->hWnd;
-  SendMessageA(GetParent(hWnd), WM_COMMAND, MAKEWPARAM(GetWindowLongW(hWnd, GWLP_ID), nCode), (LPARAM)hWnd);
+  ITextHost_TxNotify(editor->texthost, nCode, NULL);
 }
 
 int ME_CountParagraphsBetween(ME_TextEditor *editor, int from, int to)
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index bcd1da1..6c93385 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -203,7 +203,7 @@ ME_Style *ME_GetSelectionInsertStyle(ME_TextEditor *editor);
 
 /* context.c */
 void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC);
-void ME_DestroyContext(ME_Context *c, HWND release);
+void ME_DestroyContext(ME_Context *c);
 
 /* wrap.c */
 BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor);
diff --git a/dlls/riched20/paint.c b/dlls/riched20/paint.c
index bc0441b..c5eafe1 100644
--- a/dlls/riched20/paint.c
+++ b/dlls/riched20/paint.c
@@ -116,11 +116,13 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT *
     ME_SendRequestResize(editor, FALSE);
   editor->nLastTotalLength = editor->nTotalLength;
   editor->nLastTotalWidth = editor->nTotalWidth;
-  ME_DestroyContext(&c, NULL);
 
   SelectClipRgn(hDC, oldRgn);
   if (oldRgn)
     DeleteObject(oldRgn);
+
+  c.hDC = NULL;
+  ME_DestroyContext(&c);
 }
 
 void ME_Repaint(ME_TextEditor *editor)
@@ -130,11 +132,9 @@ void ME_Repaint(ME_TextEditor *editor)
     ME_UpdateScrollBar(editor);
     FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
   }
-  if (!IsWindowVisible(editor->hWnd))
-    return;
   if (!editor->bEmulateVersion10 || (editor->nEventMask & ENM_UPDATE))
     ME_SendOldNotify(editor, EN_UPDATE);
-  UpdateWindow(editor->hWnd);
+  ITextHost_TxViewChange(editor->texthost, TRUE);
 }
 
 void ME_UpdateRepaint(ME_TextEditor *editor)
@@ -232,7 +232,8 @@ static void ME_HighlightSpace(ME_Context *c, int x, int y, LPCWSTR szText,
     rect.top = ymin;
     rect.right = x + selWidth;
     rect.bottom = ymin + cy;
-    hBrush = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
+    hBrush = CreateSolidBrush(ITextHost_TxGetSysColor(c->editor->texthost,
+                                                      COLOR_HIGHLIGHT));
     FillRect(hDC, &rect, hBrush);
     DeleteObject(hBrush);
   }
@@ -274,7 +275,7 @@ static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText,
   if ((s->fmt.dwMask & CFM_LINK) && (s->fmt.dwEffects & CFE_LINK))
     rgb = RGB(0,0,255);
   else if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR))
-    rgb = GetSysColor(COLOR_WINDOWTEXT);
+    rgb = ITextHost_TxGetSysColor(c->editor->texthost, COLOR_WINDOWTEXT);
   else
     rgb = s->fmt.crTextColor;
 
@@ -351,8 +352,10 @@ static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText,
     dim.bottom = ymin + cy;
     dim.left = xSelStart;
     dim.right = xSelEnd;
-    SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
-    rgbBackOld = SetBkColor(hDC, GetSysColor(COLOR_HIGHLIGHT));
+    SetTextColor(hDC, ITextHost_TxGetSysColor(c->editor->texthost,
+                                              COLOR_HIGHLIGHTTEXT));
+    rgbBackOld = SetBkColor(hDC, ITextHost_TxGetSysColor(c->editor->texthost,
+                                                         COLOR_HIGHLIGHT));
     ExtTextOutW(hDC, xSelStart, y-yOffset, ETO_OPAQUE, &dim,
                 szText+nSelFrom, nSelTo-nSelFrom, lpDx);
     if (hPen)
@@ -625,7 +628,8 @@ static void ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, RECT
     POINT       pt;
 
     if (para->pFmt->wBorders & 64) /* autocolor */
-      pencr = GetSysColor(COLOR_WINDOWTEXT);
+      pencr = ITextHost_TxGetSysColor(c->editor->texthost,
+                                      COLOR_WINDOWTEXT);
     else
       pencr = pen_colors[(para->pFmt->wBorders >> 12) & 0xF];
 
@@ -1039,7 +1043,7 @@ void ME_ScrollAbs(ME_TextEditor *editor, int x, int y)
   if (editor->horz_si.nPos != x) {
     x = min(x, editor->horz_si.nMax);
     x = max(x, editor->horz_si.nMin);
-    SetScrollPos(editor->hWnd, SB_HORZ, x, TRUE);
+    ITextHost_TxSetScrollPos(editor->texthost, SB_HORZ, x, TRUE);
     scrollX = editor->horz_si.nPos - x;
     editor->horz_si.nPos = x;
   }
@@ -1047,17 +1051,18 @@ void ME_ScrollAbs(ME_TextEditor *editor, int x, int y)
   if (editor->vert_si.nPos != y) {
     y = min(y, editor->vert_si.nMax - (int)editor->vert_si.nPage);
     y = max(y, editor->vert_si.nMin);
-    SetScrollPos(editor->hWnd, SB_VERT, y, TRUE);
+    ITextHost_TxSetScrollPos(editor->texthost, SB_VERT, y, TRUE);
     scrollY = editor->vert_si.nPos - y;
     editor->vert_si.nPos = y;
   }
 
   if (abs(scrollX) > editor->sizeWindow.cx ||
       abs(scrollY) > editor->sizeWindow.cy)
-    InvalidateRect(editor->hWnd, NULL, TRUE);
+    ITextHost_TxInvalidateRect(editor->texthost, NULL, TRUE);
   else
-    ScrollWindowEx(editor->hWnd, scrollX, scrollY, &editor->rcFormat,
-                   &editor->rcFormat, NULL, NULL, SW_INVALIDATE);
+    ITextHost_TxScrollWindowEx(editor->texthost, scrollX, scrollY,
+                               &editor->rcFormat, &editor->rcFormat,
+                               NULL, NULL, SW_INVALIDATE);
   ME_Repaint(editor);
 
   winStyle = GetWindowLongW(editor->hWnd, GWL_STYLE);
@@ -1065,14 +1070,15 @@ void ME_ScrollAbs(ME_TextEditor *editor, int x, int y)
   bScrollBarWillBeVisible = (editor->nTotalWidth > editor->sizeWindow.cx)
                             || (editor->styleFlags & ES_DISABLENOSCROLL);
   if (bScrollBarIsVisible != bScrollBarWillBeVisible)
-    ShowScrollBar(editor->hWnd, SB_HORZ, bScrollBarWillBeVisible);
+    ITextHost_TxShowScrollBar(editor->texthost, SB_HORZ,
+                              bScrollBarWillBeVisible);
 
   bScrollBarIsVisible = (winStyle & WS_VSCROLL) != 0;
   bScrollBarWillBeVisible = (editor->nTotalLength > editor->sizeWindow.cy)
                             || (editor->styleFlags & ES_DISABLENOSCROLL);
   if (bScrollBarIsVisible != bScrollBarWillBeVisible)
-    ShowScrollBar(editor->hWnd, SB_VERT, bScrollBarWillBeVisible);
-
+    ITextHost_TxShowScrollBar(editor->texthost, SB_VERT,
+                              bScrollBarWillBeVisible);
   ME_UpdateScrollBar(editor);
 }
 
@@ -1154,7 +1160,7 @@ void ME_UpdateScrollBar(ME_TextEditor *editor)
     bScrollBarWillBeVisible = TRUE;
 
   if (bScrollBarWasVisible != bScrollBarWillBeVisible)
-    ShowScrollBar(editor->hWnd, SB_HORZ, bScrollBarWillBeVisible);
+    ITextHost_TxShowScrollBar(editor->texthost, SB_HORZ, bScrollBarWillBeVisible);
 
   /* Update vertical scrollbar */
   bScrollBarWasVisible = editor->vert_si.nMax > editor->vert_si.nPage;
@@ -1188,7 +1194,8 @@ void ME_UpdateScrollBar(ME_TextEditor *editor)
     bScrollBarWillBeVisible = TRUE;
 
   if (bScrollBarWasVisible != bScrollBarWillBeVisible)
-    ShowScrollBar(editor->hWnd, SB_VERT, bScrollBarWillBeVisible);
+    ITextHost_TxShowScrollBar(editor->texthost, SB_VERT,
+                              bScrollBarWillBeVisible);
 }
 
 void ME_EnsureVisible(ME_TextEditor *editor, ME_Cursor *pCursor)
@@ -1233,7 +1240,7 @@ ME_InvalidateFromOfs(ME_TextEditor *editor, int nCharOfs)
   rc.top = y;
   rc.bottom = y + height;
   rc.right = editor->rcFormat.right;
-  InvalidateRect(editor->hWnd, &rc, FALSE);
+  ITextHost_TxInvalidateRect(editor->texthost, &rc, FALSE);
 }
 
 
diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
index 00d81a2..00d997a 100644
--- a/dlls/riched20/para.c
+++ b/dlls/riched20/para.c
@@ -36,7 +36,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
   ME_DisplayItem *run;
   ME_Style *style;
 
-  ME_InitContext(&c, editor, GetDC(editor->hWnd));
+  ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
 
   hf = GetStockObject(SYSTEM_FONT);
   assert(hf);
@@ -78,7 +78,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
 
   text->pLast->member.para.nCharOfs = editor->bEmulateVersion10 ? 2 : 1;
 
-  ME_DestroyContext(&c, editor->hWnd);
+  ME_DestroyContext(&c);
 }
 
 static void ME_MarkForWrapping(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last)
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index 2823905..8ee95bb 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -550,12 +550,12 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
       return 0;
     return 1;
   }
-  ME_InitContext(&c, editor, GetDC(editor->hWnd));
+  ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
   if (run->nFlags & MERF_GRAPHICS)
   {
     SIZE sz;
     ME_GetOLEObjectSize(&c, run, &sz);
-    ME_DestroyContext(&c, editor->hWnd);
+    ME_DestroyContext(&c);
     if (cx < sz.cx/2)
       return 0;
     return 1;
@@ -584,7 +584,7 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
     ME_DestroyString(strRunText);
   
   ME_UnselectStyleFont(&c, run->style, hOldFont);
-  ME_DestroyContext(&c, editor->hWnd);
+  ME_DestroyContext(&c);
   return fit;
 }
 
@@ -614,12 +614,12 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset)
   ME_String *strRunText;
   /* This could point to either the run's real text, or it's masked form in a password control */
 
-  ME_InitContext(&c, editor, GetDC(editor->hWnd));
+  ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
   if (pRun->nFlags & MERF_GRAPHICS)
   {
     if (nOffset)
       ME_GetOLEObjectSize(&c, pRun, &size);
-    ReleaseDC(editor->hWnd, c.hDC);
+    ITextHost_TxReleaseDC(editor->texthost, c.hDC);
     return nOffset != 0;
   }
   
@@ -629,7 +629,7 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset)
     strRunText = pRun->strText;
 
   ME_GetTextExtent(&c,  strRunText->szData, nOffset, pRun->style, &size);
-  ReleaseDC(editor->hWnd, c.hDC);
+  ITextHost_TxReleaseDC(editor->texthost, c.hDC);
   if (editor->cPasswordMask)
     ME_DestroyString(strRunText);
   return size.cx;
diff --git a/dlls/riched20/table.c b/dlls/riched20/table.c
index c9aadb0..0b6eaf4 100644
--- a/dlls/riched20/table.c
+++ b/dlls/riched20/table.c
@@ -581,7 +581,7 @@ void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow)
   }
   ME_InvalidateSelection(editor);
   ME_Repaint(editor);
-  HideCaret(editor->hWnd);
+  ITextHost_TxShowCaret(editor->texthost, FALSE);
   ME_ShowCaret(editor);
   ME_SendSelChange(editor);
 }
diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c
index 9012cfe..4edbbb2 100644
--- a/dlls/riched20/wrap.c
+++ b/dlls/riched20/wrap.c
@@ -582,7 +582,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor)
   int yStart = -1;
   int totalWidth = 0;
 
-  ME_InitContext(&c, editor, GetDC(editor->hWnd));
+  ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
   c.pt.x = 0;
   item = editor->pBuffer->pFirst->next;
   while(item != editor->pBuffer->pLast) {
@@ -723,7 +723,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor)
   editor->pBuffer->pLast->member.para.pt.x = 0;
   editor->pBuffer->pLast->member.para.pt.y = c.pt.y;
 
-  ME_DestroyContext(&c, editor->hWnd);
+  ME_DestroyContext(&c);
 
   if (bModified || editor->nTotalLength < editor->nLastTotalLength)
     ME_InvalidateMarkedParagraphs(editor);
@@ -737,7 +737,7 @@ void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor)
   int ofs;
   ME_DisplayItem *item;
 
-  ME_InitContext(&c, editor, GetDC(editor->hWnd));
+  ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
   rc = c.rcView;
   ofs = editor->vert_si.nPos;
 
@@ -748,7 +748,7 @@ void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor)
       rc.bottom = max(c.rcView.top + item->member.para.pt.y
                       + item->member.para.nHeight - ofs,
                       c.rcView.bottom);
-      InvalidateRect(editor->hWnd, &rc, TRUE);
+      ITextHost_TxInvalidateRect(editor->texthost, &rc, TRUE);
     }
     item = item->member.para.next_para;
   }
@@ -756,9 +756,9 @@ void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor)
   {
     rc.top = c.rcView.top + editor->nTotalLength - ofs;
     rc.bottom = c.rcView.top + editor->nLastTotalLength - ofs;
-    InvalidateRect(editor->hWnd, &rc, TRUE);
+    ITextHost_TxInvalidateRect(editor->texthost, &rc, TRUE);
   }
-  ME_DestroyContext(&c, editor->hWnd);
+  ME_DestroyContext(&c);
 }
 
 
@@ -769,22 +769,19 @@ ME_SendRequestResize(ME_TextEditor *editor, BOOL force)
   {
     RECT rc;
 
-    GetClientRect(editor->hWnd, &rc);
+    ITextHost_TxGetClientRect(editor->texthost, &rc);
 
     if (force || rc.bottom != editor->nTotalLength)
     {
       REQRESIZE info;
 
-      info.nmhdr.hwndFrom = editor->hWnd;
-      info.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
       info.nmhdr.code = EN_REQUESTRESIZE;
       info.rc = rc;
       info.rc.right = editor->nTotalWidth;
       info.rc.bottom = editor->nTotalLength;
 
       editor->nEventMask &= ~ENM_REQUESTRESIZE;
-      SendMessageW(GetParent(editor->hWnd), WM_NOTIFY,
-                   info.nmhdr.idFrom, (LPARAM)&info);
+      ITextHost_TxNotify(editor->texthost, info.nmhdr.code, &info);
       editor->nEventMask |= ENM_REQUESTRESIZE;
     }
   }


More information about the wine-patches mailing list