PolycodeView.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. #ifdef NO_PEN_API
  83. case WM_TOUCH:
  84. if(core) {
  85. if(core->isMultiTouchEnabled()) {
  86. core->handleTouchEvent(lParam, wParam);
  87. }
  88. }
  89. break;
  90. #else
  91. case WM_POINTERUPDATE:
  92. case WM_POINTERUP:
  93. case WM_POINTERDOWN:
  94. if (core)
  95. core->handlePointerUpdate(lParam, wParam);
  96. break;
  97. #endif
  98. #endif
  99. case WM_MBUTTONDOWN:
  100. if(core)
  101. core->handleMouseDown(CoreInput::MOUSE_BUTTON3, lParam,wParam);
  102. break;
  103. case WM_MBUTTONUP:
  104. if(core)
  105. core->handleMouseUp(CoreInput::MOUSE_BUTTON3, lParam,wParam);
  106. break;
  107. case WM_KEYDOWN:
  108. case WM_SYSKEYDOWN:
  109. if(core) {
  110. wchar_t unicodeChar = 0;
  111. MSG m;
  112. m.hwnd = hWnd;
  113. m.message = message;
  114. m.wParam = wParam;
  115. m.lParam = lParam;
  116. m.time = 0;
  117. if ( PeekMessage(&m, hWnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) {
  118. GetMessage(&m, hWnd, 0, WM_USER);
  119. unicodeChar = (wchar_t)m.wParam;
  120. }
  121. core->handleKeyDown(lParam,wParam, unicodeChar);
  122. }
  123. break;
  124. case WM_KEYUP:
  125. case WM_SYSKEYUP:
  126. if(core)
  127. core->handleKeyUp(lParam,wParam);
  128. break;
  129. case WM_CLOSE:
  130. if(core)
  131. core->Shutdown();
  132. useDefault = true;
  133. break;
  134. case WM_DESTROY:
  135. PostQuitMessage(0);
  136. break;
  137. default:
  138. useDefault = true;
  139. break;
  140. }
  141. if (useDefault)
  142. return DefWindowProc(hWnd, message, wParam, lParam);
  143. else
  144. return 0;
  145. }
  146. PolycodeView::PolycodeView(HINSTANCE hInstance, int nCmdShow, LPCTSTR windowTitle, bool resizable, bool showDebugConsole) : PolycodeViewBase() {
  147. /*
  148. typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID);
  149. SetProcessDPIAwarePtr set_process_dpi_aware_func = GetProcAddress(GetModuleHandleA("user32.dll"), "SetProcessDPIAware");
  150. if (set_process_dpi_aware_func) {
  151. set_process_dpi_aware_func();
  152. }
  153. */
  154. WNDCLASSEX wcex;
  155. wcex.cbSize = sizeof(WNDCLASSEX);
  156. wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  157. wcex.lpfnWndProc = WndProc;
  158. wcex.cbClsExtra = 0;
  159. wcex.cbWndExtra = 0;
  160. wcex.hInstance = hInstance;
  161. wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
  162. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  163. wcex.hbrBackground = NULL;
  164. wcex.lpszMenuName = NULL;
  165. wcex.lpszClassName = L"POLYCODEAPPLICATION";
  166. wcex.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
  167. RegisterClassEx(&wcex);
  168. this->resizable = resizable;
  169. if(resizable) {
  170. hwnd = CreateWindowEx(WS_EX_APPWINDOW, L"POLYCODEAPPLICATION", windowTitle, WS_OVERLAPPEDWINDOW | WS_SYSMENU, 0, 0, 640, 480, NULL, NULL, hInstance, NULL);
  171. } else {
  172. hwnd = CreateWindowEx(WS_EX_APPWINDOW, L"POLYCODEAPPLICATION", windowTitle, WS_CAPTION | WS_POPUP | WS_SYSMENU, 0, 0, 640, 480, NULL, NULL, hInstance, NULL);
  173. }
  174. windowData = (void*)&hwnd;
  175. ShowWindow(hwnd, nCmdShow);
  176. UpdateWindow(hwnd);
  177. if(showDebugConsole) {
  178. OpenConsole();
  179. }
  180. }
  181. PolycodeView::~PolycodeView() {
  182. }