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.

106 lines
2.6 KiB

  1. #include "header.h"
  2. #include "navpane.h"
  3. #include "navui.h"
  4. // Common Control Macros
  5. #include <windowsx.h>
  6. ///////////////////////////////////////////////////////////
  7. //
  8. // Non-Member helper functions.
  9. //
  10. ///////////////////////////////////////////////////////////
  11. //
  12. // Convert a rect from screen to client.
  13. //
  14. void ScreenRectToClientRect(HWND hWnd, RECT* prect)
  15. {
  16. // Save the size.
  17. SIZE size ;
  18. size.cx = prect->right - prect->left ;
  19. size.cy = prect->bottom - prect->top ;
  20. // Convert the origin.
  21. ::ScreenToClient(hWnd, reinterpret_cast<POINT*>(prect)) ;
  22. // Add the size back.
  23. prect->right = prect->left + size.cx ;
  24. prect->bottom = prect->top + size.cy;
  25. }
  26. ///////////////////////////////////////////////////////////
  27. //
  28. // GetAcceleratorKey - Find the accelerator key from the ctrl.
  29. //
  30. int
  31. GetAcceleratorKey(HWND hwndctrl)
  32. {
  33. int iReturn = 0 ;
  34. char text[256] ;
  35. ::GetWindowText(hwndctrl, text, 256) ;
  36. int len = (int)strlen(text) ;
  37. if (len != 0)
  38. {
  39. // Find the '&' key.
  40. char* p = strchr(text, '&') ;
  41. if (p != NULL)
  42. {
  43. iReturn = tolower(*(p+1)) ;
  44. }
  45. }
  46. return iReturn ;
  47. }
  48. ///////////////////////////////////////////////////////////
  49. //
  50. // ProcessMenuChar --- Process accelerator keys.
  51. //
  52. // REVIEW: NavPanes need base class.
  53. //
  54. //
  55. bool
  56. ProcessMenuChar(INavUI* pNavUI,
  57. HWND hwndParent,
  58. CDlgItemInfo* DlgItems, // Array of dialog items
  59. int NumDlgItems, // Number of items in the array
  60. int ch // accelerator to act on.
  61. )
  62. {
  63. bool iReturn = false ;
  64. for (int i = 0 ; i < NumDlgItems ; i++)
  65. {
  66. if (DlgItems[i].m_accelkey == ch)
  67. {
  68. if (DlgItems[i].m_Type == ItemInfo::Button)
  69. {
  70. // Its a button so do the command.
  71. ASSERT(pNavUI != NULL) ;
  72. pNavUI->OnCommand(hwndParent, DlgItems[i].m_id, BN_CLICKED, 0) ;
  73. }
  74. else if (DlgItems[i].m_Type == ItemInfo::CheckBox)
  75. {
  76. // Its a checkbox, so select/unselect it.
  77. int state = Button_GetCheck(DlgItems[i].m_hWnd) ;
  78. Button_SetCheck(DlgItems[i].m_hWnd, (state == BST_CHECKED) ? BST_UNCHECKED : BST_CHECKED) ;
  79. // Set focus.
  80. ::SetFocus(DlgItems[i].m_hWnd) ;
  81. }
  82. else
  83. {
  84. // Set focus.
  85. ::SetFocus(DlgItems[i].m_hWnd) ;
  86. }
  87. // Found it!
  88. iReturn = true ;
  89. // Finished
  90. break ;
  91. }
  92. }
  93. return iReturn ;
  94. }