2
0

PolycodeView.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include "PolycodeView.h"
  2. #include "PolyWinCore.h"
  3. #include "PolyCoreServices.h"
  4. #include "PolyCoreInput.h"
  5. #include "PolyRenderer.h"
  6. #include <io.h>
  7. #include <fcntl.h>
  8. #include <ios>
  9. using namespace Polycode;
  10. Win32Core *core = NULL;
  11. static void OpenConsole()
  12. {
  13. int outHandle, errHandle, inHandle;
  14. FILE *outFile, *errFile, *inFile;
  15. AllocConsole();
  16. CONSOLE_SCREEN_BUFFER_INFO coninfo;
  17. GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
  18. coninfo.dwSize.Y = 9999;
  19. SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
  20. outHandle = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
  21. errHandle = _open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE),_O_TEXT);
  22. inHandle = _open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE),_O_TEXT );
  23. outFile = _fdopen(outHandle, "w" );
  24. errFile = _fdopen(errHandle, "w");
  25. inFile = _fdopen(inHandle, "r");
  26. *stdout = *outFile;
  27. *stderr = *errFile;
  28. *stdin = *inFile;
  29. setvbuf( stdout, NULL, _IONBF, 0 );
  30. setvbuf( stderr, NULL, _IONBF, 0 );
  31. setvbuf( stdin, NULL, _IONBF, 0 );
  32. std::ios::sync_with_stdio();
  33. }
  34. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  35. {
  36. int nWidth, nHeight;
  37. bool useDefault = false;
  38. if(!core)
  39. return DefWindowProc(hWnd, message, wParam, lParam);
  40. switch (message)
  41. {
  42. case WM_COPYDATA:
  43. {
  44. COPYDATASTRUCT *cp = (COPYDATASTRUCT*)lParam;
  45. wchar_t *stringData = (wchar_t*)cp->lpData;
  46. core->copyDataString = String(stringData);
  47. core->hasCopyDataString = true;
  48. }
  49. break;
  50. case WM_SIZE:
  51. nWidth = LOWORD(lParam);
  52. nHeight = HIWORD(lParam);
  53. if(core) {
  54. core->handleViewResize(nWidth, nHeight);
  55. }
  56. break;
  57. case WM_MOUSEMOVE:
  58. if(core)
  59. core->handleMouseMove(lParam,wParam);
  60. break;
  61. case WM_MOUSEWHEEL:
  62. if(core)
  63. core->handleMouseWheel(lParam,wParam);
  64. break;
  65. case WM_LBUTTONDOWN:
  66. if(core)
  67. core->handleMouseDown(CoreInput::MOUSE_BUTTON1, lParam,wParam);
  68. break;
  69. case WM_LBUTTONUP:
  70. if(core)
  71. core->handleMouseUp(CoreInput::MOUSE_BUTTON1, lParam,wParam);
  72. break;
  73. case WM_RBUTTONDOWN:
  74. if(core)
  75. core->handleMouseDown(CoreInput::MOUSE_BUTTON2, lParam,wParam);
  76. break;
  77. case WM_RBUTTONUP:
  78. if(core)
  79. core->handleMouseUp(CoreInput::MOUSE_BUTTON2, lParam,wParam);
  80. break;
  81. #ifndef NO_TOUCH_API
  82. case WM_TOUCH:
  83. if(core) {
  84. if(core->isMultiTouchEnabled()) {
  85. core->handleTouchEvent(lParam, wParam);
  86. }
  87. }
  88. break;
  89. #endif
  90. case WM_MBUTTONDOWN:
  91. if(core)
  92. core->handleMouseDown(CoreInput::MOUSE_BUTTON3, lParam,wParam);
  93. break;
  94. case WM_MBUTTONUP:
  95. if(core)
  96. core->handleMouseUp(CoreInput::MOUSE_BUTTON3, lParam,wParam);
  97. break;
  98. case WM_KEYDOWN:
  99. if(core) {
  100. wchar_t unicodeChar = 0;
  101. MSG m;
  102. m.hwnd = hWnd;
  103. m.message = message;
  104. m.wParam = wParam;
  105. m.lParam = lParam;
  106. m.time = 0;
  107. if ( PeekMessage(&m, hWnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) {
  108. GetMessage(&m, hWnd, 0, WM_USER);
  109. unicodeChar = (wchar_t)m.wParam;
  110. }
  111. core->handleKeyDown(lParam,wParam, unicodeChar);
  112. }
  113. break;
  114. case WM_KEYUP:
  115. if(core)
  116. core->handleKeyUp(lParam,wParam);
  117. break;
  118. case WM_CLOSE:
  119. if(core)
  120. core->Shutdown();
  121. useDefault = true;
  122. break;
  123. case WM_DESTROY:
  124. PostQuitMessage(0);
  125. break;
  126. default:
  127. useDefault = true;
  128. break;
  129. }
  130. if (useDefault)
  131. return DefWindowProc(hWnd, message, wParam, lParam);
  132. else
  133. return 0;
  134. }
  135. PolycodeView::PolycodeView(HINSTANCE hInstance, int nCmdShow, LPCTSTR windowTitle, bool resizable, bool showDebugConsole) : PolycodeViewBase() {
  136. WNDCLASSEX wcex;
  137. wcex.cbSize = sizeof(WNDCLASSEX);
  138. wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  139. wcex.lpfnWndProc = WndProc;
  140. wcex.cbClsExtra = 0;
  141. wcex.cbWndExtra = 0;
  142. wcex.hInstance = hInstance;
  143. wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
  144. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  145. wcex.hbrBackground = NULL;
  146. wcex.lpszMenuName = NULL;
  147. wcex.lpszClassName = L"POLYCODEAPPLICATION";
  148. wcex.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
  149. RegisterClassEx(&wcex);
  150. if(resizable) {
  151. hwnd = CreateWindowEx(WS_EX_APPWINDOW, L"POLYCODEAPPLICATION", windowTitle, WS_OVERLAPPEDWINDOW|WS_SYSMENU, 0, 0, 640, 480, NULL, NULL, hInstance, NULL);
  152. } else {
  153. hwnd = CreateWindowEx(WS_EX_APPWINDOW, L"POLYCODEAPPLICATION", windowTitle, WS_OVERLAPPED|WS_SYSMENU, 0, 0, 640, 480, NULL, NULL, hInstance, NULL);
  154. }
  155. windowData = (void*)&hwnd;
  156. ShowWindow(hwnd, nCmdShow);
  157. UpdateWindow(hwnd);
  158. if(showDebugConsole) {
  159. OpenConsole();
  160. }
  161. }
  162. PolycodeView::~PolycodeView() {
  163. }