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.

91 lines
2.6 KiB

  1. #ifndef INCLUDE_IPSUTIL_H
  2. #define INCLUDE_IPSUTIL_H
  3. // This file contains utility functions for wireless components
  4. // Function: SELECT_PREV_LISTITEM
  5. // Description:
  6. // Intended to be used after deleting a CListCtrl item to reset
  7. // the selected item.
  8. // Returns:
  9. // index - returns with the new index which is -1 if the list
  10. // is empty.
  11. template<class T>
  12. inline int SELECT_PREV_LISTITEM(T &list, int nIndex)
  13. {
  14. int nSelectIndex;
  15. if (0 == list.GetItemCount())
  16. return -1;
  17. else
  18. nSelectIndex = max( 0, nIndex - 1 );
  19. ASSERT( nSelectIndex < list.GetItemCount() );
  20. if (nSelectIndex >= 0)
  21. {
  22. VERIFY(list.SetItemState( nSelectIndex, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED ));
  23. }
  24. return nSelectIndex;
  25. }
  26. // Function: SELECT_NO_LISTITEM
  27. // Description:
  28. // This function is intended to used on a CListCtrl. It ensures
  29. // no list items are selected.
  30. template<class T>
  31. inline void SELECT_NO_LISTITEM(T &list)
  32. {
  33. if (0 == list.GetSelectedCount())
  34. return;
  35. int nIndex = -1;
  36. while (-1 != (nIndex = list.GetNextItem( nIndex, LVNI_SELECTED )))
  37. {
  38. VERIFY(list.SetItemState( nIndex, 0, LVIS_SELECTED | LVIS_FOCUSED ));
  39. }
  40. ASSERT( 0 == list.GetSelectedCount() );
  41. return;
  42. }
  43. // Function: SET_POST_REMOVE_FOCUS
  44. // Description:
  45. // This function is intended to be used on a dialogs. It sets the
  46. // focus to an appropriate control after a list item has been deleted.
  47. template<class T>
  48. inline void SET_POST_REMOVE_FOCUS( T *pDlg, int nListSel, UINT nAddId, UINT nRemoveId, CWnd *pWndPrevFocus )
  49. {
  50. ASSERT( 0 != nAddId );
  51. ASSERT( 0 != nRemoveId );
  52. // Fix up focus, if necessary
  53. if (::GetFocus() == NULL)
  54. {
  55. if (-1 == nListSel)
  56. {
  57. // Set focus to add button when theres is nothing in the list
  58. CWnd *pWndButton = pDlg->GetDlgItem( nAddId );
  59. ASSERT( NULL != pWndButton );
  60. pDlg->GotoDlgCtrl( pWndButton );
  61. }
  62. else
  63. {
  64. if (NULL != pWndPrevFocus)
  65. {
  66. // Restore lost focus
  67. pDlg->GotoDlgCtrl( pWndPrevFocus );
  68. }
  69. else
  70. {
  71. // Restore focus to remove button
  72. CWnd *pWndButton = pDlg->GetDlgItem( nRemoveId );
  73. ASSERT( NULL != pWndButton );
  74. pDlg->GotoDlgCtrl( pWndButton );
  75. }
  76. }
  77. }
  78. return;
  79. }
  80. #endif //#ifndef INCLUDE_IPSUTIL_H