| 1 | /* |
|---|
| 2 | * SapphireMediaMenuController.m |
|---|
| 3 | * Sapphire |
|---|
| 4 | * |
|---|
| 5 | * Created by Graham Booker on Oct. 29, 2007. |
|---|
| 6 | * Copyright 2007 Sapphire Development Team and/or www.nanopi.net |
|---|
| 7 | * All rights reserved. |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
|---|
| 10 | * General Public License as published by the Free Software Foundation; either version 3 of the License, |
|---|
| 11 | * or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
|---|
| 14 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|---|
| 15 | * Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License along with this program; if not, |
|---|
| 18 | * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #import "SapphireMediaMenuController.h" |
|---|
| 22 | #import "SapphireFrontRowCompat.h" |
|---|
| 23 | |
|---|
| 24 | @interface SapphireMediaMenuController (compat) |
|---|
| 25 | - (id)firstSublayerNamed:(NSString *)name; |
|---|
| 26 | - (id)firstControlNamed:(NSString *)name; |
|---|
| 27 | - (void)setLayoutManager:(id)newLayout; |
|---|
| 28 | - (id)layoutManager; |
|---|
| 29 | @end |
|---|
| 30 | |
|---|
| 31 | @interface BRMediaMenuController (compat) |
|---|
| 32 | - (void)resetPreviewController; |
|---|
| 33 | @end |
|---|
| 34 | |
|---|
| 35 | @interface BRLayerController (compat) |
|---|
| 36 | - (void)wasBuried; |
|---|
| 37 | - (void)wasExhumed; |
|---|
| 38 | @end |
|---|
| 39 | |
|---|
| 40 | @interface SapphireCustomMediaLayout : NSObject |
|---|
| 41 | { |
|---|
| 42 | id realLayout; |
|---|
| 43 | id <SapphireListLayoutDelegate> delegate; //Not retained |
|---|
| 44 | } |
|---|
| 45 | @end |
|---|
| 46 | |
|---|
| 47 | @implementation SapphireCustomMediaLayout |
|---|
| 48 | - (id)initWithReal:(id)real |
|---|
| 49 | { |
|---|
| 50 | self = [super init]; |
|---|
| 51 | if(self == nil) |
|---|
| 52 | return self; |
|---|
| 53 | realLayout = [real retain]; |
|---|
| 54 | return self; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | - (void)setDelegate:(id <SapphireListLayoutDelegate>)del |
|---|
| 58 | { |
|---|
| 59 | delegate = del; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | - (void) dealloc |
|---|
| 63 | { |
|---|
| 64 | [realLayout release]; |
|---|
| 65 | [super dealloc]; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | - (void)layoutSublayersOfLayer:(id)layer |
|---|
| 69 | { |
|---|
| 70 | [realLayout layoutSublayersOfLayer:layer]; |
|---|
| 71 | NSRect master = [layer frame]; |
|---|
| 72 | |
|---|
| 73 | id listLayer; |
|---|
| 74 | |
|---|
| 75 | if([layer respondsToSelector:@selector(firstControlNamed:)]) |
|---|
| 76 | listLayer = [layer firstControlNamed:@"list"]; |
|---|
| 77 | else |
|---|
| 78 | listLayer = [layer firstSublayerNamed:@"list"]; |
|---|
| 79 | |
|---|
| 80 | NSRect listFrame = [listLayer frame]; |
|---|
| 81 | listFrame = [delegate listRectWithSize:listFrame inMaster:master]; |
|---|
| 82 | [listLayer setFrame:listFrame]; |
|---|
| 83 | } |
|---|
| 84 | - (NSSize)preferredSizeOfLayer:(id)layer |
|---|
| 85 | { |
|---|
| 86 | return [realLayout preferredSizeOfLayer:layer]; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | @end |
|---|
| 90 | |
|---|
| 91 | @implementation SapphireMediaMenuController |
|---|
| 92 | |
|---|
| 93 | - (id)initWithScene:(BRRenderScene *)scene |
|---|
| 94 | { |
|---|
| 95 | Class mediaMenuControllerClass = [BRMediaMenuController class]; |
|---|
| 96 | if([mediaMenuControllerClass instancesRespondToSelector:@selector(initWithScene:)]) |
|---|
| 97 | return [super initWithScene:scene]; |
|---|
| 98 | |
|---|
| 99 | self = [super init]; |
|---|
| 100 | if([mediaMenuControllerClass instancesRespondToSelector:@selector(layoutManager)]) |
|---|
| 101 | { |
|---|
| 102 | SapphireCustomMediaLayout *newLayout = [[SapphireCustomMediaLayout alloc] initWithReal:[self layoutManager]]; |
|---|
| 103 | [newLayout setDelegate:self]; |
|---|
| 104 | [self setLayoutManager:newLayout]; |
|---|
| 105 | [newLayout release]; |
|---|
| 106 | } |
|---|
| 107 | return self; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | - (BRRenderScene *)scene |
|---|
| 111 | { |
|---|
| 112 | if([[BRMediaMenuController class] instancesRespondToSelector:@selector(scene)]) |
|---|
| 113 | return [super scene]; |
|---|
| 114 | |
|---|
| 115 | if(NSClassFromString(@"BRRenderScene") != nil) |
|---|
| 116 | return [BRRenderScene sharedInstance]; |
|---|
| 117 | return nil; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | - (NSRect)listRectWithSize:(NSRect)listFrame inMaster:(NSRect)master |
|---|
| 121 | { |
|---|
| 122 | return listFrame; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | - (void)_doLayout |
|---|
| 126 | { |
|---|
| 127 | //Shrink the list frame to make room for displaying the filename |
|---|
| 128 | [super _doLayout]; |
|---|
| 129 | NSRect master = [SapphireFrontRowCompat frameOfController:self]; |
|---|
| 130 | NSRect listFrame = [[_listControl layer] frame]; |
|---|
| 131 | listFrame = [self listRectWithSize:listFrame inMaster:master]; |
|---|
| 132 | [[_listControl layer] setFrame:listFrame]; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | /*Just because so many classes use self as the list data source*/ |
|---|
| 136 | - (float)heightForRow:(long)row |
|---|
| 137 | { |
|---|
| 138 | return 0.0f; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | - (BOOL)rowSelectable:(long)row |
|---|
| 142 | { |
|---|
| 143 | return YES; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | - (int)getSelection |
|---|
| 147 | { |
|---|
| 148 | BRListControl *list = [self list]; |
|---|
| 149 | int row; |
|---|
| 150 | NSMethodSignature *signature = [list methodSignatureForSelector:@selector(selection)]; |
|---|
| 151 | NSInvocation *selInv = [NSInvocation invocationWithMethodSignature:signature]; |
|---|
| 152 | [selInv setSelector:@selector(selection)]; |
|---|
| 153 | [selInv invokeWithTarget:list]; |
|---|
| 154 | if([signature methodReturnLength] == 8) |
|---|
| 155 | { |
|---|
| 156 | double retDoub = 0; |
|---|
| 157 | [selInv getReturnValue:&retDoub]; |
|---|
| 158 | row = retDoub; |
|---|
| 159 | } |
|---|
| 160 | else |
|---|
| 161 | [selInv getReturnValue:&row]; |
|---|
| 162 | return row; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | - (void)setSelection:(int)sel |
|---|
| 166 | { |
|---|
| 167 | BRListControl *list = [self list]; |
|---|
| 168 | NSMethodSignature *signature = [list methodSignatureForSelector:@selector(setSelection:)]; |
|---|
| 169 | NSInvocation *selInv = [NSInvocation invocationWithMethodSignature:signature]; |
|---|
| 170 | [selInv setSelector:@selector(setSelection:)]; |
|---|
| 171 | if(strcmp([signature getArgumentTypeAtIndex:2], "l")) |
|---|
| 172 | { |
|---|
| 173 | double dvalue = sel; |
|---|
| 174 | [selInv setArgument:&dvalue atIndex:2]; |
|---|
| 175 | } |
|---|
| 176 | else |
|---|
| 177 | { |
|---|
| 178 | long lvalue = sel; |
|---|
| 179 | [selInv setArgument:&lvalue atIndex:2]; |
|---|
| 180 | } |
|---|
| 181 | [selInv invokeWithTarget:list]; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | - (void)resetPreviewController |
|---|
| 185 | { |
|---|
| 186 | if([[SapphireMediaMenuController superclass] instancesRespondToSelector:@selector(resetPreviewController)]) |
|---|
| 187 | [super resetPreviewController]; |
|---|
| 188 | else |
|---|
| 189 | //Reset calls update, so we shouldn't if reset exists |
|---|
| 190 | [self updatePreviewController]; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | - (BOOL)brEventAction:(BREvent *)event |
|---|
| 194 | { |
|---|
| 195 | BREventRemoteAction remoteAction = [SapphireFrontRowCompat remoteActionForEvent:event]; |
|---|
| 196 | if ([(BRControllerStack *)[self stack] peekController] != self) |
|---|
| 197 | remoteAction = 0; |
|---|
| 198 | |
|---|
| 199 | int itemCount = [[(BRListControl *)[self list] datasource] itemCount]; |
|---|
| 200 | switch (remoteAction) |
|---|
| 201 | { |
|---|
| 202 | case kBREventRemoteActionUp: |
|---|
| 203 | case kBREventRemoteActionHoldUp: |
|---|
| 204 | if([self getSelection] == 0 && [event value] == 1) |
|---|
| 205 | { |
|---|
| 206 | [self setSelection:itemCount-1]; |
|---|
| 207 | [self resetPreviewController]; |
|---|
| 208 | return YES; |
|---|
| 209 | } |
|---|
| 210 | break; |
|---|
| 211 | case kBREventRemoteActionDown: |
|---|
| 212 | case kBREventRemoteActionHoldDown: |
|---|
| 213 | if([self getSelection] == itemCount-1 && [event value] == 1) |
|---|
| 214 | { |
|---|
| 215 | [self setSelection:0]; |
|---|
| 216 | [self resetPreviewController]; |
|---|
| 217 | return YES; |
|---|
| 218 | } |
|---|
| 219 | break; |
|---|
| 220 | } |
|---|
| 221 | return [super brEventAction:event]; |
|---|
| 222 | } |
|---|
| 223 | #include "SapphireStackControllerCompatFunctions.h" |
|---|
| 224 | |
|---|
| 225 | @end |
|---|