Counter Strike : Global Offensive Source Code
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.

126 lines
2.3 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxPopupMenu.cpp
  5. // implementation: Win32 API
  6. // last modified: Mar 18 1999, Mete Ciragan
  7. // copyright: The programs and associated files contained in this
  8. // distribution were developed by Mete Ciragan. The programs
  9. // are not in the public domain, but they are freely
  10. // distributable without licensing fees. These programs are
  11. // provided without guarantee or warrantee expressed or
  12. // implied.
  13. //
  14. #include "mxtk/mxPopupMenu.h"
  15. #include <windows.h>
  16. class mxPopupMenu_i
  17. {
  18. public:
  19. int dummy;
  20. };
  21. mxPopupMenu::mxPopupMenu ()
  22. : mxWidget (0, 0, 0, 0, 0)
  23. {
  24. void *handle = (void *) CreatePopupMenu ();
  25. setHandle (handle);
  26. setType (MX_POPUPMENU);
  27. }
  28. mxPopupMenu::~mxPopupMenu ()
  29. {
  30. }
  31. int
  32. mxPopupMenu::popup (mxWidget *widget, int x, int y)
  33. {
  34. POINT pt;
  35. pt.x = x;
  36. pt.y = y;
  37. ClientToScreen ((HWND) widget->getHandle (), &pt);
  38. return (int) TrackPopupMenu ((HMENU) getHandle (), /*TPM_NONOTIFY | TPM_RETURNCMD | */ TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y, 0, (HWND) widget->getHandle (), NULL);
  39. }
  40. void
  41. mxPopupMenu::add (const char *item, int id)
  42. {
  43. AppendMenu ((HMENU) getHandle (), MF_STRING, (UINT) id, item);
  44. }
  45. void
  46. mxPopupMenu::addMenu (const char *item, mxPopupMenu *menu)
  47. {
  48. AppendMenu ((HMENU) getHandle (), MF_POPUP, (UINT) menu->getHandle (), item);
  49. }
  50. void
  51. mxPopupMenu::addSeparator ()
  52. {
  53. AppendMenu ((HMENU) getHandle (), MF_SEPARATOR, 0, 0);
  54. }
  55. void
  56. mxPopupMenu::setEnabled (int id, bool b)
  57. {
  58. EnableMenuItem ((HMENU) getHandle (), (UINT) id, MF_BYCOMMAND | (b ? MF_ENABLED:MF_GRAYED));
  59. }
  60. void
  61. mxPopupMenu::setChecked (int id, bool b)
  62. {
  63. CheckMenuItem ((HMENU) getHandle (), (UINT) id, MF_BYCOMMAND | (b ? MF_CHECKED:MF_UNCHECKED));
  64. }
  65. bool
  66. mxPopupMenu::isEnabled (int id) const
  67. {
  68. MENUITEMINFO mii;
  69. memset (&mii, 0, sizeof (mii));
  70. mii.cbSize = sizeof (mii);
  71. mii.fMask = MIIM_STATE;
  72. GetMenuItemInfo ((HMENU) getHandle (), (UINT) id, false, &mii);
  73. if (mii.fState & MFS_GRAYED)
  74. return true;
  75. return false;
  76. }
  77. bool
  78. mxPopupMenu::isChecked (int id) const
  79. {
  80. MENUITEMINFO mii;
  81. memset (&mii, 0, sizeof (mii));
  82. mii.cbSize = sizeof (mii);
  83. mii.fMask = MIIM_STATE;
  84. GetMenuItemInfo ((HMENU) getHandle (), (UINT) id, false, &mii);
  85. if (mii.fState & MFS_CHECKED)
  86. return true;
  87. return false;
  88. }