⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listviews.cpp

📁 VLC媒体播放程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
PlaylistView::KeyDown( const char* bytes, int32 numBytes ){	if ( numBytes < 1 )		return;			if ( ( bytes[0] == B_BACKSPACE ) || ( bytes[0] == B_DELETE ) )	{		RemoveSelected();	}	DragSortableListView::KeyDown( bytes, numBytes );}/***************************************************************************** * PlaylistView::Pulse *****************************************************************************/voidPlaylistView::Pulse(){	if ( fMainWindow->IsStopped() )		SetPlaying( false );}/***************************************************************************** * PlaylistView::SelectionChanged *****************************************************************************/voidPlaylistView::SelectionChanged(){	BLooper* looper = Looper();	if ( fSelectionChangeMessage && looper )	{		BMessage message( *fSelectionChangeMessage );		looper->PostMessage( &message );	}}/***************************************************************************** * PlaylistView::MoveItems *****************************************************************************/voidPlaylistView::MoveItems( BList& items, int32 index ){	DeselectAll();	// we remove the items while we look at them, the insertion index is decreased	// when the items index is lower, so that we insert at the right spot after	// removal	if ( fVlcWrapper->PlaylistLock() )	{		BList removedItems;		BList removeItems;		int32 count = items.CountItems();		int32 indexOriginal = index;		// remember currently playing item		BListItem* playingItem = _PlayingItem();		// collect item pointers for removal by index		for ( int32 i = 0; i < count; i++ )		{			int32 removeIndex = IndexOf( (BListItem*)items.ItemAt( i ) );			void* item = fVlcWrapper->PlaylistItemAt( removeIndex );			if ( item && removeItems.AddItem( item ) )			{				if ( removeIndex < index )					index--;			}			// else ??? -> blow up		}		// actually remove items using pointers		for ( int32 i = 0; i < count; i++ )		{			void* item = fVlcWrapper->PlaylistRemoveItem( removeItems.ItemAt( i ) );			if ( item && !removedItems.AddItem( item ) )				free( item );		}		// add items at index		for ( int32 i = 0; void* item = removedItems.ItemAt( i ); i++ )		{			if ( fVlcWrapper->PlaylistAddItem( item, index ) )				// next items will be inserted after this one				index++;			else				free( item );		}		// update GUI		DragSortableListView::MoveItems( items, indexOriginal );		// restore currently playing item		_SetPlayingIndex( playingItem );		// update interface (in case it isn't playing,		// there is a chance that it needs to update)		fMainWindow->PostMessage( MSG_UPDATE );		fVlcWrapper->PlaylistUnlock();	}}/***************************************************************************** * PlaylistView::CopyItems *****************************************************************************/voidPlaylistView::CopyItems( BList& items, int32 toIndex ){	DeselectAll();	// we remove the items while we look at them, the insertion index is decreased	// when the items index is lower, so that we insert at the right spot after	// removal	if ( fVlcWrapper->PlaylistLock() )	{		BList clonedItems;		int32 count = items.CountItems();		// remember currently playing item		BListItem* playingItem = _PlayingItem();		// collect cloned item pointers		for ( int32 i = 0; i < count; i++ )		{			int32 index = IndexOf( (BListItem*)items.ItemAt( i ) );			void* item = fVlcWrapper->PlaylistItemAt( index );			void* cloned = fVlcWrapper->PlaylistCloneItem( item );			if ( cloned && !clonedItems.AddItem( cloned ) )				free( cloned );					}		// add cloned items at index		int32 index = toIndex;		for ( int32 i = 0; void* item = clonedItems.ItemAt( i ); i++ )		{			if ( fVlcWrapper->PlaylistAddItem( item, index ) )				// next items will be inserted after this one				index++;			else				free( item );		}		// update GUI		DragSortableListView::CopyItems( items, toIndex );		// restore currently playing item		_SetPlayingIndex( playingItem );		// update interface (in case it isn't playing,		// there is a chance that it needs to update)		fMainWindow->PostMessage( MSG_UPDATE );		fVlcWrapper->PlaylistUnlock();	}}/***************************************************************************** * PlaylistView::RemoveItemList *****************************************************************************/voidPlaylistView::RemoveItemList( BList& items ){	if ( fVlcWrapper->PlaylistLock() )	{		// remember currently playing item		BListItem* playingItem = _PlayingItem();		// collect item pointers for removal		BList removeItems;		int32 count = items.CountItems();		for ( int32 i = 0; i < count; i++ )		{			int32 index = IndexOf( (BListItem*)items.ItemAt( i ) );			void* item = fVlcWrapper->PlaylistItemAt( index );			if ( item && !removeItems.AddItem( item ) )				free( item );		}		// remove items from playlist		count = removeItems.CountItems();		for ( int32 i = 0; void* item = removeItems.ItemAt( i ); i++ )		{			fVlcWrapper->PlaylistRemoveItem( item );		}		// update GUI		DragSortableListView::RemoveItemList( items );		// restore currently playing item		_SetPlayingIndex( playingItem );		// update interface (in case it isn't playing,		// there is a chance that it needs to update)		fMainWindow->PostMessage( MSG_UPDATE );		fVlcWrapper->PlaylistUnlock();	}}/***************************************************************************** * PlaylistView::CloneItem *****************************************************************************/BListItem*PlaylistView::CloneItem( int32 atIndex ) const{	BListItem* clone = NULL;	if ( PlaylistItem* item = dynamic_cast<PlaylistItem*>( ItemAt( atIndex ) ) )		clone = new PlaylistItem( item->Text() );	return clone;}/***************************************************************************** * PlaylistView::DrawListItem *****************************************************************************/voidPlaylistView::DrawListItem( BView* owner, int32 index, BRect frame ) const{	if ( PlaylistItem* item = dynamic_cast<PlaylistItem*>( ItemAt( index ) ) )		item->Draw( owner,  frame, index % 2,					fDisplayMode, index == fCurrentIndex, fPlaying );}/***************************************************************************** * PlaylistView::MakeDragMessage *****************************************************************************/voidPlaylistView::MakeDragMessage( BMessage* message ) const{	if ( message )	{		message->AddPointer( "list", (void*)this );		int32 index;		for ( int32 i = 0; ( index = CurrentSelection( i ) ) >= 0; i++ )		{			message->AddInt32( "index", index );			// add refs to message (inter application communication)			if ( BStringItem* item = dynamic_cast<BStringItem*>( ItemAt( index ) ) )			{				entry_ref ref;				if ( get_ref_for_path( item->Text(), &ref ) == B_OK )					message->AddRef( "refs", &ref );			}		}	}}/***************************************************************************** * PlaylistView::SetCurrent *****************************************************************************/voidPlaylistView::SetCurrent( int32 index ){	if ( fCurrentIndex != index )	{		InvalidateItem( fCurrentIndex );		fCurrentIndex = index;		InvalidateItem( fCurrentIndex );	}}/***************************************************************************** * PlaylistView::SetPlaying *****************************************************************************/voidPlaylistView::SetPlaying( bool playing ){	if ( fPlaying != playing )	{		fPlaying = playing;		InvalidateItem( fCurrentIndex );	}}/***************************************************************************** * PlaylistView::SetPlaying *****************************************************************************/voidPlaylistView::RebuildList(){	// remove all items	int32 count = CountItems();	while ( BListItem* item = RemoveItem( --count ) )		delete item;		// rebuild listview from VLC's playlist	for ( int i = 0; i < fVlcWrapper->PlaylistSize(); i++ )		AddItem( new PlaylistItem( fVlcWrapper->PlaylistItemName( i ) ) );}/***************************************************************************** * PlaylistView::SortReverse *****************************************************************************/voidPlaylistView::SortReverse(){	if ( int32 count = CountSelectedItems() )	{		int32 last  = count - 1;		// remember currently playing item		BListItem* playingItem = _PlayingItem();		for ( int32 first = 0; first < count / 2; first++, last-- )		{			int32 index1 = CurrentSelection( first);			int32 index2 = CurrentSelection( last);			if ( SwapItems( index1, index2 ) )			{				// index2 > index1, so the list won't get messed up				// if we remove the items in that order				// TODO: Error checking + handling!				void* item2 = fVlcWrapper->PlaylistRemoveItem( index2 );				void* item1 = fVlcWrapper->PlaylistRemoveItem( index1 );				fVlcWrapper->PlaylistAddItem( item2, index1 );				fVlcWrapper->PlaylistAddItem( item1, index2 );			}		}		// restore currently playing item		_SetPlayingIndex( playingItem );	}}/***************************************************************************** * PlaylistView::SortByPath *****************************************************************************/voidPlaylistView::SortByPath(){	}/***************************************************************************** * PlaylistView::SortByName *****************************************************************************/voidPlaylistView::SortByName(){}/***************************************************************************** * PlaylistView::SetDisplayMode *****************************************************************************/voidPlaylistView::SetDisplayMode( uint32 mode ){	if ( mode != fDisplayMode )	{		fDisplayMode = mode;		Invalidate();	}}/***************************************************************************** * PlaylistView::_PlayingItem *****************************************************************************/BListItem*PlaylistView::_PlayingItem() const{	int32 currentIndex, size;	fVlcWrapper->GetPlaylistInfo( currentIndex, size );	return ItemAt( currentIndex );}/***************************************************************************** * PlaylistView::_SetPlayingIndex *****************************************************************************/voidPlaylistView::_SetPlayingIndex( BListItem* playingItem ){	for ( int32 i = 0; BListItem* item = ItemAt( i ); i++ )	{		if ( item == playingItem )		{			fVlcWrapper->PlaylistSetPlaying( i );			SetCurrent( i );			break;		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -