Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22590-Add-support-of-text-input-different-from-keystrokes #1923

Merged
merged 2 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/OSWindow-Core/OSNullWindowHandle.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Class {
#name : #OSNullWindowHandle,
#superclass : #OSWindowHandle,
#instVars : [
'attributes'
'attributes',
'isTextInputActive'
],
#category : #'OSWindow-Core-Utilities'
}
Expand Down Expand Up @@ -52,6 +53,18 @@ OSNullWindowHandle >> extent: newExtent [
OSNullWindowHandle >> hide [
]

{ #category : #initialize }
OSNullWindowHandle >> initialize [
super initialize.

isTextInputActive := false
]

{ #category : #'text input' }
OSNullWindowHandle >> isTextInputActive [
^ isTextInputActive
]

{ #category : #accessing }
OSNullWindowHandle >> isValid [
^ true
Expand Down Expand Up @@ -86,6 +99,16 @@ OSNullWindowHandle >> position: position [
OSNullWindowHandle >> show [
]

{ #category : #'text input' }
OSNullWindowHandle >> startTextInput [
isTextInputActive := true
]

{ #category : #'text input' }
OSNullWindowHandle >> stopTextInput [
isTextInputActive := false
]

{ #category : #accessing }
OSNullWindowHandle >> title [
^attributes title
Expand Down
39 changes: 39 additions & 0 deletions src/OSWindow-Core/OSWindow.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ Currently there's two kinds of renderers available:
OSWindow instance and its handle:
- all operations with window (like hiding/showing/resizing etc) is possible only if its handle is valid. If window gets destroyed, or image opened in a new session while window was created in previous session, the handle becomes invalid, and any operations will lead to error.
To test if window is still valid, you can just use #isValid message.

Text input

Why does OSWindow need a text input API?
When I press a key on my keyboard, my program receives a character event, right?
Well, it's not always that simple. Sometimes it can take multiple key presses to produce a character. Sometimes a single key press can produce multiple characters.
Text input is not as simple as it seems, particularly when you consider International users (and you should). It's not hard to figure out why that is when you look at languages like Chinese, Japanese, and Korean. These languages, collectively referred to as the CJK, have thousands of symbols.
It would not be feasible to have a keyboard with over ten-thousand keys, would it? The solution to this is a software input method.

Related methods:
- startTextInput
- stopTextInput
- isTextInputActive

(reference https://wiki.libsdl.org/Tutorials/TextInput)
"
Class {
#name : #OSWindow,
Expand Down Expand Up @@ -222,6 +237,13 @@ OSWindow >> invalidHandle [
self error: 'Invalid window handle'
]

{ #category : #'text input' }
OSWindow >> isTextInputActive [
"Check whether or not Unicode text input events are enabled"

^ self validHandle isTextInputActive
]

{ #category : #testing }
OSWindow >> isValid [
^ handle notNil and: [ handle isValid ]
Expand Down Expand Up @@ -348,6 +370,23 @@ OSWindow >> show [
handle show
]

{ #category : #'text input' }
OSWindow >> startTextInput [
"Start accepting Unicode text input events.
I will start accepting Unicode text input events in the focused window, and start emitting text input and text editing events.
Please use me in pair with stopTextInput.
On some platforms using I may activates the screen keyboard."

self validHandle startTextInput
]

{ #category : #'text input' }
OSWindow >> stopTextInput [
"Stop receiving any text input events"

self validHandle stopTextInput
]

{ #category : #accessing }
OSWindow >> title [
^ self validHandle title
Expand Down
15 changes: 15 additions & 0 deletions src/OSWindow-Core/OSWindowHandle.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ OSWindowHandle >> hide [
OSWindowHandle >> icon: aForm [
]

{ #category : #'text input' }
OSWindowHandle >> isTextInputActive [
^ self subclassResponsibility
]

{ #category : #testing }
OSWindowHandle >> isValid [
self subclassResponsibility
Expand Down Expand Up @@ -168,6 +173,16 @@ OSWindowHandle >> show [
self subclassResponsibility
]

{ #category : #'text input' }
OSWindowHandle >> startTextInput [
self subclassResponsibility
]

{ #category : #'text input' }
OSWindowHandle >> stopTextInput [
self subclassResponsibility
]

{ #category : #accessing }
OSWindowHandle >> title [
self subclassResponsibility
Expand Down
21 changes: 21 additions & 0 deletions src/OSWindow-SDL2/OSSDL2WindowHandle.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ OSSDL2WindowHandle >> initWithHandle: aHandle attributes: attributes [
attributes applyTo: self
]

{ #category : #'text input' }
OSSDL2WindowHandle >> isTextInputActive [
"See https://wiki.libsdl.org/SDL_IsTextInputActive"

^ handle isTextInputActive
]

{ #category : #testing }
OSSDL2WindowHandle >> isValid [
^ true
Expand Down Expand Up @@ -342,6 +349,20 @@ OSSDL2WindowHandle >> showCursor: aBoolean [
SDL2 showCursor: (aBoolean ifTrue: [SDL_ENABLE] ifFalse: [SDL_DISABLE]).
]

{ #category : #'text input' }
OSSDL2WindowHandle >> startTextInput [
"See https://wiki.libsdl.org/SDL_StartTextInput"

handle startTextInput
]

{ #category : #'text input' }
OSSDL2WindowHandle >> stopTextInput [
"See https://wiki.libsdl.org/SDL_StopTextInput"

handle stopTextInput
]

{ #category : #accessing }
OSSDL2WindowHandle >> title [
^ handle title
Expand Down
15 changes: 15 additions & 0 deletions src/OSWindow-SDL2/SDL_Window.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ SDL_Window >> icon: surface [
^ self ffiCall: #( void SDL_SetWindowIcon ( self , SDL_Surface* surface ) )
]

{ #category : #'text input' }
SDL_Window >> isTextInputActive [
^ self ffiCall: #(bool SDL_IsTextInputActive(void))
]

{ #category : #'window management' }
SDL_Window >> maximize [
^ self ffiCall: #( void SDL_MaximizeWindow( self ) )
Expand Down Expand Up @@ -137,6 +142,16 @@ SDL_Window >> show [
^ self ffiCall: #( void SDL_ShowWindow( self ) )
]

{ #category : #'text input' }
SDL_Window >> startTextInput [
^ self ffiCall: #(void SDL_StartTextInput(void))
]

{ #category : #'text input' }
SDL_Window >> stopTextInput [
^ self ffiCall: #(void SDL_StopTextInput(void))
]

{ #category : #accessing }
SDL_Window >> title [
^ self ffiCall: #( String SDL_GetWindowTitle ( self ) )
Expand Down
2 changes: 1 addition & 1 deletion src/OSWindow-Tests/OSWindowAttributesTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {
#superclass : #TestCase,
#category : #'OSWindow-Tests-Tests'
}

{ #category : #tests }
OSWindowAttributesTest >> testDefaults [

Expand Down
5 changes: 3 additions & 2 deletions src/OSWindow-Tests/OSWindowTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ OSWindowTest >> testSettingUpWindow [
window := OSWindow newWithNullDriver.

[ window extent: 150@150.
self assert: window extent equals: (150@150).
self assert: (window isValid)
self assert: window extent equals: (150@150).
self assert: (window isValid).
self assert: (window isTextInputActive not)
] ensure: [ window destroy ].

self deny: window isValid
Expand Down