Changeset 7314de69eb5a019333872430eb17c3a48a7d0abd

Show
Ignore:
Timestamp:
03/17/03 18:10:21 (5 years ago)
Author:
Derk-Jan Hartman <hartman@videolan.org>
git-committer:
Derk-Jan Hartman <hartman@videolan.org> 1047921021 +0000
git-parent:

[453fe58a0617ac1d0c72e7f24b50b97ed9c0e256]

git-author:
Derk-Jan Hartman <hartman@videolan.org> 1047921021 +0000
Message:

* 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.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_playlist.h

    r88f691d r7314de6  
    33 ***************************************************************************** 
    44 * Copyright (C) 1999, 2000, 2001, 2002 VideoLAN 
    5  * $Id: vlc_playlist.h,v 1.8 2003/01/29 11:34:11 jlj Exp $ 
     5 * $Id: vlc_playlist.h,v 1.9 2003/03/17 17:10:21 hartman Exp $ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     
    8080VLC_EXPORT( int,  playlist_AddItem, ( playlist_t *, playlist_item_t *, int, int ) ); 
    8181VLC_EXPORT( int,  playlist_Delete, ( playlist_t *, int ) ); 
     82VLC_EXPORT( int,  playlist_Move, ( playlist_t *, int, int ) ); 
    8283VLC_EXPORT( int,  playlist_LoadFile, ( playlist_t *, const char * ) ); 
    8384VLC_EXPORT( int,  playlist_SaveFile, ( playlist_t *, const char * ) ); 
  • modules/gui/macosx/playlist.h

    r8345dff r7314de6  
    33 ***************************************************************************** 
    44 * Copyright (C) 2002-2003 VideoLAN 
    5  * $Id: playlist.h,v 1.6 2003/02/23 05:53:53 jlj Exp $ 
     5 * $Id: playlist.h,v 1.7 2003/03/17 17:10:21 hartman Exp $ 
    66 * 
    77 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> 
     
    2828@interface VLCPlaylistView : NSTableView 
    2929{ 
     30} 
    3031 
    31 
     32- (void) drawStripesInRect:(NSRect)clipRect; 
    3233 
    3334@end 
  • modules/gui/macosx/playlist.m

    rff859e4 r7314de6  
    33 ***************************************************************************** 
    44 * Copyright (C) 2002-2003 VideoLAN 
    5  * $Id: playlist.m,v 1.14 2003/03/06 15:24:12 hartman Exp $ 
     5 * $Id: playlist.m,v 1.15 2003/03/17 17:10:21 hartman Exp $ 
    66 * 
    77 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> 
    88 *          Derk-Jan Hartman <thedj@users.sourceforge.net> 
     9 * Thanks:  Andrew Stone for documenting the row reordering methods on the net 
     10 *              http://www.omnigroup.com/mailman/archive/macosx-dev/ 
     11 *              2001-January/008195.html 
     12 *          Apple Computer for documenting the Alternating row colors 
     13 *      http://developer.apple.com/samplecode/Sample_Code/Cocoa/ 
     14 *              MP3_Player/MyTableView.m.htm 
    915 * 
    1016 * This program is free software; you can redistribute it and/or modify 
     
    3339#include "playlist.h" 
    3440 
     41// RGB values for stripe color (light blue) 
     42#define STRIPE_RED   (237.0 / 255.0) 
     43#define STRIPE_GREEN (243.0 / 255.0) 
     44#define STRIPE_BLUE  (254.0 / 255.0) 
     45static NSColor *sStripeColor = nil; 
     46 
    3547/***************************************************************************** 
    3648 * VLCPlaylistView implementation  
     
    103115} 
    104116 
     117 
     118/* This is called after the table background is filled in, but before the cell contents are drawn. 
     119 * We override it so we can do our own light-blue row stripes a la iTunes. 
     120 */ 
     121- (void) highlightSelectionInClipRect:(NSRect)rect { 
     122    [self drawStripesInRect:rect]; 
     123    [super highlightSelectionInClipRect:rect]; 
     124} 
     125 
     126/* This routine does the actual blue stripe drawing, filling in every other row of the table 
     127 * with a blue background so you can follow the rows easier with your eyes. 
     128 */ 
     129- (void) drawStripesInRect:(NSRect)clipRect { 
     130    NSRect stripeRect; 
     131    float fullRowHeight = [self rowHeight] + [self intercellSpacing].height; 
     132    float clipBottom = NSMaxY(clipRect); 
     133    int firstStripe = clipRect.origin.y / fullRowHeight; 
     134    if (firstStripe % 2 == 0) 
     135        firstStripe++;   // we're only interested in drawing the stripes 
     136                         // set up first rect 
     137    stripeRect.origin.x = clipRect.origin.x; 
     138    stripeRect.origin.y = firstStripe * fullRowHeight; 
     139    stripeRect.size.width = clipRect.size.width; 
     140    stripeRect.size.height = fullRowHeight; 
     141    // set the color 
     142    if (sStripeColor == nil) 
     143        sStripeColor = [[NSColor colorWithCalibratedRed:STRIPE_RED green:STRIPE_GREEN blue:STRIPE_BLUE alpha:1.0] retain]; 
     144    [sStripeColor set]; 
     145    // and draw the stripes 
     146    while (stripeRect.origin.y < clipBottom) { 
     147        NSRectFill(stripeRect); 
     148        stripeRect.origin.y += fullRowHeight * 2.0; 
     149    } 
     150} 
     151 
    105152@end 
    106153 
     
    134181{ 
    135182    return( NO ); 
    136 } 
    137  
    138 - (NSDragOperation)tableView:(NSTableView*)o_tv  
    139                    validateDrop:(id <NSDraggingInfo>)info  
    140                    proposedRow:(int)i_row  
    141                    proposedDropOperation:(NSTableViewDropOperation)operation 
    142 { 
    143     return( NSDragOperationPrivate ); 
    144 } 
    145  
    146 - (BOOL)tableView:(NSTableView*)o_tv  
    147                   acceptDrop:(id <NSDraggingInfo>)info  
    148                   row:(int)i_row  
    149                   dropOperation:(NSTableViewDropOperation)operation 
    150 { 
    151     NSArray * o_values; 
    152     NSPasteboard * o_pasteboard; 
    153  
    154     o_pasteboard = [info draggingPasteboard]; 
    155  
    156     if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] ) 
    157     { 
    158         o_values = [o_pasteboard propertyListForType: NSFilenamesPboardType]; 
    159  
    160         [self appendArray: o_values atPos: i_row enqueue:YES]; 
    161  
    162         return( YES ); 
    163     } 
    164  
    165     return( NO );  
    166 } 
    167  
    168 - (void)tableView:(NSTableView *)o_tv willDisplayCell:(id)o_cell 
    169                   forTableColumn:(NSTableColumn *)o_tc row:(int)i_row 
    170 { 
    171     NSColor * o_color; 
    172  
    173     [o_cell setDrawsBackground: YES]; 
    174  
    175     if( i_row % 2 ) 
    176     { 
    177         o_color = [[NSColor alternateSelectedControlColor] 
    178                             highlightWithLevel: 0.90]; 
    179     } 
    180     else 
    181     { 
    182         o_color = [o_tv backgroundColor];  
    183     } 
    184  
    185     [o_cell setBackgroundColor: o_color]; 
    186183} 
    187184 
     
    373370} 
    374371 
     372// NEW API for Dragging in TableView: 
     373// typedef enum { NSTableViewDropOn, NSTableViewDropAbove } NSTableViewDropOperation; 
     374// 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. 
     375 
     376static int _moveRow = -1; 
     377 
     378- (BOOL)tableView:(NSTableView *)tv 
     379                    writeRows:(NSArray*)rows 
     380                    toPasteboard:(NSPasteboard*)pboard  
     381// 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. 
     382{ 
     383    int rowCount = [rows count]; 
     384    NSArray *o_filenames = [NSArray array]; 
     385     
     386    // we should allow group selection and copy between windows: PENDING 
     387    [pboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:self]; 
     388    [pboard setPropertyList:o_filenames forType:NSFilenamesPboardType]; 
     389    if (rowCount == 1) 
     390    { 
     391        _moveRow = [[rows objectAtIndex:0]intValue]; 
     392        return YES; 
     393    } 
     394    return NO; 
     395} 
     396 
     397- (NSDragOperation)tableView:(NSTableView*)tv 
     398                    validateDrop:(id <NSDraggingInfo>)info 
     399                    proposedRow:(int)row 
     400                    proposedDropOperation:(NSTableViewDropOperation)op  
     401// 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). 
     402{ 
     403    if ( op == NSTableViewDropAbove ) 
     404    { 
     405        if ( row != _moveRow && _moveRow >= 0 ) 
     406        { 
     407            return NSDragOperationMove; 
     408        } 
     409        return NSDragOperationLink; 
     410    } 
     411    return NSDragOperationNone; 
     412} 
     413 
     414- (BOOL)tableView:(NSTableView*)tv 
     415                    acceptDrop:(id <NSDraggingInfo>)info 
     416                    row:(int)i_row 
     417                    dropOperation:(NSTableViewDropOperation)op  
     418// 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.  
     419{ 
     420    if (  _moveRow >= 0 ) 
     421    { 
     422        BOOL result = [self tableView:tv didDepositRow:_moveRow at:(int)i_row]; 
     423        [self playlistUpdated]; 
     424        _moveRow = -1; 
     425        return result; 
     426    } 
     427    else 
     428    { 
     429        NSArray * o_values; 
     430        NSPasteboard * o_pasteboard; 
     431         
     432        o_pasteboard = [info draggingPasteboard]; 
     433         
     434        if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] ) 
     435        { 
     436            o_values = [o_pasteboard propertyListForType: NSFilenamesPboardType]; 
     437         
     438            [self appendArray: o_values atPos: i_row enqueue:YES]; 
     439         
     440            return( YES ); 
     441        } 
     442         
     443        return( NO ); 
     444    } 
     445} 
     446 
     447-  (BOOL)tableView:(NSTableView *)tv didDepositRow:(int)i_row at:(int)i_newrow 
     448{ 
     449    if (i_row != -1 && i_newrow != -1) 
     450    { 
     451        intf_thread_t * p_intf = [NSApp getIntf]; 
     452        playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
     453                                                        FIND_ANYWHERE ); 
     454     
     455        if( p_playlist == NULL ) 
     456        { 
     457            return NO; 
     458        } 
     459 
     460        playlist_Move( p_playlist, i_row, i_newrow );  
     461     
     462        vlc_object_release( p_playlist ); 
     463        return YES; 
     464    } 
     465    return NO; 
     466} 
     467 
    375468@end 
    376469 
  • src/playlist/playlist.c

    r626c340 r7314de6  
    33 ***************************************************************************** 
    44 * Copyright (C) 1999-2001 VideoLAN 
    5  * $Id: playlist.c,v 1.32 2003/02/13 00:09:51 hartman Exp $ 
     5 * $Id: playlist.c,v 1.33 2003/03/17 17:10:21 hartman Exp $ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     
    299299 
    300300/***************************************************************************** 
     301 * playlist_Move: move an item in the playlist 
     302 ***************************************************************************** 
     303 * Move the item in the playlist with position i_pos before the current item 
     304 * at position i_newpos. 
     305 *****************************************************************************/ 
     306int playlist_Move( playlist_t * p_playlist, int i_pos, int i_newpos) 
     307{ 
     308    vlc_value_t     val; 
     309    vlc_mutex_lock( &p_playlist->object_lock ); 
     310 
     311    /* take into account that our own row disappears. */ 
     312    if ( i_pos < i_newpos ) i_newpos--; 
     313 
     314    if( i_pos >= 0 && i_newpos >=0 && i_pos <= p_playlist->i_size  
     315                     && i_newpos <= p_playlist->i_size ) 
     316    { 
     317        msg_Dbg( p_playlist, "moving playlist item � %s �", 
     318                             p_playlist->pp_items[i_pos]->psz_name ); 
     319 
     320        if( i_pos == p_playlist->i_index ) 
     321        { 
     322            p_playlist->i_index = i_newpos; 
     323        } 
     324        else if( i_pos > p_playlist->i_index && i_newpos <= p_playlist->i_index ) 
     325        { 
     326            p_playlist->i_index++; 
     327        } 
     328        else if( i_pos < p_playlist->i_index && i_newpos >= p_playlist->i_index ) 
     329        { 
     330            p_playlist->i_index--; 
     331        } 
     332         
     333        playlist_item_t * temp; 
     334        if ( i_pos < i_newpos ) 
     335        { 
     336              
     337            temp = p_playlist->pp_items[i_pos]; 
     338            while ( i_pos < i_newpos ) 
     339            { 
     340                p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos+1]; 
     341                i_pos++; 
     342            } 
     343            p_playlist->pp_items[i_newpos] = temp; 
     344        } 
     345        else if ( i_pos > i_newpos ) 
     346        { 
     347            temp = p_playlist->pp_items[i_pos]; 
     348            while ( i_pos > i_newpos ) 
     349            { 
     350                p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos-1]; 
     351                i_pos--; 
     352            } 
     353            p_playlist->pp_items[i_newpos] = temp; 
     354        } 
     355    } 
     356 
     357    vlc_mutex_unlock( &p_playlist->object_lock ); 
     358 
     359    val.b_bool = VLC_TRUE; 
     360    var_Set( p_playlist, "intf-change", val ); 
     361 
     362    return 0; 
     363} 
     364 
     365/***************************************************************************** 
    301366 * playlist_Command: do a playlist action 
    302367 *****************************************************************************