x11_window.cpp
来自「VLC媒体播放程序」· C++ 代码 · 共 621 行 · 第 1/2 页
CPP
621 行
case ButtonPress: // Raise all the windows for( list<SkinWindow *>::const_iterator win = p_intf->p_sys->p_theme->WindowList.begin(); win != p_intf->p_sys->p_theme->WindowList.end(); win++ ) { Window id = ( (X11Window *)(*win) )->GetHandle(); // the current window is raised last if( id != Wnd ) { XLOCK; XRaiseWindow( display, id ); XUNLOCK; } } XLOCK; XRaiseWindow( display, Wnd ); XUNLOCK; button = 0; if( ((XButtonEvent *)p2 )->state & ControlMask ) { button |= KEY_CTRL; } if( ((XButtonEvent *)p2 )->state & ShiftMask ) { button |= KEY_SHIFT; } switch( ( (XButtonEvent *)p2 )->button ) { case 1: // Left button button |= MOUSE_LEFT; time = OSAPI_GetTime(); OSAPI_GetMousePos( posX, posY ); if( time - ClickedTime < DblClickDelay && posX == ClickedX && posY == ClickedY ) { // Double-click ClickedTime = 0; MouseDblClick( (int)( (XButtonEvent *)p2 )->x, (int)( (XButtonEvent *)p2 )->y, button ); } else { ClickedTime = time; ClickedX = posX; ClickedY = posY; LButtonDown = true; MouseDown( (int)( (XButtonEvent *)p2 )->x, (int)( (XButtonEvent *)p2 )->y, button ); } break; case 3: // Right button button |= MOUSE_RIGHT; RButtonDown = true; MouseDown( (int)( (XButtonEvent *)p2 )->x, (int)( (XButtonEvent *)p2 )->y, button ); break; default: break; } return true; case ButtonRelease: button = 0; if( ((XButtonEvent *)p2 )->state & ControlMask ) { button |= KEY_CTRL; } if( ((XButtonEvent *)p2 )->state & ShiftMask ) { button |= KEY_SHIFT; } switch( ( (XButtonEvent *)p2 )->button ) { case 1: // Left button button |= MOUSE_LEFT; LButtonDown = false; MouseUp( (int)( (XButtonEvent *)p2 )->x, (int)( (XButtonEvent *)p2 )->y, button ); break; case 3: button |= MOUSE_RIGHT; // Right button RButtonDown = false; MouseUp( (int)( (XButtonEvent *)p2 )->x, (int)( (XButtonEvent *)p2 )->y, button ); break; case 4: // Scroll up MouseScroll( (int)( (XButtonEvent *)p2 )->x, (int)( (XButtonEvent *)p2 )->y, MOUSE_SCROLL_UP); break; case 5: // Scroll down MouseScroll( (int)( (XButtonEvent *)p2 )->x, (int)( (XButtonEvent *)p2 )->y, MOUSE_SCROLL_DOWN); break; default: break; } return true; case LeaveNotify: OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 ); return true; case ClientMessage: XLOCK; type = XGetAtomName( display, ( (XClientMessageEvent*) p2 )->message_type ); XUNLOCK; if( type == "XdndEnter" ) { DropObject->DndEnter( ((XClientMessageEvent*)p2)->data.l ); return true; } else if( type == "XdndPosition" ) { DropObject->DndPosition( ((XClientMessageEvent*)p2)->data.l ); return true; } else if( type == "XdndLeave" ) { DropObject->DndLeave( ((XClientMessageEvent*)p2)->data.l ); return true; } else if( type == "XdndDrop" ) { DropObject->DndDrop( ((XClientMessageEvent*)p2)->data.l ); return true; } return false; default: return false; }}//---------------------------------------------------------------------------void X11Window::SetTransparency( int Value ){/* if( Value > -1 ) Alpha = Value; SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY ); UpdateWindow( hWnd );*/}//---------------------------------------------------------------------------void X11Window::RefreshFromImage( int x, int y, int w, int h ){ Drawable drawable = (( X11Graphics* )Image )->GetImage(); XLOCK; XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y ); XSync( display, 0); XUNLOCK;}//---------------------------------------------------------------------------void X11Window::WindowManualMove(){ // Get mouse cursor position int x, y; OSAPI_GetMousePos( x, y ); // Move window and chek for magnetism p_intf->p_sys->p_theme->MoveSkinMagnet( this, WindowX + x - CursorX, WindowY + y - CursorY );}//---------------------------------------------------------------------------void X11Window::WindowManualMoveInit(){ OSAPI_GetMousePos( CursorX, CursorY ); WindowX = Left; WindowY = Top;}//---------------------------------------------------------------------------void X11Window::Move( int left, int top ){ Left = left; Top = top; XMoveWindow( display, Wnd, left, top );}//---------------------------------------------------------------------------void X11Window::Size( int width, int height ){ Width = width; Height = height; XResizeWindow( display, Wnd, width, height );}//---------------------------------------------------------------------------bool ToolTipCallback( void *data ){ int direction, fontAscent, fontDescent; Display *disp = ((tooltip_t*)data)->display; Window win = ((tooltip_t*)data)->window; Font font = ((tooltip_t*)data)->font; GC gc = ((tooltip_t*)data)->gc; string text = ((tooltip_t*)data)->text; int curX = ((tooltip_t*)data)->curX; int curY = ((tooltip_t*)data)->curY; XLOCK; XClearWindow( disp, win ); XCharStruct overall; XQueryTextExtents( disp, font, text.c_str(), text.size(), &direction, &fontAscent, &fontDescent, &overall ); int w = overall.rbearing - overall.lbearing; int h = overall.ascent + overall.descent; XMapRaised( disp, win ); XMoveWindow( disp, win, curX - w/4, curY + 20 ); XResizeWindow( disp, win, w+8, h+8 ); XDrawString( disp, win, gc, 4, overall.ascent+4, text.c_str(), text.size() ); XSync( disp, 0 ); ((tooltip_t*)data)->active = True; XUNLOCK; return False;}void DrawToolTipText( tooltip_t *tooltip ){ int direction, fontAscent, fontDescent; Display *disp = tooltip->display; Window win = tooltip->window; Font font = tooltip->font; GC gc = tooltip->gc; string text = tooltip->text; int curX = tooltip->curX; int curY = tooltip->curY; XLOCK; XClearWindow( disp, win ); XCharStruct overall; XQueryTextExtents( disp, font, text.c_str(), text.size(), &direction, &fontAscent, &fontDescent, &overall ); int w = overall.rbearing - overall.lbearing; int h = overall.ascent + overall.descent; XMoveWindow( disp, win, curX - w/4, curY + 20 ); XResizeWindow( disp, win, w+8, h+8 ); XDrawString( disp, win, gc, 4, overall.ascent+4, text.c_str(), text.size() ); XSync( disp, 0 ); XUNLOCK;}void X11Window::ChangeToolTipText( string text ){ if( text == "none" ) { if( ToolTipText != "none" ) { ToolTipText = "none"; XLOCK; // Hide the tooltip window X11TimerManager *timerManager = X11TimerManager::Instance( p_intf ); timerManager->removeTimer( ToolTip.timer ); XUnmapWindow( display, ToolTip.window ); XResizeWindow( display, ToolTip.window, 1, 1 ); XSync( display, 0 ); ToolTip.active = False; XUNLOCK; } } else { if( text != ToolTipText ) { ToolTipText = text; ToolTip.text = text; if( !ToolTip.active ) { // Create the tooltip OSAPI_GetMousePos( ToolTip.curX, ToolTip.curY ); X11TimerManager *timerManager = X11TimerManager::Instance( p_intf ); timerManager->addTimer( ToolTip.timer ); } else { // Refresh the tooltip DrawToolTipText( &ToolTip ); } } }}//---------------------------------------------------------------------------#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?