Class CPWindow

CPObject
    extended byCPResponder
        extended byCPWindow
Direct Known Subclasses:
CPPanel,

@implementation CPWindow : CPResponder

An CPWindow instance represents a window, panel or menu on the screen.

Each window has a style, which determines how the window is decorated; whether it has a border, a title bar, a resize bar, minimise and close buttons.

A window has a frame. This is the frame of the entire window on the screen, including all decorations and borders. The origin of the frame represents its bottom left corner and the frame is expressed in screen coordinates.

A window always contains a content view which is the highest level view available for public (application) use. This view fills the area of the window inside any decoration/border. This is the only part of the window that application programmers are allowed to draw in directly.

You can convert between view coordinates and window base coordinates using the [CPView -convertPoint:fromView:], [CPView -convertPoint:toView:], [CPView -convertRect:fromView:], and [CPView -convertRect:toView:] methods with a nil view argument.


Global Variables
CPBorderlessBridgeWindowMask = 1 << 20
        
CPTitledWindowMask = 1 << 0
        Titled window mask option.
CPResizableWindowMask = 1 << 3
        Resizable window mask option.
CPClosableWindowMask = 1 << 1
        Closeable window mask option.
CPHUDBackgroundWindowMask = 1 << 21
        
CPBorderlessWindowMask = 0
        Borderless window mask option.
CPMiniaturizableWindowMask = 1 << 2
        Miniaturizabe window mask option.
CPTexturedBackgroundWindowMask = 1 << 8
        Textured window mask option.

Method Summary
+(CGRect)frameRectForContentRect:(CGRect)aContentRect styleMask:(unsigned)aStyleMask
          Returns the frame rectangle used by a window.
-(id)initWithContentRect:(CGRect)aContentRect styleMask:(unsigned int)aStyleMask
          Initializes the window.
-(BOOL)acceptsFirstResponder
          Returns YES if the receiver is able to become the first responder.
-(BOOL)acceptsMouseMovedEvents
-(CPWindow)attachedSheet
          Returns the window's attached sheet.
-(CPColor)backgroundColor
          Returns the window's background color.
-(void)becomeKeyWindow
          Called when the receiver should become the key window.
-(void)becomeMainWindow
          Called to tell the receiver that it has become the main window.
-(BOOL)canBecomeKeyWindow
          Determines if the window can become the key window.
-(BOOL)canBecomeMainWindow
          Returns YES if the window can become the main window.
-(void)center
          Sets the window location to be the center of the screen.
-(void)close
          Closes the window.
-(CGRect)contentRectForFrameRect:(CGRect)aFrame
          Returns the receiver's content rectangle.
-(CPView)contentView
          Returns the window's current content view.
-(id)delegate
          Returns window's delegate.
-(void)doCommandBySelector:(SEL)aSelector
          The receiver will attempt to perform the command, if it responds to it.
-(void)dragImage:(CPImage)anImage at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(CPEvent)anEvent pasteboard:(CPPasteboard)aPasteboard source:(id)aSourceObject slideBack:(BOOL)slideBack
          Initiates a drag operation from the receiver to another view that accepts dragged data.
-(void)dragView:(CPView)aView at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(CPEvent)anEvent pasteboard:(CPPasteboard)aPasteboard source:(id)aSourceObject slideBack:(BOOL)slideBack
          Initiates a drag operation from the receiver to another view that accepts dragged data.
-(CPResponder)firstResponder
          Returns the window's current first responder.
-(CGRect)frame
          Returns the window's frame rectangle.
-(CGRect)frameRectForContentRect:(CGRect)aContentRect
          Retrieves the frame rectangle for this window.
-(BOOL)hasShadow
          Returns YES if the window has a drop shadow.
-(BOOL)isDocumentEdited
          Returns YES if the document has been edited.
-(BOOL)isDocumentSaving
-(BOOL)isKeyWindow
          Returns YES if the window is the key window.
-(BOOL)isMainWindow
          Returns YES if this the main window.
-(BOOL)isMovableByWindowBackground
          Returns YES if the window can be moved by dragging its background.
-(BOOL)isSheet
          Returns YES if the window has ever run as a sheet.
-(BOOL)isVisible
          Returns YES if the window is visible.
-(int)level
          Returns the window's current level.
-(void)makeFirstResponder:(CPResponder)aResponder
          Attempts to make the aResponder the first responder.
-(void)makeKeyAndOrderFront:(id)aSender
          Makes the window the key window and brings it to the front of the screen list.
-(void)makeKeyWindow
          Makes this window the key window.
-(void)makeMainWindow
          Makes the receiver the main window.
-(CGSize)maxSize
          Returns the window's maximum size.
-(CGSize)minSize
          Returns the windows minimum size.
-(void)orderFront:(id)aSender
          Makes the receiver the front most window in the screen ordering.
-(void)orderOut:(id)aSender
          Hides the window.
-(void)orderWindow:(CPWindowOrderingMode)aPlace relativeTo:(int)otherWindowNumber
          Relocates the window in the screen list.
-(void)performClose:(id)aSender
          Simulates the user closing the window, then closes the window.
-(void)redo:(id)aSender
          Sends the undo manager a redo: message.
-(CPString)representedFilename
          Returns the path to the file the receiver represents.
-(CPURL)representedURL
          Returns the URL that the receiver represents.
-(void)resignKeyWindow
          Causes the window to resign it's key window status.
-(void)resignMainWindow
          Called when the window resigns main window status.
-(CGSize)resizeIndicatorOffset
          Returns the offset of the window's resize indicator.
-(void)sendEvent:(CPEvent)anEvent
          Dispatches events that are sent to it from CPApplication.
-(void)setAcceptsMouseMovedEvents:(BOOL)shouldAcceptMouseMovedEvents
-(void)setBackgroundColor:(CPColor)aColor
          Sets the window's background color.
-(void)setContentView:(CPView)aView
          Sets the window's content view.
-(void)setDelegate:(id)aDelegate
          Sets the delegate for the window.
-(void)setDocumentEdited:(BOOL)isDocumentEdited
          Sets whether the document has been edited.
-(void)setDocumentSaving:(BOOL)isDocumentSaving
-(void)setFrame:(CGRect)aFrame
          Sets the window's frame rectangle.
-(void)setFrameOrigin:(CGPoint)anOrigin
          Sets the window's location.
-(void)setFrameSize:(CGSize)aSize
          Sets the window's size.
-(void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate
          Sets the window's frame rectangle.
-(void)setHasShadow:(BOOL)shouldHaveShadow
          Sets whether the window should have a drop shadow.
-(void)setLevel:(int)aLevel
          Sets the window's level.
-(void)setMaxSize:(CGSize)aSize
          Sets the window's maximum size.
-(void)setMinSize:(CGSize)aSize
          Sets the window's minimum size.
-(void)setMovableByWindowBackground:(BOOL)shouldBeMovableByWindowBackground
          Sets whether the window can be moved by dragging its background.
-(void)setRepresentedFilename:(CPString)aFilePath
          Sets the path to the file the receiver represents.
-(void)setRepresentedURL:(CPURL)aURL
          Sets the URL that the receiver represents.
-(void)setResizeIndicatorOffset:(CGSize)anOffset
          Sets the offset of the window's resize indicator.
-(void)setShowsResizeIndicator:(BOOL)shouldShowResizeIndicator
          Sets the window's resize indicator.
-(void)setTitle:(CPString)aTitle
          Sets the window's title bar string.
-(void)setTitleWithRepresentedFilename:(CPString)aFilePath
          Sets the title bar to represent a file path.
-(void)setToolbar:(CPToolbar)aToolbar
          Sets the window's toolbar.
-(void)setWindowController:(CPWindowController)aWindowController
          Sets the window's controller.
-(BOOL)showsResizeIndicator
          Returns YES if the window's resize indicator is showing.
-(unsigned)styleMask
          Returns the window's style mask.
-(CPString)title
          Returns the window's title bar string.
-(CPToolbar)toolbar
          Return's the window's toolbar.
-(void)undo:(id)aSender
          Sends the undo manager an undo message.
-(CPUndoManager)undoManager
          Returns the window's undo manager.
-(CPWindowController)windowController
          Returns the window's controller.
-(int)windowNumber
          Returns the window's number in the desktop's screen list.
-(BOOL)worksWhenModal
          Returns YES if the receiver is able to receive input events even when a modal session is active.

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)windowDidResize:(CPNotification)notification
          Sent from the notification center when the window has been resized.
-(CPUndoManager)windowWillReturnUndoManager:(CPWindow)window
          Called to obtain the undo manager for a window.
-(void)windowDidBecomeMain:(CPNotification)notification
          Sent from the notification center when the delegate's window becomes the main window.
-(void)windowDidResignMain:(CPNotification)notification
          Sent from the notification center when the delegate's window has resigned main window status.
-(void)windowDidResignKey:(CPNotification)notification
          Sent from the notification center when the delegate's window has resigned key window status.
-(BOOL)windowShouldClose:(id)window
          Called when the user tries to close the window.


Method Detail

frameRectForContentRect

+(CGRect)frameRectForContentRect:(CGRect)aContentRect styleMask:(unsigned)aStyleMask
Returns the frame rectangle used by a window.
Parameters:
aContentRect - the content rectangle of the window
aStyleMask - the style mask of the window
Returns:
the matching window's frame rectangle

initWithContentRect

-(id)initWithContentRect:(CGRect)aContentRect styleMask:(unsigned int)aStyleMask
Initializes the window. The method also takes a style bit mask made up of any of the following values:
CPBorderlessWindowMask
CPTitledWindowMask
CPClosableWindowMask
CPMiniaturizableWindowMask
CPResizableWindowMask
CPTexturedBackgroundWindowMask
Parameters:
aContentRect - the size and location of the window in screen space
aStyleMask - a style mask
Returns:
the initialized window

acceptsFirstResponder

-(BOOL)acceptsFirstResponder
Returns YES if the receiver is able to become the first responder. NO otherwise.

acceptsMouseMovedEvents

-(BOOL)acceptsMouseMovedEvents

attachedSheet

-(CPWindow)attachedSheet
Returns the window's attached sheet.

backgroundColor

-(CPColor)backgroundColor
Returns the window's background color.

becomeKeyWindow

-(void)becomeKeyWindow
Called when the receiver should become the key window. It also sends the becomeKeyWindow message to the first responder.

becomeMainWindow

-(void)becomeMainWindow
Called to tell the receiver that it has become the main window.

canBecomeKeyWindow

-(BOOL)canBecomeKeyWindow
Determines if the window can become the key window.
Returns:
YES means the window can become the key window.

canBecomeMainWindow

-(BOOL)canBecomeMainWindow
Returns YES if the window can become the main window.

center

-(void)center
Sets the window location to be the center of the screen

close

-(void)close
Closes the window. Posts a CPWindowWillCloseNotification to the notification center before closing the window.

contentRectForFrameRect

-(CGRect)contentRectForFrameRect:(CGRect)aFrame
Returns the receiver's content rectangle. A content rectangle does not include toolbars.
Parameters:
aFrame - the window's frame rectangle

contentView

-(CPView)contentView
Returns the window's current content view.

delegate

-(id)delegate
Returns window's delegate

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

dragImage

-(void)dragImage:(CPImage)anImage at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(CPEvent)anEvent pasteboard:(CPPasteboard)aPasteboard source:(id)aSourceObject slideBack:(BOOL)slideBack
Initiates a drag operation from the receiver to another view that accepts dragged data.
Parameters:
anImage - the image to be dragged
imageLocation
mouseOffset - the distance from the mouseDown: location and the current location
anEvent - the mouseDown: that triggered the drag
aPasteboard
aSourceObject - the drag operation controller
slideBack - Whether the image should 'slide back' if the drag is rejected

dragView

-(void)dragView:(CPView)aView at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(CPEvent)anEvent pasteboard:(CPPasteboard)aPasteboard source:(id)aSourceObject slideBack:(BOOL)slideBack
Initiates a drag operation from the receiver to another view that accepts dragged data.
Parameters:
aView - the view to be dragged
imageLocation
mouseOffset - the distance from the mouseDown: location and the current location
anEvent - the mouseDown: that triggered the drag
aPasteboard
aSourceObject - the drag operation controller
slideBack - Whether the view should 'slide back' if the drag is rejected

firstResponder

-(CPResponder)firstResponder
Returns the window's current first responder.

frame

-(CGRect)frame
Returns the window's frame rectangle

frameRectForContentRect

-(CGRect)frameRectForContentRect:(CGRect)aContentRect
Retrieves the frame rectangle for this window.
Parameters:
aContentRect - the window's content rectangle
Returns:
the window's frame rectangle

hasShadow

-(BOOL)hasShadow
Returns YES if the window has a drop shadow. NO otherwise.

isDocumentEdited

-(BOOL)isDocumentEdited
Returns YES if the document has been edited.

isDocumentSaving

-(BOOL)isDocumentSaving

isKeyWindow

-(BOOL)isKeyWindow
Returns YES if the window is the key window.

isMainWindow

-(BOOL)isMainWindow
Returns YES if this the main window.

isMovableByWindowBackground

-(BOOL)isMovableByWindowBackground
Returns YES if the window can be moved by dragging its background.

isSheet

-(BOOL)isSheet
Returns YES if the window has ever run as a sheet.

isVisible

-(BOOL)isVisible
Returns YES if the window is visible. It does not mean that the window is not obscured by other windows.

level

-(int)level
Returns the window's current level

makeFirstResponder

-(void)makeFirstResponder:(CPResponder)aResponder
Attempts to make the aResponder the first responder. Before trying to make it the first responder, the receiver will ask the current first responder to resign its first responder status. If it resigns, it will ask aResponder accept first responder, then finally tell it to become first responder.
Parameters:
aResponder
Returns:
YES if the attempt was successful. NO otherwise.

makeKeyAndOrderFront

-(void)makeKeyAndOrderFront:(id)aSender
Makes the window the key window and brings it to the front of the screen list.
Parameters:
aSender - the object requesting this

makeKeyWindow

-(void)makeKeyWindow
Makes this window the key window.

makeMainWindow

-(void)makeMainWindow
Makes the receiver the main window.

maxSize

-(CGSize)maxSize
Returns the window's maximum size.

minSize

-(CGSize)minSize
Returns the windows minimum size.

orderFront

-(void)orderFront:(id)aSender
Makes the receiver the front most window in the screen ordering.
Parameters:
aSender - the object that requested this

orderOut

-(void)orderOut:(id)aSender
Hides the window.
Parameters:
aSender

orderWindow

-(void)orderWindow:(CPWindowOrderingMode)aPlace relativeTo:(int)otherWindowNumber
Relocates the window in the screen list.
Parameters:
aPlace - the positioning relative to otherWindowNumber
otherWindowNumber - the window relative to which the receiver should be placed

performClose

-(void)performClose:(id)aSender
Simulates the user closing the window, then closes the window.
Parameters:
aSender - the object making this request

redo

-(void)redo:(id)aSender
Sends the undo manager a redo: message.
Parameters:
aSender - the object requesting this

representedFilename

-(CPString)representedFilename
Returns the path to the file the receiver represents

representedURL

-(CPURL)representedURL
Returns the URL that the receiver represents

resignKeyWindow

-(void)resignKeyWindow
Causes the window to resign it's key window status.

resignMainWindow

-(void)resignMainWindow
Called when the window resigns main window status.

resizeIndicatorOffset

-(CGSize)resizeIndicatorOffset
Returns the offset of the window's resize indicator.

sendEvent

-(void)sendEvent:(CPEvent)anEvent
Dispatches events that are sent to it from CPApplication.
Parameters:
anEvent - the event to be dispatched

setAcceptsMouseMovedEvents

-(void)setAcceptsMouseMovedEvents:(BOOL)shouldAcceptMouseMovedEvents
Parameters:
shouldAcceptMouseMovedEvents

setBackgroundColor

-(void)setBackgroundColor:(CPColor)aColor
Sets the window's background color.
Parameters:
aColor - the new color for the background

setContentView

-(void)setContentView:(CPView)aView
Sets the window's content view. The new view will be resized to fit inside the content rectangle of the window.
Parameters:
aView - the new content view for the receiver

setDelegate

-(void)setDelegate:(id)aDelegate
Sets the delegate for the window. Passing nil will just remove the window's current delegate.
Parameters:
aDelegate - an object to respond to the various delegate methods of CPWindow

setDocumentEdited

-(void)setDocumentEdited:(BOOL)isDocumentEdited
Sets whether the document has been edited.
Parameters:
isDocumentEdited - YES if the document has been edited.

setDocumentSaving

-(void)setDocumentSaving:(BOOL)isDocumentSaving
Parameters:
isDocumentSaving

setFrame

-(void)setFrame:(CGRect)aFrame
Sets the window's frame rectangle
Parameters:
aFrame

setFrameOrigin

-(void)setFrameOrigin:(CGPoint)anOrigin
Sets the window's location.
Parameters:
anOrigin - the new location for the window

setFrameSize

-(void)setFrameSize:(CGSize)aSize
Sets the window's size.
Parameters:
aSize - the new size for the window

setFrame

-(void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate
Sets the window's frame rectangle. Also tells the window whether it should animate the resize operation, and redraw itself if necessary.
Parameters:
aFrame - the new size and location for the window
shouldDisplay - whether the window should redraw its views
shouldAnimate - whether the window resize should be animated

setHasShadow

-(void)setHasShadow:(BOOL)shouldHaveShadow
Sets whether the window should have a drop shadow.
Parameters:
shouldHaveShadow - YES to have a drop shadow.

setLevel

-(void)setLevel:(int)aLevel
Sets the window's level
Parameters:
aLevel

setMaxSize

-(void)setMaxSize:(CGSize)aSize
Sets the window's maximum size. If the provided size is the same as the current maximum size, the method simply returns.
Parameters:
aSize - the new maximum size

setMinSize

-(void)setMinSize:(CGSize)aSize
Sets the window's minimum size. If the provided size is the same as the current minimum size, the method simply returns.
Parameters:
aSize

setMovableByWindowBackground

-(void)setMovableByWindowBackground:(BOOL)shouldBeMovableByWindowBackground
Sets whether the window can be moved by dragging its background. The default is based on the window style.
Parameters:
shouldBeMovableByWindowBackground - YES makes the window move from a background drag.

setRepresentedFilename

-(void)setRepresentedFilename:(CPString)aFilePath
Sets the path to the file the receiver represents
Parameters:
aFilePath

setRepresentedURL

-(void)setRepresentedURL:(CPURL)aURL
Sets the URL that the receiver represents
Parameters:
aURL

setResizeIndicatorOffset

-(void)setResizeIndicatorOffset:(CGSize)anOffset
Sets the offset of the window's resize indicator.
Parameters:
anOffset

setShowsResizeIndicator

-(void)setShowsResizeIndicator:(BOOL)shouldShowResizeIndicator
Sets the window's resize indicator.
Parameters:
shouldShowResizeIndicator - YES sets the window to show its resize indicator.

setTitle

-(void)setTitle:(CPString)aTitle
Sets the window's title bar string
Parameters:
aTitle

setTitleWithRepresentedFilename

-(void)setTitleWithRepresentedFilename:(CPString)aFilePath
Sets the title bar to represent a file path
Parameters:
aFilePath

setToolbar

-(void)setToolbar:(CPToolbar)aToolbar
Sets the window's toolbar.
Parameters:
aToolbar - the window's new toolbar

setWindowController

-(void)setWindowController:(CPWindowController)aWindowController
Sets the window's controller
Parameters:
aWindowController - a window controller

showsResizeIndicator

-(BOOL)showsResizeIndicator
Returns YES if the window's resize indicator is showing. NO otherwise.

styleMask

-(unsigned)styleMask
Returns the window's style mask.

title

-(CPString)title
Returns the window's title bar string

toolbar

-(CPToolbar)toolbar
Return's the window's toolbar

undo

-(void)undo:(id)aSender
Sends the undo manager an undo message.
Parameters:
aSender - the object requesting this

undoManager

-(CPUndoManager)undoManager
Returns the window's undo manager.

windowController

-(CPWindowController)windowController
Returns the window's controller.

windowNumber

-(int)windowNumber
Returns the window's number in the desktop's screen list

worksWhenModal

-(BOOL)worksWhenModal
Returns YES if the receiver is able to receive input events even when a modal session is active.

Delegate Method Detail

windowDidResize

-(void)windowDidResize:(CPNotification)notification
Sent from the notification center when the window has been resized.
Parameters:
notification - contains information about the resize event

windowWillReturnUndoManager

-(CPUndoManager)windowWillReturnUndoManager:(CPWindow)window
Called to obtain the undo manager for a window
Parameters:
window - the window for which to return the undo manager
Returns:
the window's undo manager

windowDidBecomeMain

-(void)windowDidBecomeMain:(CPNotification)notification
Sent from the notification center when the delegate's window becomes the main window.
Parameters:
notification - contains information about the event

windowDidResignMain

-(void)windowDidResignMain:(CPNotification)notification
Sent from the notification center when the delegate's window has resigned main window status.
Parameters:
notification - contains information about the event

windowDidResignKey

-(void)windowDidResignKey:(CPNotification)notification
Sent from the notification center when the delegate's window has resigned key window status.
Parameters:
notification - contains information about the event

windowShouldClose

-(BOOL)windowShouldClose:(id)window
Called when the user tries to close the window.
Parameters:
window - the window to close
Returns:
YES allows the window to close. NO vetoes the close operation and leaves the window open.

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