VLCVideoView.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*****************************************************************************
  2. * VLCVideoView.h: VLC.framework VLCVideoView implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007 the VideoLAN team
  6. * $Id$
  7. *
  8. * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. *****************************************************************************/
  24. #import "VLCVideoView.h"
  25. #import "VLCLibrary.h"
  26. #import "VLCEventManager.h"
  27. /* Libvlc */
  28. #include <vlc/vlc.h>
  29. #include <vlc/libvlc.h>
  30. /* Notifications */
  31. NSString *VLCVideoViewEnteredFullScreen = @"VLCVideoViewEnteredFullScreen";
  32. NSString *VLCVideoViewLeftFullScreen = @"VLCVideoViewLeftFullScreen";
  33. /* This is a forward reference to VLCOpenGLVoutView specified in minimal_macosx
  34. library. We could get rid of this, but it prevents warnings from the
  35. compiler. */
  36. @interface VLCOpenGLVoutView : NSView
  37. - (void)detachFromVout;
  38. @end
  39. @implementation VLCVideoView
  40. - (id)initWithFrame:(NSRect)rect
  41. {
  42. if (self = [super initWithFrame:rect])
  43. {
  44. delegate = nil;
  45. [self setBackColor:[NSColor blackColor]];
  46. [self setStretchesVideo:NO];
  47. [self setAutoresizesSubviews:YES];
  48. }
  49. return self;
  50. }
  51. - (void)dealloc
  52. {
  53. delegate = nil;
  54. [backColor release];
  55. [super dealloc];
  56. }
  57. - (void)setDelegate:(id)value
  58. {
  59. delegate = value;
  60. }
  61. - (id)delegate
  62. {
  63. return delegate;
  64. }
  65. - (void)setBackColor:(NSColor *)value
  66. {
  67. if (backColor != value)
  68. {
  69. [backColor release];
  70. backColor = [value retain];
  71. }
  72. }
  73. - (NSColor *)backColor
  74. {
  75. return backColor;
  76. }
  77. - (void)setStretchesVideo:(BOOL)value
  78. {
  79. stretchesVideo = value;
  80. }
  81. - (BOOL)stretchesVideo
  82. {
  83. return stretchesVideo;
  84. }
  85. /* This is called by the libvlc module 'minimal_macosx' as soon as there is one
  86. * vout available
  87. */
  88. - (void)addVoutSubview:(NSView *)aView
  89. {
  90. if( [[self subviews] count] )
  91. {
  92. /* XXX: This is a hack until core gets fixed */
  93. int i;
  94. for( i = 0; i < [[self subviews] count]; i++ )
  95. {
  96. [[[self subviews] objectAtIndex:i] detachFromVout];
  97. [[[self subviews] objectAtIndex:i] retain];
  98. [[[self subviews] objectAtIndex:i] removeFromSuperview];
  99. }
  100. }
  101. [self addSubview:aView];
  102. [aView setFrame:[self bounds]];
  103. // TODO: Should we let the media player specify these values?
  104. [aView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
  105. }
  106. - (void)removeVoutSubview:(NSView *)view
  107. {
  108. // Should we do something? I don't know, however the protocol requires
  109. // this to be implemented
  110. }
  111. /* This is a LibVLC notification that we're about to enter into full screen,
  112. there is no other place where I can see where we can trap this event */
  113. - (void)enterFullscreen
  114. {
  115. // Go ahead and send a notification to the world we're going into full screen
  116. [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
  117. withDelegateMethod:nil
  118. withNotificationName:VLCVideoViewEnteredFullScreen];
  119. // There is nothing else to do, as this object strictly displays the video feed
  120. }
  121. /* This is a LibVLC notification that we're about to enter leaving full screen,
  122. there is no other place where I can see where we can trap this event */
  123. - (void)leaveFullscreen
  124. {
  125. // Go ahead and send a notification to the world we're leaving full screen
  126. [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
  127. withDelegateMethod:nil
  128. withNotificationName:VLCVideoViewLeftFullScreen];
  129. // There is nothing else to do, as this object strictly displays the video feed
  130. }
  131. - (void)drawRect:(NSRect)aRect
  132. {
  133. [self lockFocus];
  134. [backColor set];
  135. NSRectFill(aRect);
  136. [self unlockFocus];
  137. }
  138. - (BOOL)isOpaque
  139. {
  140. return YES;
  141. }
  142. @end