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

📄 listviews.cpp

📁 VLC媒体播放程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				if ( replaceAll )				{					BRect r( Bounds() );					r.bottom--;	// compensate for scrollbar offset					_SetDropAnticipationRect( r );					fDropIndex = -1;				}				else				{					// offset where by half of item height					BRect r( ItemFrame( 0 ) );					where.y += r.Height() / 2.0;						int32 index = IndexOf( where );					if ( index < 0 )						index = CountItems();					_SetDropIndex( index );				}				break;			}			case B_EXITED_VIEW:				// forget drag message				fDragMessageCopy.what = 0;			case B_OUTSIDE_VIEW:				_RemoveDropAnticipationRect();				break;		}	}	else	{		_RemoveDropAnticipationRect();		BListView::MouseMoved(where, transit, msg);		fDragMessageCopy.what = 0;	}}/***************************************************************************** * DragSortableListView::MouseUp *****************************************************************************/voidDragSortableListView::MouseUp( BPoint where ){	// remove drop mark	_SetDropAnticipationRect( BRect( 0.0, 0.0, -1.0, -1.0 ) );	// be sure to forget drag message	fDragMessageCopy.what = 0;	BListView::MouseUp( where );}/***************************************************************************** * DragSortableListView::DrawItem *****************************************************************************/voidDragSortableListView::DrawItem( BListItem *item, BRect itemFrame, bool complete ){	DrawListItem( this, IndexOf( item ), itemFrame );}/***************************************************************************** * DragSortableListView::ModifiersChaned *****************************************************************************/voidDragSortableListView::ModifiersChanged(){	BPoint where;	uint32 buttons;	GetMouse( &where, &buttons, false );	uint32 transit = Bounds().Contains( where ) ? B_INSIDE_VIEW : B_OUTSIDE_VIEW;	MouseMoved( where, transit, &fDragMessageCopy );}/***************************************************************************** * DragSortableListView::MoveItems *****************************************************************************/voidDragSortableListView::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	BList removedItems;	int32 count = items.CountItems();	for ( int32 i = 0; i < count; i++ )	{		BListItem* item = (BListItem*)items.ItemAt( i );		int32 removeIndex = IndexOf( item );		if ( RemoveItem( item ) && removedItems.AddItem( (void*)item ) )		{			if ( removeIndex < index )				index--;		}		// else ??? -> blow up	}	for ( int32 i = 0; BListItem* item = (BListItem*)removedItems.ItemAt( i ); i++ )	{		if ( AddItem( item, index ) )		{			// after we're done, the newly inserted items will be selected			Select( index, true );			// next items will be inserted after this one			index++;		}		else			delete item;	}}/***************************************************************************** * DragSortableListView::CopyItems *****************************************************************************/voidDragSortableListView::CopyItems( BList& items, int32 index ){	DeselectAll();	// by inserting the items after we copied all items first, we avoid	// cloning an item we already inserted and messing everything up	// in other words, don't touch the list before we know which items	// need to be cloned	BList clonedItems;	int32 count = items.CountItems();	for ( int32 i = 0; i < count; i++ )	{		BListItem* item = CloneItem( IndexOf( (BListItem*)items.ItemAt( i ) ) );		if ( item && !clonedItems.AddItem( (void*)item ) )			delete item;	}	for ( int32 i = 0; BListItem* item = (BListItem*)clonedItems.ItemAt( i ); i++ )	{		if ( AddItem( item, index ) )		{			// after we're done, the newly inserted items will be selected			Select( index, true );			// next items will be inserted after this one			index++;		}		else			delete item;	}}/***************************************************************************** * DragSortableListView::RemoveItemList *****************************************************************************/voidDragSortableListView::RemoveItemList( BList& items ){	int32 count = items.CountItems();	for ( int32 i = 0; i < count; i++ )	{		BListItem* item = (BListItem*)items.ItemAt( i );		if ( RemoveItem( item ) )			delete item;	}}/***************************************************************************** * DragSortableListView::RemoveSelected *****************************************************************************/voidDragSortableListView::RemoveSelected(){	BList items;	for ( int32 i = 0; BListItem* item = ItemAt( CurrentSelection( i ) ); i++ )		items.AddItem( (void*)item );	RemoveItemList( items );}/***************************************************************************** * DragSortableListView::CountSelectedItems *****************************************************************************/int32DragSortableListView::CountSelectedItems() const{	int32 count = 0;	while ( CurrentSelection( count ) >= 0 )		count++;	return count;}/***************************************************************************** * DragSortableListView::_SetDropAnticipationRect *****************************************************************************/voidDragSortableListView::_SetDropAnticipationRect( BRect r ){	if ( fDropRect != r )	{		if ( fDropRect.IsValid() )			Invalidate( fDropRect );		fDropRect = r;		if ( fDropRect.IsValid() )			Invalidate( fDropRect );	}}/***************************************************************************** * DragSortableListView::_SetDropAnticipationRect *****************************************************************************/voidDragSortableListView::_SetDropIndex( int32 index ){	if ( fDropIndex != index )	{		fDropIndex = index;		if ( fDropIndex == -1 )			_SetDropAnticipationRect( BRect( 0.0, 0.0, -1.0, -1.0 ) );		else		{			int32 count = CountItems();			if ( fDropIndex == count )			{				BRect r;				if ( BListItem* item = ItemAt( count - 1 ) )				{					r = ItemFrame( count - 1 );					r.top = r.bottom + 1.0;					r.bottom = r.top + 1.0;				}				else				{					r = Bounds();					r.bottom--;	// compensate for scrollbars moved slightly out of window				}				_SetDropAnticipationRect( r );			}			else			{				BRect r = ItemFrame( fDropIndex );				r.bottom = r.top + 1.0;				_SetDropAnticipationRect( r );			}		}	}}/***************************************************************************** * DragSortableListView::_RemoveDropAnticipationRect *****************************************************************************/voidDragSortableListView::_RemoveDropAnticipationRect(){	_SetDropAnticipationRect( BRect( 0.0, 0.0, -1.0, -1.0 ) );	_SetDropIndex( -1 );}/***************************************************************************** * PlaylistView class *****************************************************************************/PlaylistView::PlaylistView( BRect frame, InterfaceWindow* mainWindow,                            VlcWrapper* wrapper,                            BMessage* selectionChangeMessage )	: DragSortableListView( frame, "playlist listview",							B_MULTIPLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES,							B_WILL_DRAW | B_NAVIGABLE | B_PULSE_NEEDED							| B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE ),	  fCurrentIndex( -1 ),	  fPlaying( false ),	  fDisplayMode( DISPLAY_PATH ),	  fMainWindow( mainWindow ),	  fSelectionChangeMessage( selectionChangeMessage ),	  fLastClickedItem( NULL ),	  fVlcWrapper( wrapper ){}PlaylistView::~PlaylistView(){	delete fSelectionChangeMessage;}/***************************************************************************** * PlaylistView::AttachedToWindow *****************************************************************************/voidPlaylistView::AttachedToWindow(){	// get pulse message every two frames	Window()->SetPulseRate( 80000 );}/***************************************************************************** * PlaylistView::MessageReceived *****************************************************************************/voidPlaylistView::MessageReceived( BMessage* message){	switch ( message->what )	{		case MSG_SOUNDPLAY:		case B_SIMPLE_DATA:			if ( message->HasPointer( "list" ) )			{				// message comes from ourself				DragSortableListView::MessageReceived( message );			}			else			{				// message comes from another app (for example Tracker)				message->AddInt32( "drop index", fDropIndex );				fMainWindow->PostMessage( message, fMainWindow );			}			break;		default:			DragSortableListView::MessageReceived( message );			break;	}}/***************************************************************************** * PlaylistView::MouseDown *****************************************************************************/voidPlaylistView::MouseDown( BPoint where ){	int32 clicks = 1;	Window()->CurrentMessage()->FindInt32( "clicks", &clicks );	bool handled = false;	for ( int32 i = 0; PlaylistItem* item = (PlaylistItem*)ItemAt( i ); i++ )	{		BRect r = ItemFrame( i );		if ( r.Contains( where ) )		{			if ( clicks == 2 )			{				// only do something if user clicked the same item twice				if ( fLastClickedItem == item )				{					fVlcWrapper->PlaylistJumpTo( i );					handled = true;				}			}			else			{				// remember last clicked item				fLastClickedItem = item;				if ( i == fCurrentIndex )				{					r.right = r.left + TEXT_OFFSET;					if ( r.Contains ( where ) )					{						fMainWindow->PostMessage( PAUSE_PLAYBACK );						InvalidateItem( i );						handled = true;					}				}			}			break;		}	}	if ( !handled )		DragSortableListView::MouseDown(where);}/***************************************************************************** * PlaylistView::KeyDown *****************************************************************************/void

⌨️ 快捷键说明

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