Huw Davies : riched20: Don't release the dc when destroying the context.

Alexandre Julliard julliard at winehq.org
Tue Mar 23 16:54:31 CDT 2021


Module: wine
Branch: master
Commit: 132a35b8225d935b30fa559cd236a6fa3232894f
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=132a35b8225d935b30fa559cd236a6fa3232894f

Author: Huw Davies <huw at codeweavers.com>
Date:   Tue Mar 23 13:04:03 2021 +0000

riched20: Don't release the dc when destroying the context.

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/riched20/caret.c   | 4 +++-
 dlls/riched20/context.c | 1 -
 dlls/riched20/paint.c   | 1 -
 dlls/riched20/para.c    | 4 +++-
 dlls/riched20/run.c     | 8 ++++++--
 dlls/riched20/wrap.c    | 5 ++++-
 dlls/riched20/writer.c  | 5 ++++-
 7 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 96765cba25d..1f4c3903a38 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -227,12 +227,13 @@ void cursor_coords( ME_TextEditor *editor, ME_Cursor *cursor,
   ME_Run *size_run = run, *prev;
   ME_Context c;
   int run_x;
+  HDC hdc = ITextHost_TxGetDC( editor->texthost );
 
   assert(~para->nFlags & MEPF_REWRAP);
 
   row = row_from_cursor( cursor );
 
-  ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
+  ME_InitContext( &c, editor, hdc );
 
   if (!cursor->nOffset && (prev = run_prev( run ))) size_run = prev;
 
@@ -243,6 +244,7 @@ void cursor_coords( ME_TextEditor *editor, ME_Cursor *cursor,
   *y = c.rcView.top + para->pt.y + row->nBaseline
        + run->pt.y - size_run->nAscent - editor->vert_si.nPos;
   ME_DestroyContext(&c);
+  ITextHost_TxReleaseDC( editor->texthost, hdc );
   return;
 }
 
diff --git a/dlls/riched20/context.c b/dlls/riched20/context.c
index 66066b39e67..24592cff10c 100644
--- a/dlls/riched20/context.c
+++ b/dlls/riched20/context.c
@@ -44,5 +44,4 @@ void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC)
 void ME_DestroyContext(ME_Context *c)
 {
     select_style( c, NULL );
-    if (c->hDC) ITextHost_TxReleaseDC( c->editor->texthost, c->hDC );
 }
diff --git a/dlls/riched20/paint.c b/dlls/riched20/paint.c
index 1c957e46ee2..bdf129b80a0 100644
--- a/dlls/riched20/paint.c
+++ b/dlls/riched20/paint.c
@@ -93,7 +93,6 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, const RECT *rcUpdate)
   if (oldRgn)
     DeleteObject(oldRgn);
 
-  c.hDC = NULL;
   ME_DestroyContext(&c);
 }
 
diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
index 29624e6c1df..78148ae7793 100644
--- a/dlls/riched20/para.c
+++ b/dlls/riched20/para.c
@@ -160,8 +160,9 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
   ME_Run *run;
   ME_Style *style;
   int eol_len;
+  HDC hdc = ITextHost_TxGetDC( editor->texthost );
 
-  ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
+  ME_InitContext( &c, editor, hdc );
 
   hf = GetStockObject(SYSTEM_FONT);
   assert(hf);
@@ -221,6 +222,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
   wine_rb_init( &editor->marked_paras, para_mark_compare );
   para_mark_add( editor, para );
   ME_DestroyContext(&c);
+  ITextHost_TxReleaseDC( editor->texthost, hdc );
 }
 
 static void para_mark_rewrap_paras( ME_TextEditor *editor, ME_Paragraph *first, const ME_Paragraph *end )
diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index bc282b20a57..51e768f8441 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -571,10 +571,12 @@ int ME_CharFromPoint(ME_TextEditor *editor, int cx, ME_Run *run, BOOL closest, B
 {
     ME_Context c;
     int ret;
+    HDC hdc = ITextHost_TxGetDC( editor->texthost );
 
-    ME_InitContext( &c, editor, ITextHost_TxGetDC( editor->texthost ) );
+    ME_InitContext( &c, editor, hdc );
     ret = ME_CharFromPointContext( &c, cx, run, closest, visual_order );
     ME_DestroyContext(&c);
+    ITextHost_TxReleaseDC( editor->texthost, hdc );
     return ret;
 }
 
@@ -648,10 +650,12 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset, BOOL visu
 {
     ME_Context c;
     int ret;
+    HDC hdc = ITextHost_TxGetDC( editor->texthost );
 
-    ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
+    ME_InitContext( &c, editor, hdc );
     ret = ME_PointFromCharContext( &c, pRun, nOffset, visual_order );
     ME_DestroyContext(&c);
+    ITextHost_TxReleaseDC( editor->texthost, hdc );
 
     return ret;
 }
diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c
index dcda041d773..3d7e030fe50 100644
--- a/dlls/riched20/wrap.c
+++ b/dlls/riched20/wrap.c
@@ -1027,10 +1027,12 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor)
   ME_Context c;
   int totalWidth = editor->nTotalWidth, prev_width;
   struct repaint_range repaint = { NULL, NULL };
+  HDC hdc;
 
   if (!editor->marked_paras.root) return FALSE;
 
-  ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
+  hdc = ITextHost_TxGetDC( editor->texthost );
+  ME_InitContext( &c, editor, hdc );
 
   entry = wine_rb_head( editor->marked_paras.root );
   while (entry)
@@ -1085,6 +1087,7 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor)
   editor->nTotalWidth = totalWidth;
 
   ME_DestroyContext(&c);
+  ITextHost_TxReleaseDC( editor->texthost, hdc );
 
   if (repaint.start || editor->nTotalLength < editor->nLastTotalLength)
     para_range_invalidate( editor, repaint.start, repaint.end);
diff --git a/dlls/riched20/writer.c b/dlls/riched20/writer.c
index 50eccfa714b..7c7e648f107 100644
--- a/dlls/riched20/writer.c
+++ b/dlls/riched20/writer.c
@@ -939,11 +939,13 @@ static BOOL stream_out_graphics( ME_TextEditor *editor, ME_OutStream *stream,
     UINT size;
     SIZE goal, pic;
     ME_Context c;
+    HDC hdc;
 
     hr = IOleObject_QueryInterface( run->reobj->obj.poleobj, &IID_IDataObject, (void **)&data );
     if (FAILED(hr)) return FALSE;
 
-    ME_InitContext( &c, editor, ITextHost_TxGetDC( editor->texthost ) );
+    hdc = ITextHost_TxGetDC( editor->texthost );
+    ME_InitContext( &c, editor, hdc );
     hr = IDataObject_QueryGetData( data, &fmt );
     if (hr != S_OK) goto done;
 
@@ -985,6 +987,7 @@ static BOOL stream_out_graphics( ME_TextEditor *editor, ME_OutStream *stream,
 
 done:
     ME_DestroyContext( &c );
+    ITextHost_TxReleaseDC( editor->texthost, hdc );
     HeapFree( GetProcessHeap(), 0, emf_bits );
     ReleaseStgMedium( &med );
     IDataObject_Release( data );




More information about the wine-cvs mailing list