src/video/uikit/SDL_uikitview.m
changeset 6010 508aa078acc0
parent 6003 fddf81967e2d
child 6044 35448a5ea044
     1.1 --- a/src/video/uikit/SDL_uikitview.m	Wed Sep 28 21:13:09 2011 +0200
     1.2 +++ b/src/video/uikit/SDL_uikitview.m	Wed Sep 28 21:25:46 2011 +0200
     1.3 @@ -311,100 +311,69 @@
     1.4  /* iPhone keyboard addition functions */
     1.5  #if SDL_IPHONE_KEYBOARD
     1.6  
     1.7 +SDL_uikitview * getWindowView(SDL_Window * window)
     1.8 +{
     1.9 +    if (window == NULL) {
    1.10 +        SDL_SetError("Window does not exist");
    1.11 +        return nil;
    1.12 +    }
    1.13 +
    1.14 +    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    1.15 +    SDL_uikitview *view = data != NULL ? data->view : nil;
    1.16 +
    1.17 +    if (view == nil) {
    1.18 +        SDL_SetError("Window has no view");
    1.19 +    }
    1.20 +
    1.21 +    return view;
    1.22 +}
    1.23 +
    1.24  int SDL_iPhoneKeyboardShow(SDL_Window * window)
    1.25  {
    1.26 -    SDL_WindowData *data;
    1.27 -    SDL_uikitview *view;
    1.28 -
    1.29 -    if (NULL == window) {
    1.30 -        SDL_SetError("Window does not exist");
    1.31 +    SDL_uikitview *view = getWindowView(window);
    1.32 +    if (view == nil) {
    1.33          return -1;
    1.34      }
    1.35  
    1.36 -    data = (SDL_WindowData *)window->driverdata;
    1.37 -    view = data->view;
    1.38 -
    1.39 -    if (nil == view) {
    1.40 -        SDL_SetError("Window has no view");
    1.41 -        return -1;
    1.42 -    }
    1.43 -    else {
    1.44 -        [view showKeyboard];
    1.45 -        return 0;
    1.46 -    }
    1.47 +    [view showKeyboard];
    1.48 +    return 0;
    1.49  }
    1.50  
    1.51  int SDL_iPhoneKeyboardHide(SDL_Window * window)
    1.52  {
    1.53 -    SDL_WindowData *data;
    1.54 -    SDL_uikitview *view;
    1.55 -
    1.56 -    if (NULL == window) {
    1.57 -        SDL_SetError("Window does not exist");
    1.58 +    SDL_uikitview *view = getWindowView(window);
    1.59 +    if (view == nil) {
    1.60          return -1;
    1.61      }
    1.62  
    1.63 -    data = (SDL_WindowData *)window->driverdata;
    1.64 -    view = data->view;
    1.65 -
    1.66 -    if (NULL == view) {
    1.67 -        SDL_SetError("Window has no view");
    1.68 -        return -1;
    1.69 -    }
    1.70 -    else {
    1.71 -        [view hideKeyboard];
    1.72 -        return 0;
    1.73 -    }
    1.74 +    [view hideKeyboard];
    1.75 +    return 0;
    1.76  }
    1.77  
    1.78  SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window)
    1.79  {
    1.80 -    SDL_WindowData *data;
    1.81 -    SDL_uikitview *view;
    1.82 -
    1.83 -    if (NULL == window) {
    1.84 -        SDL_SetError("Window does not exist");
    1.85 -        return -1;
    1.86 +    SDL_uikitview *view = getWindowView(window);
    1.87 +    if (view == nil) {
    1.88 +        return 0;
    1.89      }
    1.90  
    1.91 -    data = (SDL_WindowData *)window->driverdata;
    1.92 -    view = data->view;
    1.93 -
    1.94 -    if (NULL == view) {
    1.95 -        SDL_SetError("Window has no view");
    1.96 -        return 0;
    1.97 -    }
    1.98 -    else {
    1.99 -        return view.keyboardVisible;
   1.100 -    }
   1.101 +    return view.keyboardVisible;
   1.102  }
   1.103  
   1.104  int SDL_iPhoneKeyboardToggle(SDL_Window * window)
   1.105  {
   1.106 -    SDL_WindowData *data;
   1.107 -    SDL_uikitview *view;
   1.108 -
   1.109 -    if (NULL == window) {
   1.110 -        SDL_SetError("Window does not exist");
   1.111 +    SDL_uikitview *view = getWindowView(window);
   1.112 +    if (view == nil) {
   1.113          return -1;
   1.114      }
   1.115  
   1.116 -    data = (SDL_WindowData *)window->driverdata;
   1.117 -    view = data->view;
   1.118 -
   1.119 -    if (NULL == view) {
   1.120 -        SDL_SetError("Window has no view");
   1.121 -        return -1;
   1.122 +    if (SDL_iPhoneKeyboardIsShown(window)) {
   1.123 +        SDL_iPhoneKeyboardHide(window);
   1.124      }
   1.125      else {
   1.126 -        if (SDL_iPhoneKeyboardIsShown(window)) {
   1.127 -            SDL_iPhoneKeyboardHide(window);
   1.128 -        }
   1.129 -        else {
   1.130 -            SDL_iPhoneKeyboardShow(window);
   1.131 -        }
   1.132 -        return 0;
   1.133 +        SDL_iPhoneKeyboardShow(window);
   1.134      }
   1.135 +    return 0;
   1.136  }
   1.137  
   1.138  #else