/** PKPreferencePane PKPreferencePane.m Preference pane class (was GSPreferencePane) Copyright (C) 2006 Yen-Ju Chen Copyright (C) 2004 Uli Kusterer Author: Yen-Ju Chen Author: Uli Kusterer Quentin Mathe Date: August 2004 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #import #import #import "GNUstep.h" NSString *NSPreferencePaneDoUnselectNotification = @"NSPreferencePaneDoUnselect"; NSString *NSPreferencePaneCancelUnselectNotification = @"NSPreferencePaneCancelUnselect"; /*

PKPreferencePane Description

*/ @implementation PKPane /** */ - (id) initWithBundle: (NSBundle *) bundle { self = [self init]; ASSIGN(_bundle, bundle); return self; } - (void) dealloc { DESTROY(_bundle); [_topLevelObjects makeObjectsPerformSelector: @selector(release)]; DESTROY(_topLevelObjects); [super dealloc]; } /**

Returns the bundle instance which the preference pane stored.

*/ - (NSBundle *) bundle { return _bundle; } /**

Loads preference pane's view by loading the nib file which contains it.

Related nib file is known by -mainNibName.

*/ - (NSView *) loadMainView { // NOTE: Paranoid check which eliminates the possibility to reload the nib // when the mainView is possibly still in use. if ([self mainView] != nil) return nil; ASSIGN(_topLevelObjects, AUTORELEASE([[NSMutableArray alloc] init])); NSDictionary* ent = [NSDictionary dictionaryWithObjectsAndKeys: self, @"NSOwner", _topLevelObjects, @"NSTopLevelObjects", nil]; if ( ![_bundle loadNibFile: [self mainNibName] externalNameTable: ent withZone: [self zone]] ) { NSLog(@"Failed to load main view bundle"); return nil; } [self assignMainView]; [self mainViewDidLoad]; return _mainView; } /**

Assigns the main view loaded with -loadMainView.

By default this method, retrieves the main view by calling -contentView on window referenced in the nib file by _window outlet.

Overrides this method if your preference pane view is located in different place within the nib file. Takes note that when assignement is done, _window is released and sets to nil. Finally this method returns -mainView if no errors occured, otherwise nil.

*/ - (NSView *) assignMainView { [self setMainView: [_window contentView]]; DESTROY(_window); return [self mainView]; } /**

Returns the nib name advertised as main in enclosing bundle's property list.

Related nib file is known by mainNibName.

*/ - (NSString *) mainNibName { return [[_bundle infoDictionary] objectForKey: @"NSMainNibFile"]; } /** */ - (void) willSelect {} /** */ - (void) didSelect {} /** */ - (void) willUnselect {} /** */ - (void) didUnselect {} /**

Notifies the preference pane that everything is set up and ready to be displayed, similarly to -windowDidLoad when the main nib file has been awaken. It is called by -loadMainView when the main view is correctly set. By default this method does nothing.

Override this method to have extra preference pane view set up according to its stored settings.

*/ - (void) mainViewDidLoad {} /**

Returns a value to state if the preference pane accepts to be deselected right now. Various values may be returned, look at NSPreferencePaneUnselectReply constants.

Overrides this method when you want to delay or cancel a deselect request, but take note that you will have to call -replyToShouldUnselect: later (when deselection is processed) if you return NSUnselectLater.

*/ - (NSPreferencePaneUnselectReply) shouldUnselect { return NSUnselectNow; } /**

Asks the preference pane to know if it accepts to be deselected.

Take care to invoke this method yourself when you have overriden -shouldUnselect to return NSUnselectLater (it implies you know when the preference should be unselected).

*/ - (void) replyToShouldUnselect: (BOOL) shouldUnselect { if ( shouldUnselect ) [_owner updateUIForPane: nil]; } /**

Sets the preference pane view which is presented to the user.

Take note, you should avoid to call this method in your code unless you have already overriden -loadMainView and -assignMainView.

*/ -(void) setMainView: (NSView *) view { ASSIGN(_mainView, view); } /**

Returns the preference pane view which is presented to the user.

*/ - (NSView *) mainView { return _mainView; } /**

Returns the view which initially owns the focus in the responder chain when the preference pane view is loaded.

*/ - (NSView *) initialKeyView { return _initialKeyView; } /**

Sets the view which initially owns the focus in the responder chain when the preference pane view is loaded.

*/ - (void) setInitialKeyView: (NSView *) view { ASSIGN(_initialKeyView, view); } /**

Returns the view which starts the responder chain bound to the preference pane view.

*/ - (NSView *) firstKeyView { return _firstKeyView; } /**

Sets the view which starts the responder chain bound to the preference pane view.

*/ - (void) setFirstKeyView: (NSView *) view { ASSIGN(_firstKeyView, view); } /**

Returns the view which ends the responder chain bound to the preference pane view.

*/ - (NSView *) lastKeyView { return _lastKeyView; } /**

Sets the view which ends the responder chain bound to the preference pane view.

*/ - (void) setLastKeyView: (NSView *) view { ASSIGN(_lastKeyView, view); } /**

Returns YES when text fields are asked to resign their responder status when -shouldUnselect is going to be called, otherwise returns NO if the preference pane must itself request each text field resigning its responder status (to have their content saved).

By default this method returns YES, but it is possible to override it to alter the returned value.

*/ - (BOOL) autoSaveTextFields { return YES; } /**

Returns YES when the receiver is the currently selected preference pane, otherwise returns NO.

*/ - (BOOL) isSelected { return( [_owner selectedPane] == self ); } /**

Not implemented.

*/ -(void) updateHelpMenuWithArray:(NSArray *)inArrayOfMenuItems { NSLog(@"PKPane: updateHelpMenuWithArray: not yet implemented."); } /* Private */ -(void) setOwner: (id )owner { _owner = owner; } @end