misc.m
上传用户:riyaled888
上传日期:2009-03-27
资源大小:7338k
文件大小:9k
源码类别:

多媒体

开发平台:

MultiPlatform

  1. /*****************************************************************************
  2.  * misc.m: code not specific to vlc
  3.  *****************************************************************************
  4.  * Copyright (C) 2003-2004 VideoLAN
  5.  * $Id: misc.m 8121 2004-07-05 01:27:35Z hartman $
  6.  *
  7.  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
  8.  *
  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.
  13.  *
  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.
  18.  *
  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.  *****************************************************************************/
  23. #include <Cocoa/Cocoa.h>
  24. #include "intf.h"                                          /* VLCApplication */
  25. #include "misc.h"
  26. #include "playlist.h"
  27. /*****************************************************************************
  28.  * VLCControllerWindow
  29.  *****************************************************************************/
  30. @implementation VLCControllerWindow
  31. - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
  32.     backing:(NSBackingStoreType)backingType defer:(BOOL)flag
  33. {
  34.     self = [super initWithContentRect:contentRect styleMask:styleMask //& ~NSTitledWindowMask
  35.     backing:backingType defer:flag];
  36.     return( self );
  37. }
  38. - (BOOL)performKeyEquivalent:(NSEvent *)o_event
  39. {
  40.     return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
  41. }
  42. @end
  43. /*****************************************************************************
  44.  * VLCControllerView
  45.  *****************************************************************************/
  46. @implementation VLCControllerView
  47. - (void)dealloc
  48. {
  49.     [self unregisterDraggedTypes];
  50.     [super dealloc];
  51. }
  52. - (void)awakeFromNib
  53. {
  54.     [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, 
  55.         NSFilenamesPboardType, nil]];
  56. }
  57. - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
  58. {
  59.     if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) 
  60.                 == NSDragOperationGeneric)
  61.     {
  62.         return NSDragOperationGeneric;
  63.     }
  64.     else
  65.     {
  66.         return NSDragOperationNone;
  67.     }
  68. }
  69. - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
  70. {
  71.     return YES;
  72. }
  73. - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
  74. {
  75.     NSPasteboard *o_paste = [sender draggingPasteboard];
  76.     NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
  77.     NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
  78.     NSData *o_carried_data = [o_paste dataForType:o_desired_type];
  79.     if( o_carried_data )
  80.     {
  81.         if ([o_desired_type isEqualToString:NSFilenamesPboardType])
  82.         {
  83.             int i;
  84.             NSArray *o_array = [NSArray array];
  85.             NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
  86.                         sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
  87.             for( i = 0; i < (int)[o_values count]; i++)
  88.             {
  89.                 NSDictionary *o_dic;
  90.                 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
  91.                 o_array = [o_array arrayByAddingObject: o_dic];
  92.             }
  93.             [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
  94.             return YES;
  95.         }
  96.     }
  97.     [self setNeedsDisplay:YES];
  98.     return YES;
  99. }
  100. - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
  101. {
  102.     [self setNeedsDisplay:YES];
  103. }
  104. @end
  105. /*****************************************************************************
  106.  * VLBrushedMetalImageView
  107.  *****************************************************************************/
  108. @implementation VLBrushedMetalImageView
  109. - (BOOL)mouseDownCanMoveWindow
  110. {
  111.     return YES;
  112. }
  113. - (void)dealloc
  114. {
  115.     [self unregisterDraggedTypes];
  116.     [super dealloc];
  117. }
  118. - (void)awakeFromNib
  119. {
  120.     [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, 
  121.         NSFilenamesPboardType, nil]];
  122. }
  123. - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
  124. {
  125.     if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) 
  126.                 == NSDragOperationGeneric)
  127.     {
  128.         return NSDragOperationGeneric;
  129.     }
  130.     else
  131.     {
  132.         return NSDragOperationNone;
  133.     }
  134. }
  135. - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
  136. {
  137.     return YES;
  138. }
  139. - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
  140. {
  141.     NSPasteboard *o_paste = [sender draggingPasteboard];
  142.     NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
  143.     NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
  144.     NSData *o_carried_data = [o_paste dataForType:o_desired_type];
  145.     if( o_carried_data )
  146.     {
  147.         if ([o_desired_type isEqualToString:NSFilenamesPboardType])
  148.         {
  149.             int i;
  150.             NSArray *o_array = [NSArray array];
  151.             NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
  152.                         sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
  153.             for( i = 0; i < (int)[o_values count]; i++)
  154.             {
  155.                 NSDictionary *o_dic;
  156.                 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
  157.                 o_array = [o_array arrayByAddingObject: o_dic];
  158.             }
  159.             [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
  160.             return YES;
  161.         }
  162.     }
  163.     [self setNeedsDisplay:YES];
  164.     return YES;
  165. }
  166. - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
  167. {
  168.     [self setNeedsDisplay:YES];
  169. }
  170. @end
  171. /*****************************************************************************
  172.  * MPSlider
  173.  *****************************************************************************/
  174. @implementation MPSlider
  175. void _drawKnobInRect(NSRect knobRect)
  176. {
  177.     // Center knob in given rect
  178.     knobRect.origin.x += (int)((float)(knobRect.size.width - 7)/2.0);
  179.     knobRect.origin.y += (int)((float)(knobRect.size.height - 7)/2.0);
  180.     
  181.     // Draw diamond
  182.     NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 6, 1, 1), NSCompositeSourceOver);
  183.     NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 5, 3, 1), NSCompositeSourceOver);
  184.     NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 4, 5, 1), NSCompositeSourceOver);
  185.     NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 0, knobRect.origin.y + 3, 7, 1), NSCompositeSourceOver);
  186.     NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 2, 5, 1), NSCompositeSourceOver);
  187.     NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 1, 3, 1), NSCompositeSourceOver);
  188.     NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 0, 1, 1), NSCompositeSourceOver);
  189. }
  190. void _drawFrameInRect(NSRect frameRect)
  191. {
  192.     // Draw frame
  193.     NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width, 1), NSCompositeSourceOver);
  194.     NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y + frameRect.size.height-1, frameRect.size.width, 1), NSCompositeSourceOver);
  195.     NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
  196.     NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x+frameRect.size.width-1, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
  197. }
  198. - (void)drawRect:(NSRect)rect
  199. {
  200.     // Draw default to make sure the slider behaves correctly
  201.     [[NSGraphicsContext currentContext] saveGraphicsState];
  202.     NSRectClip(NSZeroRect);
  203.     [super drawRect:rect];
  204.     [[NSGraphicsContext currentContext] restoreGraphicsState];
  205.     
  206.     // Full size
  207.     rect = [self bounds];
  208.     int diff = (int)(([[self cell] knobThickness] - 7.0)/2.0) - 1;
  209.     rect.origin.x += diff-1;
  210.     rect.origin.y += diff;
  211.     rect.size.width -= 2*diff-2;
  212.     rect.size.height -= 2*diff;
  213.     
  214.     // Draw dark
  215.     NSRect knobRect = [[self cell] knobRectFlipped:NO];
  216.     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
  217.     _drawFrameInRect(rect);
  218.     _drawKnobInRect(knobRect);
  219.     
  220.     // Draw shadow
  221.     [[[NSColor blackColor] colorWithAlphaComponent:0.1] set];
  222.     rect.origin.x++;
  223.     rect.origin.y++;
  224.     knobRect.origin.x++;
  225.     knobRect.origin.y++;
  226.     _drawFrameInRect(rect);
  227.     _drawKnobInRect(knobRect);
  228. }
  229. @end