diff --git a/reactos/include/win32k/ntuser.h b/reactos/include/win32k/ntuser.h index a78321417d0..c7fc7b5ac53 100644 --- a/reactos/include/win32k/ntuser.h +++ b/reactos/include/win32k/ntuser.h @@ -350,11 +350,8 @@ NtUserDeferWindowPos(HDWP WinPosInfo, int cx, int cy, UINT Flags); -DWORD -STDCALL -NtUserDefSetText( - DWORD Unknown0, - DWORD Unknown1); +BOOL STDCALL +NtUserDefSetText(HWND WindowHandle, PANSI_STRING Text); BOOL STDCALL diff --git a/reactos/lib/user32/windows/defwnd.c b/reactos/lib/user32/windows/defwnd.c index 5f21992193f..9e287a172b4 100644 --- a/reactos/lib/user32/windows/defwnd.c +++ b/reactos/lib/user32/windows/defwnd.c @@ -1,4 +1,4 @@ -/* $Id: defwnd.c,v 1.105 2003/11/08 15:33:51 mf Exp $ +/* $Id: defwnd.c,v 1.106 2003/11/09 11:42:08 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS user32.dll @@ -1347,75 +1347,56 @@ DefWindowProcA(HWND hWnd, WPARAM wParam, LPARAM lParam) { - static LPSTR WindowTextAtom = 0; - PSTR WindowText; - switch (Msg) { case WM_NCCREATE: { - CREATESTRUCTA *Cs = (CREATESTRUCTA*)lParam; - if (HIWORD(Cs->lpszName)) - { - if (0 == WindowTextAtom) - { - WindowTextAtom = - (LPSTR)(ULONG)GlobalAddAtomA("USER32!WindowTextAtomA"); - } - WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0, - (strlen(Cs->lpszName) + 1) * sizeof(CHAR)); - strcpy(WindowText, Cs->lpszName); - SetPropA(hWnd, WindowTextAtom, WindowText); - } - return (1); + return TRUE; } case WM_GETTEXTLENGTH: { - if (WindowTextAtom == 0 || - (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL) - { - return(0); - } - return (strlen(WindowText)); + return InternalGetWindowText(hWnd, NULL, 0); } case WM_GETTEXT: { - if (WindowTextAtom == 0 || - (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL) + UNICODE_STRING UnicodeString; + LPSTR AnsiBuffer = (LPSTR)lParam; + BOOL Result; + + if (wParam > 1) { - if (wParam > 1) - { - *((PSTR)lParam) = '\0'; - } - return (0); + *((PWSTR)lParam) = '\0'; } - strncpy((LPSTR)lParam, WindowText, wParam); - return (min(wParam, strlen(WindowText))); + UnicodeString.Length = UnicodeString.MaximumLength = + wParam * sizeof(WCHAR); + UnicodeString.Buffer = HeapAlloc(GetProcessHeap(), 0, + UnicodeString.Length); + if (!UnicodeString.Buffer) + return FALSE; + Result = InternalGetWindowText(hWnd, UnicodeString.Buffer, wParam); + if (wParam > 0 && + !WideCharToMultiByte(CP_ACP, 0, UnicodeString.Buffer, -1, + AnsiBuffer, wParam, NULL, NULL)) + { + AnsiBuffer[wParam - 1] = 0; + } + HeapFree(GetProcessHeap(), 0, UnicodeString.Buffer); + + return Result; } case WM_SETTEXT: { - if (0 == WindowTextAtom) - { - WindowTextAtom = - (LPSTR)(DWORD)GlobalAddAtomA("USER32!WindowTextAtomA"); - } - if (WindowTextAtom != 0 && - (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL) - { - RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText); - } - WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0, - (strlen((PSTR)lParam) + 1) * sizeof(CHAR)); - strcpy(WindowText, (PSTR)lParam); - SetPropA(hWnd, WindowTextAtom, WindowText); + ANSI_STRING AnsiString; + RtlInitAnsiString(&AnsiString, (LPSTR)lParam); + NtUserDefSetText(hWnd, &AnsiString); if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION) { DefWndNCPaint(hWnd, (HRGN)1); } - return (1); + return TRUE; } /* @@ -1429,16 +1410,6 @@ DefWindowProcA(HWND hWnd, case WM_IME_SELECT: case WM_IME_SETCONTEXT: */ - - case WM_NCDESTROY: - { - if (WindowTextAtom != 0 && - (WindowText = RemovePropA(hWnd, WindowTextAtom)) == NULL) - { - RtlFreeHeap(GetProcessHeap(), 0, WindowText); - } - return(0); - } } return User32DefWindowProc(hWnd, Msg, wParam, lParam, FALSE); @@ -1451,70 +1422,38 @@ DefWindowProcW(HWND hWnd, WPARAM wParam, LPARAM lParam) { - static LPWSTR WindowTextAtom = 0; - PWSTR WindowText; - switch (Msg) { case WM_NCCREATE: { - CREATESTRUCTW* CreateStruct = (CREATESTRUCTW*)lParam; - if (HIWORD(CreateStruct->lpszName)) - { - if (0 == WindowTextAtom) - { - WindowTextAtom = - (LPWSTR)(DWORD)GlobalAddAtomW(L"USER32!WindowTextAtomW"); - } - WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0, - (wcslen(CreateStruct->lpszName) + 1) * sizeof(WCHAR)); - wcscpy(WindowText, CreateStruct->lpszName); - SetPropW(hWnd, WindowTextAtom, WindowText); - } - return (1); + return TRUE; } case WM_GETTEXTLENGTH: { - if (WindowTextAtom == 0 || - (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL) - { - return(0); - } - return (wcslen(WindowText)); + return InternalGetWindowText(hWnd, NULL, 0); } case WM_GETTEXT: { - if (WindowTextAtom == 0 || - (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL) + DWORD Result; + if (wParam > 1) { - if (wParam > 1) - { - *((PWSTR)lParam) = '\0'; - } - return (0); + *((PWSTR)lParam) = '\0'; } - wcsncpy((PWSTR)lParam, WindowText, wParam); - return (min(wParam, wcslen(WindowText))); + Result = InternalGetWindowText(hWnd, (PWSTR)lParam, wParam); + return Result; } case WM_SETTEXT: { - if (WindowTextAtom == 0) - { - WindowTextAtom = - (LPWSTR)(DWORD)GlobalAddAtomW(L"USER32!WindowTextAtomW"); - } - if (WindowTextAtom != 0 && - (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL) - { - RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText); - } - WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0, - (wcslen((PWSTR)lParam) + 1) * sizeof(WCHAR)); - wcscpy(WindowText, (PWSTR)lParam); - SetPropW(hWnd, WindowTextAtom, WindowText); + UNICODE_STRING UnicodeString; + ANSI_STRING AnsiString; + + RtlInitUnicodeString(&UnicodeString, (LPWSTR)lParam); + RtlUnicodeStringToAnsiString(&AnsiString, &UnicodeString, TRUE); + NtUserDefSetText(hWnd, &AnsiString); + RtlFreeAnsiString(&AnsiString); if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION) { DefWndNCPaint(hWnd, (HRGN)1); @@ -1533,16 +1472,6 @@ DefWindowProcW(HWND hWnd, /* FIXME */ return (0); } - - case WM_NCDESTROY: - { - if (WindowTextAtom != 0 && - (WindowText = RemovePropW(hWnd, WindowTextAtom)) == NULL) - { - RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText); - } - return (0); - } } return User32DefWindowProc(hWnd, Msg, wParam, lParam, TRUE); diff --git a/reactos/lib/user32/windows/window.c b/reactos/lib/user32/windows/window.c index e4a31570019..6df77e61299 100644 --- a/reactos/lib/user32/windows/window.c +++ b/reactos/lib/user32/windows/window.c @@ -1,4 +1,4 @@ -/* $Id: window.c,v 1.78 2003/11/02 06:58:57 navaraf Exp $ +/* $Id: window.c,v 1.79 2003/11/09 11:42:08 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS user32.dll @@ -1598,29 +1598,7 @@ DWORD STDCALL InternalGetWindowText(HWND hWnd, LPWSTR lpString, int nMaxCount) { - DWORD res = 0; - LPWSTR lps = NULL; - if(lpString && (nMaxCount > 0)) - { - lps = RtlAllocateHeap(RtlGetProcessHeap(), 0, nMaxCount * sizeof(WCHAR)); - if(!lps) - { - SetLastError(ERROR_OUTOFMEMORY); - return 0; - } - } - - res = NtUserInternalGetWindowText(hWnd, lps, nMaxCount); - - if(lps) - { - RtlCopyMemory(lpString, lps, res * sizeof(WCHAR)); - lpString[res] = (WCHAR)"\0"; /* null-terminate the string */ - - RtlFreeHeap(RtlGetProcessHeap(), 0, lps); - } - - return res; + return NtUserInternalGetWindowText(hWnd, lpString, nMaxCount); } /* diff --git a/reactos/subsys/win32k/ntuser/stubs.c b/reactos/subsys/win32k/ntuser/stubs.c index 318f99b0a63..d5e51896c0f 100644 --- a/reactos/subsys/win32k/ntuser/stubs.c +++ b/reactos/subsys/win32k/ntuser/stubs.c @@ -1,4 +1,4 @@ -/* $Id: stubs.c,v 1.31 2003/11/02 16:33:33 ekohl Exp $ +/* $Id: stubs.c,v 1.32 2003/11/09 11:42:08 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -265,17 +265,6 @@ NtUserDdeSetQualityOfService( return 0; } -DWORD -STDCALL -NtUserDefSetText( - DWORD Unknown0, - DWORD Unknown1) -{ - UNIMPLEMENTED - - return 0; -} - DWORD STDCALL NtUserDestroyAcceleratorTable( diff --git a/reactos/subsys/win32k/ntuser/window.c b/reactos/subsys/win32k/ntuser/window.c index fd23669b8ce..774388d2de8 100644 --- a/reactos/subsys/win32k/ntuser/window.c +++ b/reactos/subsys/win32k/ntuser/window.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: window.c,v 1.130 2003/11/08 15:00:36 gvg Exp $ +/* $Id: window.c,v 1.131 2003/11/09 11:42:08 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -1486,7 +1486,11 @@ NtUserCreateWindowEx(DWORD dwExStyle, ExInitializeFastMutex(&WindowObject->ChildrenListLock); RtlInitUnicodeString(&WindowObject->WindowName, WindowName.Buffer); +/* + This is incorrect!!! -- Filip + RtlFreeUnicodeString(&WindowName); +*/ /* Correct the window style. */ @@ -2955,44 +2959,6 @@ NtUserGetWindowThreadProcessId(HWND hWnd, LPDWORD UnsafePid) } -/* - * @unimplemented - */ -DWORD STDCALL -NtUserInternalGetWindowText(HWND hWnd, - LPWSTR lpString, - int nMaxCount) -{ - DWORD res = 0; - PWINDOW_OBJECT WindowObject; - - IntAcquireWinLockShared(); /* ??? */ - WindowObject = IntGetWindowObject(hWnd); - if(!WindowObject) - { - IntReleaseWinLock(); /* ??? */ - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); - return 0; - } - - if(lpString) - { - /* FIXME - Window text is currently stored - in the Atom 'USER32!WindowTextAtomA' */ - - } - else - { - /* FIXME - return length of window text */ - } - - IntReleaseWindowObject(WindowObject); - - IntReleaseWinLock(); /* ??? */ - return res; -} - - /* * @unimplemented */ @@ -3696,4 +3662,83 @@ NtUserWindowFromPoint(LONG X, LONG Y) return hWnd; } + +/* + * NtUserDefSetText + * + * Undocumented function that is called from DefWindowProc to set + * window text. + * + * FIXME: Call this from user32.dll! + * + * Status + * @unimplemented + */ + +BOOL STDCALL +NtUserDefSetText(HWND WindowHandle, PANSI_STRING Text) +{ + PWINDOW_OBJECT WindowObject; + UNICODE_STRING NewWindowName; + BOOL Result = FALSE; + + WindowObject = IntGetWindowObject(WindowHandle); + if (!WindowObject) + { + SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); + return FALSE; + } + + if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&NewWindowName, Text, TRUE))) + { + RtlFreeUnicodeString(&WindowObject->WindowName); + WindowObject->WindowName.Buffer = NewWindowName.Buffer; + WindowObject->WindowName.Length = NewWindowName.Length; + WindowObject->WindowName.MaximumLength = NewWindowName.MaximumLength; + Result = TRUE; + } + + IntReleaseWindowObject(WindowObject); + + return Result; +} + +/* + * NtUserInternalGetWindowText + * + * FIXME: Call this from user32.dll! + * + * Status + * @implemented + */ + +DWORD STDCALL +NtUserInternalGetWindowText(HWND WindowHandle, LPWSTR Text, INT MaxCount) +{ + PWINDOW_OBJECT WindowObject; + DWORD Result; + + WindowObject = IntGetWindowObject(WindowHandle); + if (!WindowObject) + { + SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); + return 0; + } + + Result = WindowObject->WindowName.Length / sizeof(WCHAR); + if (Text) + { + /* FIXME: Shouldn't it be always NULL terminated? */ + wcsncpy(Text, WindowObject->WindowName.Buffer, MaxCount); + if (MaxCount < Result) + { + Result = MaxCount; + } + } + + IntReleaseWindowObject(WindowObject); + + return Result; +} + /* EOF */