win32_loop.cpp
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:11k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * win32_loop.cpp
  3.  *****************************************************************************
  4.  * Copyright (C) 2003 the VideoLAN team
  5.  * $Id: 1ddc580b362cefec91f0c5d534cff0f7a74b3c7e $
  6.  *
  7.  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  8.  *          Olivier Teulière <ipkiss@via.ecp.fr>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23.  *****************************************************************************/
  24. #ifdef WIN32_SKINS
  25. #include "win32_factory.hpp"
  26. #include "win32_loop.hpp"
  27. #include "../src/generic_window.hpp"
  28. #include "../events/evt_key.hpp"
  29. #include "../events/evt_leave.hpp"
  30. #include "../events/evt_menu.hpp"
  31. #include "../events/evt_motion.hpp"
  32. #include "../events/evt_mouse.hpp"
  33. #include "../events/evt_refresh.hpp"
  34. #include "../events/evt_scroll.hpp"
  35. #include "vlc_keys.h"
  36. // XXX: Cygwin (at least) doesn't define these macros. Too bad...
  37. #ifndef GET_X_LPARAM
  38.     #define GET_X_LPARAM(a) ((int16_t)(a))
  39.     #define GET_Y_LPARAM(a) ((int16_t)((a)>>16))
  40. #endif
  41. Win32Loop::Win32Loop( intf_thread_t *pIntf ): OSLoop( pIntf )
  42. {
  43.     // Initialize the map
  44.     virtKeyToVlcKey[VK_F1] = KEY_F1;
  45.     virtKeyToVlcKey[VK_F2] = KEY_F2;
  46.     virtKeyToVlcKey[VK_F3] = KEY_F3;
  47.     virtKeyToVlcKey[VK_F4] = KEY_F4;
  48.     virtKeyToVlcKey[VK_F5] = KEY_F5;
  49.     virtKeyToVlcKey[VK_F6] = KEY_F6;
  50.     virtKeyToVlcKey[VK_F7] = KEY_F7;
  51.     virtKeyToVlcKey[VK_F8] = KEY_F8;
  52.     virtKeyToVlcKey[VK_F9] = KEY_F9;
  53.     virtKeyToVlcKey[VK_F10] = KEY_F10;
  54.     virtKeyToVlcKey[VK_F11] = KEY_F11;
  55.     virtKeyToVlcKey[VK_F12] = KEY_F12;
  56.     virtKeyToVlcKey[VK_RETURN] = KEY_ENTER;
  57.     virtKeyToVlcKey[VK_SPACE] = KEY_SPACE;
  58.     virtKeyToVlcKey[VK_ESCAPE] = KEY_ESC;
  59.     virtKeyToVlcKey[VK_LEFT] = KEY_LEFT;
  60.     virtKeyToVlcKey[VK_RIGHT] = KEY_RIGHT;
  61.     virtKeyToVlcKey[VK_UP] = KEY_UP;
  62.     virtKeyToVlcKey[VK_DOWN] = KEY_DOWN;
  63.     virtKeyToVlcKey[VK_INSERT] = KEY_INSERT;
  64.     virtKeyToVlcKey[VK_DELETE] = KEY_DELETE;
  65.     virtKeyToVlcKey[VK_HOME] = KEY_HOME;
  66.     virtKeyToVlcKey[VK_END] = KEY_END;
  67.     virtKeyToVlcKey[VK_PRIOR] = KEY_PAGEUP;
  68.     virtKeyToVlcKey[VK_NEXT] = KEY_PAGEDOWN;
  69.     virtKeyToVlcKey[VK_BROWSER_BACK] = KEY_BROWSER_BACK;
  70.     virtKeyToVlcKey[VK_BROWSER_FORWARD] = KEY_BROWSER_FORWARD;
  71.     virtKeyToVlcKey[VK_BROWSER_REFRESH] = KEY_BROWSER_REFRESH;
  72.     virtKeyToVlcKey[VK_BROWSER_STOP] = KEY_BROWSER_STOP;
  73.     virtKeyToVlcKey[VK_BROWSER_SEARCH] = KEY_BROWSER_SEARCH;
  74.     virtKeyToVlcKey[VK_BROWSER_FAVORITES] = KEY_BROWSER_FAVORITES;
  75.     virtKeyToVlcKey[VK_BROWSER_HOME] = KEY_BROWSER_HOME;
  76.     virtKeyToVlcKey[VK_VOLUME_MUTE] = KEY_VOLUME_MUTE;
  77.     virtKeyToVlcKey[VK_VOLUME_DOWN] = KEY_VOLUME_DOWN;
  78.     virtKeyToVlcKey[VK_VOLUME_UP] = KEY_VOLUME_UP;
  79.     virtKeyToVlcKey[VK_MEDIA_NEXT_TRACK] = KEY_MEDIA_NEXT_TRACK;
  80.     virtKeyToVlcKey[VK_MEDIA_PREV_TRACK] = KEY_MEDIA_PREV_TRACK;
  81.     virtKeyToVlcKey[VK_MEDIA_STOP] = KEY_MEDIA_STOP;
  82.     virtKeyToVlcKey[VK_MEDIA_PLAY_PAUSE] = KEY_MEDIA_PLAY_PAUSE;
  83. }
  84. Win32Loop::~Win32Loop()
  85. {
  86. }
  87. OSLoop *Win32Loop::instance( intf_thread_t *pIntf )
  88. {
  89.     if( pIntf->p_sys->p_osLoop == NULL )
  90.     {
  91.         OSLoop *pOsLoop = new Win32Loop( pIntf );
  92.         pIntf->p_sys->p_osLoop = pOsLoop;
  93.     }
  94.     return pIntf->p_sys->p_osLoop;
  95. }
  96. void Win32Loop::destroy( intf_thread_t *pIntf )
  97. {
  98.     if( pIntf->p_sys->p_osLoop )
  99.     {
  100.         delete pIntf->p_sys->p_osLoop;
  101.         pIntf->p_sys->p_osLoop = NULL;
  102.     }
  103. }
  104. void Win32Loop::run()
  105. {
  106.     MSG msg;
  107.     // Compute windows message list
  108.     while( GetMessage( &msg, NULL, 0, 0 ) )
  109.     {
  110.         Win32Factory *pFactory =
  111.             (Win32Factory*)Win32Factory::instance( getIntf() );
  112.         GenericWindow *pWin = pFactory->m_windowMap[msg.hwnd];
  113.         if( pWin == NULL )
  114.         {
  115.             // We are probably getting a message for a tooltip (which has no
  116.             // associated GenericWindow), for a timer, or for the parent window
  117.             DispatchMessage( &msg );
  118.             continue;
  119.         }
  120.         GenericWindow &win = *pWin;
  121.         switch( msg.message )
  122.         {
  123.             case WM_PAINT:
  124.             {
  125.                 PAINTSTRUCT Infos;
  126.                 BeginPaint( msg.hwnd, &Infos );
  127.                 EvtRefresh evt( getIntf(),
  128.                                 Infos.rcPaint.left,
  129.                                 Infos.rcPaint.top,
  130.                                 Infos.rcPaint.right - Infos.rcPaint.left + 1,
  131.                                 Infos.rcPaint.bottom - Infos.rcPaint.top + 1 );
  132.                 EndPaint( msg.hwnd, &Infos );
  133.                 win.processEvent( evt );
  134.                 break;
  135.             }
  136.             case WM_COMMAND:
  137.             {
  138.                 EvtMenu evt( getIntf(), LOWORD( msg.wParam ) );
  139.                 win.processEvent( evt );
  140.                 break;
  141.             }
  142.             case WM_MOUSEMOVE:
  143.             {
  144.                 // Needed to generate WM_MOUSELEAVE events
  145.                 TRACKMOUSEEVENT TrackEvent;
  146.                 TrackEvent.cbSize      = sizeof( TRACKMOUSEEVENT );
  147.                 TrackEvent.dwFlags     = TME_LEAVE;
  148.                 TrackEvent.hwndTrack   = msg.hwnd;
  149.                 TrackEvent.dwHoverTime = 1;
  150.                 TrackMouseEvent( &TrackEvent );
  151.                 // Compute the absolute position of the mouse
  152.                 int x = GET_X_LPARAM( msg.lParam ) + win.getLeft();
  153.                 int y = GET_Y_LPARAM( msg.lParam ) + win.getTop();
  154.                 EvtMotion evt( getIntf(), x, y );
  155.                 win.processEvent( evt );
  156.                 break;
  157.             }
  158.             case WM_MOUSELEAVE:
  159.             {
  160.                 EvtLeave evt( getIntf() );
  161.                 win.processEvent( evt );
  162.                 break;
  163.             }
  164.             case WM_MOUSEWHEEL:
  165.             {
  166.                 int x = GET_X_LPARAM( msg.lParam ) - win.getLeft();
  167.                 int y = GET_Y_LPARAM( msg.lParam ) - win.getTop();
  168.                 int mod = getMod( msg.wParam );
  169.                 if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 )
  170.                 {
  171.                     EvtScroll evt( getIntf(), x, y, EvtScroll::kUp, mod );
  172.                     win.processEvent( evt );
  173.                 }
  174.                 else
  175.                 {
  176.                     EvtScroll evt( getIntf(), x, y, EvtScroll::kDown, mod );
  177.                     win.processEvent( evt );
  178.                 }
  179.                 break;
  180.             }
  181.             case WM_LBUTTONDOWN:
  182.             {
  183.                 SetCapture( msg.hwnd );
  184.                 EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
  185.                               GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
  186.                               EvtMouse::kDown, getMod( msg.wParam ) );
  187.                 win.processEvent( evt );
  188.                 break;
  189.             }
  190.             case WM_RBUTTONDOWN:
  191.             {
  192.                 SetCapture( msg.hwnd );
  193.                 EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
  194.                               GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
  195.                               EvtMouse::kDown, getMod( msg.wParam ) );
  196.                 win.processEvent( evt );
  197.                 break;
  198.             }
  199.             case WM_LBUTTONUP:
  200.             {
  201.                 ReleaseCapture();
  202.                 EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
  203.                               GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
  204.                               EvtMouse::kUp, getMod( msg.wParam ) );
  205.                 win.processEvent( evt );
  206.                 break;
  207.             }
  208.             case WM_RBUTTONUP:
  209.             {
  210.                 ReleaseCapture();
  211.                 EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
  212.                               GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
  213.                               EvtMouse::kUp, getMod( msg.wParam ) );
  214.                 win.processEvent( evt );
  215.                 break;
  216.             }
  217.             case WM_LBUTTONDBLCLK:
  218.             {
  219.                 ReleaseCapture();
  220.                 EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
  221.                               GET_Y_LPARAM( msg.lParam ), EvtMouse::kLeft,
  222.                               EvtMouse::kDblClick, getMod( msg.wParam ) );
  223.                 win.processEvent( evt );
  224.                 break;
  225.             }
  226.             case WM_RBUTTONDBLCLK:
  227.             {
  228.                 ReleaseCapture();
  229.                 EvtMouse evt( getIntf(), GET_X_LPARAM( msg.lParam ),
  230.                               GET_Y_LPARAM( msg.lParam ), EvtMouse::kRight,
  231.                               EvtMouse::kDblClick, getMod( msg.wParam ) );
  232.                 win.processEvent( evt );
  233.                 break;
  234.             }
  235.             case WM_KEYDOWN:
  236.             case WM_SYSKEYDOWN:
  237.             case WM_KEYUP:
  238.             case WM_SYSKEYUP:
  239.             {
  240.                 // The key events are first processed here and not translated
  241.                 // into WM_CHAR events because we need to know the status of
  242.                 // the modifier keys.
  243.                 // Get VLC key code from the virtual key code
  244.                 int key = virtKeyToVlcKey[msg.wParam];
  245.                 if( !key )
  246.                 {
  247.                     // This appears to be a "normal" (ascii) key
  248.                     key = tolower( MapVirtualKey( msg.wParam, 2 ) );
  249.                 }
  250.                 if( key )
  251.                 {
  252.                     // Get the modifier
  253.                     int mod = 0;
  254.                     if( GetKeyState( VK_CONTROL ) & 0x8000 )
  255.                     {
  256.                         mod |= EvtInput::kModCtrl;
  257.                     }
  258.                     if( GetKeyState( VK_SHIFT ) & 0x8000 )
  259.                     {
  260.                         mod |= EvtInput::kModShift;
  261.                     }
  262.                     if( GetKeyState( VK_MENU ) & 0x8000 )
  263.                     {
  264.                         mod |= EvtInput::kModAlt;
  265.                     }
  266.                     // Get the state
  267.                     EvtKey::ActionType_t state;
  268.                     if( msg.message == WM_KEYDOWN ||
  269.                         msg.message == WM_SYSKEYDOWN )
  270.                     {
  271.                         state = EvtKey::kDown;
  272.                     }
  273.                     else
  274.                     {
  275.                         state = EvtKey::kUp;
  276.                     }
  277.                     EvtKey evt( getIntf(), key, state, mod );
  278.                     win.processEvent( evt );
  279.                 }
  280.                 break;
  281.             }
  282.             default:
  283.                 TranslateMessage( &msg );
  284.                 DispatchMessage( &msg );
  285.         }
  286.     }
  287. }
  288. int Win32Loop::getMod( WPARAM wParam ) const
  289. {
  290.     int mod = EvtInput::kModNone;
  291.     if( wParam & MK_CONTROL )
  292.         mod |= EvtInput::kModCtrl;
  293.     if( wParam & MK_SHIFT )
  294.         mod |= EvtInput::kModShift;
  295.     return mod;
  296. }
  297. void Win32Loop::exit()
  298. {
  299.     PostQuitMessage(0);
  300. }
  301. #endif