Applied the Area events change to the Mac OS X backend, restructuring a few function signatures in the process.

This commit is contained in:
Pietro Gagliardi 2014-06-02 12:27:23 -04:00
parent c82949b8d2
commit 09a5a859a0
2 changed files with 26 additions and 34 deletions

View File

@ -132,42 +132,41 @@ func areaView_mouseUp(self C.id, e C.id) {
areaMouseEvent(self, e, true, true)
}
func sendKeyEvent(self C.id, e C.id, ke KeyEvent) bool {
func sendKeyEvent(self C.id, ke KeyEvent) {
s := getSysData(self)
handled, repaint := s.handler.Key(ke)
repaint := s.handler.Key(ke)
if repaint {
C.display(self)
}
return handled
}
func areaKeyEvent(self C.id, e C.id, up bool) bool {
func areaKeyEvent(self C.id, e C.id, up bool) {
var ke KeyEvent
keyCode := uintptr(C.keyCode(e))
ke, ok := fromKeycode(keyCode)
if !ok {
// no such key; modifiers by themselves are handled by -[self flagsChanged:]
return false
return
}
// either ke.Key or ke.ExtKey will be set at this point
ke.Modifiers = parseModifiers(e)
ke.Up = up
return sendKeyEvent(self, e, ke)
sendKeyEvent(self, ke)
}
//export areaView_keyDown
func areaView_keyDown(self C.id, e C.id) C.BOOL {
return toBOOL(areaKeyEvent(self, e, false))
func areaView_keyDown(self C.id, e C.id) {
areaKeyEvent(self, e, false)
}
//export areaView_keyUp
func areaView_keyUp(self C.id, e C.id) C.BOOL {
return toBOOL(areaKeyEvent(self, e, true))
func areaView_keyUp(self C.id, e C.id) {
areaKeyEvent(self, e, true)
}
//export areaView_flagsChanged
func areaView_flagsChanged(self C.id, e C.id) C.BOOL {
func areaView_flagsChanged(self C.id, e C.id) {
var ke KeyEvent
// Mac OS X sends this event on both key up and key down.
@ -175,12 +174,12 @@ func areaView_flagsChanged(self C.id, e C.id) C.BOOL {
keyCode := uintptr(C.keyCode(e))
mod, ok := keycodeModifiers[keyCode] // comma-ok form to avoid adding entries
if !ok { // unknown modifier; ignore
return C.NO
return
}
ke.Modifiers = parseModifiers(e)
ke.Up = (ke.Modifiers & mod) == 0
ke.Modifier = mod
// don't include the modifier in ke.Modifiers
ke.Modifiers &^= mod
return toBOOL(sendKeyEvent(self, e, ke))
sendKeyEvent(self, ke)
}

View File

@ -74,31 +74,24 @@ extern NSRect dummyRect;
[self retrack];
}
#define mouseEvent(m, f) \
#define event(m, f) \
- (void)m:(NSEvent *)e \
{ \
f(self, e); \
}
mouseEvent(mouseMoved, areaView_mouseMoved_mouseDragged)
mouseEvent(mouseDragged, areaView_mouseMoved_mouseDragged)
mouseEvent(rightMouseDragged, areaView_mouseMoved_mouseDragged)
mouseEvent(otherMouseDragged, areaView_mouseMoved_mouseDragged)
mouseEvent(mouseDown, areaView_mouseDown)
mouseEvent(rightMouseDown, areaView_mouseDown)
mouseEvent(otherMouseDown, areaView_mouseDown)
mouseEvent(mouseUp, areaView_mouseUp)
mouseEvent(rightMouseUp, areaView_mouseUp)
mouseEvent(otherMouseUp, areaView_mouseUp)
#define keyEvent(m, f) \
- (void)m:(NSEvent *)e \
{ \
if (f(self, e) == NO) \
[super m:e]; \
}
keyEvent(keyDown, areaView_keyDown)
keyEvent(keyUp, areaView_keyUp)
keyEvent(flagsChanged, areaView_flagsChanged)
event(mouseMoved, areaView_mouseMoved_mouseDragged)
event(mouseDragged, areaView_mouseMoved_mouseDragged)
event(rightMouseDragged, areaView_mouseMoved_mouseDragged)
event(otherMouseDragged, areaView_mouseMoved_mouseDragged)
event(mouseDown, areaView_mouseDown)
event(rightMouseDown, areaView_mouseDown)
event(otherMouseDown, areaView_mouseDown)
event(mouseUp, areaView_mouseUp)
event(rightMouseUp, areaView_mouseUp)
event(otherMouseUp, areaView_mouseUp)
event(keyDown, areaView_keyDown)
event(keyUp, areaView_keyUp)
event(flagsChanged, areaView_flagsChanged)
@end