BackendWindow.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // zlib open source license
  2. //
  3. // Copyright (c) 2017 to 2019 David Forsgren Piuva
  4. //
  5. // This software is provided 'as-is', without any express or implied
  6. // warranty. In no event will the authors be held liable for any damages
  7. // arising from the use of this software.
  8. //
  9. // Permission is granted to anyone to use this software for any purpose,
  10. // including commercial applications, and to alter it and redistribute it
  11. // freely, subject to the following restrictions:
  12. //
  13. // 1. The origin of this software must not be misrepresented; you must not
  14. // claim that you wrote the original software. If you use this software
  15. // in a product, an acknowledgment in the product documentation would be
  16. // appreciated but is not required.
  17. //
  18. // 2. Altered source versions must be plainly marked as such, and must not be
  19. // misrepresented as being the original software.
  20. //
  21. // 3. This notice may not be removed or altered from any source
  22. // distribution.
  23. #include "BackendWindow.h"
  24. using namespace dsr;
  25. // Used when access to the external clipboard is not implemented.
  26. static String backupClipboard;
  27. ReadableString BackendWindow::loadFromClipboard(double timeoutInSeconds) {
  28. sendWarning(U"loadFromClipboard is not implemented! Simulating clipboard using a variable within the same application.");
  29. return backupClipboard;
  30. }
  31. void BackendWindow::saveToClipboard(const ReadableString &text, double timeoutInSeconds) {
  32. sendWarning(U"saveToClipboard is not implemented! Simulating clipboard using a variable within the same application.");
  33. backupClipboard = text;
  34. }
  35. bool BackendWindow::executeEvents() {
  36. bool executedEvent = false;
  37. this->prefetchEvents();
  38. // Execute any resize first
  39. // This makes sure that following events gets a canvas size synchronized with the window size
  40. if (this->requestingResize) {
  41. executedEvent = true;
  42. this->callback_resizeEvent(this->requestedWidth, this->requestedHeight);
  43. this->requestingResize = false;
  44. }
  45. // Look for events
  46. for (int e = 0; e < this->eventQueue.length(); e++) {
  47. InputEvent* event = this->eventQueue[e];
  48. if (event) {
  49. executedEvent = true;
  50. KeyboardEvent* kEvent = dynamic_cast<KeyboardEvent*>(event);
  51. MouseEvent* mEvent = dynamic_cast<MouseEvent*>(event);
  52. WindowEvent* wEvent = dynamic_cast<WindowEvent*>(event);
  53. if (kEvent) {
  54. this->callback_keyboardEvent(*kEvent);
  55. } else if (mEvent) {
  56. this->callback_mouseEvent(*mEvent);
  57. } else if (wEvent) {
  58. if (wEvent->windowEventType == WindowEventType::Close) {
  59. this->callback_closeEvent();
  60. } else if (wEvent->windowEventType == WindowEventType::Redraw) {
  61. //this->showCanvas();
  62. }
  63. }
  64. }
  65. delete event;
  66. }
  67. // Check for resize again in case that one was triggered by a callback
  68. if (this->requestingResize) {
  69. this->callback_resizeEvent(this->requestedWidth, this->requestedHeight);
  70. this->requestingResize = false;
  71. }
  72. // Clear the event queue to avoid repeating events
  73. this->eventQueue.clear();
  74. // Tell the caller if we did something
  75. return executedEvent;
  76. }