| 1 | /* |
|---|
| 2 | * SapphireFrontRowCompat.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 "SapphireFrontRowCompat.h" |
|---|
| 22 | #import <ExceptionHandling/NSExceptionHandler.h> |
|---|
| 23 | #import "SapphireButtonControl.h" |
|---|
| 24 | |
|---|
| 25 | /*Yes, this is the wrong class, but otherwise gcc gripes about BRImage class not existing; this removes warnings so no harm*/ |
|---|
| 26 | @interface SapphireFrontRowCompat (compat) |
|---|
| 27 | + (id)imageWithPath:(NSString *)path; |
|---|
| 28 | - (id)downsampledImageForMaxSize:(NSSize)size; |
|---|
| 29 | + (id)imageWithCGImageRef:(CGImageRef)ref; |
|---|
| 30 | - (CGImageRef)image; |
|---|
| 31 | @end |
|---|
| 32 | |
|---|
| 33 | NSData *CreateBitmapDataFromImage(CGImageRef image, unsigned int width, unsigned int height); |
|---|
| 34 | |
|---|
| 35 | /*Yes, wrong class and other wrong things, just to shut up warnings*/ |
|---|
| 36 | @interface BRAdornedMenuItemLayer (compat) |
|---|
| 37 | + (id)folderMenuItem; |
|---|
| 38 | + (id)menuItem; |
|---|
| 39 | - (void)setTitle:(NSString *)title; |
|---|
| 40 | - (void)setRightJustifiedText:(NSString *)text; |
|---|
| 41 | - (void)setLeftIconInfo:(BRTexture *)icon; |
|---|
| 42 | - (void)setRightIconInfo:(BRTexture *)icon; |
|---|
| 43 | @end |
|---|
| 44 | |
|---|
| 45 | @interface BRThemeInfo (compat) |
|---|
| 46 | - (id)selectedSettingImage; |
|---|
| 47 | @end |
|---|
| 48 | |
|---|
| 49 | @interface BRButtonControl (compat) |
|---|
| 50 | - (id)initWithMasterLayerSize:(NSSize)fp8; |
|---|
| 51 | @end |
|---|
| 52 | |
|---|
| 53 | @interface BRTextControl (compat) |
|---|
| 54 | - (void)setText:(NSString *)text withAttributes:(NSDictionary *)attr; |
|---|
| 55 | - (NSRect)controllerFrame; /*technically wrong; it is really a CGRect*/ |
|---|
| 56 | @end |
|---|
| 57 | |
|---|
| 58 | @interface NSException (compat) |
|---|
| 59 | - (NSArray *)callStackReturnAddresses; |
|---|
| 60 | @end |
|---|
| 61 | |
|---|
| 62 | @implementation SapphireFrontRowCompat |
|---|
| 63 | |
|---|
| 64 | static BOOL usingFrontRow = NO; |
|---|
| 65 | |
|---|
| 66 | + (void)initialize |
|---|
| 67 | { |
|---|
| 68 | if(NSClassFromString(@"BRAdornedMenuItemLayer") == nil) |
|---|
| 69 | usingFrontRow = YES; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | + (BOOL)usingFrontRow |
|---|
| 73 | { |
|---|
| 74 | return usingFrontRow; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | + (id)imageAtPath:(NSString *)path |
|---|
| 78 | { |
|---|
| 79 | Class cls = NSClassFromString(@"BRImage"); |
|---|
| 80 | return [cls imageWithPath:path]; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | + (BRAdornedMenuItemLayer *)textMenuItemForScene:(BRRenderScene *)scene folder:(BOOL)folder |
|---|
| 84 | { |
|---|
| 85 | if(usingFrontRow) |
|---|
| 86 | { |
|---|
| 87 | if(folder) |
|---|
| 88 | return [NSClassFromString(@"BRTextMenuItemLayer") folderMenuItem]; |
|---|
| 89 | else |
|---|
| 90 | return [NSClassFromString(@"BRTextMenuItemLayer") menuItem]; |
|---|
| 91 | } |
|---|
| 92 | else |
|---|
| 93 | { |
|---|
| 94 | if(folder) |
|---|
| 95 | return [NSClassFromString(@"BRAdornedMenuItemLayer") adornedFolderMenuItemWithScene:scene]; |
|---|
| 96 | else |
|---|
| 97 | return [NSClassFromString(@"BRAdornedMenuItemLayer") adornedMenuItemWithScene:scene]; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | + (void)setTitle:(NSString *)title forMenu:(BRAdornedMenuItemLayer *)menu |
|---|
| 102 | { |
|---|
| 103 | if(usingFrontRow) |
|---|
| 104 | [menu setTitle:title]; |
|---|
| 105 | else |
|---|
| 106 | [[menu textItem] setTitle:title]; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | + (void)setRightJustifiedText:(NSString *)text forMenu:(BRAdornedMenuItemLayer *)menu |
|---|
| 110 | { |
|---|
| 111 | if(usingFrontRow) |
|---|
| 112 | [menu setRightJustifiedText:text]; |
|---|
| 113 | else |
|---|
| 114 | [[menu textItem] setRightJustifiedText:text]; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | + (void)setLeftIcon:(BRTexture *)icon forMenu:(BRAdornedMenuItemLayer *)menu |
|---|
| 118 | { |
|---|
| 119 | if(usingFrontRow) |
|---|
| 120 | [menu setLeftIconInfo:[NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 121 | icon, @"BRMenuIconImageKey", |
|---|
| 122 | nil]]; |
|---|
| 123 | else |
|---|
| 124 | [menu setLeftIcon:icon]; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | + (void)setRightIcon:(BRTexture *)icon forMenu:(BRAdornedMenuItemLayer *)menu |
|---|
| 128 | { |
|---|
| 129 | if(usingFrontRow) |
|---|
| 130 | [menu setRightIconInfo:[NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 131 | icon, @"BRMenuIconImageKey", |
|---|
| 132 | nil]]; |
|---|
| 133 | else |
|---|
| 134 | [menu setRightIcon:icon]; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | + (id)selectedSettingImageForScene:(BRRenderScene *)scene |
|---|
| 138 | { |
|---|
| 139 | if(usingFrontRow) |
|---|
| 140 | return [[BRThemeInfo sharedTheme] selectedSettingImage]; |
|---|
| 141 | else |
|---|
| 142 | return [[BRThemeInfo sharedTheme] selectedSettingImageForScene:scene]; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | + (NSRect)frameOfController:(id)controller |
|---|
| 146 | { |
|---|
| 147 | if(usingFrontRow) |
|---|
| 148 | { |
|---|
| 149 | return [controller controllerFrame]; |
|---|
| 150 | } |
|---|
| 151 | else |
|---|
| 152 | return [[controller masterLayer] frame]; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | + (void)setText:(NSString *)text withAtrributes:(NSDictionary *)attributes forControl:(BRTextControl *)control |
|---|
| 156 | { |
|---|
| 157 | if(usingFrontRow) |
|---|
| 158 | [control setText:text withAttributes:attributes]; |
|---|
| 159 | else |
|---|
| 160 | { |
|---|
| 161 | if(attributes != nil) |
|---|
| 162 | [control setTextAttributes:attributes]; |
|---|
| 163 | [control setText:text]; |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | + (void)addDividerAtIndex:(int)index toList:(BRListControl *)list |
|---|
| 168 | { |
|---|
| 169 | if(usingFrontRow) |
|---|
| 170 | [list addDividerAtIndex:index withLabel:@""]; |
|---|
| 171 | else |
|---|
| 172 | [list addDividerAtIndex:index]; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | + (void)addSublayer:(id)sub toControl:(id)controller |
|---|
| 176 | { |
|---|
| 177 | if(usingFrontRow) |
|---|
| 178 | [[controller layer] addSublayer:sub]; |
|---|
| 179 | else |
|---|
| 180 | [[controller masterLayer] addSublayer:sub]; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | + (BRHeaderControl *)newHeaderControlWithScene:(BRRenderScene *)scene |
|---|
| 184 | { |
|---|
| 185 | if(usingFrontRow) |
|---|
| 186 | return [[BRHeaderControl alloc] init]; |
|---|
| 187 | else |
|---|
| 188 | return [[BRHeaderControl alloc] initWithScene:scene]; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | + (BRButtonControl *)newButtonControlWithScene:(BRRenderScene *)scene masterLayerSize:(NSSize)size; |
|---|
| 192 | { |
|---|
| 193 | if(usingFrontRow) |
|---|
| 194 | return [[SapphireButtonControl alloc] initWithMasterLayerSize:size]; |
|---|
| 195 | else |
|---|
| 196 | return [[BRButtonControl alloc] initWithScene:scene masterLayerSize:size]; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | + (BRTextControl *)newTextControlWithScene:(BRRenderScene *)scene |
|---|
| 200 | { |
|---|
| 201 | if(usingFrontRow) |
|---|
| 202 | return [[BRTextControl alloc] init]; |
|---|
| 203 | else |
|---|
| 204 | return [[BRTextControl alloc] initWithScene:scene]; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | + (BRProgressBarWidget *)newProgressBarWidgetWithScene:(BRRenderScene *)scene |
|---|
| 208 | { |
|---|
| 209 | if(usingFrontRow) |
|---|
| 210 | return [[BRProgressBarWidget alloc] init]; |
|---|
| 211 | else |
|---|
| 212 | return [[BRProgressBarWidget alloc] initWithScene:scene]; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | + (BRMarchingIconLayer *)newMarchingIconLayerWithScene:(BRRenderScene *)scene |
|---|
| 216 | { |
|---|
| 217 | if(usingFrontRow) |
|---|
| 218 | return [[BRMarchingIconLayer alloc] init]; |
|---|
| 219 | else |
|---|
| 220 | return [[BRMarchingIconLayer alloc] initWithScene:scene]; |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | + (void)renderScene:(BRRenderScene *)scene |
|---|
| 224 | { |
|---|
| 225 | if(!usingFrontRow) |
|---|
| 226 | [scene renderScene]; |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | + (NSArray *)callStackReturnAddressesForException:(NSException *)exception |
|---|
| 230 | { |
|---|
| 231 | if([exception respondsToSelector:@selector(callStackReturnAddresses)]) |
|---|
| 232 | { |
|---|
| 233 | NSArray *ret = [exception callStackReturnAddresses]; |
|---|
| 234 | if([ret count]) |
|---|
| 235 | return ret; |
|---|
| 236 | } |
|---|
| 237 | return [[exception userInfo] objectForKey:NSStackTraceKey]; |
|---|
| 238 | } |
|---|
| 239 | @end |
|---|