Mercurial > sdl-ios-xcode
comparison src/video/cocoa/SDL_cocoakeyboard.m @ 4465:3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Plus, this lets me start implementing cursor support.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 09 May 2010 20:47:22 -0700 |
parents | d3c193100522 |
children | 3d91e31fcf71 |
comparison
equal
deleted
inserted
replaced
4464:fa77a6429698 | 4465:3e69e077cb95 |
---|---|
60 { | 60 { |
61 NSString *_markedText; | 61 NSString *_markedText; |
62 NSRange _markedRange; | 62 NSRange _markedRange; |
63 NSRange _selectedRange; | 63 NSRange _selectedRange; |
64 SDL_Rect _inputRect; | 64 SDL_Rect _inputRect; |
65 int _keyboard; | |
66 } | 65 } |
67 - (void) doCommandBySelector:(SEL)myselector; | 66 - (void) doCommandBySelector:(SEL)myselector; |
68 - (void) setInputRect:(SDL_Rect *) rect; | 67 - (void) setInputRect:(SDL_Rect *) rect; |
69 - (void) setKeyboard:(int) keyboard; | |
70 @end | 68 @end |
71 | 69 |
72 @implementation SDLTranslatorResponder | 70 @implementation SDLTranslatorResponder |
73 | |
74 - (void) setKeyboard:(int) keyboard | |
75 { | |
76 _keyboard = keyboard; | |
77 } | |
78 | 71 |
79 - (void) setInputRect:(SDL_Rect *) rect | 72 - (void) setInputRect:(SDL_Rect *) rect |
80 { | 73 { |
81 _inputRect = *rect; | 74 _inputRect = *rect; |
82 } | 75 } |
92 if ([aString isKindOfClass: [NSAttributedString class]]) | 85 if ([aString isKindOfClass: [NSAttributedString class]]) |
93 str = [[aString string] UTF8String]; | 86 str = [[aString string] UTF8String]; |
94 else | 87 else |
95 str = [aString UTF8String]; | 88 str = [aString UTF8String]; |
96 | 89 |
97 SDL_SendKeyboardText(_keyboard, str); | 90 SDL_SendKeyboardText(str); |
98 } | 91 } |
99 | 92 |
100 - (void) doCommandBySelector:(SEL) myselector | 93 - (void) doCommandBySelector:(SEL) myselector |
101 { | 94 { |
102 // No need to do anything since we are not using Cocoa | 95 // No need to do anything since we are not using Cocoa |
138 } | 131 } |
139 | 132 |
140 _selectedRange = selRange; | 133 _selectedRange = selRange; |
141 _markedRange = NSMakeRange(0, [aString length]); | 134 _markedRange = NSMakeRange(0, [aString length]); |
142 | 135 |
143 SDL_SendEditingText(_keyboard, [aString UTF8String], | 136 SDL_SendEditingText([aString UTF8String], |
144 selRange.location, selRange.length); | 137 selRange.location, selRange.length); |
145 | 138 |
146 DEBUG_IME(@"setMarkedText: %@, (%d, %d)", _markedText, | 139 DEBUG_IME(@"setMarkedText: %@, (%d, %d)", _markedText, |
147 selRange.location, selRange.length); | 140 selRange.location, selRange.length); |
148 } | 141 } |
202 | 195 |
203 /* This is the original behavior, before support was added for | 196 /* This is the original behavior, before support was added for |
204 * differentiating between left and right versions of the keys. | 197 * differentiating between left and right versions of the keys. |
205 */ | 198 */ |
206 static void | 199 static void |
207 DoUnsidedModifiers(int keyboard, unsigned short scancode, | 200 DoUnsidedModifiers(unsigned short scancode, |
208 unsigned int oldMods, unsigned int newMods) | 201 unsigned int oldMods, unsigned int newMods) |
209 { | 202 { |
210 const int mapping[] = { | 203 const int mapping[] = { |
211 SDL_SCANCODE_CAPSLOCK, | 204 SDL_SCANCODE_CAPSLOCK, |
212 SDL_SCANCODE_LSHIFT, | 205 SDL_SCANCODE_LSHIFT, |
224 newMask = newMods & bit; | 217 newMask = newMods & bit; |
225 | 218 |
226 if (oldMask && oldMask != newMask) { /* modifier up event */ | 219 if (oldMask && oldMask != newMask) { /* modifier up event */ |
227 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ | 220 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ |
228 if (bit == NSAlphaShiftKeyMask) { | 221 if (bit == NSAlphaShiftKeyMask) { |
229 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, mapping[i]); | 222 SDL_SendKeyboardKey(SDL_PRESSED, mapping[i]); |
230 } | 223 } |
231 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, mapping[i]); | 224 SDL_SendKeyboardKey(SDL_RELEASED, mapping[i]); |
232 } else if (newMask && oldMask != newMask) { /* modifier down event */ | 225 } else if (newMask && oldMask != newMask) { /* modifier down event */ |
233 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, mapping[i]); | 226 SDL_SendKeyboardKey(SDL_PRESSED, mapping[i]); |
234 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ | 227 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ |
235 if (bit == NSAlphaShiftKeyMask) { | 228 if (bit == NSAlphaShiftKeyMask) { |
236 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, mapping[i]); | 229 SDL_SendKeyboardKey(SDL_RELEASED, mapping[i]); |
237 } | 230 } |
238 } | 231 } |
239 } | 232 } |
240 } | 233 } |
241 | 234 |
242 /* This is a helper function for HandleModifierSide. This | 235 /* This is a helper function for HandleModifierSide. This |
243 * function reverts back to behavior before the distinction between | 236 * function reverts back to behavior before the distinction between |
244 * sides was made. | 237 * sides was made. |
245 */ | 238 */ |
246 static void | 239 static void |
247 HandleNonDeviceModifier(int keyboard, | 240 HandleNonDeviceModifier(unsigned int device_independent_mask, |
248 unsigned int device_independent_mask, | |
249 unsigned int oldMods, | 241 unsigned int oldMods, |
250 unsigned int newMods, | 242 unsigned int newMods, |
251 SDL_scancode scancode) | 243 SDL_scancode scancode) |
252 { | 244 { |
253 unsigned int oldMask, newMask; | 245 unsigned int oldMask, newMask; |
257 */ | 249 */ |
258 oldMask = oldMods & device_independent_mask; | 250 oldMask = oldMods & device_independent_mask; |
259 newMask = newMods & device_independent_mask; | 251 newMask = newMods & device_independent_mask; |
260 | 252 |
261 if (oldMask && oldMask != newMask) { | 253 if (oldMask && oldMask != newMask) { |
262 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, scancode); | 254 SDL_SendKeyboardKey(SDL_RELEASED, scancode); |
263 } else if (newMask && oldMask != newMask) { | 255 } else if (newMask && oldMask != newMask) { |
264 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, scancode); | 256 SDL_SendKeyboardKey(SDL_PRESSED, scancode); |
265 } | 257 } |
266 } | 258 } |
267 | 259 |
268 /* This is a helper function for HandleModifierSide. | 260 /* This is a helper function for HandleModifierSide. |
269 * This function sets the actual SDL_PrivateKeyboard event. | 261 * This function sets the actual SDL_PrivateKeyboard event. |
270 */ | 262 */ |
271 static void | 263 static void |
272 HandleModifierOneSide(int keyboard, | 264 HandleModifierOneSide(unsigned int oldMods, unsigned int newMods, |
273 unsigned int oldMods, unsigned int newMods, | |
274 SDL_scancode scancode, | 265 SDL_scancode scancode, |
275 unsigned int sided_device_dependent_mask) | 266 unsigned int sided_device_dependent_mask) |
276 { | 267 { |
277 unsigned int old_dep_mask, new_dep_mask; | 268 unsigned int old_dep_mask, new_dep_mask; |
278 | 269 |
285 /* We now know that this side bit flipped. But we don't know if | 276 /* We now know that this side bit flipped. But we don't know if |
286 * it went pressed to released or released to pressed, so we must | 277 * it went pressed to released or released to pressed, so we must |
287 * find out which it is. | 278 * find out which it is. |
288 */ | 279 */ |
289 if (new_dep_mask && old_dep_mask != new_dep_mask) { | 280 if (new_dep_mask && old_dep_mask != new_dep_mask) { |
290 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, scancode); | 281 SDL_SendKeyboardKey(SDL_PRESSED, scancode); |
291 } else { | 282 } else { |
292 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, scancode); | 283 SDL_SendKeyboardKey(SDL_RELEASED, scancode); |
293 } | 284 } |
294 } | 285 } |
295 | 286 |
296 /* This is a helper function for DoSidedModifiers. | 287 /* This is a helper function for DoSidedModifiers. |
297 * This function will figure out if the modifier key is the left or right side, | 288 * This function will figure out if the modifier key is the left or right side, |
298 * e.g. left-shift vs right-shift. | 289 * e.g. left-shift vs right-shift. |
299 */ | 290 */ |
300 static void | 291 static void |
301 HandleModifierSide(int keyboard, | 292 HandleModifierSide(int device_independent_mask, |
302 int device_independent_mask, | |
303 unsigned int oldMods, unsigned int newMods, | 293 unsigned int oldMods, unsigned int newMods, |
304 SDL_scancode left_scancode, | 294 SDL_scancode left_scancode, |
305 SDL_scancode right_scancode, | 295 SDL_scancode right_scancode, |
306 unsigned int left_device_dependent_mask, | 296 unsigned int left_device_dependent_mask, |
307 unsigned int right_device_dependent_mask) | 297 unsigned int right_device_dependent_mask) |
314 * no device dependent flags set, we'll assume that we can't detect this | 304 * no device dependent flags set, we'll assume that we can't detect this |
315 * keyboard and revert to the unsided behavior. | 305 * keyboard and revert to the unsided behavior. |
316 */ | 306 */ |
317 if ((device_dependent_mask & newMods) == 0) { | 307 if ((device_dependent_mask & newMods) == 0) { |
318 /* Revert to the old behavior */ | 308 /* Revert to the old behavior */ |
319 HandleNonDeviceModifier(keyboard, device_independent_mask, oldMods, newMods, left_scancode); | 309 HandleNonDeviceModifier(device_independent_mask, oldMods, newMods, left_scancode); |
320 return; | 310 return; |
321 } | 311 } |
322 | 312 |
323 /* XOR the previous state against the new state to see if there's a change */ | 313 /* XOR the previous state against the new state to see if there's a change */ |
324 diff_mod = (device_dependent_mask & oldMods) ^ | 314 diff_mod = (device_dependent_mask & oldMods) ^ |
327 /* A change in state was found. Isolate the left and right bits | 317 /* A change in state was found. Isolate the left and right bits |
328 * to handle them separately just in case the values can simulataneously | 318 * to handle them separately just in case the values can simulataneously |
329 * change or if the bits don't both exist. | 319 * change or if the bits don't both exist. |
330 */ | 320 */ |
331 if (left_device_dependent_mask & diff_mod) { | 321 if (left_device_dependent_mask & diff_mod) { |
332 HandleModifierOneSide(keyboard, oldMods, newMods, left_scancode, left_device_dependent_mask); | 322 HandleModifierOneSide(oldMods, newMods, left_scancode, left_device_dependent_mask); |
333 } | 323 } |
334 if (right_device_dependent_mask & diff_mod) { | 324 if (right_device_dependent_mask & diff_mod) { |
335 HandleModifierOneSide(keyboard, oldMods, newMods, right_scancode, right_device_dependent_mask); | 325 HandleModifierOneSide(oldMods, newMods, right_scancode, right_device_dependent_mask); |
336 } | 326 } |
337 } | 327 } |
338 } | 328 } |
339 | 329 |
340 /* This is a helper function for DoSidedModifiers. | 330 /* This is a helper function for DoSidedModifiers. |
341 * This function will release a key press in the case that | 331 * This function will release a key press in the case that |
342 * it is clear that the modifier has been released (i.e. one side | 332 * it is clear that the modifier has been released (i.e. one side |
343 * can't still be down). | 333 * can't still be down). |
344 */ | 334 */ |
345 static void | 335 static void |
346 ReleaseModifierSide(int keyboard, | 336 ReleaseModifierSide(unsigned int device_independent_mask, |
347 unsigned int device_independent_mask, | |
348 unsigned int oldMods, unsigned int newMods, | 337 unsigned int oldMods, unsigned int newMods, |
349 SDL_scancode left_scancode, | 338 SDL_scancode left_scancode, |
350 SDL_scancode right_scancode, | 339 SDL_scancode right_scancode, |
351 unsigned int left_device_dependent_mask, | 340 unsigned int left_device_dependent_mask, |
352 unsigned int right_device_dependent_mask) | 341 unsigned int right_device_dependent_mask) |
360 */ | 349 */ |
361 if ((device_dependent_mask & oldMods) == 0) { | 350 if ((device_dependent_mask & oldMods) == 0) { |
362 /* In this case, we can't detect the keyboard, so use the left side | 351 /* In this case, we can't detect the keyboard, so use the left side |
363 * to represent both, and release it. | 352 * to represent both, and release it. |
364 */ | 353 */ |
365 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, left_scancode); | 354 SDL_SendKeyboardKey(SDL_RELEASED, left_scancode); |
366 return; | 355 return; |
367 } | 356 } |
368 | 357 |
369 /* | 358 /* |
370 * This could have been done in an if-else case because at this point, | 359 * This could have been done in an if-else case because at this point, |
371 * we know that all keys have been released when calling this function. | 360 * we know that all keys have been released when calling this function. |
372 * But I'm being paranoid so I want to handle each separately, | 361 * But I'm being paranoid so I want to handle each separately, |
373 * so I hope this doesn't cause other problems. | 362 * so I hope this doesn't cause other problems. |
374 */ | 363 */ |
375 if ( left_device_dependent_mask & oldMods ) { | 364 if ( left_device_dependent_mask & oldMods ) { |
376 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, left_scancode); | 365 SDL_SendKeyboardKey(SDL_RELEASED, left_scancode); |
377 } | 366 } |
378 if ( right_device_dependent_mask & oldMods ) { | 367 if ( right_device_dependent_mask & oldMods ) { |
379 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, right_scancode); | 368 SDL_SendKeyboardKey(SDL_RELEASED, right_scancode); |
380 } | 369 } |
381 } | 370 } |
382 | 371 |
383 /* This is a helper function for DoSidedModifiers. | 372 /* This is a helper function for DoSidedModifiers. |
384 * This function handles the CapsLock case. | 373 * This function handles the CapsLock case. |
385 */ | 374 */ |
386 static void | 375 static void |
387 HandleCapsLock(int keyboard, unsigned short scancode, | 376 HandleCapsLock(unsigned short scancode, |
388 unsigned int oldMods, unsigned int newMods) | 377 unsigned int oldMods, unsigned int newMods) |
389 { | 378 { |
390 unsigned int oldMask, newMask; | 379 unsigned int oldMask, newMask; |
391 | 380 |
392 oldMask = oldMods & NSAlphaShiftKeyMask; | 381 oldMask = oldMods & NSAlphaShiftKeyMask; |
393 newMask = newMods & NSAlphaShiftKeyMask; | 382 newMask = newMods & NSAlphaShiftKeyMask; |
394 | 383 |
395 if (oldMask != newMask) { | 384 if (oldMask != newMask) { |
396 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); | 385 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); |
397 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, SDL_SCANCODE_CAPSLOCK); | 386 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK); |
398 } | 387 } |
399 | 388 |
400 oldMask = oldMods & NSNumericPadKeyMask; | 389 oldMask = oldMods & NSNumericPadKeyMask; |
401 newMask = newMods & NSNumericPadKeyMask; | 390 newMask = newMods & NSNumericPadKeyMask; |
402 | 391 |
403 if (oldMask != newMask) { | 392 if (oldMask != newMask) { |
404 SDL_SendKeyboardKey(keyboard, SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR); | 393 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR); |
405 SDL_SendKeyboardKey(keyboard, SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR); | 394 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR); |
406 } | 395 } |
407 } | 396 } |
408 | 397 |
409 /* This function will handle the modifier keys and also determine the | 398 /* This function will handle the modifier keys and also determine the |
410 * correct side of the key. | 399 * correct side of the key. |
411 */ | 400 */ |
412 static void | 401 static void |
413 DoSidedModifiers(int keyboard, unsigned short scancode, | 402 DoSidedModifiers(unsigned short scancode, |
414 unsigned int oldMods, unsigned int newMods) | 403 unsigned int oldMods, unsigned int newMods) |
415 { | 404 { |
416 /* Set up arrays for the key syms for the left and right side. */ | 405 /* Set up arrays for the key syms for the left and right side. */ |
417 const SDL_scancode left_mapping[] = { | 406 const SDL_scancode left_mapping[] = { |
418 SDL_SCANCODE_LSHIFT, | 407 SDL_SCANCODE_LSHIFT, |
433 const unsigned int right_device_mapping[] = { NX_DEVICERSHIFTKEYMASK, NX_DEVICERCTLKEYMASK, NX_DEVICERALTKEYMASK, NX_DEVICERCMDKEYMASK }; | 422 const unsigned int right_device_mapping[] = { NX_DEVICERSHIFTKEYMASK, NX_DEVICERCTLKEYMASK, NX_DEVICERALTKEYMASK, NX_DEVICERCMDKEYMASK }; |
434 | 423 |
435 unsigned int i, bit; | 424 unsigned int i, bit; |
436 | 425 |
437 /* Handle CAPSLOCK separately because it doesn't have a left/right side */ | 426 /* Handle CAPSLOCK separately because it doesn't have a left/right side */ |
438 HandleCapsLock(keyboard, scancode, oldMods, newMods); | 427 HandleCapsLock(scancode, oldMods, newMods); |
439 | 428 |
440 /* Iterate through the bits, testing each against the old modifiers */ | 429 /* Iterate through the bits, testing each against the old modifiers */ |
441 for (i = 0, bit = NSShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) { | 430 for (i = 0, bit = NSShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) { |
442 unsigned int oldMask, newMask; | 431 unsigned int oldMask, newMask; |
443 | 432 |
446 | 435 |
447 /* If the bit is set, we must always examine it because the left | 436 /* If the bit is set, we must always examine it because the left |
448 * and right side keys may alternate or both may be pressed. | 437 * and right side keys may alternate or both may be pressed. |
449 */ | 438 */ |
450 if (newMask) { | 439 if (newMask) { |
451 HandleModifierSide(keyboard, bit, oldMods, newMods, | 440 HandleModifierSide(bit, oldMods, newMods, |
452 left_mapping[i], right_mapping[i], | 441 left_mapping[i], right_mapping[i], |
453 left_device_mapping[i], right_device_mapping[i]); | 442 left_device_mapping[i], right_device_mapping[i]); |
454 } | 443 } |
455 /* If the state changed from pressed to unpressed, we must examine | 444 /* If the state changed from pressed to unpressed, we must examine |
456 * the device dependent bits to release the correct keys. | 445 * the device dependent bits to release the correct keys. |
457 */ | 446 */ |
458 else if (oldMask && oldMask != newMask) { | 447 else if (oldMask && oldMask != newMask) { |
459 ReleaseModifierSide(keyboard, bit, oldMods, newMods, | 448 ReleaseModifierSide(bit, oldMods, newMods, |
460 left_mapping[i], right_mapping[i], | 449 left_mapping[i], right_mapping[i], |
461 left_device_mapping[i], right_device_mapping[i]); | 450 left_device_mapping[i], right_device_mapping[i]); |
462 } | 451 } |
463 } | 452 } |
464 } | 453 } |
475 /* | 464 /* |
476 * Starting with Panther (10.3.0), the ability to distinguish between | 465 * Starting with Panther (10.3.0), the ability to distinguish between |
477 * left side and right side modifiers is available. | 466 * left side and right side modifiers is available. |
478 */ | 467 */ |
479 if (data->osversion >= 0x1030) { | 468 if (data->osversion >= 0x1030) { |
480 DoSidedModifiers(data->keyboard, scancode, data->modifierFlags, modifierFlags); | 469 DoSidedModifiers(scancode, data->modifierFlags, modifierFlags); |
481 } else { | 470 } else { |
482 DoUnsidedModifiers(data->keyboard, scancode, data->modifierFlags, modifierFlags); | 471 DoUnsidedModifiers(scancode, data->modifierFlags, modifierFlags); |
483 } | 472 } |
484 data->modifierFlags = modifierFlags; | 473 data->modifierFlags = modifierFlags; |
485 } | 474 } |
486 | 475 |
487 static void | 476 static void |
547 | 536 |
548 if (len > 0 && s[0] != 0x10) { | 537 if (len > 0 && s[0] != 0x10) { |
549 keymap[scancode] = s[0]; | 538 keymap[scancode] = s[0]; |
550 } | 539 } |
551 } | 540 } |
552 SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES); | 541 SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); |
553 return; | 542 return; |
554 } | 543 } |
555 | 544 |
556 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 | 545 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 |
557 cleanup: | 546 cleanup: |
601 c = macroman_table[c - 128]; | 590 c = macroman_table[c - 128]; |
602 } | 591 } |
603 keymap[scancode] = c; | 592 keymap[scancode] = c; |
604 } | 593 } |
605 } | 594 } |
606 SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES); | 595 SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); |
607 return; | 596 return; |
608 } | 597 } |
609 #endif | 598 #endif |
610 } | 599 } |
611 | 600 |
612 void | 601 void |
613 Cocoa_InitKeyboard(_THIS) | 602 Cocoa_InitKeyboard(_THIS) |
614 { | 603 { |
615 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 604 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
616 SDL_Keyboard keyboard; | 605 |
617 | |
618 SDL_zero(keyboard); | |
619 data->keyboard = SDL_AddKeyboard(&keyboard, -1); | |
620 UpdateKeymap(data); | 606 UpdateKeymap(data); |
621 | 607 |
622 /* Set our own names for the platform-dependent but layout-independent keys */ | 608 /* Set our own names for the platform-dependent but layout-independent keys */ |
623 /* This key is NumLock on the MacBook keyboard. :) */ | 609 /* This key is NumLock on the MacBook keyboard. :) */ |
624 /*SDL_SetScancodeName(SDL_SCANCODE_NUMLOCKCLEAR, "Clear");*/ | 610 /*SDL_SetScancodeName(SDL_SCANCODE_NUMLOCKCLEAR, "Clear");*/ |
643 if (!data->fieldEdit) { | 629 if (!data->fieldEdit) { |
644 data->fieldEdit = | 630 data->fieldEdit = |
645 [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)]; | 631 [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)]; |
646 } | 632 } |
647 | 633 |
648 [data->fieldEdit setKeyboard: data->keyboard]; | |
649 | |
650 if (![[data->fieldEdit superview] isEqual: parentView]) | 634 if (![[data->fieldEdit superview] isEqual: parentView]) |
651 { | 635 { |
652 // DEBUG_IME(@"add fieldEdit to window contentView"); | 636 // DEBUG_IME(@"add fieldEdit to window contentView"); |
653 [data->fieldEdit removeFromSuperview]; | 637 [data->fieldEdit removeFromSuperview]; |
654 [parentView addSubview: data->fieldEdit]; | 638 [parentView addSubview: data->fieldEdit]; |
684 Cocoa_HandleKeyEvent(_THIS, NSEvent *event) | 668 Cocoa_HandleKeyEvent(_THIS, NSEvent *event) |
685 { | 669 { |
686 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 670 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
687 unsigned short scancode = [event keyCode]; | 671 unsigned short scancode = [event keyCode]; |
688 SDL_scancode code; | 672 SDL_scancode code; |
673 #if 0 | |
689 const char *text; | 674 const char *text; |
675 #endif | |
690 | 676 |
691 if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) { | 677 if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) { |
692 /* see comments in SDL_cocoakeys.h */ | 678 /* see comments in SDL_cocoakeys.h */ |
693 scancode = 60 - scancode; | 679 scancode = 60 - scancode; |
694 } | 680 } |
704 case NSKeyDown: | 690 case NSKeyDown: |
705 if (![event isARepeat]) { | 691 if (![event isARepeat]) { |
706 /* See if we need to rebuild the keyboard layout */ | 692 /* See if we need to rebuild the keyboard layout */ |
707 UpdateKeymap(data); | 693 UpdateKeymap(data); |
708 | 694 |
709 SDL_SendKeyboardKey(data->keyboard, SDL_PRESSED, code); | 695 SDL_SendKeyboardKey(SDL_PRESSED, code); |
710 #if 1 | 696 #if 1 |
711 if (code == SDL_SCANCODE_UNKNOWN) { | 697 if (code == SDL_SCANCODE_UNKNOWN) { |
712 fprintf(stderr, "The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL mailing list <sdl@libsdl.org> or to Christian Walther <cwalther@gmx.ch>. Mac virtual key code is %d.\n", scancode); | 698 fprintf(stderr, "The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL mailing list <sdl@libsdl.org> or to Christian Walther <cwalther@gmx.ch>. Mac virtual key code is %d.\n", scancode); |
713 } | 699 } |
714 #endif | 700 #endif |
717 /* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */ | 703 /* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */ |
718 [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]]; | 704 [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]]; |
719 #if 0 | 705 #if 0 |
720 text = [[event characters] UTF8String]; | 706 text = [[event characters] UTF8String]; |
721 if(text && *text) { | 707 if(text && *text) { |
722 SDL_SendKeyboardText(data->keyboard, text); | 708 SDL_SendKeyboardText(text); |
723 [data->fieldEdit setString:@""]; | 709 [data->fieldEdit setString:@""]; |
724 } | 710 } |
725 #endif | 711 #endif |
726 } | 712 } |
727 break; | 713 break; |
728 case NSKeyUp: | 714 case NSKeyUp: |
729 SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, code); | 715 SDL_SendKeyboardKey(SDL_RELEASED, code); |
730 break; | 716 break; |
731 case NSFlagsChanged: | 717 case NSFlagsChanged: |
732 /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */ | 718 /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */ |
733 HandleModifiers(_this, scancode, [event modifierFlags]); | 719 HandleModifiers(_this, scancode, [event modifierFlags]); |
734 break; | 720 break; |
738 } | 724 } |
739 | 725 |
740 void | 726 void |
741 Cocoa_QuitKeyboard(_THIS) | 727 Cocoa_QuitKeyboard(_THIS) |
742 { | 728 { |
743 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
744 NSAutoreleasePool *pool; | |
745 | |
746 SDL_DelKeyboard(data->keyboard); | |
747 } | 729 } |
748 | 730 |
749 /* vi: set ts=4 sw=4 expandtab: */ | 731 /* vi: set ts=4 sw=4 expandtab: */ |