# NSApplication

scottc@net-community.com
far@ix.netcom.com
richard@brainstorm.co.uk

The one and only application class

1996,1999 Free Software Foundation, Inc.
Software documentation for the NSApplication class
AppKit/NSApplication.h
NSCoding
Description forthcoming.
detachDrawingThread:
selector
toTarget:
target
withObject:
argument
Description forthcoming.
sharedApplication
Description forthcoming.
abortModal
Description forthcoming.
activateIgnoringOtherApps:
flag
Description forthcoming.
addWindowsItem:
aWindow
title:
aString
filename:
isFilename
Description forthcoming.
applicationIconImage
Description forthcoming.
arrangeInFront:
sender
Description forthcoming.
beginModalSessionForWindow:
theWindow
Description forthcoming.
beginSheet:
sheet
modalForWindow:
docWindow
modalDelegate:
modalDelegate
didEndSelector:
didEndSelector
contextInfo:
contextInfo
Description forthcoming.
cancelUserAttentionRequest:
request
Description forthcoming.
changeWindowsItem:
aWindow
title:
aString
filename:
isFilename
Description forthcoming.
context
Description forthcoming.
currentEvent
Description forthcoming.
deactivate
Description forthcoming.
delegate
Returns the applications delegate, as set by the -setDelegate: method.

The application delegate will automatically be sent various notifications (as long as it implements the appropriate methods) when application events occur. The method to handle each of these notifications has name mirroring the notification name, so for instance an NSApplicationDidBecomeActiveNotification is handled by an `applicationDidBecomeActive:` method.

NSApplicationDidBecomeActiveNotification
NSApplicationDidFinishLaunchingNotification
NSApplicationDidHideNotification
NSApplicationDidResignActiveNotification
NSApplicationDidUnhideNotification
NSApplicationDidUpdateNotification
NSApplicationWillBecomeActiveNotification
NSApplicationWillFinishLaunchingNotification
NSApplicationWillHideNotification
NSApplicationWillResignActiveNotification
NSApplicationWillTerminateNotification
NSApplicationWillUnhideNotification
NSApplicationWillUpdateNotification

The delegate is also sent various messages to ask for authorisation to perform actions, or to ask it to perform actions (again, as long as it implements the appropriate methods).

applicationShouldTerminateAfterLastWindowClosed:
applicationShouldOpenUntitledFile:
applicationOpenUntitledFile:
applicationShouldTerminate:

The delegate is also called upon to respond to any actions which are not handled by a window, a window delgate, or by the application object itsself.. This is controlled by the -targetForAction: method.

Finally, the application delegate is responsible for handling messages sent to the application from remote processes (see the section documenting distributed objects for NSPasteboard ).

discardEventsMatchingMask:
mask
beforeEvent:
lastEvent
Description forthcoming.
endModalSession:
theSession
Description forthcoming.
endSheet:
sheet
Description forthcoming.
endSheet:
sheet
returnCode:
returnCode
Description forthcoming.
finishLaunching
Description forthcoming.
hide:
sender
Description forthcoming.
hideOtherApplications:
sender
Description forthcoming.
isActive
Description forthcoming.
isHidden
Description forthcoming.
isRunning
Description forthcoming.
keyWindow
Description forthcoming.
mainMenu
Description forthcoming.
mainWindow
Description forthcoming.
makeWindowsPerform:
aSelector
inOrder:
flag
Description forthcoming.
miniaturizeAll:
sender
Description forthcoming.
modalWindow

Returns the window that is part of the current modal session, if any.

See -runModalForWindow:

nextEventMatchingMask:
mask
untilDate:
expiration
inMode:
mode
dequeue:
flag
Description forthcoming.
orderFrontStandardAboutPanel:
sender
Description forthcoming.
orderFrontStandardAboutPanelWithOptions:
dictionary
Description forthcoming.
orderFrontStandardInfoPanel:
sender
Description forthcoming.
orderFrontStandardInfoPanelWithOptions:
dictionary
Description forthcoming.
orderedDocuments
Description forthcoming.
orderedWindows
Description forthcoming.
postEvent:
event
atStart:
flag
Description forthcoming.
preventWindowOrdering
Description forthcoming.
registerServicesMenuSendTypes:
sendTypes
returnTypes:
returnTypes
Description forthcoming.
removeWindowsItem:
aWindow
Description forthcoming.
replyToApplicationShouldTerminate:
shouldTerminate
Description forthcoming.
reportException:
anException
Description forthcoming.
requestUserAttention:
requestType
Description forthcoming.
run
Description forthcoming.
runModalForWindow:
theWindow
Description forthcoming.
runModalForWindow:
theWindow
relativeToWindow:
docWindow
Description forthcoming.
runModalSession:
theSession

Processes one event for a modal session described by the theSession variable. Before processing the event, it makes the session window key and orders the window front, so there is no need to do this separately. When finished, it returns the state of the session (i.e. whether it is still running or has been stopped, etc)

See Also: -runModalForWindow:

sendAction:
aSelector
to:
aTarget
from:
sender
Sends the aSelector message to the receiver returned by the -targetForAction:to:from: method (to which the aTarget and sender arguments are passed).
The method in the receiver must expect a single argument ... the sender.
Any value returned by the method in the receiver is ignored.
This method returns `YES` on success, `NO` on failure (when no receiver can be found for aSelector).
sendEvent:
theEvent
Description forthcoming.
servicesMenu
Description forthcoming.
servicesProvider
Returns the services provided previously registered using the -setServicesProvider: method.
setAppleMenu:
aMenu
Description forthcoming.
setApplicationIconImage:
anImage
Description forthcoming.
setDelegate:
anObject
Sets the delegate of the application to anObject.

Beware, this does not retain anObject, so you must be sure that, in the event of anObject being deallocated, you stop it being the application delagate by calling this method again with another object (or `nil`) as the argument.

setMainMenu:
aMenu
Description forthcoming.
setServicesMenu:
aMenu
Description forthcoming.
setServicesProvider:
anObject
Sets the object which provides services to other applications.
Passing a `nil` value for anObject will result in the provision of services to other applications by this application being disabled.
See NSPasteboard for information about providing services.
setWindowsMenu:
aMenu
Description forthcoming.
setWindowsNeedUpdate:
flag
Description forthcoming.
stop:
sender
Description forthcoming.
stopModal
Description forthcoming.
stopModalWithCode:
returnCode
Description forthcoming.
targetForAction:
aSelector

Returns the target object that will respond to aSelector, if any. The method first checks if any of the key window's first responders, the key window or its delegate responds. Next it checks the main window in the same way. Finally it checks the receiver (NSApplication) and it's delegate.

targetForAction:
theAction
to:
theTarget
from:
sender
If theTarget responds to theAction it is returned, otherwise the application searches for an object which will handle theAction and returns the first object found.
Returns `nil` on failure.
terminate:
sender
Description forthcoming.
tryToPerform:
aSelector
with:
anObject
Attempts to perform aSelector using [NSResponder -tryToPerform:with:] and if that is not possible, attempts to get the application delegate to perform the aSelector.
Returns `YES` if an object was found to perform aSelector, `NO` otherwise.
unhide:
sender
Description forthcoming.
unhideAllApplications:
sender
Description forthcoming.
unhideWithoutActivation
Description forthcoming.
updateWindows
Description forthcoming.
updateWindowsItem:
aWindow
Description forthcoming.
validRequestorForSendType:
sendType
returnType:
returnType
Description forthcoming.
windowWithWindowNumber:
windowNum
Description forthcoming.
windows
Description forthcoming.
windowsMenu
Description forthcoming.
Software documentation for the NSObject(NSServicesRequests) informal protocol
AppKit/NSApplication.h
Description forthcoming.
iconWindow
Description forthcoming.
readSelectionFromPasteboard:
pboard
Description forthcoming.
writeSelectionToPasteboard:
pboard
types:
types
Description forthcoming.
Software documentation for the GSAppDelegateProtocol protocol
AppKit/NSApplication.h
Description forthcoming.
application:
sender
delegateHandlesKey:
key
Description forthcoming.
application:
app
openFile:
filename
Description forthcoming.
application:
app
openFileWithoutUI:
filename
Description forthcoming.
application:
app
openTempFile:
filename
Description forthcoming.
application:
theApplication
printFile:
filename
Description forthcoming.
applicationDidBecomeActive:
aNotification
Description forthcoming.
applicationDidChangeScreenParameters:
aNotification
Description forthcoming.
applicationDidFinishLaunching:
aNotification
Description forthcoming.
applicationDidHide:
aNotification
Description forthcoming.
applicationDidResignActive:
aNotification
Description forthcoming.
applicationDidUnhide:
aNotification
Description forthcoming.
applicationDidUpdate:
aNotification
Description forthcoming.
applicationDockMenu:
sender
Description forthcoming.
applicationOpenUntitledFile:
app
Description forthcoming.
applicationShouldHandleReopen:
theApplication
hasVisibleWindows:
flag
Description forthcoming.
applicationShouldOpenUntitledFile:
sender
Description forthcoming.
applicationShouldTerminate:
sender
Description forthcoming.
applicationShouldTerminateAfterLastWindowClosed:
sender
Description forthcoming.
applicationWillBecomeActive:
aNotification
Description forthcoming.
applicationWillFinishLaunching:
aNotification
Description forthcoming.
applicationWillHide:
aNotification
Description forthcoming.
applicationWillResignActive:
aNotification
Description forthcoming.
applicationWillTerminate:
aNotification
Description forthcoming.
applicationWillUnhide:
aNotification
Description forthcoming.
applicationWillUpdate:
aNotification
Description forthcoming.