Source code of Windows XP (NT5)
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.

178 lines
4.7 KiB

  1. #include "pch.hxx" // pch
  2. #pragma hdrstop
  3. #include "resource.h"
  4. #include "pgcaret.h"
  5. #include "w95trace.c"
  6. #define BLINK 1000
  7. #define BLINK_OFF -1
  8. #define CURSORMIN 200
  9. #define CURSORMAX 1300
  10. #define CURSORSUM (CURSORMIN + CURSORMAX)
  11. #define CURSORRANGE (CURSORMAX - CURSORMIN)
  12. CCaretPg::CCaretPg( LPPROPSHEETPAGE ppsp ) : WizardPage(ppsp, IDS_CARETTITLE, IDS_CARETSUBTITLE)
  13. {
  14. m_dwPageId = IDD_CARET;
  15. ppsp->pszTemplate = MAKEINTRESOURCE(m_dwPageId);
  16. hwndCursorScroll = NULL;
  17. uNewBlinkTime = uBlinkTime = 0;
  18. dwOriginalSize = dwNewSize = 0;
  19. fBlink = TRUE;
  20. }
  21. CCaretPg::~CCaretPg(void)
  22. {
  23. }
  24. LRESULT CCaretPg::OnInitDialog( HWND hwnd, WPARAM wParam,LPARAM lParam )
  25. {
  26. DBPRINTF(TEXT("OnInitDialog\r\n"));
  27. BOOL fRv = SystemParametersInfo(SPI_GETCARETWIDTH, 0, (PVOID)&dwOriginalSize, 0);
  28. dwNewSize = dwOriginalSize;
  29. uBlinkTime = RegQueryStrDW(
  30. DEFAULT_BLINK_RATE
  31. , HKEY_CURRENT_USER
  32. , CONTROL_PANEL_DESKTOP
  33. , CURSOR_BLINK_RATE);
  34. // Blink rate of -1 means it is off; a special case to CURSORMAX
  35. if (uBlinkTime == BLINK_OFF)
  36. uBlinkTime = CURSORMAX;
  37. uNewBlinkTime = uBlinkTime;
  38. // Update the Caret UI
  39. SendMessage(GetDlgItem(hwnd, KCURSOR_WIDTH), TBM_SETRANGE, 0, MAKELONG(1, 20));
  40. SendMessage(GetDlgItem(hwnd, KCURSOR_WIDTH), TBM_SETPOS, TRUE, (LONG)dwOriginalSize);
  41. SendMessage(GetDlgItem(hwnd, KCURSOR_RATE), TBM_SETRANGE, 0, MAKELONG(CURSORMIN / 100, CURSORMAX / 100));
  42. SendMessage(GetDlgItem(hwnd, KCURSOR_RATE), TBM_SETPOS, TRUE, (LONG)(CURSORSUM - uBlinkTime) / 100);
  43. // Update Blink and caret size
  44. hwndCaret = GetDlgItem(hwnd, KCURSOR_BLINK);
  45. GetWindowRect(hwndCaret, &rCursor);
  46. MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&rCursor, 2);
  47. rCursor.right = rCursor.left + dwOriginalSize;
  48. return 1;
  49. }
  50. void CCaretPg::UpdateControls()
  51. {
  52. // Nothing to do
  53. }
  54. void CCaretPg::DrawCaret(HWND hwnd, BOOL fClearFirst)
  55. {
  56. HDC hDC = GetDC(hwnd);
  57. if (hDC)
  58. {
  59. HBRUSH hBrush;
  60. if (fClearFirst)
  61. {
  62. hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  63. if (hBrush)
  64. {
  65. RECT rect;
  66. GetWindowRect(hwndCaret, &rect);
  67. MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&rect, 2);
  68. FillRect(hDC, &rect, hBrush);
  69. InvalidateRect(hwndCaret, &rect, TRUE);
  70. DeleteObject(hBrush);
  71. }
  72. }
  73. hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNTEXT));
  74. if (hBrush)
  75. {
  76. FillRect(hDC, &rCursor, hBrush);
  77. InvalidateRect(hwndCaret, &rCursor, TRUE);
  78. DeleteObject(hBrush);
  79. }
  80. ReleaseDC(hwnd,hDC);
  81. }
  82. }
  83. LRESULT CCaretPg::OnTimer( HWND hwnd, WPARAM wParam, LPARAM lParam )
  84. {
  85. if (wParam == BLINK)
  86. {
  87. BOOL fNoBlinkRate = (uNewBlinkTime == CURSORMAX)?TRUE:FALSE;
  88. if (fBlink || fNoBlinkRate)
  89. {
  90. DrawCaret(hwnd, fNoBlinkRate);
  91. }
  92. else
  93. {
  94. InvalidateRect(hwndCaret, NULL, TRUE);
  95. }
  96. if (fNoBlinkRate)
  97. KillTimer(hwnd, wParam);
  98. fBlink = !fBlink;
  99. }
  100. return 1;
  101. }
  102. LRESULT CCaretPg::OnHScroll( HWND hwnd, WPARAM wParam, LPARAM lParam )
  103. {
  104. if ((HWND)lParam == GetDlgItem(hwnd, KCURSOR_RATE))
  105. {
  106. // blink rate setting
  107. int nCurrent = (int)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0L );
  108. uNewBlinkTime = CURSORSUM - (nCurrent * 100);
  109. // reset the bink rate timer
  110. SetTimer(hwnd, BLINK, uNewBlinkTime, NULL);
  111. if (uNewBlinkTime == CURSORMAX) // draw the caret immediately; if we wait
  112. DrawCaret(hwnd, TRUE); // for the timer there is a visible delay
  113. }
  114. else
  115. {
  116. // cursor width setting
  117. dwNewSize = (int)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0L );
  118. rCursor.right = rCursor.left + dwNewSize;
  119. DrawCaret(hwnd, (uNewBlinkTime == CURSORMAX));
  120. }
  121. return 1;
  122. }
  123. LRESULT CCaretPg::OnPSN_SetActive(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  124. {
  125. DBPRINTF(TEXT("OnPSN_SetActive: uNewBlinkTime = %d\r\n"), uNewBlinkTime);
  126. if (uNewBlinkTime < CURSORMAX)
  127. {
  128. // start the blink rate timer to simulate cursor
  129. SetTimer(hwnd, BLINK, uBlinkTime, NULL);
  130. }
  131. else
  132. {
  133. // get the timer to draw the caret immediately
  134. SetTimer(hwnd, BLINK, 0, NULL);
  135. }
  136. return 1;
  137. }
  138. LRESULT CCaretPg::OnPSN_WizNext(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  139. {
  140. g_Options.m_schemePreview.m_uCursorBlinkTime = (uNewBlinkTime < CURSORMAX)?uNewBlinkTime:BLINK_OFF;
  141. g_Options.m_schemePreview.m_dwCaretWidth = dwNewSize;
  142. g_Options.ApplyPreview();
  143. return WizardPage::OnPSN_WizNext(hwnd, idCtl, pnmh);
  144. }