2 // **********************************************************************
3 // The Cheat - A universal game cheater for Mac OS X
4 // (C) 2003-2005 Chaz McGarvey (BrokenZipper)
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)
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.
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.
21 #import "PreferenceController.h"
24 @implementation PreferenceController
29 if ( self = [super initWithWindowNibName
:@
"Preferences"] )
31 [self setWindowFrameAutosaveName
:@
"TCPreferencWindowPosition"];
39 [_contentView release
];
46 _toolbar
= [[NSToolbar alloc
] initWithIdentifier
:@
"TCPreferencesToolbar"];
47 [_toolbar setDelegate
:self];
48 [_toolbar setVisible
:YES
];
49 [[self window
] setToolbar
:_toolbar
];
51 _contentView
= [[[self window
] contentView
] retain
];
53 [self initialInterfaceSetup
];
57 - (void)initialInterfaceSetup
59 [self chooseGeneral
:self];
63 - (void)chooseGeneral
:(id)object
65 NSWindow
*window
= [self window
];
66 [self switchToView
:ibGeneralView
];
67 [window setTitle
:@
"General"];
68 if ( MacOSXVersion() >= 0x1030 ) {
69 [_toolbar setSelectedItemIdentifier
:@
"General"];
73 - (void)chooseServer
:(id)object
75 NSWindow
*window
= [self window
];
76 [self switchToView
:ibServerView
];
77 [window setTitle
:@
"Server"];
78 if ( MacOSXVersion() >= 0x1030 ) {
79 [_toolbar setSelectedItemIdentifier
:@
"Server"];
83 - (void)chooseUpdate
:(id)object
85 NSWindow
*window
= [self window
];
86 [self switchToView
:ibUpdateCheckView
];
87 [window setTitle
:@
"Update Check"];
88 if ( MacOSXVersion() >= 0x1030 ) {
89 [_toolbar setSelectedItemIdentifier
:@
"Update Check"];
93 - (void)switchToView
:(NSView
*)view
95 NSWindow
*window
= [self window
];
96 NSRect frame
= [window frame
];
99 if ( view
== [window contentView
] ) {
103 xdif
= [view frame
].size.width
- [[window contentView
] frame
].size.width
;
104 ydif
= [view frame
].size.height
- [[window contentView
] frame
].size.height
;
106 frame.size.width
+= xdif
;
107 frame.size.height
+= ydif
;
108 frame.origin.y
-= ydif
;
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
];
118 - (NSToolbarItem
*)toolbar
:(NSToolbar
*)toolbar itemForItemIdentifier
:(NSString
*)itemIdentifier willBeInsertedIntoToolbar
:(BOOL)flag
120 NSToolbarItem
*item
= [[NSToolbarItem alloc
] initWithItemIdentifier
:itemIdentifier
];
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
] )];
128 return [item autorelease
];
131 - (NSArray
*)toolbarAllowedItemIdentifiers
:(NSToolbar
*)toolbar
133 return [NSArray arrayWithObjects
:@
"General", @
"Update", @
"Server", nil];
136 - (NSArray
*)toolbarDefaultItemIdentifiers
:(NSToolbar
*)toolbar
138 return [NSArray arrayWithObjects
:@
"General", @
"Update", @
"Server", nil];
141 - (NSArray
*)toolbarSelectableItemIdentifiers
:(NSToolbar
*)toolbar
143 return [NSArray arrayWithObjects
:@
"General", @
"Update", @
"Server", nil];