From cd9d36b82c4c46e651ddccfdc0f986b85bbac2b8 Mon Sep 17 00:00:00 2001 From: slava Date: Sat, 14 Oct 2006 00:37:14 +0000 Subject: [PATCH] Cocoa: support method redefinition --- TODO.FACTOR.txt | 11 +++---- .../compiler/alien/objc/subclassing.factor | 32 ++++++++++--------- library/ui/cocoa/callback.factor | 2 +- library/ui/cocoa/services.factor | 2 +- library/ui/cocoa/test/cocoa.factor | 2 -- library/ui/cocoa/ui.factor | 2 +- library/ui/cocoa/view-utils.factor | 2 +- library/ui/cocoa/window-utils.factor | 2 +- library/ui/gadgets/lists.factor | 4 ++- 9 files changed, 30 insertions(+), 29 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index b51c04905d..4f3317d188 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,11 +1,14 @@ - auto-invoke code gc - fix alien-callback/SEH bug on win32 -- x11: scroll up/down wiggles caret +- live search: timer delay would be nice +- help responder has no way to access { "foo" "bar" } +- httpd search tools +- polish OS X menu bar code +- list selection broken + ui: - completion is not ideal: eg, search for "buttons" -- live search: timer delay would be nice - some way of intercepting all gestures - slider needs to be modelized - better help result ranking @@ -28,7 +31,6 @@ space - grid slows down with 2000 lines - see if its possible to only repaint dirty regions -- polish OS X menu bar code - structure editor + module system: @@ -46,7 +48,6 @@ + compiler/ffi: - more compact relocation info -- cocoa: support real redefinition - relocation should not cons at all - stdcall callbacks - [ [ dup call ] dup call ] infer hangs @@ -85,6 +86,4 @@ + httpd: -- help responder has no way to access { "foo" "bar" } -- httpd search tools - remaining HTML issues need fixing diff --git a/library/compiler/alien/objc/subclassing.factor b/library/compiler/alien/objc/subclassing.factor index 927984a152..06319a8279 100644 --- a/library/compiler/alien/objc/subclassing.factor +++ b/library/compiler/alien/objc/subclassing.factor @@ -19,9 +19,8 @@ libc math namespaces sequences strings words ; dup length dup -rot [ pick method-list@ objc-method-nth init-method ] 2each ; -: ( methods -- lists ) - alien-address - "void*" [ 0 set-alien-unsigned-cell ] keep ; +: define-objc-methods ( class methods -- ) + class_addMethods ; : ( name info -- class ) "objc-class" @@ -42,23 +41,23 @@ libc math namespaces sequences strings words ; dup objc-class-super-class objc-class-instance-size swap set-objc-class-instance-size ; -: ( methods superclass name -- class ) +: ( superclass name -- class ) CLS_META [ >r dup objc-class-isa r> set-objc-class-super-class ] keep [ >r meta-meta-class r> set-objc-class-isa ] keep - [ >r r> set-objc-class-methodLists ] keep dup copy-instance-size ; -: ( methods metaclass superclass name -- class ) +: ( metaclass superclass name -- class ) CLS_CLASS [ set-objc-class-super-class ] keep [ set-objc-class-isa ] keep - [ >r r> set-objc-class-methodLists ] keep dup copy-instance-size ; -: (define-objc-class) ( imeth cmeth superclass name -- ) - >r objc-class r> [ ] 2keep - objc_addClass ; +: (define-objc-class) ( superclass name imeth -- ) + >r + >r objc-class r> + [ ] 2keep dup objc_addClass + r> class_addMethods ; : encode-types ( return types -- encoding ) >r 1array r> append @@ -78,8 +77,11 @@ libc math namespaces sequences strings words ; : prepare-methods ( methods -- methods ) [ first4 prepare-method 3array ] map ; -: define-objc-class ( superclass name imeth cmeth -- ) - pick >r - [ prepare-methods ] 2apply - [ 2array % 2array % \ (define-objc-class) , ] [ ] make - r> swap import-objc-class ; +: redefine-objc-methods ( name imeth -- ) + >r objc_getClass r> define-objc-methods ; + +: define-objc-class ( superclass name imeth -- ) + prepare-methods + over class-exists? [ 2dup redefine-objc-methods ] when + over >r [ 3array % \ (define-objc-class) , ] [ ] make r> + swap import-objc-class ; diff --git a/library/ui/cocoa/callback.factor b/library/ui/cocoa/callback.factor index 9f7c2ee628..0e1e12624c 100644 --- a/library/ui/cocoa/callback.factor +++ b/library/ui/cocoa/callback.factor @@ -25,7 +25,7 @@ reset-callbacks SUPER-> dealloc ] } -} { } define-objc-class +} define-objc-class : ( quot -- id ) FactorCallback -> alloc -> init diff --git a/library/ui/cocoa/services.factor b/library/ui/cocoa/services.factor index cf24e1d941..6de6879819 100644 --- a/library/ui/cocoa/services.factor +++ b/library/ui/cocoa/services.factor @@ -39,7 +39,7 @@ parser prettyprint styles gadgets-listener gadgets-workspace ; { "id" "SEL" "id" "id" "void*" } [ nip [ eval>string ] do-service 2drop ] } -} { } define-objc-class +} define-objc-class : register-services ( -- ) NSApp diff --git a/library/ui/cocoa/test/cocoa.factor b/library/ui/cocoa/test/cocoa.factor index 040954daf2..dda189c2a5 100644 --- a/library/ui/cocoa/test/cocoa.factor +++ b/library/ui/cocoa/test/cocoa.factor @@ -7,7 +7,6 @@ USING: cocoa compiler kernel objc namespaces objc-classes test memory ; "NSObject" "Foo" { { "foo:" "void" { "id" "SEL" "NSRect" } [ full-gc "x" set 2drop ] } } -{ } define-objc-class : test-foo @@ -24,7 +23,6 @@ test-foo "NSObject" "Bar" { { "bar" "NSRect" { "id" "SEL" } [ 2drop test-foo "x" get ] } } -{ } define-objc-class Bar [ diff --git a/library/ui/cocoa/ui.factor b/library/ui/cocoa/ui.factor index 57d4b6623e..e7a455a517 100644 --- a/library/ui/cocoa/ui.factor +++ b/library/ui/cocoa/ui.factor @@ -19,7 +19,7 @@ hashtables kernel memory namespaces objc sequences errors freetype ; { "application:openFiles:" "void" { "id" "SEL" "id" "id" } [ >r 3drop r> finder-run-files ] } -} { } define-objc-class +} define-objc-class : install-app-delegate ( -- ) NSApp FactorApplicationDelegate install-delegate ; diff --git a/library/ui/cocoa/view-utils.factor b/library/ui/cocoa/view-utils.factor index 50ed465501..3b3d22f464 100644 --- a/library/ui/cocoa/view-utils.factor +++ b/library/ui/cocoa/view-utils.factor @@ -272,7 +272,7 @@ opengl sequences ; SUPER-> dealloc ] } -} { } define-objc-class +} define-objc-class : ( world -- view ) FactorView over rect-dim [ register-window ] keep ; diff --git a/library/ui/cocoa/window-utils.factor b/library/ui/cocoa/window-utils.factor index 8752b579cd..76d93e2db2 100644 --- a/library/ui/cocoa/window-utils.factor +++ b/library/ui/cocoa/window-utils.factor @@ -77,7 +77,7 @@ USING: arrays gadgets kernel math objc sequences ; 2nip -> object -> contentView window unfocus-world ] } -} { } define-objc-class +} define-objc-class : install-window-delegate ( window -- ) FactorWindowDelegate install-delegate ; diff --git a/library/ui/gadgets/lists.factor b/library/ui/gadgets/lists.factor index 8329b11307..c35b09c0ec 100644 --- a/library/ui/gadgets/lists.factor +++ b/library/ui/gadgets/lists.factor @@ -31,7 +31,9 @@ M: list model-changed M: list draw-gadget* dup list-color gl-color - selected-rect [ rect-bounds gl-fill-rect ] when* ; + selected-rect [ + rect-bounds >r origin get v+ r> gl-fill-rect + ] when* ; M: list focusable-child* drop t ; -- 2.34.1