Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. caret.cpp
  5. Abstract:
  6. This file implements the CCaret Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "private.h"
  12. #include "caret.h"
  13. #include "globals.h"
  14. //+---------------------------------------------------------------------------
  15. //
  16. // CCaret::ctor
  17. // CCaret::dtor
  18. //
  19. //+---------------------------------------------------------------------------
  20. CCaret::CCaret()
  21. {
  22. m_hCaretTimer = NULL;
  23. m_caret_pos.x = 0;
  24. m_caret_pos.y = 0;
  25. m_caret_size.cx = 0;
  26. m_caret_size.cy = 0;
  27. }
  28. CCaret::~CCaret()
  29. {
  30. HideCaret();
  31. KillTimer(m_hParentWnd, m_hCaretTimer);
  32. m_hCaretTimer = NULL;
  33. }
  34. //+---------------------------------------------------------------------------
  35. //
  36. // CCaret::CreateCaret
  37. //
  38. //+---------------------------------------------------------------------------
  39. HRESULT
  40. CCaret::CreateCaret(
  41. HWND hParentWnd,
  42. SIZE caret_size)
  43. {
  44. HRESULT hr;
  45. m_hParentWnd = hParentWnd;
  46. m_caret_size = caret_size;
  47. if (IsWindow(m_hParentWnd))
  48. m_hCaretTimer = SetTimer(m_hParentWnd, TIMER_EVENT_ID, GetCaretBlinkTime(), NULL);
  49. return S_OK;
  50. }
  51. //+---------------------------------------------------------------------------
  52. //
  53. // CCaret::DestroyCaret
  54. //
  55. //+---------------------------------------------------------------------------
  56. HRESULT
  57. CCaret::DestroyCaret()
  58. {
  59. HideCaret();
  60. KillTimer(m_hParentWnd, m_hCaretTimer);
  61. m_hCaretTimer = NULL;
  62. return S_OK;
  63. }
  64. //+---------------------------------------------------------------------------
  65. //
  66. // CCaret::OnTimer
  67. //
  68. //+---------------------------------------------------------------------------
  69. HRESULT
  70. CCaret::OnTimer()
  71. {
  72. if (m_show.IsSetFlag())
  73. {
  74. m_toggle.Toggle();
  75. InvertCaret();
  76. }
  77. return S_OK;
  78. }
  79. //+---------------------------------------------------------------------------
  80. //
  81. // CCaret::InvertCaret
  82. //
  83. //+---------------------------------------------------------------------------
  84. HRESULT
  85. CCaret::InvertCaret()
  86. {
  87. HDC hDC = GetDC(m_hParentWnd);
  88. PatBlt(hDC, m_caret_pos.x, m_caret_pos.y, m_caret_size.cx, m_caret_size.cy, DSTINVERT);
  89. ReleaseDC(m_hParentWnd, hDC);
  90. return S_OK;
  91. }
  92. //+---------------------------------------------------------------------------
  93. //
  94. // CCaret::UpdateCaretPos
  95. //
  96. //+---------------------------------------------------------------------------
  97. HRESULT
  98. CCaret::UpdateCaretPos(
  99. POINT pos)
  100. {
  101. BOOL fInvert = FALSE;
  102. if (m_toggle.IsOn())
  103. {
  104. fInvert = TRUE;
  105. InvertCaret();
  106. }
  107. m_caret_pos = pos;
  108. if (fInvert)
  109. {
  110. InvertCaret();
  111. }
  112. return S_OK;
  113. }
  114. //+---------------------------------------------------------------------------
  115. //
  116. // CCaret::SetCaretPos
  117. //
  118. //+---------------------------------------------------------------------------
  119. HRESULT
  120. CCaret::SetCaretPos(
  121. POINT pos)
  122. {
  123. return UpdateCaretPos(pos);
  124. }
  125. //+---------------------------------------------------------------------------
  126. //
  127. // CCaret::HideCaret
  128. //
  129. //+---------------------------------------------------------------------------
  130. HRESULT
  131. CCaret::HideCaret()
  132. {
  133. if (m_toggle.IsOn())
  134. {
  135. m_toggle.Toggle();
  136. InvertCaret();
  137. }
  138. m_show.ResetFlag();
  139. return S_OK;
  140. }