Commit 5d36c47e authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

richedit: Fixed object leaks generated by context creation & destruction.

parent 33d7cea1
...@@ -215,9 +215,8 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor, ...@@ -215,9 +215,8 @@ ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor,
*height = pSizeRun->member.run.nAscent + pSizeRun->member.run.nDescent; *height = pSizeRun->member.run.nAscent + pSizeRun->member.run.nDescent;
*x = run->member.run.pt.x + sz.cx; *x = run->member.run.pt.x + sz.cx;
*y = para->member.para.nYPos + row->member.row.nBaseline + pSizeRun->member.run.pt.y - pSizeRun->member.run.nAscent - ME_GetYScrollPos(editor); *y = para->member.para.nYPos + row->member.row.nBaseline + pSizeRun->member.run.pt.y - pSizeRun->member.run.nAscent - ME_GetYScrollPos(editor);
ME_DestroyContext(&c); ME_DestroyContext(&c, editor->hWnd);
ReleaseDC(editor->hWnd, hDC);
return; return;
} }
} }
......
...@@ -33,7 +33,8 @@ void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC) ...@@ -33,7 +33,8 @@ void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC)
c->dpi.cy = GetDeviceCaps(hDC, LOGPIXELSY); c->dpi.cy = GetDeviceCaps(hDC, LOGPIXELSY);
} }
void ME_DestroyContext(ME_Context *c) void ME_DestroyContext(ME_Context *c, HWND hWnd)
{ {
if (hWnd) ReleaseDC(hWnd, c->hDC);
DeleteObject(c->hbrMargin); DeleteObject(c->hbrMargin);
} }
...@@ -190,7 +190,7 @@ void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor); ...@@ -190,7 +190,7 @@ void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor);
BOOL ME_ArrowKey(ME_TextEditor *ed, int nVKey, BOOL extend, BOOL ctrl); BOOL ME_ArrowKey(ME_TextEditor *ed, int nVKey, BOOL extend, BOOL ctrl);
void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC); void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC);
void ME_DestroyContext(ME_Context *c); void ME_DestroyContext(ME_Context *c, HWND release);
ME_Style *GetInsertStyle(ME_TextEditor *editor, int nCursor); ME_Style *GetInsertStyle(ME_TextEditor *editor, int nCursor);
void ME_MustBeWrapped(ME_Context *c, ME_DisplayItem *para); void ME_MustBeWrapped(ME_Context *c, ME_DisplayItem *para);
void ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor, void ME_GetCursorCoordinates(ME_TextEditor *editor, ME_Cursor *pCursor,
......
...@@ -91,7 +91,7 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT * ...@@ -91,7 +91,7 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT *
if (editor->nTotalLength != editor->nLastTotalLength) if (editor->nTotalLength != editor->nLastTotalLength)
ME_SendRequestResize(editor, FALSE); ME_SendRequestResize(editor, FALSE);
editor->nLastTotalLength = editor->nTotalLength; editor->nLastTotalLength = editor->nTotalLength;
ME_DestroyContext(&c); ME_DestroyContext(&c, NULL);
} }
void ME_Repaint(ME_TextEditor *editor) void ME_Repaint(ME_TextEditor *editor)
......
...@@ -28,7 +28,6 @@ static const WCHAR wszParagraphSign[] = {0xB6, 0}; ...@@ -28,7 +28,6 @@ static const WCHAR wszParagraphSign[] = {0xB6, 0};
void ME_MakeFirstParagraph(ME_TextEditor *editor) void ME_MakeFirstParagraph(ME_TextEditor *editor)
{ {
ME_Context c; ME_Context c;
HDC hDC;
PARAFORMAT2 fmt; PARAFORMAT2 fmt;
CHARFORMAT2W cf; CHARFORMAT2W cf;
LOGFONTW lf; LOGFONTW lf;
...@@ -38,9 +37,8 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor) ...@@ -38,9 +37,8 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
ME_DisplayItem *run; ME_DisplayItem *run;
ME_Style *style; ME_Style *style;
hDC = GetDC(editor->hWnd); ME_InitContext(&c, editor, GetDC(editor->hWnd));
ME_InitContext(&c, editor, hDC);
hf = (HFONT)GetStockObject(SYSTEM_FONT); hf = (HFONT)GetStockObject(SYSTEM_FONT);
assert(hf); assert(hf);
GetObjectW(hf, sizeof(LOGFONTW), &lf); GetObjectW(hf, sizeof(LOGFONTW), &lf);
...@@ -85,8 +83,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor) ...@@ -85,8 +83,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
text->pLast->member.para.nCharOfs = 1; text->pLast->member.para.nCharOfs = 1;
ME_DestroyContext(&c); ME_DestroyContext(&c, editor->hWnd);
ReleaseDC(editor->hWnd, hDC);
} }
void ME_MarkAllForWrapping(ME_TextEditor *editor) void ME_MarkAllForWrapping(ME_TextEditor *editor)
......
...@@ -551,7 +551,7 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run) ...@@ -551,7 +551,7 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
{ {
SIZE sz; SIZE sz;
ME_GetOLEObjectSize(&c, run, &sz); ME_GetOLEObjectSize(&c, run, &sz);
ReleaseDC(editor->hWnd, c.hDC); ME_DestroyContext(&c, editor->hWnd);
if (cx < sz.cx/2) if (cx < sz.cx/2)
return 0; return 0;
return 1; return 1;
...@@ -580,7 +580,7 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run) ...@@ -580,7 +580,7 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
ME_DestroyString(strRunText); ME_DestroyString(strRunText);
ME_UnselectStyleFont(&c, run->style, hOldFont); ME_UnselectStyleFont(&c, run->style, hOldFont);
ReleaseDC(editor->hWnd, c.hDC); ME_DestroyContext(&c, editor->hWnd);
return fit; return fit;
} }
......
...@@ -467,14 +467,12 @@ static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp) { ...@@ -467,14 +467,12 @@ static void ME_PrepareParagraphForWrapping(ME_Context *c, ME_DisplayItem *tp) {
} }
BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) { BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) {
HWND hWnd = editor->hWnd;
HDC hDC = GetDC(hWnd);
ME_DisplayItem *item; ME_DisplayItem *item;
ME_Context c; ME_Context c;
BOOL bModified = FALSE; BOOL bModified = FALSE;
int yStart = -1, yEnd = -1; int yStart = -1, yEnd = -1;
ME_InitContext(&c, editor, hDC); ME_InitContext(&c, editor, GetDC(editor->hWnd));
c.pt.x = 0; c.pt.x = 0;
c.pt.y = 0; c.pt.y = 0;
editor->nHeight = 0; editor->nHeight = 0;
...@@ -510,9 +508,8 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) { ...@@ -510,9 +508,8 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) {
editor->nTotalLength = c.pt.y; editor->nTotalLength = c.pt.y;
ME_DestroyContext(&c); ME_DestroyContext(&c, editor->hWnd);
ReleaseDC(hWnd, hDC);
if (bModified || editor->nTotalLength < editor->nLastTotalLength) if (bModified || editor->nTotalLength < editor->nLastTotalLength)
ME_InvalidateMarkedParagraphs(editor); ME_InvalidateMarkedParagraphs(editor);
return bModified; return bModified;
...@@ -520,9 +517,8 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) { ...@@ -520,9 +517,8 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) {
void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor) { void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor) {
ME_Context c; ME_Context c;
HDC hDC = GetDC(editor->hWnd);
ME_InitContext(&c, editor, hDC); ME_InitContext(&c, editor, GetDC(editor->hWnd));
if (editor->bRedraw) if (editor->bRedraw)
{ {
RECT rc = c.rcView; RECT rc = c.rcView;
...@@ -544,8 +540,7 @@ void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor) { ...@@ -544,8 +540,7 @@ void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor) {
InvalidateRect(editor->hWnd, &rc, TRUE); InvalidateRect(editor->hWnd, &rc, TRUE);
} }
} }
ME_DestroyContext(&c); ME_DestroyContext(&c, editor->hWnd);
ReleaseDC(editor->hWnd, hDC);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment