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.

154 lines
3.2 KiB

  1. #include "ulib.hxx"
  2. #include "vscroll.hxx"
  3. BOOLEAN
  4. VERTICAL_TEXT_SCROLL::Initialize(
  5. IN HWND WindowHandle,
  6. IN INT NumLines,
  7. IN INT ClientHeight,
  8. IN INT ClientWidth,
  9. IN INT CharHeight,
  10. IN INT CharWidth
  11. )
  12. {
  13. _client_height = ClientHeight;
  14. _client_width = ClientWidth;
  15. _char_height = CharHeight;
  16. _char_width = CharWidth;
  17. _scroll_position = 0;
  18. return TRUE;
  19. }
  20. VOID
  21. VERTICAL_TEXT_SCROLL::SetRange(
  22. IN HWND WindowHandle,
  23. IN INT NumLines
  24. )
  25. {
  26. _num_lines = NumLines - _client_height/_char_height;
  27. SetScrollRange(WindowHandle, SB_VERT, 0, _num_lines, FALSE);
  28. }
  29. VOID
  30. VERTICAL_TEXT_SCROLL::ClientSize(
  31. IN INT Height,
  32. IN INT Width
  33. )
  34. {
  35. _client_height = Height;
  36. _client_width = Width;
  37. }
  38. VOID
  39. VERTICAL_TEXT_SCROLL::ScrollUp(
  40. IN HWND WindowHandle
  41. )
  42. {
  43. _scroll_position--;
  44. UpdateScrollPosition(WindowHandle);
  45. }
  46. VOID
  47. VERTICAL_TEXT_SCROLL::ScrollDown(
  48. IN HWND WindowHandle
  49. )
  50. {
  51. _scroll_position++;
  52. UpdateScrollPosition(WindowHandle);
  53. }
  54. VOID
  55. VERTICAL_TEXT_SCROLL::PageUp(
  56. IN HWND WindowHandle
  57. )
  58. {
  59. _scroll_position -= _client_height/_char_height;
  60. UpdateScrollPosition(WindowHandle);
  61. }
  62. VOID
  63. VERTICAL_TEXT_SCROLL::PageDown(
  64. IN HWND WindowHandle
  65. )
  66. {
  67. _scroll_position += _client_height/_char_height;
  68. UpdateScrollPosition(WindowHandle);
  69. }
  70. VOID
  71. VERTICAL_TEXT_SCROLL::ThumbPosition(
  72. IN HWND WindowHandle,
  73. IN INT NewThumbPosition
  74. )
  75. {
  76. _scroll_position = NewThumbPosition;
  77. UpdateScrollPosition(WindowHandle);
  78. }
  79. VOID
  80. VERTICAL_TEXT_SCROLL::UpdateScrollPosition(
  81. IN HWND WindowHandle
  82. )
  83. {
  84. INT current_pos;
  85. current_pos = GetScrollPos(WindowHandle, SB_VERT);
  86. _scroll_position = max(0, min(_scroll_position, _num_lines));
  87. if (_scroll_position != current_pos) {
  88. SetScrollPos(WindowHandle, SB_VERT, _scroll_position, TRUE);
  89. ScrollWindow(WindowHandle, 0,
  90. QueryCharHeight()*(current_pos - _scroll_position),
  91. NULL, NULL);
  92. UpdateWindow(WindowHandle);
  93. }
  94. }
  95. STATIC TCHAR buf[1024];
  96. VOID
  97. VERTICAL_TEXT_SCROLL::WriteLine(
  98. IN HDC DeviceContext,
  99. IN INT LineNumber,
  100. IN PTCHAR String
  101. )
  102. {
  103. if( LineNumber >= QueryScrollPosition() &&
  104. LineNumber <= QueryScrollPosition() + QueryClientHeight()/QueryCharHeight() + 1) {
  105. CONST INT tabstop = 8;
  106. INT pos, bufpos;
  107. //
  108. // Copy string into buf, expanding tabs into spaces as we go. This
  109. // is because the window to which we are displaying does not do tabs.
  110. //
  111. for (pos = 0, bufpos = 0; String[pos] != '\0'; ++pos) {
  112. if ('\t' == String[pos]) {
  113. do {
  114. buf[bufpos++] = ' ';
  115. } while (0 != bufpos % tabstop);
  116. continue;
  117. }
  118. buf[bufpos++] = String[pos];
  119. }
  120. buf[bufpos++] = '\0';
  121. TextOut( DeviceContext,
  122. 0,
  123. (LineNumber - QueryScrollPosition())*QueryCharHeight(),
  124. buf,
  125. wcslen( buf ) );
  126. }
  127. }