Basic text input API gsoc2009_IME
authorJiang Jiang <gzjjgod@gmail.com>
Fri, 26 Jun 2009 10:37:57 +0000
branchgsoc2009_IME
changeset 3130fef1a835af43
parent 3129 e42873b9c6f1
child 3131 009bd8f81947
Basic text input API
include/SDL_video.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/cocoa/SDL_cocoakeyboard.h
src/video/cocoa/SDL_cocoakeyboard.m
src/video/cocoa/SDL_cocoavideo.h
src/video/cocoa/SDL_cocoavideo.m
     1.1 --- a/include/SDL_video.h	Sun May 31 16:57:29 2009 +0000
     1.2 +++ b/include/SDL_video.h	Fri Jun 26 10:37:57 2009 +0000
     1.3 @@ -1467,6 +1467,12 @@
     1.4   */
     1.5  extern DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context);
     1.6  
     1.7 +/**
     1.8 + * \fn void SDL_StartTextInput(SDL_rect *rect)
     1.9 + *
    1.10 + * \brief Start Unicode text input within the given rectangle.
    1.11 + */
    1.12 +extern DECLSPEC void SDLCALL SDL_StartTextInput(SDL_Rect *rect);
    1.13  
    1.14  /* Ends C function definitions when using C++ */
    1.15  #ifdef __cplusplus
     2.1 --- a/src/video/SDL_sysvideo.h	Sun May 31 16:57:29 2009 +0000
     2.2 +++ b/src/video/SDL_sysvideo.h	Fri Jun 26 10:37:57 2009 +0000
     2.3 @@ -277,6 +277,9 @@
     2.4      /* Suspend the screensaver */
     2.5      void (*SuspendScreenSaver) (_THIS);
     2.6  
     2.7 +    /* Text input */
     2.8 +    void (*StartTextInput) (_THIS, SDL_Rect *rect);
     2.9 +
    2.10      /* * * */
    2.11      /* Data common to all drivers */
    2.12      SDL_bool suspend_screensaver;
     3.1 --- a/src/video/SDL_video.c	Sun May 31 16:57:29 2009 +0000
     3.2 +++ b/src/video/SDL_video.c	Fri Jun 26 10:37:57 2009 +0000
     3.3 @@ -3067,4 +3067,12 @@
     3.4      return (_this->GetWindowWMInfo(_this, window, info));
     3.5  }
     3.6  
     3.7 +void
     3.8 +SDL_StartTextInput(SDL_Rect *rect)
     3.9 +{
    3.10 +    if (_this->StartTextInput) {
    3.11 +        _this->StartTextInput(_this, rect);
    3.12 +    }
    3.13 +}
    3.14 +
    3.15  /* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/cocoa/SDL_cocoakeyboard.h	Sun May 31 16:57:29 2009 +0000
     4.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.h	Fri Jun 26 10:37:57 2009 +0000
     4.3 @@ -28,6 +28,8 @@
     4.4  extern void Cocoa_HandleKeyEvent(_THIS, NSEvent * event);
     4.5  extern void Cocoa_QuitKeyboard(_THIS);
     4.6  
     4.7 +extern void Cocoa_StartTextInput(_THIS, SDL_Rect *rect);
     4.8 +
     4.9  #endif /* _SDL_cocoakeyboard_h */
    4.10  
    4.11  /* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Sun May 31 16:57:29 2009 +0000
     5.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Fri Jun 26 10:37:57 2009 +0000
     5.3 @@ -59,12 +59,19 @@
     5.4      NSString *_markedText;
     5.5      NSRange   _markedRange;
     5.6      NSRange   _selectedRange;
     5.7 +    SDL_Rect inputRect;
     5.8  }
     5.9  - (void) doCommandBySelector:(SEL)myselector;
    5.10 +- (void) setInputRect:(SDL_Rect *) rect;
    5.11  @end
    5.12  
    5.13  @implementation SDLTranslatorResponder
    5.14  
    5.15 +- (void) setInputRect:(SDL_Rect *) rect
    5.16 +{
    5.17 +    inputRect = *rect;
    5.18 +}
    5.19 +
    5.20  - (void) insertText:(id) aString
    5.21  {
    5.22      const char *str;
    5.23 @@ -135,11 +142,20 @@
    5.24  
    5.25  - (NSRect) firstRectForCharacterRange: (NSRange) theRange
    5.26  {
    5.27 -    return NSMakeRect(0, 0, 0, 0);
    5.28 +    float windowHeight = [[self window] frame].size.height;
    5.29 +    NSRect rect = NSMakeRect(inputRect.x, windowHeight - inputRect.y, inputRect.w, inputRect.h);
    5.30 +
    5.31 +    NSLog(@"firstRectForCharacterRange: (%d, %d): windowHeight = %g, rect = %@",
    5.32 +            theRange.location, theRange.length, windowHeight,
    5.33 +            NSStringFromRect(rect));
    5.34 +    rect.origin = [[self window] convertBaseToScreen: rect.origin];
    5.35 +
    5.36 +    return rect;
    5.37  }
    5.38  
    5.39  - (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange
    5.40  {
    5.41 +    NSLog(@"attributedSubstringFromRange: (%d, %d)", theRange.location, theRange.length);
    5.42      return nil;
    5.43  }
    5.44  
    5.45 @@ -152,6 +168,7 @@
    5.46  // nearest to thePoint.  thPoint is in screen coordinate system.
    5.47  - (NSUInteger) characterIndexForPoint:(NSPoint) thePoint
    5.48  {
    5.49 +    NSLog(@"characterIndexForPoint: (%g, %g)", thePoint.x, thePoint.y);
    5.50      return 0;
    5.51  }
    5.52  
    5.53 @@ -578,6 +595,15 @@
    5.54  }
    5.55  
    5.56  void
    5.57 +Cocoa_StartTextInput(_THIS, SDL_Rect *rect)
    5.58 +{
    5.59 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    5.60 +
    5.61 +    NSLog(@"StartTextInput: (%d, %d) (w=%d, h=%d)", rect->x, rect->y, rect->w, rect->h);
    5.62 +    [data->fieldEdit setInputRect: rect];
    5.63 +}
    5.64 +
    5.65 +void
    5.66  Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
    5.67  {
    5.68      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     6.1 --- a/src/video/cocoa/SDL_cocoavideo.h	Sun May 31 16:57:29 2009 +0000
     6.2 +++ b/src/video/cocoa/SDL_cocoavideo.h	Fri Jun 26 10:37:57 2009 +0000
     6.3 @@ -41,6 +41,8 @@
     6.4  
     6.5  /* Private display data */
     6.6  
     6.7 +@class SDLTranslatorResponder;
     6.8 +
     6.9  typedef struct SDL_VideoData
    6.10  {
    6.11      SInt32 osversion;
    6.12 @@ -48,7 +50,7 @@
    6.13      int mouse;
    6.14      int keyboard;
    6.15      void *key_layout;
    6.16 -    NSText *fieldEdit;
    6.17 +    SDLTranslatorResponder *fieldEdit;
    6.18      Uint32 screensaver_activity;
    6.19  } SDL_VideoData;
    6.20  
     7.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Sun May 31 16:57:29 2009 +0000
     7.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Fri Jun 26 10:37:57 2009 +0000
     7.3 @@ -102,6 +102,8 @@
     7.4      device->GL_DeleteContext = Cocoa_GL_DeleteContext;
     7.5  #endif
     7.6  
     7.7 +    device->StartTextInput = Cocoa_StartTextInput;
     7.8 +
     7.9      device->free = Cocoa_DeleteDevice;
    7.10  
    7.11      return device;