]> git.sesse.net Git - vlc/blob - plugins/macosx/intf_controller.c
New interface for MacOS X, courtesy of Florian G. Pflug.
[vlc] / plugins / macosx / intf_controller.c
1 /*****************************************************************************
2  * intf_controller.c : MacOS X plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $$
6  *
7  * Authors: Florian G. Pflug <fgp@phlo.org>
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
24 /* Remark:
25     I need to subclass NSQuickDrawView, and post a notification when its display
26     method is called. This is necessary because GetPortBound and similar functions
27     return the actual on-screen size of the QDPort, which isn't updated immidiately
28     after calling e.g. setFrame
29 */
30
31 #include <QuickTime/QuickTime.h>
32 #include <ApplicationServices/ApplicationServices.h>
33 #import "intf_controller.h"
34 #import "intf_vlc_wrapper.h"
35
36 @implementation Intf_Controller
37 //Initialization & Event-Management
38     - (void) awakeFromNib {
39         o_vlc = [Intf_VlcWrapper instance] ;
40         b_window_is_fullscreen = FALSE ;
41         [NSTimer scheduledTimerWithTimeInterval: 0.5
42             target: self
43             selector: @selector(manage:)
44             userInfo: nil
45             repeats:TRUE
46         ] ;
47         [o_vlc initWithDelegate:self] ;
48     }
49
50     - (void) manage:(NSTimer *)timer {
51         if ([o_vlc manage])
52             [NSApp terminate: self] ;
53         
54         [o_currenttime setStringValue: [o_vlc getTimeAsString]] ;
55         [o_timeslider setFloatValue: [o_vlc getTimeAsFloat]] ;
56    }
57     
58     - (void)applicationDidBecomeActive:(NSNotification*)aNotification {
59         if (b_window_is_fullscreen) {
60             [o_window orderFront:self] ;
61             [o_vlc play] ;
62         }
63     }
64     
65     - (void)applicationDidResignActive:(NSNotification*)aNotification {
66         if (b_window_is_fullscreen) {
67             [o_vlc pause] ;
68             [o_window orderOut:self] ;
69         }
70     }
71         
72         
73         
74         
75 //Functions attached to user interface         
76     - (IBAction) pause:(id)sender {
77         [o_vlc pause] ;
78     }
79     
80     - (IBAction) play:(id)sender {
81         [o_vlc play] ;
82     }
83     
84     - (IBAction) timeslider_update:(id)slider {
85         [o_vlc setTimeAsFloat: [o_timeslider floatValue]] ;
86     }
87     
88     - (IBAction) speedslider_update:(id)slider {
89         [o_vlc setSpeed: (intf_speed_t) [slider intValue]] ;
90     }
91   
92     - (IBAction) fullscreen_toggle:(id)sender {
93         [self requestQDPortFullscreen:!b_window_is_fullscreen] ;
94     }
95
96
97
98                                
99 //Callbacks - we are the delegate for the VlcWrapper
100     - (void) requestQDPortFullscreen:(bool)b_fullscreen {
101         NSRect s_rect ;
102         VlcQuickDrawView *o_qdview ;
103         
104         s_rect.origin.x = s_rect.origin.y = 0 ;
105         
106         [self releaseQDPort] ;
107         o_window = [NSWindow alloc] ;
108         if (b_fullscreen) {
109             [o_window
110                 initWithContentRect: [[NSScreen mainScreen] frame]
111                 styleMask: NSBorderlessWindowMask
112                 backing: NSBackingStoreBuffered
113                 defer:NO screen:[NSScreen mainScreen]
114             ] ;
115             [o_window setLevel:CGShieldingWindowLevel()] ;
116             b_window_is_fullscreen = TRUE ;
117         }
118         else {
119             s_rect.size = [o_vlc videoSize] ;
120             [o_window
121                 initWithContentRect: s_rect
122                 styleMask: (NSTitledWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
123                 backing: NSBackingStoreBuffered
124                 defer:NO screen:[NSScreen mainScreen]
125             ] ;
126             [o_window setAspectRatio:[o_vlc videoSize]] ;            
127             [o_window center] ;
128             [o_window setDelegate:self] ;
129             b_window_is_fullscreen = FALSE ;
130         }
131         o_qdview = [[VlcQuickDrawView alloc] init] ;
132         [o_qdview setPostsFrameChangedNotifications:YES] ;
133         [[NSNotificationCenter defaultCenter]
134             addObserver: o_vlc
135             selector: @selector(sizeChangeQDPort)
136             name: VlcQuickDrawViewDidResize
137             object: o_qdview
138         ] ;
139         [o_window setContentView:o_qdview] ;
140         [o_window orderFront:self] ;
141         [o_vlc setQDPort:[o_qdview qdPort]] ;
142         [o_menu_fullscreen setState:(b_window_is_fullscreen ? NSOnState : NSOffState)] ;
143     }
144     
145     - (void) releaseQDPort {
146         [[NSNotificationCenter defaultCenter]
147             removeObserver: nil
148             name: nil
149             object: [o_window contentView]
150         ] ;
151         [o_vlc setQDPort:nil] ;
152         if (o_window) {
153             [o_window close] ;
154             o_window = nil ;
155         }
156     }
157     
158     - (void) resizeQDPortFullscreen:(bool)b_fullscreen {
159         if (b_window_is_fullscreen != b_fullscreen) {
160             [self requestQDPortFullscreen:b_fullscreen] ;
161         }
162         else if (!b_window_is_fullscreen && !b_fullscreen) {
163             [o_window setAspectRatio:[o_vlc videoSize]] ;
164         }
165     }
166 @end
167
168 @implementation Intf_PlaylistDS
169     - (void ) awakeFromNib {
170         o_vlc = [Intf_VlcWrapper instance] ;
171         o_playlist = [[NSMutableArray arrayWithCapacity:10] retain] ;
172     }
173     
174     - (void) readPlaylist {
175         static unsigned int i_length_old = 0;
176         unsigned int i ;
177     
178         if (i_length_old == [o_vlc getPlaylistLength])
179             return ;
180     
181         [o_playlist removeAllObjects] ;
182         [o_vlc lockPlaylist] ;
183         for(i=0; i < [o_vlc getPlaylistLength]; i++)
184             [o_playlist addObject:[o_vlc getPlaylistItem:i]] ;
185         [o_vlc unlockPlaylist] ;
186     }
187
188     - (int) numberOfRowsInTableView:(NSTableView*)o_table {
189         [self readPlaylist] ;
190         return [o_playlist count] ;
191     }
192     
193     - (id) tableView:(NSTableView*)o_table objectValueForTableColumn:(NSTableColumn*)o_column row:(int)i_row {
194         return [o_playlist objectAtIndex:i_row] ;
195     }
196     
197     - (void)tableView:(NSTableView *)aTableView setObjectValue:anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
198     }
199 @end