1 /* 2 * PROJECT: ReactOS Cicero 3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) 4 * PURPOSE: Displaying Cicero caret 5 * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com> 6 */ 7 8 #include "precomp.h" 9 #include "ciccaret.h" 10 11 /** 12 * @implemented 13 */ 14 CicCaret::CicCaret() 15 { 16 m_bCaretBlinking = FALSE; 17 m_bCaretVisible = FALSE; 18 m_uCaretBlinkTimerID = 0; 19 m_pt.x = m_pt.y = 0; 20 m_size.cx = m_size.cy = 0; 21 } 22 23 /** 24 * @implemented 25 */ 26 CicCaret::~CicCaret() 27 { 28 HideCaret(); 29 ::KillTimer(m_hWnd, m_uCaretBlinkTimerID); 30 m_uCaretBlinkTimerID = 0; 31 } 32 33 /** 34 * @implemented 35 */ 36 void CicCaret::CreateCaret(HWND hWnd, SIZE size) 37 { 38 m_hWnd = hWnd; 39 m_size = size; 40 if (::IsWindow(hWnd)) 41 m_uCaretBlinkTimerID = ::SetTimer(m_hWnd, TIMER_ID, ::GetCaretBlinkTime(), NULL); 42 } 43 44 /** 45 * @implemented 46 */ 47 void CicCaret::DestroyCaret() 48 { 49 HideCaret(); 50 ::KillTimer(m_hWnd, m_uCaretBlinkTimerID); 51 m_uCaretBlinkTimerID = 0; 52 } 53 54 /** 55 * @implemented 56 */ 57 void CicCaret::HideCaret() 58 { 59 if (m_bCaretVisible) 60 { 61 m_bCaretVisible = FALSE; 62 InvertCaret(); 63 } 64 m_bCaretBlinking = FALSE; 65 } 66 67 /** 68 * @implemented 69 */ 70 void CicCaret::InvertCaret() 71 { 72 HDC hDC = ::GetDC(m_hWnd); 73 ::PatBlt(hDC, m_pt.x, m_pt.y, m_size.cx, m_size.cy, DSTINVERT); 74 ::ReleaseDC(m_hWnd, hDC); 75 } 76 77 /** 78 * @implemented 79 */ 80 void CicCaret::OnTimer() 81 { 82 if (m_bCaretBlinking) 83 { 84 m_bCaretVisible = !m_bCaretVisible; 85 InvertCaret(); 86 } 87 } 88 89 /** 90 * @implemented 91 */ 92 void CicCaret::SetCaretPos(POINT pt) 93 { 94 BOOL bCaretVisible = m_bCaretVisible; 95 if (bCaretVisible) 96 InvertCaret(); 97 98 m_pt = pt; 99 100 if (bCaretVisible) 101 InvertCaret(); 102 } 103 104 /** 105 * @implemented 106 */ 107 void CicCaret::SetBlinking(BOOL bBlinking) 108 { 109 m_bCaretBlinking = bBlinking; 110 } 111