2
0

BFWindow.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #include "BFWindow.h"
  2. #include "gfx/RenderDevice.h"
  3. USING_NS_BF;
  4. BFMenu::BFMenu()
  5. {
  6. mParent = NULL;
  7. mKeyCode = 0;
  8. mKeyCtrl = 0;
  9. mKeyAlt = 0;
  10. mKeyShift = 0;
  11. }
  12. struct BFNamedVirtKey
  13. {
  14. public:
  15. const char* mName;
  16. int mKeyCode;
  17. };
  18. #define VK_SPACE 0x20
  19. #define VK_PRIOR 0x21
  20. #define VK_NEXT 0x22
  21. #define VK_END 0x23
  22. #define VK_HOME 0x24
  23. #define VK_LEFT 0x25
  24. #define VK_UP 0x26
  25. #define VK_RIGHT 0x27
  26. #define VK_DOWN 0x28
  27. #define VK_SELECT 0x29
  28. #define VK_PRINT 0x2A
  29. #define VK_EXECUTE 0x2B
  30. #define VK_SNAPSHOT 0x2C
  31. #define VK_INSERT 0x2D
  32. #define VK_DELETE 0x2E
  33. #define VK_HELP 0x2F
  34. #define VK_F1 0x70
  35. #define VK_F2 0x71
  36. #define VK_F3 0x72
  37. #define VK_F4 0x73
  38. #define VK_F5 0x74
  39. #define VK_F6 0x75
  40. #define VK_F7 0x76
  41. #define VK_F8 0x77
  42. #define VK_F9 0x78
  43. #define VK_F10 0x79
  44. #define VK_F11 0x7A
  45. #define VK_F12 0x7B
  46. #define VK_SEMICOLON 0xBA
  47. #define VK_EQUALS 0xBB
  48. #define VK_COMMA 0xBC
  49. #define VK_MINUS 0xBD
  50. #define VK_PERIOD 0xBE
  51. #define VK_SLASH 0xBF
  52. #define VK_GRAVE 0xC0
  53. #define VK_LBRACKET 0xDB
  54. #define VK_BACKSLASH 0xDC
  55. #define VK_RBRACKET 0xDD
  56. #define VK_APOSTROPHE 0xDE
  57. #define VK_BACKTICK 0xDF
  58. #define VK_PAUSE 0x13
  59. #define VK_CANCEL 0x03
  60. static BFNamedVirtKey gNamedKeys[] =
  61. {{"F1", VK_F1}, {"F2", VK_F2}, {"F3", VK_F3}, {"F4", VK_F4}, {"F5", VK_F5}, {"F6", VK_F6},
  62. {"F7", VK_F7}, {"F8", VK_F8}, {"F9", VK_F9}, {"F10", VK_F10}, {"F11", VK_F11}, {"F12", VK_F12},
  63. {"INSERT", VK_INSERT}, {"INSERT", VK_INSERT}, {"DE", VK_DELETE}, {"DELETE", VK_DELETE},
  64. {"BREAK", VK_PAUSE},
  65. {"HOME", VK_HOME}, {"END", VK_END}, {"PGUP", VK_PRIOR}, {"PAGEUP", VK_PRIOR}, {"PGDN", VK_NEXT}, {"PAGEDN", VK_NEXT}, {"PAGEDOWN", VK_NEXT},
  66. {"UP", VK_UP}, {"LEFT", VK_LEFT}, {"RIGHT", VK_RIGHT}, {"DOWN", VK_DOWN}
  67. };
  68. bool BFMenu::ParseHotKey(const StringImpl& hotKey)
  69. {
  70. String aHotKey = ToUpper(hotKey);
  71. if (aHotKey.StartsWith("#"))
  72. return false;
  73. while (true)
  74. {
  75. int idx = (int)aHotKey.IndexOf('+');
  76. if (idx == -1)
  77. idx = (int)aHotKey.IndexOf('-');
  78. if (idx == -1)
  79. break;
  80. String aModifier = Trim(aHotKey.Substring(0, idx));
  81. aHotKey = Trim(aHotKey.Substring(idx + 1));
  82. if (aModifier == "SHIFT")
  83. mKeyShift = true;
  84. else if (aModifier == "CTRL")
  85. mKeyCtrl = true;
  86. else if (aModifier == "ALT")
  87. mKeyAlt = true;
  88. else
  89. {
  90. BF_FATAL("Unknown hotkey modifier");
  91. return false;
  92. }
  93. }
  94. if (aHotKey.length() == 1)
  95. {
  96. if (aHotKey == ",")
  97. mKeyCode = /*VK_COMMA*/0xBC;
  98. else
  99. mKeyCode = (int) aHotKey[0];
  100. return true;
  101. }
  102. int count = sizeof(gNamedKeys) / sizeof(BFNamedVirtKey);
  103. for (int i = 0; i < count; i++)
  104. {
  105. if (aHotKey == gNamedKeys[i].mName)
  106. {
  107. mKeyCode = gNamedKeys[i].mKeyCode;
  108. if ((mKeyCode == VK_PAUSE) && (mKeyCtrl))
  109. {
  110. // Ctrl-Pause is really "Cancel"
  111. mKeyCode = VK_CANCEL;
  112. }
  113. return true;
  114. }
  115. }
  116. BF_FATAL("Unknown hotkey key name");
  117. return false;
  118. }
  119. ///
  120. BFWindow::BFWindow()
  121. {
  122. mParent = NULL;
  123. mMenu = NULL;
  124. mRenderWindow = NULL;
  125. mNonExclusiveMouseCapture = false;
  126. mParent = NULL;
  127. mMovedFunc = NULL;
  128. mCloseQueryFunc = NULL;
  129. mClosedFunc = NULL;
  130. mGotFocusFunc = NULL;
  131. mLostFocusFunc = NULL;
  132. mKeyCharFunc = NULL;
  133. mKeyDownFunc = NULL;
  134. mKeyUpFunc = NULL;
  135. mMouseMoveFunc = NULL;
  136. mMouseProxyMoveFunc = NULL;
  137. mMouseDownFunc = NULL;
  138. mMouseUpFunc = NULL;
  139. mMouseWheelFunc = NULL;
  140. mMouseLeaveFunc = NULL;
  141. mMenuItemSelectedFunc = NULL;
  142. mDragDropFileFunc = NULL;
  143. mHitTestFunc = NULL;
  144. mFlags = 0;
  145. for (int i = 0; i < KEYCODE_MAX; i++)
  146. mIsKeyDown[i] = false;
  147. for (int i = 0; i < MOUSEBUTTON_MAX; i++)
  148. {
  149. mIsMouseDown[i] = false;
  150. mMouseClickCount[i] = 0;
  151. mMouseDownTicks[i] = 0;
  152. mMouseDownCoords[i] = { -1, -1 };
  153. }
  154. }
  155. BFWindow::~BFWindow()
  156. {
  157. delete mRenderWindow;
  158. delete mMenu;
  159. }