factor/library/ui/cocoa/window-utils.factor

80 lines
2.2 KiB
Factor
Raw Normal View History

2006-02-09 20:36:11 -05:00
! Copyright (C) 2006 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
IN: objc-classes
DEFER: FactorWindowDelegate
2006-02-09 20:36:11 -05:00
IN: cocoa
USING: arrays gadgets kernel math objc sequences ;
2006-02-09 20:36:11 -05:00
: NSBorderlessWindowMask 0 ; inline
: NSTitledWindowMask 1 ; inline
: NSClosableWindowMask 2 ; inline
: NSMiniaturizableWindowMask 4 ; inline
: NSResizableWindowMask 8 ; inline
: NSBackingStoreRetained 0 ; inline
: NSBackingStoreNonretained 1 ; inline
: NSBackingStoreBuffered 2 ; inline
: standard-window-type
NSTitledWindowMask
NSClosableWindowMask bitor
NSMiniaturizableWindowMask bitor
NSResizableWindowMask bitor ; inline
2006-05-26 02:29:44 -04:00
: <NSWindow> ( rect -- window )
NSWindow -> alloc swap
2006-02-09 22:11:22 -05:00
standard-window-type NSBackingStoreBuffered 1
-> initWithContentRect:styleMask:backing:defer: ;
2006-03-17 02:50:16 -05:00
: <ViewWindow> ( view bounds -- window )
<NSWindow> [ swap -> setContentView: ] keep
dup dup -> contentView -> setInitialFirstResponder:
dup 1 -> setAcceptsMouseMovedEvents: ;
: window-pref-dim -> contentView window pref-dim ;
: frame-content-rect ( window rect -- rect )
swap -> styleMask NSWindow -rot
-> frameRectForContentRect:styleMask: ;
: window-content-rect ( window -- rect )
NSWindow over -> frame rot -> styleMask
-> contentRectForFrameRect:styleMask: ;
"NSObject" "FactorWindowDelegate" {
{
"windowWillUseStandardFrame:defaultFrame:" "NSRect"
{ "id" "SEL" "id" "NSRect" }
[
drop 2nip
dup window-content-rect NSRect-x-far-y
pick window-pref-dim first2 <far-y-NSRect>
frame-content-rect
]
}
2006-05-28 18:35:01 -04:00
{
"windowDidMove:" "void" { "id" "SEL" "id" } [
2nip -> object
2006-06-23 00:06:53 -04:00
dup window-content-rect NSRect-x-y 2array
swap -> contentView window set-world-loc
]
}
2006-05-28 18:35:01 -04:00
{
"windowDidBecomeKey:" "void" { "id" "SEL" "id" } [
2nip -> object -> contentView window focus-world
2006-05-28 18:35:01 -04:00
]
}
{
"windowDidResignKey:" "void" { "id" "SEL" "id" } [
2nip -> object -> contentView window unfocus-world
2006-05-28 18:35:01 -04:00
]
}
} { } define-objc-class
: install-window-delegate ( window -- )
2006-05-28 20:28:26 -04:00
FactorWindowDelegate install-delegate ;