/platform/win/scaffold/menu.d

http://github.com/wilkie/djehuty · D · 95 lines · 70 code · 15 blank · 10 comment · 14 complexity · 3771d73b8d10ab9a389e22db8f85b3d9 MD5 · raw file

  1. /*
  2. * menu.d
  3. *
  4. * This file implements the Scaffold for platform specific Menu
  5. * operations in Windows.
  6. *
  7. * Author: Dave Wilkinson
  8. *
  9. */
  10. module scaffold.menu;
  11. import scaffold.window;
  12. import binding.win32.windef;
  13. import binding.win32.winnt;
  14. import binding.win32.winbase;
  15. import binding.win32.wingdi;
  16. import binding.win32.winuser;
  17. import platform.win.main;
  18. import platform.vars.menu;
  19. import platform.vars.window;
  20. import core.string;
  21. import core.main;
  22. import core.definitions;
  23. import core.unicode;
  24. import io.console;
  25. import gui.window;
  26. import resource.menu;
  27. void MenuCreate(MenuPlatformVars* menuVars) {
  28. menuVars.hMenu = CreateMenu();
  29. }
  30. void MenuDestroy(MenuPlatformVars* menuVars) {
  31. DestroyMenu(menuVars.hMenu);
  32. menuVars.hMenu = null;
  33. }
  34. void MenuAppend(void* identifier, MenuPlatformVars* mnuVars, MenuPlatformVars* toAppendVars, string text, bool hasSubitems) {
  35. wstring s;
  36. if (text == "") {
  37. if (hasSubitems) {
  38. AppendMenuW(mnuVars.hMenu,MF_SEPARATOR,cast(UINT_PTR)toAppendVars.hMenu,"\0"w.ptr);
  39. }
  40. else {
  41. AppendMenuW(mnuVars.hMenu,MF_SEPARATOR,cast(UINT_PTR)identifier,"\0"w.ptr);
  42. }
  43. }
  44. else {
  45. s = Unicode.toUtf16(text);
  46. s ~= '\0';
  47. if (hasSubitems) {
  48. AppendMenuW(mnuVars.hMenu,MF_POPUP,cast(UINT_PTR)toAppendVars.hMenu,s.ptr);
  49. }
  50. else {
  51. AppendMenuW(mnuVars.hMenu,MF_STRING,cast(UINT_PTR)identifier,s.ptr);
  52. }
  53. }
  54. }
  55. void MenuUpdate(void* identifier, MenuPlatformVars* mnuVars, MenuPlatformVars* toUpdateVars, string text, uint position, bool hasSubitems) {
  56. wstring s;
  57. if (text.trim() == "") {
  58. if (hasSubitems) {
  59. ModifyMenuW(mnuVars.hMenu,position,MF_BYPOSITION | MF_SEPARATOR,cast(UINT_PTR)toUpdateVars.hMenu,"\0"w.ptr);
  60. }
  61. else {
  62. ModifyMenuW(mnuVars.hMenu,position,MF_BYPOSITION | MF_SEPARATOR,cast(UINT_PTR)identifier,"\0"w.ptr);
  63. }
  64. }
  65. else {
  66. s = Unicode.toUtf16(text);
  67. s ~= '\0';
  68. if (hasSubitems) {
  69. ModifyMenuW(mnuVars.hMenu,position,MF_BYPOSITION | MF_POPUP,cast(UINT_PTR)toUpdateVars.hMenu,s.ptr);
  70. }
  71. else {
  72. ModifyMenuW(mnuVars.hMenu,position,MF_BYPOSITION | MF_STRING,cast(UINT_PTR)identifier,s.ptr);
  73. }
  74. }
  75. }
  76. void WindowSetMenu(MenuPlatformVars* mnuVars, ref Window wnd, WindowPlatformVars* windowVars) {
  77. SetMenu(windowVars.hWnd, mnuVars.hMenu);
  78. // resize to adapt client area
  79. WindowRebound(wnd,windowVars);
  80. }