Commit 172ce3ee authored by Andrew Nguyen's avatar Andrew Nguyen Committed by Alexandre Julliard

regedit: Convert the hex edit code to Unicode.

parent 9b586bc2
...@@ -58,7 +58,7 @@ const WCHAR szHexEditClass[] = {'H','e','x','E','d','i','t',0}; ...@@ -58,7 +58,7 @@ const WCHAR szHexEditClass[] = {'H','e','x','E','d','i','t',0};
static inline LRESULT HexEdit_SetFont (HEXEDIT_INFO *infoPtr, HFONT hFont, BOOL redraw); static inline LRESULT HexEdit_SetFont (HEXEDIT_INFO *infoPtr, HFONT hFont, BOOL redraw);
static inline BYTE hexchar_to_byte(TCHAR ch) static inline BYTE hexchar_to_byte(WCHAR ch)
{ {
if (ch >= '0' && ch <= '9') if (ch >= '0' && ch <= '9')
return ch - '0'; return ch - '0';
...@@ -70,17 +70,19 @@ static inline BYTE hexchar_to_byte(TCHAR ch) ...@@ -70,17 +70,19 @@ static inline BYTE hexchar_to_byte(TCHAR ch)
return -1; return -1;
} }
static LPTSTR HexEdit_GetLineText(BYTE *pData, LONG cbData, LONG pad) static LPWSTR HexEdit_GetLineText(BYTE *pData, LONG cbData, LONG pad)
{ {
LPTSTR lpszLine = HeapAlloc(GetProcessHeap(), 0, static const WCHAR percent_02xW[] = {'%','0','2','X',' ',0};
(cbData * 3 + pad * 3 + DIV_SPACES + cbData + 1) * sizeof(TCHAR));
LPWSTR lpszLine = HeapAlloc(GetProcessHeap(), 0,
(cbData * 3 + pad * 3 + DIV_SPACES + cbData + 1) * sizeof(WCHAR));
LONG i; LONG i;
if (!lpszLine) if (!lpszLine)
return NULL; return NULL;
for (i = 0; i < cbData; i++) for (i = 0; i < cbData; i++)
wsprintf(lpszLine + i*3, TEXT("%02X "), pData[i]); wsprintfW(lpszLine + i*3, percent_02xW, pData[i]);
for (i = 0; i < pad * 3; i++) for (i = 0; i < pad * 3; i++)
lpszLine[cbData * 3 + i] = ' '; lpszLine[cbData * 3 + i] = ' ';
...@@ -117,7 +119,7 @@ HexEdit_Paint(HEXEDIT_INFO *infoPtr) ...@@ -117,7 +119,7 @@ HexEdit_Paint(HEXEDIT_INFO *infoPtr)
nXStart = GetSystemMetrics(SM_CXBORDER); nXStart = GetSystemMetrics(SM_CXBORDER);
nYStart = GetSystemMetrics(SM_CYBORDER); nYStart = GetSystemMetrics(SM_CYBORDER);
if (GetWindowLong(infoPtr->hwndSelf, GWL_STYLE) & WS_DISABLED) if (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & WS_DISABLED)
clrOldText = SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT)); clrOldText = SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
else else
clrOldText = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT)); clrOldText = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
...@@ -127,14 +129,14 @@ HexEdit_Paint(HEXEDIT_INFO *infoPtr) ...@@ -127,14 +129,14 @@ HexEdit_Paint(HEXEDIT_INFO *infoPtr)
for (pData = infoPtr->pData + lByteOffset; pData < infoPtr->pData + infoPtr->cbData; pData += infoPtr->nBytesPerLine) for (pData = infoPtr->pData + lByteOffset; pData < infoPtr->pData + infoPtr->cbData; pData += infoPtr->nBytesPerLine)
{ {
LPTSTR lpszLine; LPWSTR lpszLine;
LONG nLineLen = min((LONG)((infoPtr->pData + infoPtr->cbData) - pData), LONG nLineLen = min((LONG)((infoPtr->pData + infoPtr->cbData) - pData),
infoPtr->nBytesPerLine); infoPtr->nBytesPerLine);
lpszLine = HexEdit_GetLineText(pData, nLineLen, infoPtr->nBytesPerLine - nLineLen); lpszLine = HexEdit_GetLineText(pData, nLineLen, infoPtr->nBytesPerLine - nLineLen);
/* FIXME: draw hex <-> ASCII mapping highlighted? */ /* FIXME: draw hex <-> ASCII mapping highlighted? */
TextOut(hdc, nXStart, nYStart, lpszLine, infoPtr->nBytesPerLine * 3 + DIV_SPACES + nLineLen); TextOutW(hdc, nXStart, nYStart, lpszLine, infoPtr->nBytesPerLine * 3 + DIV_SPACES + nLineLen);
nYStart += infoPtr->nHeight; nYStart += infoPtr->nHeight;
HeapFree(GetProcessHeap(), 0, lpszLine); HeapFree(GetProcessHeap(), 0, lpszLine);
...@@ -157,7 +159,7 @@ HexEdit_UpdateCaret(HEXEDIT_INFO *infoPtr) ...@@ -157,7 +159,7 @@ HexEdit_UpdateCaret(HEXEDIT_INFO *infoPtr)
INT nByteLinePos = nCaretBytePos % infoPtr->nBytesPerLine; INT nByteLinePos = nCaretBytePos % infoPtr->nBytesPerLine;
INT nLine = nCaretBytePos / infoPtr->nBytesPerLine; INT nLine = nCaretBytePos / infoPtr->nBytesPerLine;
LONG nLineLen = min(infoPtr->cbData - nLine * infoPtr->nBytesPerLine, infoPtr->nBytesPerLine); LONG nLineLen = min(infoPtr->cbData - nLine * infoPtr->nBytesPerLine, infoPtr->nBytesPerLine);
LPTSTR lpszLine = HexEdit_GetLineText(infoPtr->pData + nLine * infoPtr->nBytesPerLine, nLineLen, infoPtr->nBytesPerLine - nLineLen); LPWSTR lpszLine = HexEdit_GetLineText(infoPtr->pData + nLine * infoPtr->nBytesPerLine, nLineLen, infoPtr->nBytesPerLine - nLineLen);
INT nCharOffset; INT nCharOffset;
/* calculate offset of character caret is on in the line */ /* calculate offset of character caret is on in the line */
...@@ -169,7 +171,7 @@ HexEdit_UpdateCaret(HEXEDIT_INFO *infoPtr) ...@@ -169,7 +171,7 @@ HexEdit_UpdateCaret(HEXEDIT_INFO *infoPtr)
hdc = GetDC(infoPtr->hwndSelf); hdc = GetDC(infoPtr->hwndSelf);
hOldFont = SelectObject(hdc, infoPtr->hFont); hOldFont = SelectObject(hdc, infoPtr->hFont);
GetTextExtentPoint32(hdc, lpszLine, nCharOffset, &size); GetTextExtentPoint32W(hdc, lpszLine, nCharOffset, &size);
SelectObject(hdc, hOldFont); SelectObject(hdc, hOldFont);
ReleaseDC(infoPtr->hwndSelf, hdc); ReleaseDC(infoPtr->hwndSelf, hdc);
...@@ -221,7 +223,7 @@ HexEdit_EnsureVisible(HEXEDIT_INFO *infoPtr, INT nCaretPos) ...@@ -221,7 +223,7 @@ HexEdit_EnsureVisible(HEXEDIT_INFO *infoPtr, INT nCaretPos)
si.fMask = SIF_POS; si.fMask = SIF_POS;
SetScrollInfo(infoPtr->hwndSelf, SB_VERT, &si, FALSE); SetScrollInfo(infoPtr->hwndSelf, SB_VERT, &si, FALSE);
SendMessage(infoPtr->hwndSelf, WM_VSCROLL, MAKELONG(SB_THUMBPOSITION, 0), 0); SendMessageW(infoPtr->hwndSelf, WM_VSCROLL, MAKELONG(SB_THUMBPOSITION, 0), 0);
} }
...@@ -255,7 +257,7 @@ HexEdit_GetData(HEXEDIT_INFO *infoPtr, INT cbData, BYTE *pData) ...@@ -255,7 +257,7 @@ HexEdit_GetData(HEXEDIT_INFO *infoPtr, INT cbData, BYTE *pData)
} }
static inline LRESULT static inline LRESULT
HexEdit_Char (HEXEDIT_INFO *infoPtr, TCHAR ch) HexEdit_Char (HEXEDIT_INFO *infoPtr, WCHAR ch)
{ {
INT nCaretBytePos = infoPtr->nCaretPos/2; INT nCaretBytePos = infoPtr->nCaretPos/2;
...@@ -349,7 +351,7 @@ HexEdit_Destroy (HEXEDIT_INFO *infoPtr) ...@@ -349,7 +351,7 @@ HexEdit_Destroy (HEXEDIT_INFO *infoPtr)
HeapFree(GetProcessHeap(), 0, infoPtr->pData); HeapFree(GetProcessHeap(), 0, infoPtr->pData);
/* free info data */ /* free info data */
HeapFree(GetProcessHeap(), 0, infoPtr); HeapFree(GetProcessHeap(), 0, infoPtr);
SetWindowLongPtr(hwnd, 0, 0); SetWindowLongPtrW(hwnd, 0, 0);
return 0; return 0;
} }
...@@ -360,12 +362,12 @@ HexEdit_EraseBackground (HEXEDIT_INFO *infoPtr, HDC hdc) ...@@ -360,12 +362,12 @@ HexEdit_EraseBackground (HEXEDIT_INFO *infoPtr, HDC hdc)
HBRUSH hBrush, hSolidBrush = NULL; HBRUSH hBrush, hSolidBrush = NULL;
RECT rc; RECT rc;
if (GetWindowLong(infoPtr->hwndSelf, GWL_STYLE) & WS_DISABLED) if (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & WS_DISABLED)
hBrush = hSolidBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); hBrush = hSolidBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
else else
{ {
hBrush = (HBRUSH)SendMessage(GetParent(infoPtr->hwndSelf), WM_CTLCOLOREDIT, hBrush = (HBRUSH)SendMessageW(GetParent(infoPtr->hwndSelf), WM_CTLCOLOREDIT,
(WPARAM)hdc, (LPARAM)infoPtr->hwndSelf); (WPARAM)hdc, (LPARAM)infoPtr->hwndSelf);
if (!hBrush) if (!hBrush)
hBrush = hSolidBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW)); hBrush = hSolidBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
} }
...@@ -505,7 +507,7 @@ HexEdit_SetFocus (HEXEDIT_INFO *infoPtr, HWND lostFocus) ...@@ -505,7 +507,7 @@ HexEdit_SetFocus (HEXEDIT_INFO *infoPtr, HWND lostFocus)
static inline LRESULT static inline LRESULT
HexEdit_SetFont (HEXEDIT_INFO *infoPtr, HFONT hFont, BOOL redraw) HexEdit_SetFont (HEXEDIT_INFO *infoPtr, HFONT hFont, BOOL redraw)
{ {
TEXTMETRIC tm; TEXTMETRICW tm;
HDC hdc; HDC hdc;
HFONT hOldFont = NULL; HFONT hOldFont = NULL;
LONG i; LONG i;
...@@ -517,7 +519,7 @@ HexEdit_SetFont (HEXEDIT_INFO *infoPtr, HFONT hFont, BOOL redraw) ...@@ -517,7 +519,7 @@ HexEdit_SetFont (HEXEDIT_INFO *infoPtr, HFONT hFont, BOOL redraw)
if (infoPtr->hFont) if (infoPtr->hFont)
hOldFont = SelectObject(hdc, infoPtr->hFont); hOldFont = SelectObject(hdc, infoPtr->hFont);
GetTextMetrics(hdc, &tm); GetTextMetricsW(hdc, &tm);
infoPtr->nHeight = tm.tmHeight + tm.tmExternalLeading; infoPtr->nHeight = tm.tmHeight + tm.tmExternalLeading;
GetClientRect(infoPtr->hwndSelf, &rcClient); GetClientRect(infoPtr->hwndSelf, &rcClient);
...@@ -525,9 +527,9 @@ HexEdit_SetFont (HEXEDIT_INFO *infoPtr, HFONT hFont, BOOL redraw) ...@@ -525,9 +527,9 @@ HexEdit_SetFont (HEXEDIT_INFO *infoPtr, HFONT hFont, BOOL redraw)
for (i = 0; ; i++) for (i = 0; ; i++)
{ {
BYTE *pData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, i); BYTE *pData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, i);
LPTSTR lpszLine = HexEdit_GetLineText(pData, i, 0); LPWSTR lpszLine = HexEdit_GetLineText(pData, i, 0);
SIZE size; SIZE size;
GetTextExtentPoint32(hdc, lpszLine, lstrlen(lpszLine), &size); GetTextExtentPoint32W(hdc, lpszLine, lstrlenW(lpszLine), &size);
HeapFree(GetProcessHeap(), 0, lpszLine); HeapFree(GetProcessHeap(), 0, lpszLine);
HeapFree(GetProcessHeap(), 0, pData); HeapFree(GetProcessHeap(), 0, pData);
if (size.cx > (rcClient.right - rcClient.left)) if (size.cx > (rcClient.right - rcClient.left))
......
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