From 04b57ad0bd6a44bc5ac548548ef20cdf03e7b6c4 Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Fri, 17 Oct 2003 20:31:56 +0000 Subject: [PATCH] implemented basic drawing of carets svn path=/trunk/; revision=6349 --- reactos/include/win32k/ntuser.h | 2 +- reactos/lib/user32/include/user32.h | 14 +++++++- reactos/lib/user32/windows/caret.c | 29 +++++++++++++++- reactos/lib/user32/windows/defwnd.c | 11 +++--- reactos/subsys/win32k/include/caret.h | 6 +++- reactos/subsys/win32k/ntuser/caret.c | 48 +++++++++++++++++++++++---- reactos/subsys/win32k/ntuser/misc.c | 9 +++-- 7 files changed, 99 insertions(+), 20 deletions(-) diff --git a/reactos/include/win32k/ntuser.h b/reactos/include/win32k/ntuser.h index ac2c0d45a0e..cf4a4eabf0b 100644 --- a/reactos/include/win32k/ntuser.h +++ b/reactos/include/win32k/ntuser.h @@ -158,7 +158,6 @@ NtUserCallNextHookEx( #define NOPARAM_ROUTINE_REGISTER_PRIMITIVE 0xffff0001 /* Private ROS */ #define NOPARAM_ROUTINE_DESTROY_CARET 0xffff0002 -#define NOPARAM_ROUTINE_SWITCHCARETSHOWING 0xffff0003 DWORD STDCALL NtUserCallNoParam( @@ -171,6 +170,7 @@ NtUserCallNoParam( #define ONEPARAM_ROUTINE_SWAPMOUSEBUTTON 0x05 #define ONEPARAM_ROUTINE_SETCARETBLINKTIME 0x06 #define ONEPARAM_ROUTINE_GETCARETINFO 0x07 +#define ONEPARAM_ROUTINE_SWITCHCARETSHOWING 0x08 DWORD STDCALL NtUserCallOneParam( diff --git a/reactos/lib/user32/include/user32.h b/reactos/lib/user32/include/user32.h index 409f109d83b..055e08c6614 100644 --- a/reactos/lib/user32/include/user32.h +++ b/reactos/lib/user32/include/user32.h @@ -15,5 +15,17 @@ typedef struct _USER32_THREAD_DATA PUSER32_THREAD_DATA User32GetThreadData(); -VOID DeleteFrameBrushes(VOID); +/* a copy of this structure is in subsys/win32k/include/caret.h */ +typedef struct _THRDCARETINFO +{ + HWND hWnd; + HBITMAP Bitmap; + POINT Pos; + SIZE Size; + BYTE Visible; + BYTE Showing; +} THRDCARETINFO, *PTHRDCARETINFO; + +VOID DeleteFrameBrushes(VOID); +void DrawCaret(HWND hWnd, PTHRDCARETINFO CaretInfo); diff --git a/reactos/lib/user32/windows/caret.c b/reactos/lib/user32/windows/caret.c index 0ba1d5059e1..c65db2fa00e 100644 --- a/reactos/lib/user32/windows/caret.c +++ b/reactos/lib/user32/windows/caret.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: caret.c,v 1.2 2003/10/16 22:07:37 weiden Exp $ +/* $Id: caret.c,v 1.3 2003/10/17 20:31:56 weiden Exp $ * * PROJECT: ReactOS user32.dll * FILE: lib/user32/windows/caret.c @@ -34,6 +34,33 @@ /* FUNCTIONS *****************************************************************/ +void DrawCaret(HWND hWnd, PTHRDCARETINFO CaretInfo) +{ + HDC hDC, hComp; + + hDC = GetDC(hWnd); + if(hDC) + { + if(CaretInfo->Bitmap && GetBitmapDimensionEx(CaretInfo->Bitmap, &CaretInfo->Size)) + { + hComp = CreateCompatibleDC(hDC); + if(hComp) + { + SelectObject(hComp, CaretInfo->Bitmap); + BitBlt(hDC, CaretInfo->Pos.x, CaretInfo->Pos.y, CaretInfo->Size.cx, CaretInfo->Size.cy, hComp, 0, 0, SRCINVERT); + DeleteDC(hComp); + } + else + PatBlt(hDC, CaretInfo->Pos.x, CaretInfo->Pos.y, CaretInfo->Size.cx, CaretInfo->Size.cy, DSTINVERT); + } + else + { + PatBlt(hDC, CaretInfo->Pos.x, CaretInfo->Pos.y, CaretInfo->Size.cx, CaretInfo->Size.cy, DSTINVERT); + } + ReleaseDC(hWnd, hDC); + } +} + /* * @implemented */ diff --git a/reactos/lib/user32/windows/defwnd.c b/reactos/lib/user32/windows/defwnd.c index 8243292002e..e46fc50dd86 100644 --- a/reactos/lib/user32/windows/defwnd.c +++ b/reactos/lib/user32/windows/defwnd.c @@ -1,4 +1,4 @@ -/* $Id: defwnd.c,v 1.98 2003/10/16 22:07:37 weiden Exp $ +/* $Id: defwnd.c,v 1.99 2003/10/17 20:31:56 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS user32.dll @@ -2268,12 +2268,15 @@ User32DefWindowProc(HWND hWnd, case WM_SYSTIMER: { + THRDCARETINFO CaretInfo; switch(wParam) { case 0xffff: /* Caret timer */ - /* switch showing byte in win32k */ - NtUserCallNoParam(NOPARAM_ROUTINE_SWITCHCARETSHOWING); - /* FIXME - get the caret information and draw the caret */ + /* switch showing byte in win32k and get information about the caret */ + if(NtUserCallOneParam((DWORD)&CaretInfo, ONEPARAM_ROUTINE_SWITCHCARETSHOWING) && (CaretInfo.hWnd == hWnd)) + { + DrawCaret(hWnd, &CaretInfo); + } break; } break; diff --git a/reactos/subsys/win32k/include/caret.h b/reactos/subsys/win32k/include/caret.h index 66147a1793e..0fac7387d18 100644 --- a/reactos/subsys/win32k/include/caret.h +++ b/reactos/subsys/win32k/include/caret.h @@ -7,6 +7,7 @@ #define IDCARETTIMER (0xffff) #define ThrdCaretInfo(x) (PTHRDCARETINFO)((PW32THREAD)(x + 1)) +/* a copy of this structure is in lib/user32/include/user32.h */ typedef struct _THRDCARETINFO { HWND hWnd; @@ -27,7 +28,10 @@ BOOL FASTCALL IntSetCaretPos(int X, int Y); BOOL FASTCALL -IntSwitchCaretShowing(VOID); +IntSwitchCaretShowing(PVOID Info); + +VOID FASTCALL +IntDrawCaret(HWND hWnd); #endif /* __WIN32K_CARET_H */ diff --git a/reactos/subsys/win32k/ntuser/caret.c b/reactos/subsys/win32k/ntuser/caret.c index 109c402da63..c1005c04faf 100644 --- a/reactos/subsys/win32k/ntuser/caret.c +++ b/reactos/subsys/win32k/ntuser/caret.c @@ -1,4 +1,4 @@ -/* $Id: caret.c,v 1.2 2003/10/16 22:07:37 weiden Exp $ +/* $Id: caret.c,v 1.3 2003/10/17 20:31:56 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -15,14 +15,28 @@ #include #include #include +#include #define NDEBUG #include +BOOL FASTCALL +IntHideCaret(PTHRDCARETINFO CaretInfo) +{ + if(CaretInfo->hWnd && CaretInfo->Visible && CaretInfo->Showing) + { + IntCallWindowProc(NULL, CaretInfo->hWnd, WM_SYSTIMER, IDCARETTIMER, 0); + CaretInfo->Showing = 0; + return TRUE; + } + return FALSE; +} + BOOL FASTCALL IntDestroyCaret(PW32THREAD Win32Thread) { PTHRDCARETINFO CaretInfo = ThrdCaretInfo(Win32Thread); + IntHideCaret(CaretInfo); RtlZeroMemory(CaretInfo, sizeof(THRDCARETINFO)); return TRUE; } @@ -48,8 +62,11 @@ IntSetCaretPos(int X, int Y) { if(CaretInfo->Pos.x != X || CaretInfo->Pos.y != Y) { + IntHideCaret(CaretInfo); + CaretInfo->Showing = 0; CaretInfo->Pos.x = X; CaretInfo->Pos.y = Y; + IntCallWindowProc(NULL, CaretInfo->hWnd, WM_SYSTIMER, IDCARETTIMER, 0); IntSetTimer(CaretInfo->hWnd, IDCARETTIMER, IntGetCaretBlinkTime(), NULL, TRUE); } return TRUE; @@ -59,19 +76,32 @@ IntSetCaretPos(int X, int Y) } BOOL FASTCALL -IntSwitchCaretShowing(VOID) +IntSwitchCaretShowing(PVOID Info) { PTHRDCARETINFO CaretInfo = ThrdCaretInfo(PsGetCurrentThread()->Win32Thread); if(CaretInfo->hWnd) { CaretInfo->Showing = (CaretInfo->Showing ? 0 : 1); + MmCopyToCaller(Info, CaretInfo, sizeof(THRDCARETINFO)); return TRUE; } return FALSE; } +VOID FASTCALL +IntDrawCaret(HWND hWnd) +{ + PTHRDCARETINFO CaretInfo = ThrdCaretInfo(PsGetCurrentThread()->Win32Thread); + + if(CaretInfo->hWnd && CaretInfo->Visible && CaretInfo->Showing) + { + IntCallWindowProc(NULL, CaretInfo->hWnd, WM_SYSTIMER, IDCARETTIMER, 0); + CaretInfo->Showing = 1; + } +} + BOOL @@ -102,6 +132,9 @@ NtUserCreateCaret( IntRemoveTimer(hWnd, IDCARETTIMER, PsGetCurrentThreadId(), TRUE); CaretInfo = ThrdCaretInfo(WindowObject->OwnerThread->Win32Thread); + + IntHideCaret(CaretInfo); + CaretInfo->hWnd = hWnd; if(hBitmap) { @@ -183,10 +216,8 @@ NtUserHideCaret( if(CaretInfo->Visible) { IntRemoveTimer(hWnd, IDCARETTIMER, PsGetCurrentThreadId(), TRUE); - if(CaretInfo->Showing) - { - /* FIXME send another WM_SYSTIMER message to hide the cursor */ - } + + IntHideCaret(CaretInfo); CaretInfo->Visible = 0; CaretInfo->Showing = 0; } @@ -229,7 +260,10 @@ NtUserShowCaret( if(!CaretInfo->Visible) { CaretInfo->Visible = 1; - CaretInfo->Showing = 0; + if(!CaretInfo->Showing) + { + IntCallWindowProc(NULL, CaretInfo->hWnd, WM_SYSTIMER, IDCARETTIMER, 0); + } IntSetTimer(hWnd, IDCARETTIMER, IntGetCaretBlinkTime(), NULL, TRUE); } diff --git a/reactos/subsys/win32k/ntuser/misc.c b/reactos/subsys/win32k/ntuser/misc.c index 15cab50cedd..cdf518a9803 100644 --- a/reactos/subsys/win32k/ntuser/misc.c +++ b/reactos/subsys/win32k/ntuser/misc.c @@ -1,4 +1,4 @@ -/* $Id: misc.c,v 1.20 2003/10/16 22:07:37 weiden Exp $ +/* $Id: misc.c,v 1.21 2003/10/17 20:31:56 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -63,10 +63,6 @@ NtUserCallNoParam(DWORD Routine) Result = (DWORD)IntDestroyCaret(PsGetCurrentThread()->Win32Thread); break; - case NOPARAM_ROUTINE_SWITCHCARETSHOWING: - Result = (DWORD)IntSwitchCaretShowing(); - break; - default: DPRINT1("Calling invalid routine number 0x%x in NtUserCallTwoParam\n"); SetLastWin32Error(ERROR_INVALID_PARAMETER); @@ -144,6 +140,9 @@ NtUserCallOneParam( ObDereferenceObject(WinStaObject); return Result; + case ONEPARAM_ROUTINE_SWITCHCARETSHOWING: + return (DWORD)IntSwitchCaretShowing((PVOID)Param); + case ONEPARAM_ROUTINE_SETCARETBLINKTIME: return (DWORD)IntSetCaretBlinkTime((UINT)Param);