* ListViews.h: BeOS interface list view class implementation
*****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: ListViews.cpp,v 1.3 2003/02/01 12:01:11 stippi Exp $
+ * $Id: ListViews.cpp,v 1.6 2004/01/26 16:52:31 zorglub Exp $
*
* Authors: Stephan Aßmus <stippi@yellowbites.com>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#include <malloc.h>
#include <Bitmap.h>
+#include <Entry.h>
#include <String.h>
/* VLC headers */
* PlaylistItem class
*****************************************************************************/
PlaylistItem::PlaylistItem( const char *name )
- : BStringItem( name )
+ : BStringItem( name ),
+ fName( "" )
{
+ entry_ref ref;
+ if ( get_ref_for_path( name, &ref) == B_OK )
+ fName.SetTo( ref.name );
}
PlaylistItem::~PlaylistItem()
*****************************************************************************/
void
PlaylistItem::Draw( BView *owner, BRect frame, bool tintedLine,
- bool active, bool playing )
+ uint32 mode, bool active, bool playing )
{
rgb_color color = (rgb_color){ 255, 255, 255, 255 };
if ( tintedLine )
owner->SetHighColor( 0, 0, 0, 255 );
font_height fh;
owner->GetFontHeight( &fh );
- BString truncatedString( Text() );
+ const char* text = Text();
+ switch ( mode )
+ {
+ case DISPLAY_NAME:
+ if ( fName.CountChars() > 0 )
+ text = fName.String();
+ break;
+ case DISPLAY_PATH:
+ default:
+ break;
+ }
+ BString truncatedString( text );
owner->TruncateString( &truncatedString, B_TRUNCATE_MIDDLE,
frame.Width() - TEXT_OFFSET - 4.0 );
owner->DrawString( truncatedString.String(),
void
DragSortableListView::MouseMoved(BPoint where, uint32 transit, const BMessage *msg)
{
- if ( msg && msg->what == B_SIMPLE_DATA )
+ if ( msg && ( msg->what == B_SIMPLE_DATA || msg->what == MSG_SOUNDPLAY ) )
{
bool replaceAll = !msg->HasPointer("list") && !(modifiers() & B_SHIFT_KEY);
switch ( transit )
{
case B_ENTERED_VIEW:
+ // remember drag message
+ // this is needed to react on modifier changes
+ fDragMessageCopy = *msg;
case B_INSIDE_VIEW:
{
if ( replaceAll )
break;
}
case B_EXITED_VIEW:
+ // forget drag message
+ fDragMessageCopy.what = 0;
case B_OUTSIDE_VIEW:
_RemoveDropAnticipationRect();
break;
}
- // remember drag message
- // this is needed to react on modifier changes
- fDragMessageCopy = *msg;
}
else
{
_RemoveDropAnticipationRect();
BListView::MouseMoved(where, transit, msg);
+ fDragMessageCopy.what = 0;
}
}
{
// 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 );
}
RemoveItemList( items );
}
+/*****************************************************************************
+ * DragSortableListView::CountSelectedItems
+ *****************************************************************************/
+int32
+DragSortableListView::CountSelectedItems() const
+{
+ int32 count = 0;
+ while ( CurrentSelection( count ) >= 0 )
+ count++;
+ return count;
+}
+
/*****************************************************************************
* DragSortableListView::_SetDropAnticipationRect
*****************************************************************************/
| B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE ),
fCurrentIndex( -1 ),
fPlaying( false ),
+ fDisplayMode( DISPLAY_PATH ),
fMainWindow( mainWindow ),
fSelectionChangeMessage( selectionChangeMessage ),
+ fLastClickedItem( NULL ),
fVlcWrapper( wrapper )
{
}
{
switch ( message->what )
{
+ case MSG_SOUNDPLAY:
case B_SIMPLE_DATA:
if ( message->HasPointer( "list" ) )
{
{
if ( clicks == 2 )
{
- fVlcWrapper->PlaylistJumpTo( i );
- handled = true;
+ // only do something if user clicked the same item twice
+ if ( fLastClickedItem == item )
+ {
+ fVlcWrapper->PlaylistJumpTo( i );
+ handled = true;
+ }
}
- else if ( i == fCurrentIndex )
+ else
{
- r.right = r.left + TEXT_OFFSET;
- if ( r.Contains ( where ) )
+ // remember last clicked item
+ fLastClickedItem = item;
+ if ( i == fCurrentIndex )
{
- fMainWindow->PostMessage( PAUSE_PLAYBACK );
- InvalidateItem( i );
- handled = true;
+ r.right = r.left + TEXT_OFFSET;
+ if ( r.Contains ( where ) )
+ {
+ fMainWindow->PostMessage( PAUSE_PLAYBACK );
+ InvalidateItem( i );
+ handled = true;
+ }
}
}
break;
int32 count = items.CountItems();
int32 indexOriginal = index;
// remember currently playing item
- int32 currentIndex, size;
- fVlcWrapper->GetPlaylistInfo( currentIndex, size );
- BListItem* playingItem = ItemAt( currentIndex );
+ BListItem* playingItem = _PlayingItem();
// collect item pointers for removal by index
for ( int32 i = 0; i < count; i++ )
{
// update GUI
DragSortableListView::MoveItems( items, indexOriginal );
// restore currently playing item
- for ( int32 i = 0; BListItem* item = ItemAt( i ); i++ )
- {
- if ( item == playingItem )
- {
- fVlcWrapper->PlaylistSetPlaying( i );
- SetCurrent( i );
- break;
- }
- }
+ _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();
}
}
BList clonedItems;
int32 count = items.CountItems();
// remember currently playing item
- int32 currentIndex, size;
- fVlcWrapper->GetPlaylistInfo( currentIndex, size );
- BListItem* playingItem = ItemAt( currentIndex );
+ BListItem* playingItem = _PlayingItem();
// collect cloned item pointers
for ( int32 i = 0; i < count; i++ )
{
// update GUI
DragSortableListView::CopyItems( items, toIndex );
// restore currently playing item
- for ( int32 i = 0; BListItem* item = ItemAt( i ); i++ )
- {
- if ( item == playingItem )
- {
- fVlcWrapper->PlaylistSetPlaying( i );
- SetCurrent( i );
- break;
- }
- }
+ _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();
}
}
{
if ( fVlcWrapper->PlaylistLock() )
{
+ // remember currently playing item
+ BListItem* playingItem = _PlayingItem();
// collect item pointers for removal
BList removeItems;
int32 count = items.CountItems();
}
// 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::DrawListItem( BView* owner, int32 index, BRect frame ) const
{
if ( PlaylistItem* item = dynamic_cast<PlaylistItem*>( ItemAt( index ) ) )
- item->Draw( owner, frame, index % 2, index == fCurrentIndex, fPlaying );
+ item->Draw( owner, frame, index % 2,
+ fDisplayMode, index == fCurrentIndex, fPlaying );
}
/*****************************************************************************
message->AddPointer( "list", (void*)this );
int32 index;
for ( int32 i = 0; ( index = CurrentSelection( i ) ) >= 0; i++ )
+ {
message->AddInt32( "index", index );
- // TODO: add refs to message (inter application communication)
+ // 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 );
+ }
+ }
}
}
for ( int i = 0; i < fVlcWrapper->PlaylistSize(); i++ )
AddItem( new PlaylistItem( fVlcWrapper->PlaylistItemName( i ) ) );
}
+
+
+/*****************************************************************************
+ * PlaylistView::SortReverse
+ *****************************************************************************/
+void
+PlaylistView::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
+ *****************************************************************************/
+void
+PlaylistView::SortByPath()
+{
+
+}
+
+/*****************************************************************************
+ * PlaylistView::SortByName
+ *****************************************************************************/
+void
+PlaylistView::SortByName()
+{
+}
+
+/*****************************************************************************
+ * PlaylistView::SetDisplayMode
+ *****************************************************************************/
+void
+PlaylistView::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
+ *****************************************************************************/
+void
+PlaylistView::_SetPlayingIndex( BListItem* playingItem )
+{
+ for ( int32 i = 0; BListItem* item = ItemAt( i ); i++ )
+ {
+ if ( item == playingItem )
+ {
+ fVlcWrapper->PlaylistSetPlaying( i );
+ SetCurrent( i );
+ break;
+ }
+ }
+}