ui.backend.cocoa.views: some formatting cleanup.

flac
John Benediktsson 2020-01-24 14:47:42 -08:00 committed by Steve Ayerhart
parent c8f82ecf2c
commit 42b6fbec70
No known key found for this signature in database
GPG Key ID: 5BFD39C5359E967D
1 changed files with 151 additions and 152 deletions

View File

@ -193,7 +193,7 @@ IMPORT: NSAttributedString
:: >codepoint-index ( str utf16-index -- codepoint-index ) :: >codepoint-index ( str utf16-index -- codepoint-index )
0 utf16-index 2 * str utf16n encode subseq utf16n decode length ; 0 utf16-index 2 * str utf16n encode subseq utf16n decode length ;
:: >utf16-index ( str codepoint-index -- utf16-index ) :: >utf16-index ( str codepoint-index -- utf16-index )
0 codepoint-index str subseq utf16n encode length 2 / >integer ; 0 codepoint-index str subseq utf16n encode length 2 / >integer ;
@ -213,7 +213,7 @@ IMPORT: NSAttributedString
0 0 <NSRange> :> effective-range 0 0 <NSRange> :> effective-range
text -> string CF>string :> str text -> string CF>string :> str
str utf16n encode :> byte-16n str utf16n encode :> byte-16n
0 :> cp-loc! 0 :> cp-loc!
"NSMarkedClauseSegment" <NSString> :> segment-attr "NSMarkedClauseSegment" <NSString> :> segment-attr
[ effective-range [ location>> ] [ length>> ] bi + text-length < ] [ [ effective-range [ location>> ] [ length>> ] bi + text-length < ] [
text text
@ -231,14 +231,14 @@ IMPORT: NSAttributedString
[ str swap >codepoint-index ] bi@ swap - :> len [ str swap >codepoint-index ] bi@ swap - :> len
cp-loc cp-loc len + dup cp-loc! cp-loc cp-loc len + dup cp-loc!
2array thickness 2array 2array thickness 2array
suffix underlines! suffix underlines!
] while ] while
underlines length 1 = [ underlines length 1 = [
underlines first first 2 2array 1array ! thickness: 2 underlines first first 2 2array 1array ! thickness: 2
] [ underlines ] if ; ] [ underlines ] if ;
:: update-marked-text ( gadget str selectedRange replacementRange -- ) :: update-marked-text ( gadget str selectedRange replacementRange -- )
replacementRange location>> NSNotFound = not [ replacementRange location>> NSNotFound = [
gadget editor-caret first gadget editor-caret first
dup gadget editor-line dup gadget editor-line
[ [
@ -253,12 +253,12 @@ IMPORT: NSAttributedString
gadget earlier-caret/mark dup gadget earlier-caret/mark dup
gadget preedit-start<< gadget preedit-start<<
0 1 2array v+ gadget preedit-end<< 0 1 2array v+ gadget preedit-end<<
] when ] unless
gadget preedit? [ gadget preedit? [
gadget remove-preedit-text gadget remove-preedit-text
] when ] when
gadget earlier-caret/mark dup gadget earlier-caret/mark dup
gadget preedit-start<< gadget preedit-start<<
0 str length 2array v+ gadget preedit-end<< 0 str length 2array v+ gadget preedit-end<<
@ -271,7 +271,7 @@ IMPORT: NSAttributedString
[ str swap >codepoint-index ] bi@ - [ str swap >codepoint-index ] bi@ -
2array v+ 2array v+
dup gadget preedit-selected-end<< dup gadget preedit-selected-end<<
dup gadget set-caret gadget set-mark dup gadget set-caret gadget set-mark
gadget preedit-start>> gadget preedit-end>> = [ gadget preedit-start>> gadget preedit-end>> = [
gadget remove-preedit-info gadget remove-preedit-info
] when ; ] when ;
@ -459,179 +459,178 @@ PRIVATE>
! Text input ! Text input
METHOD: void insertText: id text replacementRange: NSRange replacementRange [ METHOD: void insertText: id text replacementRange: NSRange replacementRange [
self window :> window self window :> window
window [ window [
"" clone :> str! "" clone :> str!
text NSString -> class -> isKindOfClass: 0 = not [ text NSString -> class -> isKindOfClass: 0 = not [
text CF>string str! text CF>string str!
] [ ] [
text -> string CF>string str! text -> string CF>string str!
] if ] if
window world-focus :> gadget window world-focus :> gadget
gadget [ gadget [
gadget support-input-methods? [ gadget support-input-methods? [
replacementRange location>> NSNotFound = [ replacementRange location>> NSNotFound = [
gadget editor-caret first gadget editor-caret first
dup gadget editor-line dup gadget editor-line
[ [
replacementRange location>> >codepoint-index replacementRange location>> >codepoint-index
2array gadget set-caret 2array gadget set-caret
] [
replacementRange [ location>> ] [ length>> ] bi +
>codepoint-index
2array gadget set-mark
] 2bi
] unless
gadget preedit? [
gadget [ remove-preedit-text ] [ remove-preedit-info ] bi
str gadget user-input* drop
f gadget preedit-selection-mode?<<
] [ ] [
str window user-input replacementRange [ location>> ] [ length>> ] bi +
] if >codepoint-index
] [ 2array gadget set-mark
] 2bi
] unless
gadget preedit? [
gadget remove-preedit-text
gadget remove-preedit-info
str gadget user-input* drop
f gadget preedit-selection-mode?<<
] [
str window user-input str window user-input
] if ] if
] when ] [
str window user-input
] if
] when ] when
] ; ] when
] ;
METHOD: char hasMarkedText [ METHOD: char hasMarkedText [
self window :> window self window :> window
window [ window [
window world-focus :> gadget window world-focus :> gadget
gadget [ gadget [
gadget preedit? [ 1 ] [ 0 ] if gadget preedit? 1 0 ?
] [ 0 ] if
] [ 0 ] if ] [ 0 ] if
] ; ] [ 0 ] if
] ;
METHOD: NSRange markedRange [ METHOD: NSRange markedRange [
self window :> window self window :> window
window [ window [
window world-focus :> gadget window world-focus :> gadget
gadget [ gadget [
gadget preedit? [ gadget preedit? [
gadget [ preedit-start>> second ] [ preedit-end>> second ] bi >= [ gadget preedit-start>> second
NSNotFound 0 gadget preedit-end>> second < [
] [ gadget preedit-start>> first gadget editor-line :> str
gadget preedit-start>> first gadget editor-line :> str gadget preedit-start>> second ! location
gadget gadget preedit-end>> second
[ preedit-start>> second ] ! location [ str swap >utf16-index ] bi@ over - ! length
[ preedit-end>> second ] ] [ NSNotFound 0 ] if
bi [ str swap >utf16-index ] bi@ over - ! length ] [ NSNotFound 0 ] if
] if
] [ NSNotFound 0 ] if
] [ NSNotFound 0 ] if
] [ NSNotFound 0 ] if ] [ NSNotFound 0 ] if
<NSRange> ] [ NSNotFound 0 ] if
] ; <NSRange>
] ;
METHOD: NSRange selectedRange [ METHOD: NSRange selectedRange [
self window :> window self window :> window
window [ window [
window world-focus :> gadget window world-focus :> gadget
gadget [ gadget [
gadget support-input-methods? [ gadget support-input-methods? [
gadget editor-caret first gadget editor-line :> str gadget editor-caret first gadget editor-line :> str
gadget preedit? [ gadget preedit? [
str str
gadget gadget preedit-selected-start>> second
[ preedit-selected-start>> second ] gadget preedit-start>> second
[ preedit-start>> second ] - >utf16-index ! location
bi - >utf16-index ! location gadget preedit-selected-end>> second
gadget gadget preedit-selected-start>> second
[ preedit-selected-end>> second ] [ str swap >utf16-index ] bi@ - ! length
[ preedit-selected-start>> second ]
bi [ str swap >utf16-index ] bi@ - ! length
] [
str gadget editor-caret second >utf16-index 0
] if
] [ 0 0 ] if
] [ 0 0 ] if
] [ 0 0 ] if
<NSRange>
] ;
METHOD: void setMarkedText: id text selectedRange: NSRange selectedRange
replacementRange: NSRange replacementRange [
self window :> window
window [
window world-focus :> gadget
gadget [
{ } clone :> underlines!
"" clone :> str!
text NSString -> class -> isKindOfClass: 0 = not [
text CF>string str!
] [ ] [
text -> string CF>string str! str gadget editor-caret second >utf16-index 0
gadget support-input-methods? [
gadget text selectedRange make-preedit-underlines underlines!
] when
] if ] if
] [ 0 0 ] if
] [ 0 0 ] if
] [ 0 0 ] if
<NSRange>
] ;
METHOD: void setMarkedText: id text selectedRange: NSRange selectedRange
replacementRange: NSRange replacementRange [
self window :> window
window [
window world-focus :> gadget
gadget [
{ } clone :> underlines!
"" clone :> str!
text NSString -> class -> isKindOfClass: 0 = not [
text CF>string str!
] [
text -> string CF>string str!
gadget support-input-methods? [ gadget support-input-methods? [
gadget str selectedRange replacementRange update-marked-text gadget text selectedRange make-preedit-underlines underlines!
underlines gadget preedit-underlines<<
] when
] when
] when
] ;
METHOD: void unmarkText [
self window :> window
window [
window world-focus :> gadget
gadget [
gadget support-input-methods? [
gadget preedit? [
gadget {
[ preedit-start>> second ]
[ preedit-end>> second ]
[ preedit-start>> first ] [ editor-line ]
} cleave subseq
gadget [ remove-preedit-text ] [ remove-preedit-info ] bi
gadget user-input* drop
] when
f gadget preedit-selection-mode?<<
] when ] when
] if
gadget support-input-methods? [
gadget str selectedRange replacementRange update-marked-text
underlines gadget preedit-underlines<<
] when ] when
] when ] when
] ; ] when
] ;
METHOD: id validAttributesForMarkedText [
NSArray "NSMarkedClauseSegment" <NSString> -> arrayWithObject: METHOD: void unmarkText [
] ; self window :> window
window [
window world-focus :> gadget
gadget [
gadget support-input-methods? [
gadget preedit? [
gadget {
[ preedit-start>> second ]
[ preedit-end>> second ]
[ preedit-start>> first ]
[ editor-line ]
} cleave subseq
gadget remove-preedit-text
gadget remove-preedit-info
gadget user-input* drop
] when
f gadget preedit-selection-mode?<<
] when
] when
] when
] ;
METHOD: id validAttributesForMarkedText [
NSArray "NSMarkedClauseSegment" <NSString> -> arrayWithObject:
] ;
METHOD: id attributedSubstringForProposedRange: NSRange aRange METHOD: id attributedSubstringForProposedRange: NSRange aRange
actualRange: id actualRange [ f ] ; actualRange: id actualRange [ f ] ;
METHOD: NSUInteger characterIndexForPoint: NSPoint point [ 0 ] ; METHOD: NSUInteger characterIndexForPoint: NSPoint point [ 0 ] ;
METHOD: NSRect firstRectForCharacterRange: NSRange aRange METHOD: NSRect firstRectForCharacterRange: NSRange aRange
actualRange: NSRange actualRange [ actualRange: NSRange actualRange [
self window :> window self window :> window
window [ window [
window world-focus :> gadget window world-focus :> gadget
gadget [ gadget [
gadget support-input-methods? [ gadget support-input-methods? [
gadget editor-caret first gadget editor-line :> str gadget editor-caret first gadget editor-line :> str
str aRange location>> >codepoint-index :> start-pos str aRange location>> >codepoint-index :> start-pos
gadget editor-caret first start-pos 2array gadget loc>x gadget editor-caret first start-pos 2array gadget loc>x
gadget caret-loc second gadget caret-dim second + gadget caret-loc second gadget caret-dim second +
2array ! character pos 2array ! character pos
gadget screen-loc v+ ! + gadget pos gadget screen-loc v+ ! + gadget pos
{ 1 -1 } v* { 1 -1 } v*
window handle>> window>> dup -> frame -> contentRectForFrameRect: window handle>> window>> dup -> frame -> contentRectForFrameRect:
CGRect-top-left 2array v+ ! + window pos CGRect-top-left 2array v+ ! + window pos
first2 [ >fixnum ] bi@ 0 gadget line-height >fixnum first2 [ >fixnum ] bi@ 0 gadget line-height >fixnum
] [ 0 0 0 0 ] if
] [ 0 0 0 0 ] if ] [ 0 0 0 0 ] if
] [ 0 0 0 0 ] if ] [ 0 0 0 0 ] if
<CGRect> ] [ 0 0 0 0 ] if
] ; <CGRect>
] ;
METHOD: void doCommandBySelector: SEL selector [ ] ; METHOD: void doCommandBySelector: SEL selector [ ] ;
! Initialization ! Initialization
METHOD: void updateFactorGadgetSize: id notification METHOD: void updateFactorGadgetSize: id notification
[ [