1 /*****************************************************************************
2 * ListViews.h: BeOS interface list view class implementation
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: ListViews.cpp,v 1.5 2003/02/03 17:18:48 stippi Exp $
7 * Authors: Stephan Aßmus <stippi@yellowbites.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
35 #include "VlcWrapper.h"
36 #include "InterfaceWindow.h"
37 #include "ListViews.h"
40 #define MAX_DRAG_HEIGHT 200.0
42 #define TEXT_OFFSET 20.0
44 /*****************************************************************************
46 *****************************************************************************/
47 PlaylistItem::PlaylistItem( const char *name )
48 : BStringItem( name ),
52 if ( get_ref_for_path( name, &ref) == B_OK )
53 fName.SetTo( ref.name );
56 PlaylistItem::~PlaylistItem()
60 /*****************************************************************************
61 * PlaylistItem::DrawItem
62 *****************************************************************************/
64 PlaylistItem::Draw( BView *owner, BRect frame, bool tintedLine,
65 uint32 mode, bool active, bool playing )
67 rgb_color color = (rgb_color){ 255, 255, 255, 255 };
69 color = tint_color( color, 1.04 );
72 color = tint_color( color, B_DARKEN_2_TINT );
73 owner->SetLowColor( color );
74 owner->FillRect( frame, B_SOLID_LOW );
76 owner->SetHighColor( 0, 0, 0, 255 );
78 owner->GetFontHeight( &fh );
79 const char* text = Text();
83 if ( fName.CountChars() > 0 )
84 text = fName.String();
90 BString truncatedString( text );
91 owner->TruncateString( &truncatedString, B_TRUNCATE_MIDDLE,
92 frame.Width() - TEXT_OFFSET - 4.0 );
93 owner->DrawString( truncatedString.String(),
94 BPoint( frame.left + TEXT_OFFSET,
95 frame.top + fh.ascent + 1.0 ) );
99 rgb_color black = (rgb_color){ 0, 0, 0, 255 };
100 rgb_color green = (rgb_color){ 0, 255, 0, 255 };
101 BRect r( 0.0, 0.0, 10.0, 10.0 );
102 r.OffsetTo( frame.left + 4.0,
103 ceilf( ( frame.top + frame.bottom ) / 2.0 ) - 5.0 );
105 green = tint_color( color, B_DARKEN_1_TINT );
106 rgb_color lightGreen = tint_color( green, B_LIGHTEN_2_TINT );
107 rgb_color darkGreen = tint_color( green, B_DARKEN_2_TINT );
109 arrow[0] = r.LeftTop();
110 arrow[1] = r.LeftBottom();
111 arrow[2].x = r.right;
112 arrow[2].y = ( r.top + r.bottom ) / 2.0;
113 owner->BeginLineArray( 6 );
115 owner->AddLine( arrow[0], arrow[1], black );
116 owner->AddLine( BPoint( arrow[1].x + 1.0, arrow[1].y - 1.0 ),
118 owner->AddLine( arrow[0], arrow[2], black );
125 // highlights and shadow
126 owner->AddLine( arrow[1], arrow[2], darkGreen );
127 owner->AddLine( arrow[0], arrow[2], lightGreen );
128 owner->AddLine( arrow[0], arrow[1], lightGreen );
129 owner->EndLineArray();
136 owner->SetHighColor( green );
137 owner->FillPolygon( arrow, 3 );
141 /*****************************************************************************
142 * DragSortableListView class
143 *****************************************************************************/
144 DragSortableListView::DragSortableListView( BRect frame, const char* name,
145 list_view_type type, uint32 resizingMode,
147 : BListView( frame, name, type, resizingMode, flags ),
148 fDropRect( 0.0, 0.0, -1.0, -1.0 ),
151 SetViewColor( B_TRANSPARENT_32_BIT );
154 DragSortableListView::~DragSortableListView()
158 /*****************************************************************************
159 * DragSortableListView::Draw
160 *****************************************************************************/
162 DragSortableListView::Draw( BRect updateRect )
164 int32 firstIndex = IndexOf( updateRect.LeftTop() );
165 int32 lastIndex = IndexOf( updateRect.RightBottom() );
166 if ( firstIndex >= 0 )
168 if ( lastIndex < firstIndex )
169 lastIndex = CountItems() - 1;
170 // update rect contains items
171 BRect r( updateRect );
172 for ( int32 i = firstIndex; i <= lastIndex; i++)
175 DrawListItem( this, i, r );
177 updateRect.top = r.bottom + 1.0;
178 if ( updateRect.IsValid() )
180 SetLowColor( 255, 255, 255, 255 );
181 FillRect( updateRect, B_SOLID_LOW );
186 SetLowColor( 255, 255, 255, 255 );
187 FillRect( updateRect, B_SOLID_LOW );
189 // drop anticipation indication
190 if ( fDropRect.IsValid() )
192 SetHighColor( 255, 0, 0, 255 );
193 StrokeRect( fDropRect );
197 /*****************************************************************************
198 * DragSortableListView::InitiateDrag
199 *****************************************************************************/
201 DragSortableListView::InitiateDrag( BPoint point, int32 index, bool )
203 bool success = false;
204 BListItem* item = ItemAt( CurrentSelection( 0 ) );
207 // workarround a timing problem
209 item = ItemAt( index );
213 // create drag message
214 BMessage msg( B_SIMPLE_DATA );
215 MakeDragMessage( &msg );
216 // figure out drag rect
217 float width = Bounds().Width();
218 BRect dragRect(0.0, 0.0, width, -1.0);
219 // figure out, how many items fit into our bitmap
222 for (numItems = 0; BListItem* item = ItemAt( CurrentSelection( numItems ) ); numItems++) {
223 dragRect.bottom += ceilf( item->Height() ) + 1.0;
224 if ( dragRect.Height() > MAX_DRAG_HEIGHT ) {
226 dragRect.bottom = MAX_DRAG_HEIGHT;
231 BBitmap* dragBitmap = new BBitmap( dragRect, B_RGB32, true );
232 if ( dragBitmap && dragBitmap->IsValid() ) {
233 if ( BView *v = new BView( dragBitmap->Bounds(), "helper", B_FOLLOW_NONE, B_WILL_DRAW ) ) {
234 dragBitmap->AddChild( v );
236 BRect itemBounds( dragRect) ;
237 itemBounds.bottom = 0.0;
238 // let all selected items, that fit into our drag_bitmap, draw
239 for ( int32 i = 0; i < numItems; i++ ) {
240 int32 index = CurrentSelection( i );
241 BListItem* item = ItemAt( index );
242 itemBounds.bottom = itemBounds.top + ceilf( item->Height() );
243 if ( itemBounds.bottom > dragRect.bottom )
244 itemBounds.bottom = dragRect.bottom;
245 DrawListItem( v, index, itemBounds );
246 itemBounds.top = itemBounds.bottom + 1.0;
248 // make a black frame arround the edge
249 v->SetHighColor( 0, 0, 0, 255 );
250 v->StrokeRect( v->Bounds() );
253 uint8 *bits = (uint8 *)dragBitmap->Bits();
254 int32 height = (int32)dragBitmap->Bounds().Height() + 1;
255 int32 width = (int32)dragBitmap->Bounds().Width() + 1;
256 int32 bpr = dragBitmap->BytesPerRow();
259 for ( int32 y = 0; y < height - ALPHA / 2; y++, bits += bpr ) {
260 uint8 *line = bits + 3;
261 for (uint8 *end = line + 4 * width; line < end; line += 4)
264 for ( int32 y = height - ALPHA / 2; y < height; y++, bits += bpr ) {
265 uint8 *line = bits + 3;
266 for (uint8 *end = line + 4 * width; line < end; line += 4)
267 *line = (height - y) << 1;
270 for ( int32 y = 0; y < height; y++, bits += bpr ) {
271 uint8 *line = bits + 3;
272 for (uint8 *end = line + 4 * width; line < end; line += 4)
276 dragBitmap->Unlock();
281 DragMessage( &msg, dragBitmap, B_OP_ALPHA, BPoint( 0.0, 0.0 ) );
284 DragMessage( &msg, dragRect.OffsetToCopy( point ), this );
290 /*****************************************************************************
291 * DragSortableListView::WindowActivated
292 *****************************************************************************/
294 DragSortableListView::WindowActivated( bool active )
296 // workarround for buggy focus indication of BScrollView
297 if ( BView* view = Parent() )
301 /*****************************************************************************
302 * DragSortableListView::MessageReceived
303 *****************************************************************************/
305 DragSortableListView::MessageReceived(BMessage* message)
307 switch ( message->what )
309 case B_MODIFIERS_CHANGED:
314 DragSortableListView *list = NULL;
315 if ( message->FindPointer( "list", (void **)&list ) == B_OK
318 int32 count = CountItems();
319 if ( fDropIndex < 0 || fDropIndex > count )
323 for ( int32 i = 0; message->FindInt32( "index", i, &index ) == B_OK; i++ )
324 if ( BListItem* item = ItemAt(index) )
325 items.AddItem( (void*)item );
326 if ( items.CountItems() > 0 )
328 if ( modifiers() & B_SHIFT_KEY )
329 CopyItems( items, fDropIndex );
331 MoveItems( items, fDropIndex );
338 BListView::MessageReceived( message );
343 /*****************************************************************************
344 * DragSortableListView::MouseMoved
345 *****************************************************************************/
347 DragSortableListView::MouseMoved(BPoint where, uint32 transit, const BMessage *msg)
349 if ( msg && ( msg->what == B_SIMPLE_DATA || msg->what == MSG_SOUNDPLAY ) )
351 bool replaceAll = !msg->HasPointer("list") && !(modifiers() & B_SHIFT_KEY);
355 // remember drag message
356 // this is needed to react on modifier changes
357 fDragMessageCopy = *msg;
363 r.bottom--; // compensate for scrollbar offset
364 _SetDropAnticipationRect( r );
369 // offset where by half of item height
370 BRect r( ItemFrame( 0 ) );
371 where.y += r.Height() / 2.0;
373 int32 index = IndexOf( where );
375 index = CountItems();
376 _SetDropIndex( index );
381 // forget drag message
382 fDragMessageCopy.what = 0;
384 _RemoveDropAnticipationRect();
390 _RemoveDropAnticipationRect();
391 BListView::MouseMoved(where, transit, msg);
392 fDragMessageCopy.what = 0;
396 /*****************************************************************************
397 * DragSortableListView::MouseUp
398 *****************************************************************************/
400 DragSortableListView::MouseUp( BPoint where )
403 _SetDropAnticipationRect( BRect( 0.0, 0.0, -1.0, -1.0 ) );
404 // be sure to forget drag message
405 fDragMessageCopy.what = 0;
406 BListView::MouseUp( where );
409 /*****************************************************************************
410 * DragSortableListView::DrawItem
411 *****************************************************************************/
413 DragSortableListView::DrawItem( BListItem *item, BRect itemFrame, bool complete )
415 DrawListItem( this, IndexOf( item ), itemFrame );
418 /*****************************************************************************
419 * DragSortableListView::ModifiersChaned
420 *****************************************************************************/
422 DragSortableListView::ModifiersChanged()
426 GetMouse( &where, &buttons, false );
427 uint32 transit = Bounds().Contains( where ) ? B_INSIDE_VIEW : B_OUTSIDE_VIEW;
428 MouseMoved( where, transit, &fDragMessageCopy );
431 /*****************************************************************************
432 * DragSortableListView::MoveItems
433 *****************************************************************************/
435 DragSortableListView::MoveItems( BList& items, int32 index )
438 // we remove the items while we look at them, the insertion index is decreased
439 // when the items index is lower, so that we insert at the right spot after
442 int32 count = items.CountItems();
443 for ( int32 i = 0; i < count; i++ )
445 BListItem* item = (BListItem*)items.ItemAt( i );
446 int32 removeIndex = IndexOf( item );
447 if ( RemoveItem( item ) && removedItems.AddItem( (void*)item ) )
449 if ( removeIndex < index )
452 // else ??? -> blow up
454 for ( int32 i = 0; BListItem* item = (BListItem*)removedItems.ItemAt( i ); i++ )
456 if ( AddItem( item, index ) )
458 // after we're done, the newly inserted items will be selected
459 Select( index, true );
460 // next items will be inserted after this one
468 /*****************************************************************************
469 * DragSortableListView::CopyItems
470 *****************************************************************************/
472 DragSortableListView::CopyItems( BList& items, int32 index )
475 // by inserting the items after we copied all items first, we avoid
476 // cloning an item we already inserted and messing everything up
477 // in other words, don't touch the list before we know which items
480 int32 count = items.CountItems();
481 for ( int32 i = 0; i < count; i++ )
483 BListItem* item = CloneItem( IndexOf( (BListItem*)items.ItemAt( i ) ) );
484 if ( item && !clonedItems.AddItem( (void*)item ) )
487 for ( int32 i = 0; BListItem* item = (BListItem*)clonedItems.ItemAt( i ); i++ )
489 if ( AddItem( item, index ) )
491 // after we're done, the newly inserted items will be selected
492 Select( index, true );
493 // next items will be inserted after this one
501 /*****************************************************************************
502 * DragSortableListView::RemoveItemList
503 *****************************************************************************/
505 DragSortableListView::RemoveItemList( BList& items )
507 int32 count = items.CountItems();
508 for ( int32 i = 0; i < count; i++ )
510 BListItem* item = (BListItem*)items.ItemAt( i );
511 if ( RemoveItem( item ) )
516 /*****************************************************************************
517 * DragSortableListView::RemoveSelected
518 *****************************************************************************/
520 DragSortableListView::RemoveSelected()
523 for ( int32 i = 0; BListItem* item = ItemAt( CurrentSelection( i ) ); i++ )
524 items.AddItem( (void*)item );
525 RemoveItemList( items );
528 /*****************************************************************************
529 * DragSortableListView::CountSelectedItems
530 *****************************************************************************/
532 DragSortableListView::CountSelectedItems() const
535 while ( CurrentSelection( count ) >= 0 )
540 /*****************************************************************************
541 * DragSortableListView::_SetDropAnticipationRect
542 *****************************************************************************/
544 DragSortableListView::_SetDropAnticipationRect( BRect r )
546 if ( fDropRect != r )
548 if ( fDropRect.IsValid() )
549 Invalidate( fDropRect );
551 if ( fDropRect.IsValid() )
552 Invalidate( fDropRect );
556 /*****************************************************************************
557 * DragSortableListView::_SetDropAnticipationRect
558 *****************************************************************************/
560 DragSortableListView::_SetDropIndex( int32 index )
562 if ( fDropIndex != index )
565 if ( fDropIndex == -1 )
566 _SetDropAnticipationRect( BRect( 0.0, 0.0, -1.0, -1.0 ) );
569 int32 count = CountItems();
570 if ( fDropIndex == count )
573 if ( BListItem* item = ItemAt( count - 1 ) )
575 r = ItemFrame( count - 1 );
576 r.top = r.bottom + 1.0;
577 r.bottom = r.top + 1.0;
582 r.bottom--; // compensate for scrollbars moved slightly out of window
584 _SetDropAnticipationRect( r );
588 BRect r = ItemFrame( fDropIndex );
589 r.bottom = r.top + 1.0;
590 _SetDropAnticipationRect( r );
596 /*****************************************************************************
597 * DragSortableListView::_RemoveDropAnticipationRect
598 *****************************************************************************/
600 DragSortableListView::_RemoveDropAnticipationRect()
602 _SetDropAnticipationRect( BRect( 0.0, 0.0, -1.0, -1.0 ) );
607 /*****************************************************************************
609 *****************************************************************************/
610 PlaylistView::PlaylistView( BRect frame, InterfaceWindow* mainWindow,
612 BMessage* selectionChangeMessage )
613 : DragSortableListView( frame, "playlist listview",
614 B_MULTIPLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES,
615 B_WILL_DRAW | B_NAVIGABLE | B_PULSE_NEEDED
616 | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE ),
619 fDisplayMode( DISPLAY_PATH ),
620 fMainWindow( mainWindow ),
621 fSelectionChangeMessage( selectionChangeMessage ),
622 fLastClickedItem( NULL ),
623 fVlcWrapper( wrapper )
627 PlaylistView::~PlaylistView()
629 delete fSelectionChangeMessage;
632 /*****************************************************************************
633 * PlaylistView::AttachedToWindow
634 *****************************************************************************/
636 PlaylistView::AttachedToWindow()
638 // get pulse message every two frames
639 Window()->SetPulseRate( 80000 );
642 /*****************************************************************************
643 * PlaylistView::MessageReceived
644 *****************************************************************************/
646 PlaylistView::MessageReceived( BMessage* message)
648 switch ( message->what )
652 if ( message->HasPointer( "list" ) )
654 // message comes from ourself
655 DragSortableListView::MessageReceived( message );
659 // message comes from another app (for example Tracker)
660 message->AddInt32( "drop index", fDropIndex );
661 fMainWindow->PostMessage( message, fMainWindow );
665 DragSortableListView::MessageReceived( message );
670 /*****************************************************************************
671 * PlaylistView::MouseDown
672 *****************************************************************************/
674 PlaylistView::MouseDown( BPoint where )
677 Window()->CurrentMessage()->FindInt32( "clicks", &clicks );
678 bool handled = false;
679 for ( int32 i = 0; PlaylistItem* item = (PlaylistItem*)ItemAt( i ); i++ )
681 BRect r = ItemFrame( i );
682 if ( r.Contains( where ) )
686 // only do something if user clicked the same item twice
687 if ( fLastClickedItem == item )
689 fVlcWrapper->PlaylistJumpTo( i );
695 // remember last clicked item
696 fLastClickedItem = item;
697 if ( i == fCurrentIndex )
699 r.right = r.left + TEXT_OFFSET;
700 if ( r.Contains ( where ) )
702 fMainWindow->PostMessage( PAUSE_PLAYBACK );
712 DragSortableListView::MouseDown(where);
715 /*****************************************************************************
716 * PlaylistView::KeyDown
717 *****************************************************************************/
719 PlaylistView::KeyDown( const char* bytes, int32 numBytes )
724 if ( ( bytes[0] == B_BACKSPACE ) || ( bytes[0] == B_DELETE ) )
728 DragSortableListView::KeyDown( bytes, numBytes );
731 /*****************************************************************************
732 * PlaylistView::Pulse
733 *****************************************************************************/
735 PlaylistView::Pulse()
737 if ( fMainWindow->IsStopped() )
741 /*****************************************************************************
742 * PlaylistView::SelectionChanged
743 *****************************************************************************/
745 PlaylistView::SelectionChanged()
747 BLooper* looper = Looper();
748 if ( fSelectionChangeMessage && looper )
750 BMessage message( *fSelectionChangeMessage );
751 looper->PostMessage( &message );
756 /*****************************************************************************
757 * PlaylistView::MoveItems
758 *****************************************************************************/
760 PlaylistView::MoveItems( BList& items, int32 index )
763 // we remove the items while we look at them, the insertion index is decreased
764 // when the items index is lower, so that we insert at the right spot after
766 if ( fVlcWrapper->PlaylistLock() )
770 int32 count = items.CountItems();
771 int32 indexOriginal = index;
772 // remember currently playing item
773 BListItem* playingItem = _PlayingItem();
774 // collect item pointers for removal by index
775 for ( int32 i = 0; i < count; i++ )
777 int32 removeIndex = IndexOf( (BListItem*)items.ItemAt( i ) );
778 void* item = fVlcWrapper->PlaylistItemAt( removeIndex );
779 if ( item && removeItems.AddItem( item ) )
781 if ( removeIndex < index )
784 // else ??? -> blow up
786 // actually remove items using pointers
787 for ( int32 i = 0; i < count; i++ )
789 void* item = fVlcWrapper->PlaylistRemoveItem( removeItems.ItemAt( i ) );
790 if ( item && !removedItems.AddItem( item ) )
793 // add items at index
794 for ( int32 i = 0; void* item = removedItems.ItemAt( i ); i++ )
796 if ( fVlcWrapper->PlaylistAddItem( item, index ) )
797 // next items will be inserted after this one
803 DragSortableListView::MoveItems( items, indexOriginal );
804 // restore currently playing item
805 _SetPlayingIndex( playingItem );
806 // update interface (in case it isn't playing,
807 // there is a chance that it needs to update)
808 fMainWindow->PostMessage( MSG_UPDATE );
809 fVlcWrapper->PlaylistUnlock();
813 /*****************************************************************************
814 * PlaylistView::CopyItems
815 *****************************************************************************/
817 PlaylistView::CopyItems( BList& items, int32 toIndex )
820 // we remove the items while we look at them, the insertion index is decreased
821 // when the items index is lower, so that we insert at the right spot after
823 if ( fVlcWrapper->PlaylistLock() )
826 int32 count = items.CountItems();
827 // remember currently playing item
828 BListItem* playingItem = _PlayingItem();
829 // collect cloned item pointers
830 for ( int32 i = 0; i < count; i++ )
832 int32 index = IndexOf( (BListItem*)items.ItemAt( i ) );
833 void* item = fVlcWrapper->PlaylistItemAt( index );
834 void* cloned = fVlcWrapper->PlaylistCloneItem( item );
835 if ( cloned && !clonedItems.AddItem( cloned ) )
839 // add cloned items at index
840 int32 index = toIndex;
841 for ( int32 i = 0; void* item = clonedItems.ItemAt( i ); i++ )
843 if ( fVlcWrapper->PlaylistAddItem( item, index ) )
844 // next items will be inserted after this one
850 DragSortableListView::CopyItems( items, toIndex );
851 // restore currently playing item
852 _SetPlayingIndex( playingItem );
853 // update interface (in case it isn't playing,
854 // there is a chance that it needs to update)
855 fMainWindow->PostMessage( MSG_UPDATE );
856 fVlcWrapper->PlaylistUnlock();
860 /*****************************************************************************
861 * PlaylistView::RemoveItemList
862 *****************************************************************************/
864 PlaylistView::RemoveItemList( BList& items )
866 if ( fVlcWrapper->PlaylistLock() )
868 // remember currently playing item
869 BListItem* playingItem = _PlayingItem();
870 // collect item pointers for removal
872 int32 count = items.CountItems();
873 for ( int32 i = 0; i < count; i++ )
875 int32 index = IndexOf( (BListItem*)items.ItemAt( i ) );
876 void* item = fVlcWrapper->PlaylistItemAt( index );
877 if ( item && !removeItems.AddItem( item ) )
880 // remove items from playlist
881 count = removeItems.CountItems();
882 for ( int32 i = 0; void* item = removeItems.ItemAt( i ); i++ )
884 fVlcWrapper->PlaylistRemoveItem( item );
887 DragSortableListView::RemoveItemList( items );
888 // restore currently playing item
889 _SetPlayingIndex( playingItem );
890 // update interface (in case it isn't playing,
891 // there is a chance that it needs to update)
892 fMainWindow->PostMessage( MSG_UPDATE );
893 fVlcWrapper->PlaylistUnlock();
897 /*****************************************************************************
898 * PlaylistView::CloneItem
899 *****************************************************************************/
901 PlaylistView::CloneItem( int32 atIndex ) const
903 BListItem* clone = NULL;
904 if ( PlaylistItem* item = dynamic_cast<PlaylistItem*>( ItemAt( atIndex ) ) )
905 clone = new PlaylistItem( item->Text() );
909 /*****************************************************************************
910 * PlaylistView::DrawListItem
911 *****************************************************************************/
913 PlaylistView::DrawListItem( BView* owner, int32 index, BRect frame ) const
915 if ( PlaylistItem* item = dynamic_cast<PlaylistItem*>( ItemAt( index ) ) )
916 item->Draw( owner, frame, index % 2,
917 fDisplayMode, index == fCurrentIndex, fPlaying );
920 /*****************************************************************************
921 * PlaylistView::MakeDragMessage
922 *****************************************************************************/
924 PlaylistView::MakeDragMessage( BMessage* message ) const
928 message->AddPointer( "list", (void*)this );
930 for ( int32 i = 0; ( index = CurrentSelection( i ) ) >= 0; i++ )
932 message->AddInt32( "index", index );
933 // add refs to message (inter application communication)
934 if ( BStringItem* item = dynamic_cast<BStringItem*>( ItemAt( index ) ) )
937 if ( get_ref_for_path( item->Text(), &ref ) == B_OK )
938 message->AddRef( "refs", &ref );
944 /*****************************************************************************
945 * PlaylistView::SetCurrent
946 *****************************************************************************/
948 PlaylistView::SetCurrent( int32 index )
950 if ( fCurrentIndex != index )
952 InvalidateItem( fCurrentIndex );
953 fCurrentIndex = index;
954 InvalidateItem( fCurrentIndex );
958 /*****************************************************************************
959 * PlaylistView::SetPlaying
960 *****************************************************************************/
962 PlaylistView::SetPlaying( bool playing )
964 if ( fPlaying != playing )
967 InvalidateItem( fCurrentIndex );
971 /*****************************************************************************
972 * PlaylistView::SetPlaying
973 *****************************************************************************/
975 PlaylistView::RebuildList()
978 int32 count = CountItems();
979 while ( BListItem* item = RemoveItem( --count ) )
982 // rebuild listview from VLC's playlist
983 for ( int i = 0; i < fVlcWrapper->PlaylistSize(); i++ )
984 AddItem( new PlaylistItem( fVlcWrapper->PlaylistItemName( i ) ) );
988 /*****************************************************************************
989 * PlaylistView::SortReverse
990 *****************************************************************************/
992 PlaylistView::SortReverse()
994 if ( int32 count = CountSelectedItems() )
996 int32 last = count - 1;
997 // remember currently playing item
998 BListItem* playingItem = _PlayingItem();
999 for ( int32 first = 0; first < count / 2; first++, last-- )
1001 int32 index1 = CurrentSelection( first);
1002 int32 index2 = CurrentSelection( last);
1003 if ( SwapItems( index1, index2 ) )
1005 // index2 > index1, so the list won't get messed up
1006 // if we remove the items in that order
1007 // TODO: Error checking + handling!
1008 void* item2 = fVlcWrapper->PlaylistRemoveItem( index2 );
1009 void* item1 = fVlcWrapper->PlaylistRemoveItem( index1 );
1010 fVlcWrapper->PlaylistAddItem( item2, index1 );
1011 fVlcWrapper->PlaylistAddItem( item1, index2 );
1014 // restore currently playing item
1015 _SetPlayingIndex( playingItem );
1019 /*****************************************************************************
1020 * PlaylistView::SortByPath
1021 *****************************************************************************/
1023 PlaylistView::SortByPath()
1028 /*****************************************************************************
1029 * PlaylistView::SortByName
1030 *****************************************************************************/
1032 PlaylistView::SortByName()
1036 /*****************************************************************************
1037 * PlaylistView::SetDisplayMode
1038 *****************************************************************************/
1040 PlaylistView::SetDisplayMode( uint32 mode )
1042 if ( mode != fDisplayMode )
1044 fDisplayMode = mode;
1049 /*****************************************************************************
1050 * PlaylistView::_PlayingItem
1051 *****************************************************************************/
1053 PlaylistView::_PlayingItem() const
1055 int32 currentIndex, size;
1056 fVlcWrapper->GetPlaylistInfo( currentIndex, size );
1057 return ItemAt( currentIndex );
1060 /*****************************************************************************
1061 * PlaylistView::_SetPlayingIndex
1062 *****************************************************************************/
1064 PlaylistView::_SetPlayingIndex( BListItem* playingItem )
1066 for ( int32 i = 0; BListItem* item = ItemAt( i ); i++ )
1068 if ( item == playingItem )
1070 fVlcWrapper->PlaylistSetPlaying( i );