📄 listviews.cpp
字号:
} 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( intf_thread_t * _p_intf, BRect frame, InterfaceWindow* mainWindow, 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 ), p_intf( _p_intf ), fCurrentIndex( -1 ), fPlaying( false ), fDisplayMode( DISPLAY_PATH ), fMainWindow( mainWindow ), fSelectionChangeMessage( selectionChangeMessage ), fLastClickedItem( NULL ){}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 ) { playlist_t * p_playlist; p_playlist = (playlist_t *) vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist ) { playlist_Goto( p_playlist, i ); vlc_object_release( p_playlist ); } 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 *****************************************************************************/voidPlaylistView::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 *****************************************************************************/void
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -