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.

192 lines
5.1 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // listbox.c
  8. //
  9. // Description:
  10. // This file contains supplemental functions for list boxes throughout
  11. // the wizard.
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "pch.h"
  15. //----------------------------------------------------------------------------
  16. //
  17. // Function: OnUpButtonPressed
  18. //
  19. // Purpose: Generic procedure called whenever a user clicks the Up arrow
  20. // button on any of the property pages
  21. //
  22. // this function shifts the currently selected item up one entry in
  23. // the list box
  24. //
  25. // Arguments: IN HWND hwnd - handle to the dialog with the list box
  26. // IN WORD ListBoxControlID - control ID of the list box
  27. //
  28. // Returns: VOID
  29. //
  30. //----------------------------------------------------------------------------
  31. VOID
  32. OnUpButtonPressed( IN HWND hwnd, IN WORD ListBoxControlID )
  33. {
  34. INT_PTR iIndex;
  35. TCHAR szBuffer[MAX_INILINE_LEN];
  36. HWND hListBox = GetDlgItem( hwnd, ListBoxControlID );
  37. iIndex = SendMessage( hListBox, LB_GETCURSEL, 0, 0 );
  38. //
  39. // If there is no currently selected item, do nothing
  40. //
  41. if( iIndex == LB_ERR )
  42. {
  43. return;
  44. }
  45. SendMessage( hListBox, LB_GETTEXT, iIndex, (LPARAM) szBuffer );
  46. SendMessage( hListBox, LB_DELETESTRING, iIndex, 0 );
  47. //
  48. // -1 so it inserts it before the current item
  49. //
  50. SendMessage( hListBox, LB_INSERTSTRING, iIndex - 1, (LPARAM) szBuffer );
  51. SendMessage( hListBox, LB_SETCURSEL, iIndex - 1, 0 );
  52. }
  53. //----------------------------------------------------------------------------
  54. //
  55. // Function: OnDownButtonPressed
  56. //
  57. // Purpose: Generic procedure called whenever a user clicks the Down arrow
  58. // button on any of the property pages
  59. //
  60. // this function shifts the currently selected item down one entry
  61. // in the list box
  62. //
  63. // Arguments: IN HWND hwnd - handle to the dialog with the list box
  64. // IN WORD ListBoxControlID - control ID of the list box
  65. //
  66. // Returns: VOID
  67. //
  68. //----------------------------------------------------------------------------
  69. VOID
  70. OnDownButtonPressed( IN HWND hwnd, IN WORD ListBoxControlID )
  71. {
  72. INT_PTR iIndex;
  73. TCHAR szBuffer[MAX_INILINE_LEN];
  74. HWND hListBox = GetDlgItem( hwnd, ListBoxControlID );
  75. iIndex = SendMessage( hListBox, LB_GETCURSEL, 0, 0 );
  76. //
  77. // If there is no currently selected item, do nothing
  78. //
  79. if( iIndex == LB_ERR )
  80. {
  81. return;
  82. }
  83. SendMessage( hListBox, LB_GETTEXT, iIndex, (LPARAM) szBuffer );
  84. SendMessage( hListBox, LB_DELETESTRING, iIndex, 0 );
  85. //
  86. // +1 so it inserts it after the current item
  87. //
  88. SendMessage( hListBox, LB_INSERTSTRING, iIndex + 1, (LPARAM) szBuffer );
  89. SendMessage( hListBox, LB_SETCURSEL, iIndex + 1, 0 );
  90. }
  91. //----------------------------------------------------------------------------
  92. //
  93. // Function: SetArrows
  94. //
  95. // Purpose: this function examines the entries in the list box and enables
  96. // and disables the up and down arrows appropriately
  97. //
  98. // Arguments:
  99. // IN HWND hwnd - handle to the dialog
  100. // IN WORD ListBoxControlID - the list box to set the arrows for
  101. // IN WORD UpButtonControlID - the up button associated with the
  102. // list box
  103. // IN WORD DownButtonControlID - the down button associated with the
  104. // list box
  105. // Returns: VOID
  106. //
  107. //----------------------------------------------------------------------------
  108. VOID
  109. SetArrows( IN HWND hwnd,
  110. IN WORD ListBoxControlID,
  111. IN WORD UpButtonControlID,
  112. IN WORD DownButtonControlID )
  113. {
  114. INT_PTR iIndex;
  115. INT_PTR iCount;
  116. HWND hListBox = GetDlgItem( hwnd, ListBoxControlID );
  117. HWND hUpButton = GetDlgItem( hwnd, UpButtonControlID );
  118. HWND hDownButton = GetDlgItem( hwnd, DownButtonControlID );
  119. iCount = SendMessage( hListBox, LB_GETCOUNT, 0, 0 );
  120. if( iCount < 2 )
  121. {
  122. EnableWindow( hUpButton, FALSE );
  123. EnableWindow( hDownButton, FALSE );
  124. }
  125. else
  126. {
  127. iIndex = SendMessage( hListBox, LB_GETCURSEL, 0, 0 );
  128. // case when the first item is selected
  129. if( iIndex == 0 )
  130. {
  131. EnableWindow( hUpButton, FALSE );
  132. EnableWindow( hDownButton, TRUE );
  133. }
  134. // case when the last item is selected, -1 because iIndex is zero-based
  135. else if( iIndex == (iCount - 1) )
  136. {
  137. EnableWindow( hUpButton, TRUE );
  138. EnableWindow( hDownButton, FALSE );
  139. }
  140. // case when an item in the middle is selected
  141. else
  142. {
  143. EnableWindow( hUpButton, TRUE );
  144. EnableWindow( hDownButton, TRUE );
  145. }
  146. }
  147. }