| 1 |
#!/usr/bin/env ikarus --r6rs-script |
| 2 |
|
| 3 |
(import (ikarus) (objc) (Cocoa) (Cocoa helpers)) |
| 4 |
|
| 5 |
(define-class NSTableView) |
| 6 |
(define-class NSTableColumn) |
| 7 |
(define-class NSColor) |
| 8 |
(define-class NSButton) |
| 9 |
(define-class NSImageView) |
| 10 |
|
| 11 |
(define pool [$ [$ NSAutoreleasePool alloc] init]) |
| 12 |
|
| 13 |
(make-app) |
| 14 |
[$ NSApplication sharedApplication] |
| 15 |
|
| 16 |
(define (setup-menu app-name) |
| 17 |
(define (make-menu title) |
| 18 |
[$ [$ NSMenu alloc] initWithTitle: (nsstring title)]) |
| 19 |
[$ NSApp setMainMenu: (make-menu "")] |
| 20 |
(let ([apple-menu (make-menu "")]) |
| 21 |
(define (add-item name key action mod) |
| 22 |
(let ([x [$ apple-menu |
| 23 |
addItemWithTitle: (nsstring name) |
| 24 |
action: (get-selector action) |
| 25 |
keyEquivalent: (nsstring key)]]) |
| 26 |
(when mod |
| 27 |
[$ x setKeyEquivalentModifierMask: mod]))) |
| 28 |
(define (add-separator) |
| 29 |
[$ apple-menu addItem: [$ NSMenuItem separatorItem]]) |
| 30 |
(add-item (string-append "About " app-name) "" |
| 31 |
"orderFrontStandardAboutPanel:" #f) |
| 32 |
(add-separator) |
| 33 |
(add-item (string-append "Hide " app-name) "h" "hide:" #f) |
| 34 |
(add-item "Hide Others" "h" "hideOtherApplications:" |
| 35 |
(bitwise-ior NSAlternateKeyMask NSCommandKeyMask)) |
| 36 |
(add-item "Show All" "" "unhideAllApplications:" #f) |
| 37 |
(add-separator) |
| 38 |
(add-item (string-append "Quit " app-name) "q" "terminate:" #f) |
| 39 |
(let ([menu-item |
| 40 |
[$ [$ NSMenuItem alloc] |
| 41 |
initWithTitle: (nsstring "") |
| 42 |
action: #f |
| 43 |
keyEquivalent: (nsstring "")]]) |
| 44 |
[$ menu-item setSubmenu: apple-menu] |
| 45 |
[$ [$ NSApp mainMenu] addItem: menu-item] |
| 46 |
[$ NSApp setAppleMenu: apple-menu] |
| 47 |
[$ menu-item release]) |
| 48 |
[$ apple-menu release])) |
| 49 |
|
| 50 |
(setup-menu "Hello Ikarus") |
| 51 |
|
| 52 |
(define style |
| 53 |
(bitwise-ior |
| 54 |
NSTitledWindowMask |
| 55 |
NSClosableWindowMask |
| 56 |
NSResizableWindowMask |
| 57 |
NSMiniaturizableWindowMask)) |
| 58 |
|
| 59 |
(define backing NSBackingStoreBuffered) |
| 60 |
|
| 61 |
(define win |
| 62 |
[$ [$ NSWindow alloc] |
| 63 |
initWithContentRect: '#(#(400 500) #(400 500)) |
| 64 |
styleMask: style |
| 65 |
backing: backing |
| 66 |
defer: #f]) |
| 67 |
|
| 68 |
[$ win setTitle: (nsstring "Hello Ikarus")] |
| 69 |
;[$ win setAlphaValue: 3/4] ; cute |
| 70 |
|
| 71 |
#; ; button test |
| 72 |
(let ([btn [$ [$ NSButton alloc] init]]) |
| 73 |
[$ btn setTitle: (nsstring "Quit")] |
| 74 |
[$ btn setTarget: NSApp] |
| 75 |
[$ btn setAction: (get-selector "terminate:")] |
| 76 |
[$ win setContentView: btn]) |
| 77 |
|
| 78 |
#; |
| 79 |
(let ([table [$ [$ NSTableView alloc] init]]) |
| 80 |
[$ table setBackgroundColor: [$ NSColor blueColor]] |
| 81 |
(printf "~s\n" [$ table headerView]) |
| 82 |
|
| 83 |
(let ([col [$ [$ NSTableColumn alloc] init]]) |
| 84 |
[$ table addTableColumn: col] |
| 85 |
[$ [$ col headerCell] setStringValue: (nsstring "header")]) |
| 86 |
[$ win setContentView: table] |
| 87 |
[$ win setDelegate: table]) |
| 88 |
|
| 89 |
[$ win makeKeyAndOrderFront: win] |
| 90 |
|
| 91 |
[$ NSApp run] |
| 92 |
[$ pool release] |
| 93 |
|
| 94 |
(printf "back!\n") |