top_window.cpp
来自「VLC Player Source Code」· C++ 代码 · 共 547 行 · 第 1/2 页
CPP
547 行
/***************************************************************************** * top_window.cpp ***************************************************************************** * Copyright (C) 2003 the VideoLAN team * $Id$ * * Authors: Cyril Deguet <asmax@via.ecp.fr> * Olivier Teulière <ipkiss@via.ecp.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/#include "top_window.hpp"#include "generic_layout.hpp"#include "os_graphics.hpp"#include "os_window.hpp"#include "os_factory.hpp"#include "theme.hpp"#include "var_manager.hpp"#include "../commands/cmd_on_top.hpp"#include "../commands/cmd_dialogs.hpp"#include "../controls/ctrl_generic.hpp"#include "../events/evt_refresh.hpp"#include "../events/evt_enter.hpp"#include "../events/evt_focus.hpp"#include "../events/evt_leave.hpp"#include "../events/evt_menu.hpp"#include "../events/evt_motion.hpp"#include "../events/evt_mouse.hpp"#include "../events/evt_key.hpp"#include "../events/evt_special.hpp"#include "../events/evt_scroll.hpp"#include "../utils/position.hpp"#include "../utils/ustring.hpp"#include <vlc_keys.h>TopWindow::TopWindow( intf_thread_t *pIntf, int left, int top, WindowManager &rWindowManager, bool dragDrop, bool playOnDrop, bool visible ): GenericWindow( pIntf, left, top, dragDrop, playOnDrop, NULL ), m_visible( visible ), m_rWindowManager( rWindowManager ), m_pActiveLayout( NULL ), m_pLastHitControl( NULL ), m_pCapturingControl( NULL ), m_pFocusControl( NULL ), m_currModifier( 0 ){ // Register as a moving window m_rWindowManager.registerWindow( *this ); // Create the "maximized" variable and register it in the manager m_pVarMaximized = new VarBoolImpl( pIntf ); VarManager::instance( pIntf )->registerVar( VariablePtr( m_pVarMaximized ) );}TopWindow::~TopWindow(){ // Unregister from the window manager m_rWindowManager.unregisterWindow( *this );}void TopWindow::processEvent( EvtRefresh &rEvtRefresh ){ // We override the behaviour defined in GenericWindow, because we don't // want to draw on a video control! if( m_pActiveLayout == NULL ) { GenericWindow::processEvent( rEvtRefresh ); } else { m_pActiveLayout->refreshRect( rEvtRefresh.getXStart(), rEvtRefresh.getYStart(), rEvtRefresh.getWidth(), rEvtRefresh.getHeight() ); }}void TopWindow::processEvent( EvtFocus &rEvtFocus ){// fprintf(stderr, rEvtFocus.getAsString().c_str());}void TopWindow::processEvent( EvtMenu &rEvtMenu ){ Popup *pPopup = m_rWindowManager.getActivePopup(); // We should never receive a menu event when there is no active popup! if( pPopup == NULL ) { msg_Warn( getIntf(), "unexpected menu event, ignoring" ); return; } pPopup->handleEvent( rEvtMenu );}void TopWindow::processEvent( EvtMotion &rEvtMotion ){ // New control hit by the mouse CtrlGeneric *pNewHitControl = findHitControl( rEvtMotion.getXPos() - getLeft(), rEvtMotion.getYPos() - getTop() ); setLastHit( pNewHitControl ); /// Update the help text VarManager *pVarManager = VarManager::instance( getIntf() ); if( pNewHitControl ) { pVarManager->getHelpText().set( pNewHitControl->getHelpText() ); } // Send a motion event to the hit control, or to the control // that captured the mouse, if any CtrlGeneric *pActiveControl = pNewHitControl; if( m_pCapturingControl ) { pActiveControl = m_pCapturingControl; } if( pActiveControl ) { // Compute the coordinates relative to the window int xPos = rEvtMotion.getXPos() - getLeft(); int yPos = rEvtMotion.getYPos() - getTop(); // Send a motion event EvtMotion evt( getIntf(), xPos, yPos ); pActiveControl->handleEvent( evt ); }}void TopWindow::processEvent( EvtLeave &rEvtLeave ){ // No more hit control setLastHit( NULL ); if( !m_pCapturingControl ) { m_rWindowManager.hideTooltip(); }}void TopWindow::processEvent( EvtMouse &rEvtMouse ){ // Get the control hit by the mouse CtrlGeneric *pNewHitControl = findHitControl( rEvtMouse.getXPos(), rEvtMouse.getYPos() ); setLastHit( pNewHitControl ); // Change the focused control if( rEvtMouse.getAction() == EvtMouse::kDown ) { // Raise the window m_rWindowManager.raise( *this ); if( pNewHitControl && pNewHitControl->isFocusable() ) { // If a new control gains the focus, the previous one loses it if( m_pFocusControl && m_pFocusControl != pNewHitControl ) { EvtFocus evt( getIntf(), false ); m_pFocusControl->handleEvent( evt ); } if( pNewHitControl != m_pFocusControl ) { m_pFocusControl = pNewHitControl; EvtFocus evt( getIntf(), false ); pNewHitControl->handleEvent( evt ); } } else if( m_pFocusControl ) { // The previous control loses the focus EvtFocus evt( getIntf(), false ); m_pFocusControl->handleEvent( evt ); m_pFocusControl = NULL; } } // Send a mouse event to the hit control, or to the control // that captured the mouse, if any CtrlGeneric *pActiveControl = pNewHitControl; if( m_pCapturingControl ) { pActiveControl = m_pCapturingControl; } if( pActiveControl ) { pActiveControl->handleEvent( rEvtMouse ); }}void TopWindow::processEvent( EvtKey &rEvtKey ){ // Forward the event to the focused control, if any if( m_pFocusControl ) { m_pFocusControl->handleEvent( rEvtKey ); return; } // Only do the action when the key is down if( rEvtKey.getAsString().find( "key:down") != string::npos ) { //XXX not to be hardcoded! // Ctrl-S = Change skin if( (rEvtKey.getMod() & EvtInput::kModCtrl) && rEvtKey.getKey() == 's' ) { CmdDlgChangeSkin cmd( getIntf() ); cmd.execute(); return; } //XXX not to be hardcoded! // Ctrl-T = Toggle on top if( (rEvtKey.getMod() & EvtInput::kModCtrl) && rEvtKey.getKey() == 't' ) { CmdOnTop cmd( getIntf() ); cmd.execute(); return; } vlc_value_t val; // Set the key val.i_int = rEvtKey.getKey(); // Set the modifiers if( rEvtKey.getMod() & EvtInput::kModAlt ) { val.i_int |= KEY_MODIFIER_ALT; } if( rEvtKey.getMod() & EvtInput::kModCtrl ) { val.i_int |= KEY_MODIFIER_CTRL; } if( rEvtKey.getMod() & EvtInput::kModShift ) { val.i_int |= KEY_MODIFIER_SHIFT; } var_Set( getIntf()->p_libvlc, "key-pressed", val ); } // Always store the modifier, which can be needed for scroll events m_currModifier = rEvtKey.getMod();}void TopWindow::processEvent( EvtScroll &rEvtScroll ){ // Raise the windows raise(); // Get the control hit by the mouse CtrlGeneric *pNewHitControl = findHitControl( rEvtScroll.getXPos(),
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?