]> Dogcows Code - chaz/thecheat/blob - PreferenceController.m
The Cheat 1.2
[chaz/thecheat] / PreferenceController.m
1
2 // **********************************************************************
3 // The Cheat - A universal game cheater for Mac OS X
4 // (C) 2003-2005 Chaz McGarvey (BrokenZipper)
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 1, or (at your option)
9 // any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 //
20
21 #import "PreferenceController.h"
22
23
24 @implementation PreferenceController
25
26
27 - (id)init
28 {
29 if ( self = [super initWithWindowNibName:@"Preferences"] )
30 {
31 [self setWindowFrameAutosaveName:@"TCPreferencWindowPosition"];
32 }
33 return self;
34 }
35
36 - (void)dealloc
37 {
38 [_toolbar release];
39 [_contentView release];
40 [super dealloc];
41 }
42
43
44 - (void)windowDidLoad
45 {
46 _toolbar = [[NSToolbar alloc] initWithIdentifier:@"TCPreferencesToolbar"];
47 [_toolbar setDelegate:self];
48 [_toolbar setVisible:YES];
49 [[self window] setToolbar:_toolbar];
50
51 _contentView = [[[self window] contentView] retain];
52
53 [self initialInterfaceSetup];
54 }
55
56
57 - (void)initialInterfaceSetup
58 {
59 [self chooseGeneral:self];
60 }
61
62
63 - (void)chooseGeneral:(id)object
64 {
65 NSWindow *window = [self window];
66 [self switchToView:ibGeneralView];
67 [window setTitle:@"General"];
68 if ( MacOSXVersion() >= 0x1030 ) {
69 [_toolbar setSelectedItemIdentifier:@"General"];
70 }
71 }
72
73 - (void)chooseServer:(id)object
74 {
75 NSWindow *window = [self window];
76 [self switchToView:ibServerView];
77 [window setTitle:@"Server"];
78 if ( MacOSXVersion() >= 0x1030 ) {
79 [_toolbar setSelectedItemIdentifier:@"Server"];
80 }
81 }
82
83 - (void)chooseUpdate:(id)object
84 {
85 NSWindow *window = [self window];
86 [self switchToView:ibUpdateCheckView];
87 [window setTitle:@"Update Check"];
88 if ( MacOSXVersion() >= 0x1030 ) {
89 [_toolbar setSelectedItemIdentifier:@"Update Check"];
90 }
91 }
92
93 - (void)switchToView:(NSView *)view
94 {
95 NSWindow *window = [self window];
96 NSRect frame = [window frame];
97 float xdif, ydif;
98
99 if ( view == [window contentView] ) {
100 return;
101 }
102
103 xdif = [view frame].size.width - [[window contentView] frame].size.width;
104 ydif = [view frame].size.height - [[window contentView] frame].size.height;
105
106 frame.size.width += xdif;
107 frame.size.height += ydif;
108 frame.origin.y -= ydif;
109
110 // switch to the new view
111 [window setContentView:_contentView];
112 [window setFrame:frame display:YES animate:YES];
113 [window setContentView:view];
114 [window makeFirstResponder:view];
115 }
116
117
118 - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
119 {
120 NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
121
122 [item setLabel:itemIdentifier];
123 [item setPaletteLabel:itemIdentifier];
124 [item setImage:[NSImage imageNamed:itemIdentifier]];
125 [item setTarget:self];
126 [item setAction:NSSelectorFromString( [NSString stringWithFormat:@"choose%@:", itemIdentifier] )];
127
128 return [item autorelease];
129 }
130
131 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
132 {
133 return [NSArray arrayWithObjects:@"General", @"Update", @"Server", nil];
134 }
135
136 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
137 {
138 return [NSArray arrayWithObjects:@"General", @"Update", @"Server", nil];
139 }
140
141 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
142 {
143 return [NSArray arrayWithObjects:@"General", @"Update", @"Server", nil];
144 }
145
146
147 @end
This page took 0.034796 seconds and 4 git commands to generate.