| [407] | 1 | /* |
|---|
| 2 | * SapphireCenteredMenuController.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 | */ |
|---|
| [263] | 20 | |
|---|
| 21 | #import "SapphireCenteredMenuController.h" |
|---|
| [264] | 22 | #import "SapphireFrontRowCompat.h" |
|---|
| [263] | 23 | |
|---|
| [329] | 24 | @interface SapphireWideCenteredLayout : NSObject |
|---|
| 25 | { |
|---|
| [694] | 26 | id realLayout; |
|---|
| [788] | 27 | id <SapphireListLayoutDelegate> delegate; //Not Retained |
|---|
| [329] | 28 | } |
|---|
| 29 | @end |
|---|
| 30 | |
|---|
| [694] | 31 | @interface BRLayerController (compat) |
|---|
| 32 | - (void)wasBuried; |
|---|
| 33 | - (void)wasExhumed; |
|---|
| 34 | @end |
|---|
| 35 | |
|---|
| [329] | 36 | @interface SapphireCenteredMenuController (compat) |
|---|
| 37 | - (id)firstSublayerNamed:(NSString *)name; |
|---|
| [489] | 38 | - (id)firstControlNamed:(NSString *)name; |
|---|
| [329] | 39 | - (void)setLayoutManager:(id)newLayout; |
|---|
| 40 | - (id)layoutManager; |
|---|
| 41 | @end |
|---|
| 42 | |
|---|
| 43 | @implementation SapphireWideCenteredLayout |
|---|
| 44 | - (id)initWithReal:(id)real |
|---|
| 45 | { |
|---|
| 46 | self = [super init]; |
|---|
| 47 | if(self == nil) |
|---|
| 48 | return self; |
|---|
| 49 | realLayout = [real retain]; |
|---|
| 50 | return self; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| [694] | 53 | - (void)setDelegate:(id <SapphireListLayoutDelegate>)del |
|---|
| [346] | 54 | { |
|---|
| [788] | 55 | delegate = del; |
|---|
| [346] | 56 | } |
|---|
| 57 | |
|---|
| [329] | 58 | - (void) dealloc |
|---|
| 59 | { |
|---|
| 60 | [realLayout release]; |
|---|
| 61 | [super dealloc]; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | - (void)layoutSublayersOfLayer:(id)layer |
|---|
| 65 | { |
|---|
| 66 | [realLayout layoutSublayersOfLayer:layer]; |
|---|
| 67 | NSRect master = [layer frame]; |
|---|
| [489] | 68 | |
|---|
| 69 | id listLayer; |
|---|
| 70 | |
|---|
| 71 | if([layer respondsToSelector:@selector(firstControlNamed:)]) |
|---|
| 72 | listLayer = [layer firstControlNamed:@"list"]; |
|---|
| 73 | else |
|---|
| 74 | listLayer = [layer firstSublayerNamed:@"list"]; |
|---|
| 75 | |
|---|
| [329] | 76 | NSRect listFrame = [listLayer frame]; |
|---|
| [346] | 77 | listFrame = [delegate listRectWithSize:listFrame inMaster:master]; |
|---|
| [329] | 78 | [listLayer setFrame:listFrame]; |
|---|
| 79 | } |
|---|
| 80 | - (NSSize)preferredSizeOfLayer:(id)layer |
|---|
| 81 | { |
|---|
| 82 | return [realLayout preferredSizeOfLayer:layer]; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | @end |
|---|
| 86 | |
|---|
| [263] | 87 | @implementation SapphireCenteredMenuController |
|---|
| 88 | |
|---|
| 89 | - (id)initWithScene:(BRRenderScene *)scene |
|---|
| 90 | { |
|---|
| [275] | 91 | if([[BRCenteredMenuController class] instancesRespondToSelector:@selector(initWithScene:)]) |
|---|
| [263] | 92 | return [super initWithScene:scene]; |
|---|
| 93 | |
|---|
| [329] | 94 | self = [super init]; |
|---|
| 95 | SapphireWideCenteredLayout *newLayout = [[SapphireWideCenteredLayout alloc] initWithReal:[self layoutManager]]; |
|---|
| [346] | 96 | [newLayout setDelegate:self]; |
|---|
| [329] | 97 | [self setLayoutManager:newLayout]; |
|---|
| 98 | [newLayout release]; |
|---|
| 99 | return self; |
|---|
| [263] | 100 | } |
|---|
| 101 | |
|---|
| 102 | - (BRRenderScene *)scene |
|---|
| 103 | { |
|---|
| [275] | 104 | if([[BRCenteredMenuController class] instancesRespondToSelector:@selector(scene)]) |
|---|
| [263] | 105 | return [super scene]; |
|---|
| 106 | |
|---|
| 107 | return [BRRenderScene sharedInstance]; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| [346] | 110 | - (NSRect)listRectWithSize:(NSRect)listFrame inMaster:(NSRect)master |
|---|
| 111 | { |
|---|
| 112 | listFrame.size.height -= 2.5f*listFrame.origin.y; |
|---|
| 113 | listFrame.size.width*=2.0f; |
|---|
| 114 | listFrame.origin.x = (master.size.width - listFrame.size.width) * 0.5f; |
|---|
| 115 | listFrame.origin.y *= 2.0f; |
|---|
| 116 | return listFrame; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | - (void)_doLayout |
|---|
| 120 | { |
|---|
| 121 | //Shrink the list frame to make room for displaying the filename |
|---|
| 122 | [super _doLayout]; |
|---|
| 123 | NSRect master = [SapphireFrontRowCompat frameOfController:self]; |
|---|
| 124 | NSRect listFrame = [[_listControl layer] frame]; |
|---|
| 125 | listFrame = [self listRectWithSize:listFrame inMaster:master]; |
|---|
| 126 | [[_listControl layer] setFrame:listFrame]; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| [272] | 129 | /*Just because so many classes use self as the list data source*/ |
|---|
| 130 | - (float)heightForRow:(long)row |
|---|
| 131 | { |
|---|
| [435] | 132 | return 0.0f; |
|---|
| [272] | 133 | } |
|---|
| 134 | |
|---|
| 135 | - (BOOL)rowSelectable:(long)row |
|---|
| 136 | { |
|---|
| 137 | return YES; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| [703] | 140 | #include "SapphireStackControllerCompatFunctions.h" |
|---|
| [694] | 141 | |
|---|
| [263] | 142 | @end |
|---|