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.

259 lines
8.6 KiB

  1. #include "pch.h"
  2. #include "resource.h"
  3. #include "main.h"
  4. INT_PTR CALLBACK SBPage_DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  5. UINT SBPage_GetScrollBarID();
  6. void SBPage_UpdateControls( HWND hwnd );
  7. void SBPage_UpdateStyle( HWND hwnd, DWORD dw, BOOL bRemove );
  8. BOOL SBPage_OnInitDlg( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  9. void SBPage_Scroll( HWND hwnd, WPARAM wParam );
  10. void SBPage_AddMessage( HWND hwnd, LPCTSTR pszMsg );
  11. void SBPage_AddScrollMessage( HWND hwnd, LPCTSTR pszMsg, WPARAM wParam, LPARAM lParam );
  12. void SBPage_UpdateStyle( HWND hwnd, DWORD dw, BOOL bRemove );
  13. //-------------------------------------------------------------------------//
  14. // 'ScrollBars' page impl
  15. //-------------------------------------------------------------------------//
  16. //-------------------------------------------------------------------------//
  17. HWND CALLBACK SBPage_CreateInstance( HWND hwndParent )
  18. {
  19. return CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_SCROLLBARS),
  20. hwndParent, SBPage_DlgProc );
  21. }
  22. //-------------------------------------------------------------------------//
  23. static BOOL s_fVert = TRUE;
  24. static BOOL s_fPort = TRUE;
  25. static SCROLLINFO s_siVert = {0};
  26. static SCROLLINFO s_siHorz = {0};
  27. static SCROLLINFO s_siVertP = {0};
  28. static SCROLLINFO s_siHorzP = {0};
  29. //-------------------------------------------------------------------------//
  30. INT_PTR CALLBACK SBPage_DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  31. {
  32. switch (uMsg)
  33. {
  34. case WM_CREATE:
  35. Log(LOG_TM, L"WM_CREATE\n");
  36. break;
  37. case WM_INITDIALOG:
  38. return SBPage_OnInitDlg( hwnd, uMsg, wParam, lParam );
  39. case WM_COMMAND:
  40. switch( LOWORD(wParam) )
  41. {
  42. case IDC_VERTICAL:
  43. s_fVert = TRUE;
  44. SBPage_UpdateControls( hwnd );
  45. break;
  46. case IDC_HORIZONTAL:
  47. s_fVert = FALSE;
  48. SBPage_UpdateControls( hwnd );
  49. break;
  50. case IDC_SBCTL_PORT:
  51. s_fPort = TRUE;
  52. SBPage_UpdateControls( hwnd );
  53. break;
  54. case IDC_SBCTL_STANDARD:
  55. s_fPort = FALSE;
  56. SBPage_UpdateControls( hwnd );
  57. break;
  58. default:
  59. break;
  60. }
  61. break;
  62. case WM_HSCROLL:
  63. s_fVert = FALSE;
  64. SBPage_Scroll( hwnd, wParam );
  65. SBPage_AddScrollMessage( hwnd, TEXT("WM_HSCROLL"), wParam, lParam );
  66. SBPage_UpdateControls( hwnd );
  67. break;
  68. case WM_VSCROLL:
  69. s_fVert = TRUE;
  70. SBPage_Scroll( hwnd, wParam );
  71. SBPage_AddScrollMessage( hwnd, TEXT("WM_VSCROLL"), wParam, lParam );
  72. SBPage_UpdateControls( hwnd );
  73. break;
  74. }
  75. return FALSE;
  76. }
  77. UINT SBPage_GetScrollBarID()
  78. {
  79. if( s_fPort )
  80. return s_fVert ? IDC_SBVERTP : IDC_SBHORZP;
  81. return s_fVert ? IDC_SBVERT : IDC_SBHORZ;
  82. }
  83. void SBPage_UpdateControls( HWND hwnd )
  84. {
  85. UINT nPortShow = s_fPort ? SW_SHOW : SW_HIDE;
  86. UINT nUserShow = s_fPort ? SW_HIDE : SW_SHOW;
  87. ShowWindow( GetDlgItem( hwnd, IDC_SBHORZ ), nUserShow );
  88. ShowWindow( GetDlgItem( hwnd, IDC_SBVERT ), nUserShow );
  89. ShowWindow( GetDlgItem( hwnd, IDC_SBHORZP ), nPortShow );
  90. ShowWindow( GetDlgItem( hwnd, IDC_SBVERTP ), nPortShow );
  91. HWND hwndSB = GetDlgItem( hwnd, SBPage_GetScrollBarID() );
  92. DWORD dwStyle = GetWindowLong( hwndSB, GWL_STYLE );
  93. DWORD dwExStyle = GetWindowLong( hwndSB, GWL_EXSTYLE );
  94. CheckDlgButton( hwnd, IDC_VERTICAL, s_fVert );
  95. CheckDlgButton( hwnd, IDC_HORIZONTAL, !s_fVert );
  96. CheckDlgButton( hwnd, IDC_SBCTL_PORT, s_fPort );
  97. CheckDlgButton( hwnd, IDC_SBCTL_STANDARD, !s_fPort );
  98. SCROLLINFO* psi = s_fPort ? (s_fVert ? &s_siVertP : &s_siHorzP) :
  99. (s_fVert ? &s_siVert : &s_siHorz);
  100. psi->fMask = -1;
  101. if( SendMessage( hwndSB, SBM_GETSCROLLINFO, 0, (LPARAM)psi ) )
  102. {
  103. SetDlgItemInt( hwnd, IDC_MIN, psi->nMin, TRUE );
  104. SetDlgItemInt( hwnd, IDC_MAX, psi->nMax, TRUE );
  105. SetDlgItemInt( hwnd, IDC_PAGE, psi->nPage, FALSE );
  106. SetDlgItemInt( hwnd, IDC_POS, psi->nPos, TRUE );
  107. SetDlgItemInt( hwnd, IDC_TRACKPOS, psi->nTrackPos, TRUE );
  108. }
  109. else
  110. {
  111. SetDlgItemText( hwnd, IDC_MIN, NULL );
  112. SetDlgItemText( hwnd, IDC_MAX, NULL );
  113. SetDlgItemText( hwnd, IDC_PAGE, NULL );
  114. SetDlgItemText( hwnd, IDC_POS, NULL );
  115. SetDlgItemText( hwnd, IDC_TRACKPOS, NULL );
  116. }
  117. }
  118. BOOL SBPage_OnInitDlg( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  119. {
  120. DWORD dwStyleV = GetWindowLong( GetDlgItem( hwnd, IDC_SBVERTP ), GWL_STYLE );
  121. DWORD dwExStyleV = GetWindowLong( GetDlgItem( hwnd, IDC_SBVERTP ), GWL_EXSTYLE );
  122. DWORD dwStyleH = GetWindowLong( GetDlgItem( hwnd, IDC_SBHORZP ), GWL_STYLE );
  123. DWORD dwExStyleH = GetWindowLong( GetDlgItem( hwnd, IDC_SBHORZP ), GWL_EXSTYLE );
  124. s_fVert = TRUE;
  125. s_siVert.cbSize = sizeof(s_siVert);
  126. s_siVert.fMask = -1;
  127. s_siVert.nMin = 0;
  128. s_siVert.nMax = 300;
  129. s_siVert.nPage = 60;
  130. s_siVert.nPos = 0;
  131. s_siVert.nTrackPos = 0;
  132. s_siVertP = s_siHorzP = s_siHorz = s_siVert;
  133. SetScrollInfo( GetDlgItem( hwnd, IDC_SBVERT ), SB_CTL, &s_siVert, FALSE );
  134. SetScrollInfo( GetDlgItem( hwnd, IDC_SBHORZ ), SB_CTL, &s_siHorz, FALSE );
  135. SetScrollInfo( GetDlgItem( hwnd, IDC_SBVERTP ), SB_CTL, &s_siVertP, FALSE );
  136. SetScrollInfo( GetDlgItem( hwnd, IDC_SBHORZP ), SB_CTL, &s_siHorzP, FALSE );
  137. SBPage_UpdateControls( hwnd );
  138. return TRUE;
  139. }
  140. void SBPage_Scroll( HWND hwnd, WPARAM wParam )
  141. {
  142. HWND hwndSB = GetDlgItem( hwnd, SBPage_GetScrollBarID() );
  143. SCROLLINFO* psi = s_fVert ? &s_siVert : &s_siHorz;
  144. const LONG nLine = 15;
  145. UINT uSBCode = LOWORD(wParam);
  146. int nNewPos = HIWORD(wParam);
  147. int nDeltaMax = (s_siVert.nMax - s_siVert.nPage) + 1;
  148. switch( uSBCode )
  149. {
  150. case SB_LEFT:
  151. psi->nPos--;
  152. break;
  153. case SB_RIGHT:
  154. psi->nPos++;
  155. break;
  156. case SB_LINELEFT:
  157. psi->nPos = max( psi->nPos - nLine, 0 );
  158. break;
  159. case SB_LINERIGHT:
  160. psi->nPos = min( psi->nPos + nLine, nDeltaMax );
  161. break;
  162. case SB_PAGELEFT:
  163. psi->nPos = max( psi->nPos - (int)psi->nPage, 0 );
  164. break;
  165. case SB_PAGERIGHT:
  166. psi->nPos = min( psi->nPos + (int)psi->nPage, nDeltaMax );
  167. break;
  168. case SB_THUMBTRACK:
  169. psi->nPos = nNewPos;
  170. break;
  171. case SB_THUMBPOSITION:
  172. psi->nPos = nNewPos;
  173. break;
  174. case SB_ENDSCROLL:
  175. return;
  176. }
  177. psi->fMask = SIF_POS;
  178. SetScrollInfo( hwndSB, SB_CTL, psi, TRUE );
  179. }
  180. void SBPage_AddMessage( HWND hwnd, LPCTSTR pszMsg )
  181. {
  182. INT_PTR i = SendDlgItemMessage( hwnd, IDC_MSGLIST, LB_ADDSTRING, 0, (LPARAM)pszMsg );
  183. SendDlgItemMessage( hwnd, IDC_MSGLIST, LB_SETCURSEL, i, 0 );
  184. }
  185. void SBPage_AddScrollMessage( HWND hwnd, LPCTSTR pszMsg, WPARAM wParam, LPARAM lParam )
  186. {
  187. TCHAR szMsg[MAX_PATH];
  188. LPCTSTR pszWparam = NULL;
  189. LPCTSTR pszLparam = NULL;
  190. switch( LOWORD(wParam) )
  191. {
  192. #define ASL_ASSIGN_WPARAM(m) case m: pszWparam = TEXT(#m); break
  193. ASL_ASSIGN_WPARAM(SB_ENDSCROLL);
  194. ASL_ASSIGN_WPARAM(SB_LEFT);
  195. ASL_ASSIGN_WPARAM(SB_RIGHT);
  196. ASL_ASSIGN_WPARAM(SB_LINELEFT);
  197. ASL_ASSIGN_WPARAM(SB_LINERIGHT);
  198. ASL_ASSIGN_WPARAM(SB_PAGELEFT);
  199. ASL_ASSIGN_WPARAM(SB_PAGERIGHT);
  200. ASL_ASSIGN_WPARAM(SB_THUMBPOSITION);
  201. ASL_ASSIGN_WPARAM(SB_THUMBTRACK);
  202. default:
  203. pszWparam = TEXT("");
  204. break;
  205. }
  206. StringCchPrintf( szMsg, ARRAYSIZE(szMsg), TEXT("%s [%s]"), pszMsg, pszWparam );
  207. SBPage_AddMessage( hwnd, szMsg );
  208. }
  209. void SBPage_UpdateStyle( HWND hwnd, DWORD dw, BOOL bRemove )
  210. {
  211. HWND hwndSB = GetDlgItem( hwnd, SBPage_GetScrollBarID() );
  212. DWORD dwStyle, dwStyleOld;
  213. dwStyle = dwStyleOld = GetWindowLong( hwndSB, GWL_STYLE );
  214. if( bRemove )
  215. dwStyle &= ~dw;
  216. else
  217. dwStyle |= dw;
  218. if( dwStyle != dwStyleOld )
  219. {
  220. SetWindowLong( hwndSB, GWL_STYLE, dwStyle );
  221. InvalidateRect( hwndSB, NULL, TRUE );
  222. }
  223. }