1
0

fsmonitor.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include "precomp__gen_ff.h"
  2. #include "fsmonitor.h"
  3. #define tag L"wa5_fsmonitorclass"
  4. LRESULT CALLBACK fsMonitorWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  5. extern HINSTANCE hInstance;
  6. //------------------------------------------------------------------------
  7. FullScreenMonitor::FullScreenMonitor()
  8. {
  9. m_go_fs_timer_set = 0;
  10. m_cancel_fs_timer_set = 0;
  11. m_fs = 0;
  12. WNDCLASSW wc;
  13. if (!GetClassInfoW( hInstance, tag, &wc ))
  14. {
  15. MEMSET( &wc, 0, sizeof( wc ) );
  16. wc.lpfnWndProc = fsMonitorWndProc;
  17. wc.hInstance = hInstance; // hInstance of DLL
  18. wc.lpszClassName = tag; // our window class name
  19. wc.style = 0;
  20. int _r = RegisterClassW( &wc );
  21. ASSERTPR( _r, "cannot create fsmonitor wndclass" );
  22. }
  23. hWnd = CreateWindowExW( 0, tag, L"", 0, 0, 0, 1, 1, NULL, NULL, hInstance, NULL );
  24. ASSERT( hWnd );
  25. SetWindowLongPtrW( hWnd, GWLP_USERDATA, (LONG_PTR) this );
  26. APPBARDATA abd;
  27. abd.cbSize = sizeof( APPBARDATA );
  28. abd.hWnd = hWnd;
  29. abd.uCallbackMessage = APPBAR_CALLBACK;
  30. SHAppBarMessage( ABM_NEW, &abd );
  31. }
  32. //------------------------------------------------------------------------
  33. FullScreenMonitor::~FullScreenMonitor()
  34. {
  35. APPBARDATA abd;
  36. abd.cbSize = sizeof( APPBARDATA );
  37. abd.hWnd = hWnd;
  38. SHAppBarMessage( ABM_REMOVE, &abd );
  39. if (IsWindow( hWnd ))
  40. DestroyWindow( hWnd );
  41. }
  42. //------------------------------------------------------------------------
  43. void FullScreenMonitor::registerCallback( FSCallback *cb )
  44. {
  45. if (m_callbacks.haveItem( cb )) return;
  46. m_callbacks.addItem( cb );
  47. }
  48. //------------------------------------------------------------------------
  49. void FullScreenMonitor::unregisterCallback( FSCallback *cb )
  50. {
  51. m_callbacks.removeItem( cb );
  52. }
  53. //------------------------------------------------------------------------
  54. void FullScreenMonitor::onGoFullscreen()
  55. {
  56. if (m_cancel_fs_timer_set)
  57. {
  58. timerclient_killTimer( 2 );
  59. m_cancel_fs_timer_set = 0;
  60. }
  61. else
  62. {
  63. timerclient_setTimer( 1, 250 );
  64. m_go_fs_timer_set = 1;
  65. }
  66. }
  67. //------------------------------------------------------------------------
  68. void FullScreenMonitor::onCancelFullscreen()
  69. {
  70. if (m_go_fs_timer_set)
  71. {
  72. timerclient_killTimer( 1 );
  73. m_go_fs_timer_set = 0;
  74. }
  75. else
  76. {
  77. timerclient_setTimer( 2, 250 );
  78. m_cancel_fs_timer_set = 1;
  79. }
  80. }
  81. //------------------------------------------------------------------------
  82. void FullScreenMonitor::sendGoFSCallbacks()
  83. {
  84. foreach( m_callbacks );
  85. m_callbacks.getfor()->onGoFullscreen();
  86. endfor;
  87. }
  88. //------------------------------------------------------------------------
  89. void FullScreenMonitor::sendCancelFSCallbacks()
  90. {
  91. foreach( m_callbacks );
  92. m_callbacks.getfor()->onCancelFullscreen();
  93. endfor;
  94. }
  95. //------------------------------------------------------------------------
  96. void FullScreenMonitor::timerclient_timerCallback( int id )
  97. {
  98. if (id == 1)
  99. {
  100. timerclient_killTimer( 1 );
  101. m_go_fs_timer_set = 0;
  102. sendGoFSCallbacks();
  103. }
  104. else if (id == 2)
  105. {
  106. timerclient_killTimer( 2 );
  107. m_cancel_fs_timer_set = 0;
  108. sendCancelFSCallbacks();
  109. }
  110. }
  111. //------------------------------------------------------------------------
  112. int FullScreenMonitor::wndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  113. {
  114. switch (uMsg)
  115. {
  116. case APPBAR_CALLBACK:
  117. {
  118. switch (wParam)
  119. {
  120. case ABN_FULLSCREENAPP:
  121. //DebugString("ABN_FULLSCREENAPP\n");
  122. if (lParam && !m_fs)
  123. {
  124. m_fs = 1;
  125. onGoFullscreen();
  126. }
  127. else if (!lParam && m_fs)
  128. {
  129. m_fs = 0;
  130. onCancelFullscreen();
  131. }
  132. break;
  133. }
  134. }
  135. }
  136. return DefWindowProc( hwnd, uMsg, wParam, lParam );
  137. }
  138. //------------------------------------------------------------------------
  139. LRESULT CALLBACK fsMonitorWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  140. {
  141. #ifdef WIN32
  142. FullScreenMonitor *gThis = (FullScreenMonitor *) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
  143. if (!gThis)
  144. return DefWindowProc( hwnd, uMsg, wParam, lParam );
  145. else
  146. return gThis->wndProc( hwnd, uMsg, wParam, lParam );
  147. #else
  148. return 0;
  149. #endif
  150. }