Team Fortress 2 Source Code as on 22/4/2020
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.

116 lines
2.0 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxMenu.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/mxMenu.h"
  15. #include <windows.h>
  16. #include <string.h>
  17. //#include <ostream.h"
  18. class mxMenu_i
  19. {
  20. public:
  21. int dummy;
  22. };
  23. mxMenu::mxMenu ()
  24. : mxWidget (0, 0, 0, 0, 0)
  25. {
  26. void *handle = (void *) CreateMenu ();
  27. setHandle (handle);
  28. setType (MX_MENU);
  29. }
  30. mxMenu::~mxMenu ()
  31. {
  32. }
  33. void
  34. mxMenu::add (const char *item, int id)
  35. {
  36. AppendMenu ((HMENU) getHandle (), MF_STRING, (UINT) id, item);
  37. }
  38. void
  39. mxMenu::addMenu (const char *item, mxMenu *menu)
  40. {
  41. AppendMenu ((HMENU) getHandle (), MF_POPUP, (UINT) menu->getHandle (), item);
  42. }
  43. void
  44. mxMenu::addSeparator ()
  45. {
  46. AppendMenu ((HMENU) getHandle (), MF_SEPARATOR, 0, 0);
  47. }
  48. void
  49. mxMenu::setEnabled (int id, bool b)
  50. {
  51. EnableMenuItem ((HMENU) getHandle (), (UINT) id, MF_BYCOMMAND | (b ? MF_ENABLED:MF_GRAYED));
  52. }
  53. void
  54. mxMenu::setChecked (int id, bool b)
  55. {
  56. CheckMenuItem ((HMENU) getHandle (), (UINT) id, MF_BYCOMMAND | (b ? MF_CHECKED:MF_UNCHECKED));
  57. }
  58. bool
  59. mxMenu::isEnabled (int id) const
  60. {
  61. MENUITEMINFO mii;
  62. memset (&mii, 0, sizeof (mii));
  63. mii.cbSize = sizeof (mii);
  64. mii.fMask = MIIM_STATE;
  65. GetMenuItemInfo ((HMENU) getHandle (), (UINT) id, false, &mii);
  66. if (mii.fState & MFS_GRAYED)
  67. return true;
  68. return false;
  69. }
  70. bool
  71. mxMenu::isChecked (int id) const
  72. {
  73. MENUITEMINFO mii;
  74. memset (&mii, 0, sizeof (mii));
  75. mii.cbSize = sizeof (mii);
  76. mii.fMask = MIIM_STATE;
  77. GetMenuItemInfo ((HMENU) getHandle (), (UINT) id, false, &mii);
  78. if (mii.fState & MFS_CHECKED)
  79. return true;
  80. return false;
  81. }