Class CPApplication

CPObject
    extended byCPResponder
        extended byCPApplication

@implementation CPApplication : CPResponder

CPApplication is THE way to start up the Cappucino framework for your application to use. Every GUI application has exactly one instance of CPApplication (or of a custom subclass of CPApplication). Your program's main() function can create that instance by calling the CPApplicationMain function. A simple example looks like this:

    function main(args, namedArgs)
    {
        CPApplicationMain(args, namedArgs);
    }
    


Method Summary
+(CPApplication)sharedApplication
          Returns the singleton instance of the running application.
-(id)init
          Initializes the Document based application with basic menu functions.
-(void)abortModal
          Aborts the event loop started by runModalForWindow:.
-(CPArray)arguments
-(CPModalSession)beginModalSessionForWindow:(CPWindow)aWindow
          Sets up a modal session with theWindow.
-(void)beginSheet:(CPWindow)aSheet modalForWindow:(CPWindow)aWindow modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo
          Displays a window as a sheet.
-(id)delegate
          Returns the application's delegate.
-(void)doCommandBySelector:(SEL)aSelector
          The receiver will attempt to perform the command, if it responds to it.
-(void)finishLaunching
          This method is called by run before the event loop begins.
-(CPWindow)keyWindow
          Returns the key window.
-(CPMenu)mainMenu
          Returns the application's main menu.
-(CPWindow)mainWindow
          Returns the main window.
-(CPWindow)modalWindow
          Returns the window for the current modal session.
-(CPDictionary)namedArguments
-(void)run
          Calls finishLaunching method which results in starting the main event loop.
-(void)runModalForWindow:(CPWindow)aWindow
          Starts a modal event loop for aWindow.
-(void)runModalSession:(CPModalSession)aModalSession
          Runs a modal session.
-(BOOL)sendAction:(SEL)anAction to:(id)aTarget from:(id)aSender
          Sends an action to a target.
-(void)sendEvent:(CPEvent)anEvent
          Dispatches events to other objects.
-(void)setCallback:(Function)aCallback forNextEventMatchingMask:(unsigned int)aMask untilDate:(CPDate)anExpiration inMode:(CPString)aMode dequeue:(BOOL)shouldDequeue
-(void)setDelegate:(id)aDelegate
          Sets the delegate for this application.
-(void)setMainMenu:(CPMenu)aMenu
          Sets the main menu for the application.
-(CPEvent)setTarget:(id)aTarget selector:(SEL)aSelector forNextEventMatchingMask:(unsigned int)aMask untilDate:(CPDate)anExpiration inMode:(CPString)aMode dequeue:(BOOL)shouldDequeue
-(void)stopModal
          Stops the modal event loop.
-(void)stopModalWithCode:(int)aCode
          Stops the event loop started by runModalForWindow: and sets the code that runModalForWindow: will return.
-(id)targetForAction:(SEL)anAction
          Looks for a target that can handle the specified action.
-(id)targetForAction:(SEL)anAction to:(id)aTarget from:(id)aSender
          Finds a target for the specified action.
-(BOOL)tryToPerform:(SEL)anAction with:(id)anObject
          Tries to perform the action with an argument.
-(CPWindow)windowWithWindowNumber:(int)aWindowNumber
          Returns the CPWindow object corresponding to aWindowNumber.
-(CPArray)windows
          Returns an array of the application's CPWindows.

Methods inherited from class CPObject
initialize, alloc, class, instanceMethodForSelector, instancesRespondToSelector, isSubclassOfClass, load, new, setVersion, superclass, version, init, autorelease, awakeAfterUsingCoder, class, classForCoder, classForKeyedArchiver, className, copy, dealloc, description, doesNotRecognizeSelector, forwardInvocation, hash, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableCopy, performSelector, performSelector, performSelector, release, replacementObjectForArchiver, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, retain, self, superclass

Methods inherited from class CPResponder
acceptsFirstResponder, becomeFirstResponder, deleteBackward, doCommandBySelector, insertLineBreak, insertText, interpretKeyEvents, keyDown, keyUp, menu, mouseDown, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseUp, nextResponder, noResponderFor, performKeyEquivalent, resignFirstResponder, scrollWheel, setMenu, setNextResponder, tryToPerform, undoManager

Delegate Method Summary
-(void)applicationDidFinishLaunching:(CPNotification)aNotification
          Sent from the notification center after the app initializes, but before receiving events.
-(void)applicationWillFinishLaunching:(CPNotification)aNotification
          Sent from the notification center before the app is initialized.

Function Summary
voidCPApplicationMain(args, namedArgs)
          Starts the GUI and Cappuccino frameworks.

Method Detail

sharedApplication

+(CPApplication)sharedApplication
Returns the singleton instance of the running application. If it doesn't exist, it will be created, and then returned.
Returns:
the application singleton

init

-(id)init
Initializes the Document based application with basic menu functions. Functions are New, Open, Undo, Redo, Save, Cut, Copy, Paste.
Returns:
the initialized application

abortModal

-(void)abortModal
Aborts the event loop started by runModalForWindow:

arguments

-(CPArray)arguments

beginModalSessionForWindow

-(CPModalSession)beginModalSessionForWindow:(CPWindow)aWindow
Sets up a modal session with theWindow.
Parameters:
aWindow - the window to set up the modal session for

beginSheet

-(void)beginSheet:(CPWindow)aSheet modalForWindow:(CPWindow)aWindow modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo
Displays a window as a sheet.
Parameters:
aSheet - the window to display as a sheet
aWindow - the window that will hold the sheet as a child
aModalDelegate -
aDidEndSelector -
aContextInfo -

delegate

-(id)delegate
Returns the application's delegate. The app can only have one delegate at a time.

doCommandBySelector

-(void)doCommandBySelector:(SEL)aSelector
The receiver will attempt to perform the command, if it responds to it. If not, the nextResponder will be called to do it.
Parameters:
aSelector - the command to attempt

finishLaunching

-(void)finishLaunching
This method is called by run before the event loop begins. When it successfully completes, it posts the notification CPApplicationDidFinishLaunchingNotification. If you override finishLaunching, the subclass method should invoke the superclass method.

keyWindow

-(CPWindow)keyWindow
Returns the key window.

mainMenu

-(CPMenu)mainMenu
Returns the application's main menu

mainWindow

-(CPWindow)mainWindow
Returns the main window.

modalWindow

-(CPWindow)modalWindow
Returns the window for the current modal session. If there is no modal session, it returns nil.

namedArguments

-(CPDictionary)namedArguments

run

-(void)run
Calls finishLaunching method which results in starting the main event loop.

runModalForWindow

-(void)runModalForWindow:(CPWindow)aWindow
Starts a modal event loop for aWindow
Parameters:
aWindow - the window to start the event loop for

runModalSession

-(void)runModalSession:(CPModalSession)aModalSession
Runs a modal session
Parameters:
aModalSession

sendAction

-(BOOL)sendAction:(SEL)anAction to:(id)aTarget from:(id)aSender
Sends an action to a target.
Parameters:
anAction - the action to send
aTarget - the target for the action
aSender - the action sender
Returns:
YES

sendEvent

-(void)sendEvent:(CPEvent)anEvent
Dispatches events to other objects.
Parameters:
anEvent - the event to dispatch

setCallback

-(void)setCallback:(Function)aCallback forNextEventMatchingMask:(unsigned int)aMask untilDate:(CPDate)anExpiration inMode:(CPString)aMode dequeue:(BOOL)shouldDequeue
Parameters:
aCallback
aMask
anExpiration
aMode
shouldDequeue

setDelegate

-(void)setDelegate:(id)aDelegate
Sets the delegate for this application. The delegate will receive various notifications caused by user interactions during the application's run. The delegate can choose to react to these events.
Parameters:
aDelegate - the delegate object

setMainMenu

-(void)setMainMenu:(CPMenu)aMenu
Sets the main menu for the application
Parameters:
aMenu - the menu to set for the application

setTarget

-(CPEvent)setTarget:(id)aTarget selector:(SEL)aSelector forNextEventMatchingMask:(unsigned int)aMask untilDate:(CPDate)anExpiration inMode:(CPString)aMode dequeue:(BOOL)shouldDequeue
Parameters:
aTarget
aSelector
aMask
anExpiration
aMode
shouldDequeue

stopModal

-(void)stopModal
Stops the modal event loop

stopModalWithCode

-(void)stopModalWithCode:(int)aCode
Stops the event loop started by runModalForWindow: and sets the code that runModalForWindow: will return.
Parameters:
aCode - the return code for the modal event

targetForAction

-(id)targetForAction:(SEL)anAction
Looks for a target that can handle the specified action. Checks for a target in the following order:
  1. a responder from the key window
  2. a responder frmo the main window
  3. the CPApplication instance
  4. the application delegate
  5. the document controller
Parameters:
anAction - the action to handle
Returns:
a target that can respond, or nil if no match could be found

targetForAction

-(id)targetForAction:(SEL)anAction to:(id)aTarget from:(id)aSender
Finds a target for the specified action. If the action is nil, returns nil. If the target is not nil, aTarget is returned. Otherwise, it calls targetForAction: to search for a target.
Parameters:
anAction - the action to find a target for
aTarget - if not nil, this will be returned
aSender
Returns:
a target for the action

tryToPerform

-(BOOL)tryToPerform:(SEL)anAction with:(id)anObject
Tries to perform the action with an argument. Performs the action on itself (if it responds to it), then tries to perform the action on the delegate.
Parameters:
anAction - the action to perform.
anObject - the argument for the action method
Returns:
YES if the action was performed

windowWithWindowNumber

-(CPWindow)windowWithWindowNumber:(int)aWindowNumber
Returns the CPWindow object corresponding to aWindowNumber.
Parameters:
aWindowNumber

windows

-(CPArray)windows
Returns an array of the application's CPWindows

Delegate Method Detail

applicationDidFinishLaunching

-(void)applicationDidFinishLaunching:(CPNotification)aNotification
Sent from the notification center after the app initializes, but before receiving events.
Parameters:
aNotification - contains information about the event

applicationWillFinishLaunching

-(void)applicationWillFinishLaunching:(CPNotification)aNotification
Sent from the notification center before the app is initialized.
Parameters:
aNotification - contains information about the event

Function Detail

CPApplicationMain

function CPApplicationMain(args, namedArgs)
Starts the GUI and Cappuccino frameworks. This function should be called from the main() function of your program.
Arguments
args
namedArgs

Created on Sat Sep 13 14:15:43 PDT 2008