Commit 7314de69 authored by hartman's avatar hartman

* src/playlist/playlist.c:

  - added playlist_Move to move an item in our playlist before the position
    of a previous item (or end) of our playlist. Keeps index at it's current
    item.
* modules/gui/macosx/playlist.?:
  - Now a reorderable playlist. Thanks to Andrew Stone for example code.
    This fixes #349 (Finally ;)
  - True alternating colors in the playlistview. Thanks to Apple Computer
    for the example code.
parent 453fe58a
......@@ -2,7 +2,7 @@
* vlc_playlist.h : Playlist functions
*****************************************************************************
* Copyright (C) 1999, 2000, 2001, 2002 VideoLAN
* $Id: vlc_playlist.h,v 1.8 2003/01/29 11:34:11 jlj Exp $
* $Id: vlc_playlist.h,v 1.9 2003/03/17 17:10:21 hartman Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -79,6 +79,7 @@ VLC_EXPORT( void, playlist_Command, ( playlist_t *, int, int ) );
VLC_EXPORT( int, playlist_Add, ( playlist_t *, const char *, int, int ) );
VLC_EXPORT( int, playlist_AddItem, ( playlist_t *, playlist_item_t *, int, int ) );
VLC_EXPORT( int, playlist_Delete, ( playlist_t *, int ) );
VLC_EXPORT( int, playlist_Move, ( playlist_t *, int, int ) );
VLC_EXPORT( int, playlist_LoadFile, ( playlist_t *, const char * ) );
VLC_EXPORT( int, playlist_SaveFile, ( playlist_t *, const char * ) );
......
......@@ -2,7 +2,7 @@
* playlist.h: MacOS X interface plugin
*****************************************************************************
* Copyright (C) 2002-2003 VideoLAN
* $Id: playlist.h,v 1.6 2003/02/23 05:53:53 jlj Exp $
* $Id: playlist.h,v 1.7 2003/03/17 17:10:21 hartman Exp $
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
* Derk-Jan Hartman <thedj@users.sourceforge.net>
......@@ -27,9 +27,10 @@
*****************************************************************************/
@interface VLCPlaylistView : NSTableView
{
}
- (void) drawStripesInRect:(NSRect)clipRect;
@end
/*****************************************************************************
......@@ -60,4 +61,4 @@
- (void)updateRowSelection;
- (void)playlistUpdated;
@end
@end
\ No newline at end of file
......@@ -2,10 +2,16 @@
* playlist.m: MacOS X interface plugin
*****************************************************************************
* Copyright (C) 2002-2003 VideoLAN
* $Id: playlist.m,v 1.14 2003/03/06 15:24:12 hartman Exp $
* $Id: playlist.m,v 1.15 2003/03/17 17:10:21 hartman Exp $
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
* Derk-Jan Hartman <thedj@users.sourceforge.net>
* Thanks: Andrew Stone for documenting the row reordering methods on the net
* http://www.omnigroup.com/mailman/archive/macosx-dev/
* 2001-January/008195.html
* Apple Computer for documenting the Alternating row colors
* http://developer.apple.com/samplecode/Sample_Code/Cocoa/
* MP3_Player/MyTableView.m.htm
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -32,6 +38,12 @@
#include "intf.h"
#include "playlist.h"
// RGB values for stripe color (light blue)
#define STRIPE_RED (237.0 / 255.0)
#define STRIPE_GREEN (243.0 / 255.0)
#define STRIPE_BLUE (254.0 / 255.0)
static NSColor *sStripeColor = nil;
/*****************************************************************************
* VLCPlaylistView implementation
*****************************************************************************/
......@@ -102,6 +114,41 @@
}
}
/* This is called after the table background is filled in, but before the cell contents are drawn.
* We override it so we can do our own light-blue row stripes a la iTunes.
*/
- (void) highlightSelectionInClipRect:(NSRect)rect {
[self drawStripesInRect:rect];
[super highlightSelectionInClipRect:rect];
}
/* This routine does the actual blue stripe drawing, filling in every other row of the table
* with a blue background so you can follow the rows easier with your eyes.
*/
- (void) drawStripesInRect:(NSRect)clipRect {
NSRect stripeRect;
float fullRowHeight = [self rowHeight] + [self intercellSpacing].height;
float clipBottom = NSMaxY(clipRect);
int firstStripe = clipRect.origin.y / fullRowHeight;
if (firstStripe % 2 == 0)
firstStripe++; // we're only interested in drawing the stripes
// set up first rect
stripeRect.origin.x = clipRect.origin.x;
stripeRect.origin.y = firstStripe * fullRowHeight;
stripeRect.size.width = clipRect.size.width;
stripeRect.size.height = fullRowHeight;
// set the color
if (sStripeColor == nil)
sStripeColor = [[NSColor colorWithCalibratedRed:STRIPE_RED green:STRIPE_GREEN blue:STRIPE_BLUE alpha:1.0] retain];
[sStripeColor set];
// and draw the stripes
while (stripeRect.origin.y < clipBottom) {
NSRectFill(stripeRect);
stripeRect.origin.y += fullRowHeight * 2.0;
}
}
@end
/*****************************************************************************
......@@ -135,56 +182,6 @@
return( NO );
}
- (NSDragOperation)tableView:(NSTableView*)o_tv
validateDrop:(id <NSDraggingInfo>)info
proposedRow:(int)i_row
proposedDropOperation:(NSTableViewDropOperation)operation
{
return( NSDragOperationPrivate );
}
- (BOOL)tableView:(NSTableView*)o_tv
acceptDrop:(id <NSDraggingInfo>)info
row:(int)i_row
dropOperation:(NSTableViewDropOperation)operation
{
NSArray * o_values;
NSPasteboard * o_pasteboard;
o_pasteboard = [info draggingPasteboard];
if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
{
o_values = [o_pasteboard propertyListForType: NSFilenamesPboardType];
[self appendArray: o_values atPos: i_row enqueue:YES];
return( YES );
}
return( NO );
}
- (void)tableView:(NSTableView *)o_tv willDisplayCell:(id)o_cell
forTableColumn:(NSTableColumn *)o_tc row:(int)i_row
{
NSColor * o_color;
[o_cell setDrawsBackground: YES];
if( i_row % 2 )
{
o_color = [[NSColor alternateSelectedControlColor]
highlightWithLevel: 0.90];
}
else
{
o_color = [o_tv backgroundColor];
}
[o_cell setBackgroundColor: o_color];
}
- (NSMenu *)menuForEvent:(NSEvent *)o_event
{
NSPoint pt;
......@@ -372,5 +369,101 @@
return( o_value );
}
// NEW API for Dragging in TableView:
// typedef enum { NSTableViewDropOn, NSTableViewDropAbove } NSTableViewDropOperation;
// In drag and drop, used to specify a dropOperation. For example, given a table with N rows (numbered with row 0 at the top visually), a row of N-1 and operation of NSTableViewDropOn would specify a drop on the last row. To specify a drop below the last row, one would use a row of N and NSTableViewDropAbove for the operation.
static int _moveRow = -1;
- (BOOL)tableView:(NSTableView *)tv
writeRows:(NSArray*)rows
toPasteboard:(NSPasteboard*)pboard
// This method is called after it has been determined that a drag should begin, but before the drag has been started. To refuse the drag, return NO. To start a drag, return YES and place the drag data onto the pasteboard (data, owner, etc...). The drag image and other drag related information will be set up and provided by the table view once this call returns with YES. The rows array is the list of row numbers that will be participating in the drag.
{
int rowCount = [rows count];
NSArray *o_filenames = [NSArray array];
// we should allow group selection and copy between windows: PENDING
[pboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:self];
[pboard setPropertyList:o_filenames forType:NSFilenamesPboardType];
if (rowCount == 1)
{
_moveRow = [[rows objectAtIndex:0]intValue];
return YES;
}
return NO;
}
- (NSDragOperation)tableView:(NSTableView*)tv
validateDrop:(id <NSDraggingInfo>)info
proposedRow:(int)row
proposedDropOperation:(NSTableViewDropOperation)op
// This method is used by NSTableView to determine a valid drop target. Based on the mouse position, the table view will suggest a proposed drop location. This method must return a value that indicates which dragging operation the data source will perform. The data source may "re-target" a drop if desired by calling setDropRow:dropOperation: and returning something other than NSDragOperationNone. One may choose to re-target for various reasons (eg. for better visual feedback when inserting into a sorted position).
{
if ( op == NSTableViewDropAbove )
{
if ( row != _moveRow && _moveRow >= 0 )
{
return NSDragOperationMove;
}
return NSDragOperationLink;
}
return NSDragOperationNone;
}
- (BOOL)tableView:(NSTableView*)tv
acceptDrop:(id <NSDraggingInfo>)info
row:(int)i_row
dropOperation:(NSTableViewDropOperation)op
// This method is called when the mouse is released over an outline view that previously decided to allow a drop via the validateDrop method. The data source should incorporate the data from the dragging pasteboard at this time.
{
if ( _moveRow >= 0 )
{
BOOL result = [self tableView:tv didDepositRow:_moveRow at:(int)i_row];
[self playlistUpdated];
_moveRow = -1;
return result;
}
else
{
NSArray * o_values;
NSPasteboard * o_pasteboard;
o_pasteboard = [info draggingPasteboard];
if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
{
o_values = [o_pasteboard propertyListForType: NSFilenamesPboardType];
[self appendArray: o_values atPos: i_row enqueue:YES];
return( YES );
}
return( NO );
}
}
- (BOOL)tableView:(NSTableView *)tv didDepositRow:(int)i_row at:(int)i_newrow
{
if (i_row != -1 && i_newrow != -1)
{
intf_thread_t * p_intf = [NSApp getIntf];
playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist == NULL )
{
return NO;
}
playlist_Move( p_playlist, i_row, i_newrow );
vlc_object_release( p_playlist );
return YES;
}
return NO;
}
@end
......@@ -2,7 +2,7 @@
* playlist.c : Playlist management functions
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: playlist.c,v 1.32 2003/02/13 00:09:51 hartman Exp $
* $Id: playlist.c,v 1.33 2003/03/17 17:10:21 hartman Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -297,6 +297,71 @@ int playlist_Delete( playlist_t * p_playlist, int i_pos )
return 0;
}
/*****************************************************************************
* playlist_Move: move an item in the playlist
*****************************************************************************
* Move the item in the playlist with position i_pos before the current item
* at position i_newpos.
*****************************************************************************/
int playlist_Move( playlist_t * p_playlist, int i_pos, int i_newpos)
{
vlc_value_t val;
vlc_mutex_lock( &p_playlist->object_lock );
/* take into account that our own row disappears. */
if ( i_pos < i_newpos ) i_newpos--;
if( i_pos >= 0 && i_newpos >=0 && i_pos <= p_playlist->i_size
&& i_newpos <= p_playlist->i_size )
{
msg_Dbg( p_playlist, "moving playlist item %s ",
p_playlist->pp_items[i_pos]->psz_name );
if( i_pos == p_playlist->i_index )
{
p_playlist->i_index = i_newpos;
}
else if( i_pos > p_playlist->i_index && i_newpos <= p_playlist->i_index )
{
p_playlist->i_index++;
}
else if( i_pos < p_playlist->i_index && i_newpos >= p_playlist->i_index )
{
p_playlist->i_index--;
}
playlist_item_t * temp;
if ( i_pos < i_newpos )
{
temp = p_playlist->pp_items[i_pos];
while ( i_pos < i_newpos )
{
p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos+1];
i_pos++;
}
p_playlist->pp_items[i_newpos] = temp;
}
else if ( i_pos > i_newpos )
{
temp = p_playlist->pp_items[i_pos];
while ( i_pos > i_newpos )
{
p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos-1];
i_pos--;
}
p_playlist->pp_items[i_newpos] = temp;
}
}
vlc_mutex_unlock( &p_playlist->object_lock );
val.b_bool = VLC_TRUE;
var_Set( p_playlist, "intf-change", val );
return 0;
}
/*****************************************************************************
* playlist_Command: do a playlist action
*****************************************************************************
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment