3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.brokenzipper.com/trac/wiki/TheCheat
6 * Copyright (c) 2003-2011, Charles McGarvey et al.
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.
12 #import "PreferenceController.h"
15 @implementation PreferenceController
20 if ( self = [super initWithWindowNibName
:@
"Preferences"] )
22 [self setWindowFrameAutosaveName
:@
"TCPreferencWindowPosition"];
30 [_contentView release
];
37 _toolbar
= [[NSToolbar alloc
] initWithIdentifier
:@
"TCPreferencesToolbar"];
38 [_toolbar setDelegate
:self];
39 [_toolbar setVisible
:YES
];
40 [[self window
] setToolbar
:_toolbar
];
42 _contentView
= [[[self window
] contentView
] retain
];
44 [self initialInterfaceSetup
];
48 - (void)initialInterfaceSetup
50 [self chooseGeneral
:self];
54 - (void)chooseGeneral
:(id)object
56 NSWindow
*window
= [self window
];
57 [self switchToView
:ibGeneralView
];
58 [window setTitle
:@
"General"];
59 if ( MacOSXVersion() >= 0x1030 ) {
60 [_toolbar setSelectedItemIdentifier
:@
"General"];
64 - (void)chooseServer
:(id)object
66 NSWindow
*window
= [self window
];
67 [self switchToView
:ibServerView
];
68 [window setTitle
:@
"Server"];
69 if ( MacOSXVersion() >= 0x1030 ) {
70 [_toolbar setSelectedItemIdentifier
:@
"Server"];
74 - (void)chooseUpdate
:(id)object
76 NSWindow
*window
= [self window
];
77 [self switchToView
:ibUpdateCheckView
];
78 [window setTitle
:@
"Update Check"];
79 if ( MacOSXVersion() >= 0x1030 ) {
80 [_toolbar setSelectedItemIdentifier
:@
"Update Check"];
84 - (void)switchToView
:(NSView
*)view
86 NSWindow
*window
= [self window
];
87 NSRect frame
= [window frame
];
90 if ( view
== [window contentView
] ) {
94 xdif
= [view frame
].size.width
- [[window contentView
] frame
].size.width
;
95 ydif
= [view frame
].size.height
- [[window contentView
] frame
].size.height
;
97 frame.size.width
+= xdif
;
98 frame.size.height
+= ydif
;
99 frame.origin.y
-= ydif
;
101 // switch to the new view
102 [window setContentView
:_contentView
];
103 [window setFrame
:frame display
:YES animate
:YES
];
104 [window setContentView
:view
];
105 [window makeFirstResponder
:view
];
109 - (NSToolbarItem
*)toolbar
:(NSToolbar
*)toolbar itemForItemIdentifier
:(NSString
*)itemIdentifier willBeInsertedIntoToolbar
:(BOOL)flag
111 NSToolbarItem
*item
= [[NSToolbarItem alloc
] initWithItemIdentifier
:itemIdentifier
];
113 [item setLabel
:itemIdentifier
];
114 [item setPaletteLabel
:itemIdentifier
];
115 [item setImage
:[NSImage imageNamed
:itemIdentifier
]];
116 [item setTarget
:self];
117 [item setAction
:NSSelectorFromString( [NSString stringWithFormat
:@
"choose%@:", itemIdentifier
] )];
119 return [item autorelease
];
122 - (NSArray
*)toolbarAllowedItemIdentifiers
:(NSToolbar
*)toolbar
124 return [NSArray arrayWithObjects
:@
"General", @
"Update", @
"Server", nil];
127 - (NSArray
*)toolbarDefaultItemIdentifiers
:(NSToolbar
*)toolbar
129 return [NSArray arrayWithObjects
:@
"General", @
"Update", @
"Server", nil];
132 - (NSArray
*)toolbarSelectableItemIdentifiers
:(NSToolbar
*)toolbar
134 return [NSArray arrayWithObjects
:@
"General", @
"Update", @
"Server", nil];