mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Fixed caret position and visibility issues
This commit is contained in:
parent
941b55f546
commit
3588072155
@ -38,6 +38,9 @@ namespace
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BOOL WINAPI hideCaret(HWND hWnd);
|
||||||
|
BOOL WINAPI showCaret(HWND hWnd);
|
||||||
|
|
||||||
void drawCaret()
|
void drawCaret()
|
||||||
{
|
{
|
||||||
if (CompatGdi::beginGdiRendering())
|
if (CompatGdi::beginGdiRendering())
|
||||||
@ -70,8 +73,13 @@ namespace
|
|||||||
DWORD /*dwEventThread*/,
|
DWORD /*dwEventThread*/,
|
||||||
DWORD /*dwmsEventTime*/)
|
DWORD /*dwmsEventTime*/)
|
||||||
{
|
{
|
||||||
|
if (OBJID_CARET != idObject)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CaretScopedThreadLock caretLock;
|
CaretScopedThreadLock caretLock;
|
||||||
if (OBJID_CARET != idObject || !g_caret.isDrawn || g_caret.hwnd != hwnd)
|
if (!g_caret.isDrawn || g_caret.hwnd != hwnd)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -90,6 +98,50 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CALLBACK caretLocationChangeEvent(
|
||||||
|
HWINEVENTHOOK /*hWinEventHook*/,
|
||||||
|
DWORD /*event*/,
|
||||||
|
HWND hwnd,
|
||||||
|
LONG idObject,
|
||||||
|
LONG /*idChild*/,
|
||||||
|
DWORD /*dwEventThread*/,
|
||||||
|
DWORD /*dwmsEventTime*/)
|
||||||
|
{
|
||||||
|
if (OBJID_CARET != idObject)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CaretScopedThreadLock caretLock;
|
||||||
|
if (g_caret.isDrawn && g_caret.hwnd == hwnd)
|
||||||
|
{
|
||||||
|
hideCaret(hwnd);
|
||||||
|
showCaret(hwnd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CALLBACK caretShowEvent(
|
||||||
|
HWINEVENTHOOK /*hWinEventHook*/,
|
||||||
|
DWORD /*event*/,
|
||||||
|
HWND hwnd,
|
||||||
|
LONG idObject,
|
||||||
|
LONG /*idChild*/,
|
||||||
|
DWORD /*dwEventThread*/,
|
||||||
|
DWORD /*dwmsEventTime*/)
|
||||||
|
{
|
||||||
|
if (OBJID_CARET != idObject)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CaretScopedThreadLock caretLock;
|
||||||
|
if (!g_caret.isDrawn && g_caret.hwnd == hwnd)
|
||||||
|
{
|
||||||
|
drawCaret();
|
||||||
|
g_caret.isDrawn = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOL WINAPI createCaret(HWND hWnd, HBITMAP hBitmap, int nWidth, int nHeight)
|
BOOL WINAPI createCaret(HWND hWnd, HBITMAP hBitmap, int nWidth, int nHeight)
|
||||||
{
|
{
|
||||||
BOOL result = CALL_ORIG_GDI(CreateCaret)(hWnd, hBitmap, nWidth, nHeight);
|
BOOL result = CALL_ORIG_GDI(CreateCaret)(hWnd, hBitmap, nWidth, nHeight);
|
||||||
@ -107,6 +159,21 @@ namespace
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL WINAPI hideCaret(HWND hWnd)
|
||||||
|
{
|
||||||
|
BOOL result = CALL_ORIG_GDI(HideCaret)(hWnd);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
CaretScopedThreadLock caretLock;
|
||||||
|
if (g_caret.isDrawn)
|
||||||
|
{
|
||||||
|
drawCaret();
|
||||||
|
g_caret.isDrawn = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
BOOL WINAPI showCaret(HWND hWnd)
|
BOOL WINAPI showCaret(HWND hWnd)
|
||||||
{
|
{
|
||||||
if (!CALL_ORIG_GDI(ShowCaret)(hWnd))
|
if (!CALL_ORIG_GDI(ShowCaret)(hWnd))
|
||||||
@ -138,21 +205,6 @@ namespace
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL WINAPI hideCaret(HWND hWnd)
|
|
||||||
{
|
|
||||||
BOOL result = CALL_ORIG_GDI(HideCaret)(hWnd);
|
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
CaretScopedThreadLock caretLock;
|
|
||||||
if (g_caret.isDrawn)
|
|
||||||
{
|
|
||||||
drawCaret();
|
|
||||||
g_caret.isDrawn = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HOOK_GDI_FUNCTION(module, func, newFunc) \
|
#define HOOK_GDI_FUNCTION(module, func, newFunc) \
|
||||||
@ -166,12 +218,16 @@ namespace CompatGdiCaret
|
|||||||
|
|
||||||
DetourTransactionBegin();
|
DetourTransactionBegin();
|
||||||
HOOK_GDI_FUNCTION(user32, CreateCaret, createCaret);
|
HOOK_GDI_FUNCTION(user32, CreateCaret, createCaret);
|
||||||
HOOK_GDI_FUNCTION(user32, ShowCaret, showCaret);
|
|
||||||
HOOK_GDI_FUNCTION(user32, HideCaret, hideCaret);
|
HOOK_GDI_FUNCTION(user32, HideCaret, hideCaret);
|
||||||
|
HOOK_GDI_FUNCTION(user32, ShowCaret, showCaret);
|
||||||
DetourTransactionCommit();
|
DetourTransactionCommit();
|
||||||
|
|
||||||
const DWORD threadId = GetCurrentThreadId();
|
const DWORD threadId = GetCurrentThreadId();
|
||||||
SetWinEventHook(EVENT_OBJECT_DESTROY, EVENT_OBJECT_DESTROY,
|
SetWinEventHook(EVENT_OBJECT_DESTROY, EVENT_OBJECT_DESTROY,
|
||||||
nullptr, &caretDestroyEvent, 0, threadId, WINEVENT_OUTOFCONTEXT);
|
nullptr, &caretDestroyEvent, 0, threadId, WINEVENT_OUTOFCONTEXT);
|
||||||
|
SetWinEventHook(EVENT_OBJECT_LOCATIONCHANGE, EVENT_OBJECT_LOCATIONCHANGE,
|
||||||
|
nullptr, &caretLocationChangeEvent, 0, threadId, WINEVENT_OUTOFCONTEXT);
|
||||||
|
SetWinEventHook(EVENT_OBJECT_SHOW, EVENT_OBJECT_SHOW,
|
||||||
|
nullptr, &caretShowEvent, 0, threadId, WINEVENT_OUTOFCONTEXT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user