]> Dogcows Code - chaz/thecheat/blob - PreferenceController.m
Remove support of Mac OS X 10.3 and earlier system, change codes for Mac OS X 10.7.
[chaz/thecheat] / PreferenceController.m
1
2 /*
3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.brokenzipper.com/trac/wiki/TheCheat
5 *
6 * Copyright (c) 2003-2011, Charles McGarvey et al.
7 *
8 * Distributable under the terms and conditions of the 2-clause BSD
9 * license; see the file COPYING for the legal text of the license.
10 */
11
12 #import "PreferenceController.h"
13
14
15 @implementation PreferenceController
16
17
18 - (id)init
19 {
20 if ( self = [super initWithWindowNibName:@"Preferences"] )
21 {
22 [self setWindowFrameAutosaveName:@"TCPreferencWindowPosition"];
23 }
24 return self;
25 }
26
27 - (void)dealloc
28 {
29 [_toolbar release];
30 [_contentView release];
31 [super dealloc];
32 }
33
34
35 - (void)windowDidLoad
36 {
37 _toolbar = [[NSToolbar alloc] initWithIdentifier:@"TCPreferencesToolbar"];
38 [_toolbar setDelegate:self];
39 [_toolbar setVisible:YES];
40 [[self window] setToolbar:_toolbar];
41
42 _contentView = [[[self window] contentView] retain];
43
44 [self initialInterfaceSetup];
45 }
46
47
48 - (void)initialInterfaceSetup
49 {
50 [self chooseGeneral:self];
51 }
52
53
54 - (void)chooseGeneral:(id)object
55 {
56 NSWindow *window = [self window];
57 [self switchToView:ibGeneralView];
58 [window setTitle:@"General"];
59 [_toolbar setSelectedItemIdentifier:@"General"];
60 }
61
62 - (void)chooseServer:(id)object
63 {
64 NSWindow *window = [self window];
65 [self switchToView:ibServerView];
66 [window setTitle:@"Server"];
67 [_toolbar setSelectedItemIdentifier:@"Server"];
68 }
69
70 - (void)chooseUpdate:(id)object
71 {
72 NSWindow *window = [self window];
73 [self switchToView:ibUpdateCheckView];
74 [window setTitle:@"Update Check"];
75 [_toolbar setSelectedItemIdentifier:@"Update Check"];
76 }
77
78 - (void)switchToView:(NSView *)view
79 {
80 NSWindow *window = [self window];
81 NSRect frame = [window frame];
82 float xdif, ydif;
83
84 if ( view == [window contentView] ) {
85 return;
86 }
87
88 xdif = [view frame].size.width - [[window contentView] frame].size.width;
89 ydif = [view frame].size.height - [[window contentView] frame].size.height;
90
91 frame.size.width += xdif;
92 frame.size.height += ydif;
93 frame.origin.y -= ydif;
94
95 // switch to the new view
96 [window setContentView:_contentView];
97 [window setFrame:frame display:YES animate:YES];
98 [window setContentView:view];
99 [window makeFirstResponder:view];
100 }
101
102
103 - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
104 {
105 NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
106
107 [item setLabel:itemIdentifier];
108 [item setPaletteLabel:itemIdentifier];
109 [item setImage:[NSImage imageNamed:itemIdentifier]];
110 [item setTarget:self];
111 [item setAction:NSSelectorFromString( [NSString stringWithFormat:@"choose%@:", itemIdentifier] )];
112
113 return [item autorelease];
114 }
115
116 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
117 {
118 return [NSArray arrayWithObjects:@"General", @"Update", @"Server", nil];
119 }
120
121 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
122 {
123 return [NSArray arrayWithObjects:@"General", @"Update", @"Server", nil];
124 }
125
126 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
127 {
128 return [NSArray arrayWithObjects:@"General", @"Update", @"Server", nil];
129 }
130
131
132 @end
This page took 0.041203 seconds and 4 git commands to generate.