source: trunk/SapphireCompatibilityClasses/SapphireCenteredMenuController.m @ 788

Revision 788, 3.7 KB checked in by gbooker, 5 years ago (diff)

Memory leak fixes

Line 
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 */
20
21#import "SapphireCenteredMenuController.h"
22#import "SapphireFrontRowCompat.h"
23
24@interface SapphireWideCenteredLayout : NSObject
25{
26        id                                                              realLayout;
27        id <SapphireListLayoutDelegate> delegate;               //Not Retained
28}
29@end
30
31@interface BRLayerController (compat)
32- (void)wasBuried;
33- (void)wasExhumed;
34@end
35
36@interface SapphireCenteredMenuController (compat)
37- (id)firstSublayerNamed:(NSString *)name;
38- (id)firstControlNamed:(NSString *)name;
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
53- (void)setDelegate:(id <SapphireListLayoutDelegate>)del
54{
55        delegate = del;
56}
57
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];
68 
69  id listLayer;
70 
71  if([layer respondsToSelector:@selector(firstControlNamed:)])
72    listLayer = [layer firstControlNamed:@"list"];
73  else
74    listLayer = [layer firstSublayerNamed:@"list"];
75 
76        NSRect listFrame = [listLayer frame];
77        listFrame = [delegate listRectWithSize:listFrame inMaster:master];
78        [listLayer setFrame:listFrame];
79}
80- (NSSize)preferredSizeOfLayer:(id)layer
81{
82        return [realLayout preferredSizeOfLayer:layer];
83}
84
85@end
86
87@implementation SapphireCenteredMenuController
88
89- (id)initWithScene:(BRRenderScene *)scene
90{
91        if([[BRCenteredMenuController class] instancesRespondToSelector:@selector(initWithScene:)])
92                return [super initWithScene:scene];
93       
94        self = [super init];
95        SapphireWideCenteredLayout *newLayout = [[SapphireWideCenteredLayout alloc] initWithReal:[self layoutManager]];
96        [newLayout setDelegate:self];
97        [self setLayoutManager:newLayout];
98        [newLayout release];
99        return self;
100}
101
102- (BRRenderScene *)scene
103{
104        if([[BRCenteredMenuController class] instancesRespondToSelector:@selector(scene)])
105                return [super scene];
106       
107        return [BRRenderScene sharedInstance];
108}
109
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
129/*Just because so many classes use self as the list data source*/
130- (float)heightForRow:(long)row
131{
132        return 0.0f;
133}
134
135- (BOOL)rowSelectable:(long)row
136{
137        return YES;
138}
139
140#include "SapphireStackControllerCompatFunctions.h"
141
142@end
Note: See TracBrowser for help on using the repository browser.