mirror of
https://github.com/reactos/reactos.git
synced 2025-04-21 20:50:29 +00:00
[UXTHEME] -ThemeDrawCaptionText: Try to avoid a heap allocation when getting the window caption.
svn path=/trunk/; revision=74552
This commit is contained in:
parent
98917d7d98
commit
6ac34f176c
1 changed files with 27 additions and 20 deletions
|
@ -100,16 +100,7 @@ UserGetWindowIcon(PDRAW_CONTEXT pcontext)
|
||||||
return hIcon;
|
return hIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
WCHAR *UserGetWindowCaption(HWND hwnd)
|
HRESULT WINAPI ThemeDrawCaptionText(PDRAW_CONTEXT pcontext, RECT* pRect, int iPartId, int iStateId)
|
||||||
{
|
|
||||||
INT len = 512;
|
|
||||||
WCHAR *text;
|
|
||||||
text = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
||||||
if (text) InternalGetWindowText(hwnd, text, len);
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT WINAPI ThemeDrawCaptionText(PDRAW_CONTEXT pcontext, RECT* pRect, int iPartId, int iStateId, LPCWSTR pszText)
|
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
HFONT hFont = NULL;
|
HFONT hFont = NULL;
|
||||||
|
@ -118,6 +109,25 @@ HRESULT WINAPI ThemeDrawCaptionText(PDRAW_CONTEXT pcontext, RECT* pRect, int iPa
|
||||||
COLORREF textColor;
|
COLORREF textColor;
|
||||||
COLORREF oldTextColor;
|
COLORREF oldTextColor;
|
||||||
|
|
||||||
|
WCHAR buffer[50];
|
||||||
|
WCHAR *pszText = buffer;
|
||||||
|
INT len;
|
||||||
|
|
||||||
|
len = InternalGetWindowText(pcontext->hWnd, NULL, 0);
|
||||||
|
if (!len)
|
||||||
|
return S_OK;
|
||||||
|
|
||||||
|
len++; /* From now on this is the size of the buffer so include the null */
|
||||||
|
|
||||||
|
if (len > 50)
|
||||||
|
{
|
||||||
|
pszText = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
||||||
|
if (!pszText)
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
InternalGetWindowText(pcontext->hWnd, pszText, len);
|
||||||
|
|
||||||
hr = GetThemeSysFont(0,TMT_CAPTIONFONT,&logfont);
|
hr = GetThemeSysFont(0,TMT_CAPTIONFONT,&logfont);
|
||||||
if(SUCCEEDED(hr))
|
if(SUCCEEDED(hr))
|
||||||
hFont = CreateFontIndirectW(&logfont);
|
hFont = CreateFontIndirectW(&logfont);
|
||||||
|
@ -136,17 +146,21 @@ HRESULT WINAPI ThemeDrawCaptionText(PDRAW_CONTEXT pcontext, RECT* pRect, int iPa
|
||||||
iPartId,
|
iPartId,
|
||||||
iStateId,
|
iStateId,
|
||||||
pszText,
|
pszText,
|
||||||
lstrlenW(pszText),
|
len - 1,
|
||||||
DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS,
|
DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS,
|
||||||
0,
|
0,
|
||||||
pRect);
|
pRect);
|
||||||
SetTextColor(pcontext->hDC, oldTextColor);
|
SetTextColor(pcontext->hDC, oldTextColor);
|
||||||
|
|
||||||
if(hFont)
|
if (hFont)
|
||||||
{
|
{
|
||||||
SelectObject(pcontext->hDC, oldFont);
|
SelectObject(pcontext->hDC, oldFont);
|
||||||
DeleteObject(hFont);
|
DeleteObject(hFont);
|
||||||
}
|
}
|
||||||
|
if (pszText != buffer)
|
||||||
|
{
|
||||||
|
HeapFree(GetProcessHeap(), 0, pszText);
|
||||||
|
}
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +334,6 @@ ThemeDrawCaption(PDRAW_CONTEXT pcontext, RECT* prcCurrent)
|
||||||
RECT rcPart;
|
RECT rcPart;
|
||||||
int iPart, iState;
|
int iPart, iState;
|
||||||
HICON hIcon;
|
HICON hIcon;
|
||||||
WCHAR *CaptionText;
|
|
||||||
|
|
||||||
// See also win32ss/user/ntuser/nonclient.c!UserDrawCaptionBar
|
// See also win32ss/user/ntuser/nonclient.c!UserDrawCaptionBar
|
||||||
// and win32ss/user/ntuser/nonclient.c!UserDrawCaption
|
// and win32ss/user/ntuser/nonclient.c!UserDrawCaption
|
||||||
|
@ -329,8 +342,6 @@ ThemeDrawCaption(PDRAW_CONTEXT pcontext, RECT* prcCurrent)
|
||||||
else
|
else
|
||||||
hIcon = NULL;
|
hIcon = NULL;
|
||||||
|
|
||||||
CaptionText = UserGetWindowCaption(pcontext->hWnd);
|
|
||||||
|
|
||||||
/* Get the caption part and state id */
|
/* Get the caption part and state id */
|
||||||
if (pcontext->wi.dwStyle & WS_MINIMIZE)
|
if (pcontext->wi.dwStyle & WS_MINIMIZE)
|
||||||
iPart = WP_MINCAPTION;
|
iPart = WP_MINCAPTION;
|
||||||
|
@ -378,11 +389,7 @@ ThemeDrawCaption(PDRAW_CONTEXT pcontext, RECT* prcCurrent)
|
||||||
rcPart.right -= 4;
|
rcPart.right -= 4;
|
||||||
|
|
||||||
/* Draw the caption */
|
/* Draw the caption */
|
||||||
if (CaptionText)
|
ThemeDrawCaptionText(pcontext, &rcPart, iPart, iState);
|
||||||
{
|
|
||||||
ThemeDrawCaptionText(pcontext, &rcPart, iPart, iState, CaptionText);
|
|
||||||
HeapFree(GetProcessHeap(), 0, CaptionText);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in a new issue