src/video/uikit/SDL_uikitviewcontroller.m
author Sam Lantinga <slouken@libsdl.org>
Tue, 19 Dec 2017 10:57:21 -0800
changeset 11782 98ea6e4c0d68
parent 11497 65698434e30d
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Fixed bug 4004 - iOS: don't hide keyboard on RETURN

Dominik Reichardt

As discussed in 2012 the iOS onscreen keyboard hides when you hit RETURN (see https://discourse.libsdl.org/t/on-screen-keyboard-change/19216).
IMO this is a bad idea to not be able to influence this behavior and just recently this was fixed for Android by adding the hint SDL_HINT_ANDROID_RETURN_HIDES_IME in changeset 11768 0f2fb9ec6ad6.
kees@5640
     1
/*
slouken@6044
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
kees@6001
     4
slouken@6044
     5
  This software is provided 'as-is', without any express or implied
slouken@6044
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@6044
     7
  arising from the use of this software.
kees@6001
     8
slouken@6044
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@6044
    10
  including commercial applications, and to alter it and redistribute it
slouken@6044
    11
  freely, subject to the following restrictions:
kees@6001
    12
slouken@6044
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@6044
    14
     claim that you wrote the original software. If you use this software
slouken@6044
    15
     in a product, an acknowledgment in the product documentation would be
slouken@6044
    16
     appreciated but is not required.
slouken@6044
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@6044
    18
     misrepresented as being the original software.
slouken@6044
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@6044
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
kees@5640
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_UIKIT
slouken@6044
    24
kees@5640
    25
#include "SDL_video.h"
kees@5640
    26
#include "SDL_assert.h"
kees@5640
    27
#include "SDL_hints.h"
kees@5640
    28
#include "../SDL_sysvideo.h"
kees@5640
    29
#include "../../events/SDL_events_c.h"
kees@5640
    30
slime73@9532
    31
#import "SDL_uikitviewcontroller.h"
slime73@9532
    32
#import "SDL_uikitmessagebox.h"
icculus@6093
    33
#include "SDL_uikitvideo.h"
slouken@6518
    34
#include "SDL_uikitmodes.h"
slouken@6518
    35
#include "SDL_uikitwindow.h"
slime73@10141
    36
#include "SDL_uikitopengles.h"
slouken@6518
    37
slime73@9532
    38
#if SDL_IPHONE_KEYBOARD
slime73@9532
    39
#include "keyinfotable.h"
slime73@9532
    40
#endif
kees@5640
    41
slime73@10340
    42
#if TARGET_OS_TV
slouken@11284
    43
static void SDLCALL
slime73@10340
    44
SDL_AppleTVControllerUIHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
slime73@10340
    45
{
slime73@10340
    46
    @autoreleasepool {
slime73@10340
    47
        SDL_uikitviewcontroller *viewcontroller = (__bridge SDL_uikitviewcontroller *) userdata;
slime73@10340
    48
        viewcontroller.controllerUserInteractionEnabled = hint && (*hint != '0');
slime73@10340
    49
    }
slime73@10340
    50
}
slime73@10340
    51
#endif
slime73@10340
    52
slime73@9532
    53
@implementation SDL_uikitviewcontroller {
slime73@9532
    54
    CADisplayLink *displayLink;
slime73@9532
    55
    int animationInterval;
slime73@9532
    56
    void (*animationCallback)(void*);
slime73@9532
    57
    void *animationCallbackParam;
slime73@9532
    58
slime73@9532
    59
#if SDL_IPHONE_KEYBOARD
slime73@9532
    60
    UITextField *textField;
slouken@10671
    61
    BOOL rotatingOrientation;
slime73@9532
    62
#endif
slime73@9532
    63
}
kees@5640
    64
kees@6011
    65
@synthesize window;
kees@6011
    66
slime73@9532
    67
- (instancetype)initWithSDLWindow:(SDL_Window *)_window
kees@6003
    68
{
slime73@9505
    69
    if (self = [super initWithNibName:nil bundle:nil]) {
slime73@9505
    70
        self.window = _window;
slime73@9532
    71
slime73@9532
    72
#if SDL_IPHONE_KEYBOARD
slime73@9532
    73
        [self initKeyboard];
slouken@10671
    74
        rotatingOrientation = FALSE;
slime73@9532
    75
#endif
slime73@10340
    76
slime73@10340
    77
#if TARGET_OS_TV
slime73@10340
    78
        SDL_AddHintCallback(SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS,
slime73@10340
    79
                            SDL_AppleTVControllerUIHintChanged,
slime73@10340
    80
                            (__bridge void *) self);
slime73@10340
    81
#endif
kees@5640
    82
    }
kees@5640
    83
    return self;
kees@5640
    84
}
kees@5640
    85
slime73@9532
    86
- (void)dealloc
slime73@9532
    87
{
slime73@9532
    88
#if SDL_IPHONE_KEYBOARD
slime73@9532
    89
    [self deinitKeyboard];
slime73@9532
    90
#endif
slime73@10340
    91
slime73@10340
    92
#if TARGET_OS_TV
slime73@10340
    93
    SDL_DelHintCallback(SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS,
slime73@10340
    94
                        SDL_AppleTVControllerUIHintChanged,
slime73@10340
    95
                        (__bridge void *) self);
slime73@10340
    96
#endif
slime73@9532
    97
}
slime73@9532
    98
slime73@9532
    99
- (void)setAnimationCallback:(int)interval
slime73@9532
   100
                    callback:(void (*)(void*))callback
slime73@9532
   101
               callbackParam:(void*)callbackParam
slime73@9532
   102
{
slime73@9532
   103
    [self stopAnimation];
slime73@9532
   104
slime73@9532
   105
    animationInterval = interval;
slime73@9532
   106
    animationCallback = callback;
slime73@9532
   107
    animationCallbackParam = callbackParam;
slime73@9532
   108
slime73@9532
   109
    if (animationCallback) {
slime73@9532
   110
        [self startAnimation];
slime73@9532
   111
    }
slime73@9532
   112
}
slime73@9532
   113
slime73@9532
   114
- (void)startAnimation
slime73@9532
   115
{
slime73@9532
   116
    displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
slime73@11147
   117
slime73@11147
   118
#ifdef __IPHONE_10_3
slime73@11147
   119
    SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
slime73@11147
   120
slime73@11147
   121
    if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)]
slime73@11147
   122
        && data != nil && data.uiwindow != nil
slime73@11147
   123
        && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
slime73@11147
   124
        displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval;
slime73@11147
   125
    } else
slime73@11147
   126
#endif
slime73@11147
   127
    {
slime73@11147
   128
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 100300
slime73@11147
   129
        [displayLink setFrameInterval:animationInterval];
slime73@11147
   130
#endif
slime73@11147
   131
    }
slime73@11147
   132
slime73@9532
   133
    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
slime73@9532
   134
}
slime73@9532
   135
slime73@9532
   136
- (void)stopAnimation
slime73@9532
   137
{
slime73@9532
   138
    [displayLink invalidate];
slime73@9532
   139
    displayLink = nil;
slime73@9532
   140
}
slime73@9532
   141
slime73@9532
   142
- (void)doLoop:(CADisplayLink*)sender
slime73@9532
   143
{
slime73@9532
   144
    /* Don't run the game loop while a messagebox is up */
slime73@9532
   145
    if (!UIKit_ShowingMessageBox()) {
slime73@10141
   146
        /* See the comment in the function definition. */
slime73@10141
   147
        UIKit_GL_RestoreCurrentContext();
slime73@10141
   148
slime73@9532
   149
        animationCallback(animationCallbackParam);
slime73@9532
   150
    }
slime73@9532
   151
}
slime73@9532
   152
slouken@6440
   153
- (void)loadView
slouken@6440
   154
{
slime73@9532
   155
    /* Do nothing. */
slouken@6440
   156
}
slouken@6440
   157
slouken@6451
   158
- (void)viewDidLayoutSubviews
slouken@6440
   159
{
slime73@9505
   160
    const CGSize size = self.view.bounds.size;
slime73@9494
   161
    int w = (int) size.width;
slime73@9494
   162
    int h = (int) size.height;
slouken@7191
   163
slime73@9494
   164
    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
slouken@6440
   165
}
slouken@6440
   166
slime73@10340
   167
#if !TARGET_OS_TV
slouken@6451
   168
- (NSUInteger)supportedInterfaceOrientations
kees@6003
   169
{
slime73@9523
   170
    return UIKit_GetSupportedOrientations(window);
kees@5640
   171
}
kees@5640
   172
slime73@11147
   173
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
slouken@6451
   174
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
kees@6003
   175
{
slime73@9532
   176
    return ([self supportedInterfaceOrientations] & (1 << orient)) != 0;
kees@5640
   177
}
slime73@11147
   178
#endif
kees@5640
   179
slouken@7862
   180
- (BOOL)prefersStatusBarHidden
slouken@7862
   181
{
slime73@9529
   182
    return (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) != 0;
slouken@7862
   183
}
slime73@10340
   184
#endif
slouken@7862
   185
slime73@9532
   186
/*
slime73@9532
   187
 ---- Keyboard related functionality below this line ----
slime73@9532
   188
 */
slime73@9532
   189
#if SDL_IPHONE_KEYBOARD
slime73@9532
   190
slime73@9532
   191
@synthesize textInputRect;
slime73@9532
   192
@synthesize keyboardHeight;
slime73@9532
   193
@synthesize keyboardVisible;
slime73@9532
   194
slime73@9532
   195
/* Set ourselves up as a UITextFieldDelegate */
slime73@9532
   196
- (void)initKeyboard
slime73@9532
   197
{
slime73@9532
   198
    textField = [[UITextField alloc] initWithFrame:CGRectZero];
slime73@9532
   199
    textField.delegate = self;
slime73@9532
   200
    /* placeholder so there is something to delete! */
slime73@9532
   201
    textField.text = @" ";
slime73@9532
   202
slime73@9532
   203
    /* set UITextInputTrait properties, mostly to defaults */
slime73@9532
   204
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
slime73@9532
   205
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
slime73@9532
   206
    textField.enablesReturnKeyAutomatically = NO;
slime73@9532
   207
    textField.keyboardAppearance = UIKeyboardAppearanceDefault;
slime73@9532
   208
    textField.keyboardType = UIKeyboardTypeDefault;
slime73@9532
   209
    textField.returnKeyType = UIReturnKeyDefault;
slime73@9532
   210
    textField.secureTextEntry = NO;
slime73@9532
   211
slime73@9532
   212
    textField.hidden = YES;
slime73@9532
   213
    keyboardVisible = NO;
slime73@9532
   214
slime73@10340
   215
#if !TARGET_OS_TV
slime73@9532
   216
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
slime73@9532
   217
    [center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
slime73@9532
   218
    [center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
slime73@10340
   219
#endif
slime73@9532
   220
}
slime73@9532
   221
slime73@9532
   222
- (void)setView:(UIView *)view
slime73@9532
   223
{
slime73@9532
   224
    [super setView:view];
slime73@9532
   225
slime73@9532
   226
    [view addSubview:textField];
slime73@9532
   227
slime73@9532
   228
    if (keyboardVisible) {
slime73@9532
   229
        [self showKeyboard];
slime73@9532
   230
    }
slime73@9532
   231
}
slime73@9532
   232
slouken@10671
   233
/* willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation are deprecated in iOS 8+ in favor of viewWillTransitionToSize */
slouken@10671
   234
#if TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
slouken@10671
   235
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
slouken@10671
   236
{
slouken@10671
   237
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
slouken@10671
   238
    rotatingOrientation = TRUE;
slouken@10671
   239
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
slouken@10671
   240
                                 completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
slouken@10671
   241
                                     rotatingOrientation = FALSE;
slouken@10671
   242
                                 }];
slouken@10671
   243
}
slouken@10671
   244
#else
slouken@10671
   245
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
slouken@10671
   246
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
slouken@10671
   247
    rotatingOrientation = TRUE;
slouken@10671
   248
}
slouken@10671
   249
slouken@10671
   250
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
slouken@10671
   251
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
slouken@10671
   252
    rotatingOrientation = FALSE;
slouken@10671
   253
}
slouken@10671
   254
#endif /* TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000 */
slouken@10671
   255
slime73@9532
   256
- (void)deinitKeyboard
slime73@9532
   257
{
slime73@10340
   258
#if !TARGET_OS_TV
slime73@9532
   259
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
slime73@9532
   260
    [center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
slime73@9532
   261
    [center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
slime73@10340
   262
#endif
slime73@9532
   263
}
slime73@9532
   264
slime73@9532
   265
/* reveal onscreen virtual keyboard */
slime73@9532
   266
- (void)showKeyboard
slime73@9532
   267
{
slime73@9532
   268
    keyboardVisible = YES;
slime73@9532
   269
    if (textField.window) {
slime73@9532
   270
        [textField becomeFirstResponder];
slime73@9532
   271
    }
slime73@9532
   272
}
slime73@9532
   273
slime73@9532
   274
/* hide onscreen virtual keyboard */
slime73@9532
   275
- (void)hideKeyboard
slime73@9532
   276
{
slime73@9532
   277
    keyboardVisible = NO;
slime73@9532
   278
    [textField resignFirstResponder];
slime73@9532
   279
}
slime73@9532
   280
slime73@9532
   281
- (void)keyboardWillShow:(NSNotification *)notification
slime73@9532
   282
{
slime73@10340
   283
#if !TARGET_OS_TV
slouken@11497
   284
    CGRect kbrect = [[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue];
slime73@9532
   285
slime73@9585
   286
    /* The keyboard rect is in the coordinate space of the screen/window, but we
slime73@9585
   287
     * want its height in the coordinate space of the view. */
slime73@9585
   288
    kbrect = [self.view convertRect:kbrect fromView:nil];
slime73@9532
   289
slime73@9585
   290
    [self setKeyboardHeight:(int)kbrect.size.height];
slime73@10340
   291
#endif
slime73@9532
   292
}
slime73@9532
   293
slime73@9532
   294
- (void)keyboardWillHide:(NSNotification *)notification
slime73@9532
   295
{
slime73@11327
   296
    if (!rotatingOrientation) {
slouken@10671
   297
        SDL_StopTextInput();
slime73@11327
   298
    }
slime73@9532
   299
    [self setKeyboardHeight:0];
slime73@9532
   300
}
slime73@9532
   301
slime73@9532
   302
- (void)updateKeyboard
slime73@9532
   303
{
slime73@9532
   304
    CGAffineTransform t = self.view.transform;
slime73@9532
   305
    CGPoint offset = CGPointMake(0.0, 0.0);
slime73@9585
   306
    CGRect frame = UIKit_ComputeViewFrame(window, self.view.window.screen);
slime73@9532
   307
slime73@9532
   308
    if (self.keyboardHeight) {
slime73@9585
   309
        int rectbottom = self.textInputRect.y + self.textInputRect.h;
slime73@9585
   310
        int keybottom = self.view.bounds.size.height - self.keyboardHeight;
slime73@9585
   311
        if (keybottom < rectbottom) {
slime73@9585
   312
            offset.y = keybottom - rectbottom;
slime73@9532
   313
        }
slime73@9532
   314
    }
slime73@9532
   315
slime73@9585
   316
    /* Apply this view's transform (except any translation) to the offset, in
slime73@9585
   317
     * order to orient it correctly relative to the frame's coordinate space. */
slime73@9532
   318
    t.tx = 0.0;
slime73@9532
   319
    t.ty = 0.0;
slime73@9532
   320
    offset = CGPointApplyAffineTransform(offset, t);
slime73@9532
   321
slime73@9585
   322
    /* Apply the updated offset to the view's frame. */
slime73@9585
   323
    frame.origin.x += offset.x;
slime73@9585
   324
    frame.origin.y += offset.y;
slime73@9532
   325
slime73@9585
   326
    self.view.frame = frame;
slime73@9532
   327
}
slime73@9532
   328
slime73@9532
   329
- (void)setKeyboardHeight:(int)height
slime73@9532
   330
{
slime73@9532
   331
    keyboardVisible = height > 0;
slime73@9532
   332
    keyboardHeight = height;
slime73@9532
   333
    [self updateKeyboard];
slime73@9532
   334
}
slime73@9532
   335
slime73@9532
   336
/* UITextFieldDelegate method.  Invoked when user types something. */
slime73@9532
   337
- (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
slime73@9532
   338
{
slime73@9532
   339
    NSUInteger len = string.length;
slime73@9532
   340
slime73@9532
   341
    if (len == 0) {
slime73@9532
   342
        /* it wants to replace text with nothing, ie a delete */
slime73@9532
   343
        SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_BACKSPACE);
slime73@9532
   344
        SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_BACKSPACE);
slime73@9532
   345
    } else {
slime73@9532
   346
        /* go through all the characters in the string we've been sent and
slime73@9532
   347
         * convert them to key presses */
slime73@9532
   348
        int i;
slime73@9532
   349
        for (i = 0; i < len; i++) {
slime73@9532
   350
            unichar c = [string characterAtIndex:i];
slime73@9532
   351
            Uint16 mod = 0;
slime73@9532
   352
            SDL_Scancode code;
slime73@9532
   353
slime73@9532
   354
            if (c < 127) {
slime73@9532
   355
                /* figure out the SDL_Scancode and SDL_keymod for this unichar */
slime73@9532
   356
                code = unicharToUIKeyInfoTable[c].code;
slime73@9532
   357
                mod  = unicharToUIKeyInfoTable[c].mod;
slime73@9532
   358
            } else {
slime73@9532
   359
                /* we only deal with ASCII right now */
slime73@9532
   360
                code = SDL_SCANCODE_UNKNOWN;
slime73@9532
   361
                mod = 0;
slime73@9532
   362
            }
slime73@9532
   363
slime73@9532
   364
            if (mod & KMOD_SHIFT) {
slime73@9532
   365
                /* If character uses shift, press shift down */
slime73@9532
   366
                SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
slime73@9532
   367
            }
slime73@9532
   368
slime73@9532
   369
            /* send a keydown and keyup even for the character */
slime73@9532
   370
            SDL_SendKeyboardKey(SDL_PRESSED, code);
slime73@9532
   371
            SDL_SendKeyboardKey(SDL_RELEASED, code);
slime73@9532
   372
slime73@9532
   373
            if (mod & KMOD_SHIFT) {
slime73@9532
   374
                /* If character uses shift, press shift back up */
slime73@9532
   375
                SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
slime73@9532
   376
            }
slime73@9532
   377
        }
slime73@9532
   378
slime73@9532
   379
        SDL_SendKeyboardText([string UTF8String]);
slime73@9532
   380
    }
slime73@9532
   381
slime73@9532
   382
    return NO; /* don't allow the edit! (keep placeholder text there) */
slime73@9532
   383
}
slime73@9532
   384
slime73@9532
   385
/* Terminates the editing session */
slime73@9532
   386
- (BOOL)textFieldShouldReturn:(UITextField*)_textField
slime73@9532
   387
{
slime73@9532
   388
    SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RETURN);
slime73@9532
   389
    SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RETURN);
slouken@11782
   390
    if (SDL_GetHintBoolean(SDL_HINT_RETURN_KEY_HIDES_IME, SDL_FALSE)) {
slouken@11782
   391
         SDL_StopTextInput();
slouken@11782
   392
    }
slime73@9532
   393
    return YES;
slime73@9532
   394
}
slime73@9532
   395
slime73@9532
   396
#endif
slime73@9532
   397
slouken@6451
   398
@end
slouken@6451
   399
slime73@9532
   400
/* iPhone keyboard addition functions */
slime73@9532
   401
#if SDL_IPHONE_KEYBOARD
slime73@9532
   402
slime73@9532
   403
static SDL_uikitviewcontroller *
slime73@9532
   404
GetWindowViewController(SDL_Window * window)
slime73@9532
   405
{
slime73@9532
   406
    if (!window || !window->driverdata) {
slime73@9532
   407
        SDL_SetError("Invalid window");
slime73@9532
   408
        return nil;
slime73@9532
   409
    }
slime73@9532
   410
slime73@9532
   411
    SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
slime73@9532
   412
slime73@9532
   413
    return data.viewcontroller;
slime73@9532
   414
}
slime73@9532
   415
slime73@9532
   416
SDL_bool
slime73@9532
   417
UIKit_HasScreenKeyboardSupport(_THIS)
slime73@9532
   418
{
slime73@9532
   419
    return SDL_TRUE;
slime73@9532
   420
}
slime73@9532
   421
slime73@9532
   422
void
slime73@9532
   423
UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window)
slime73@9532
   424
{
slime73@9532
   425
    @autoreleasepool {
slime73@9532
   426
        SDL_uikitviewcontroller *vc = GetWindowViewController(window);
slime73@9532
   427
        [vc showKeyboard];
slime73@9532
   428
    }
slime73@9532
   429
}
slime73@9532
   430
slime73@9532
   431
void
slime73@9532
   432
UIKit_HideScreenKeyboard(_THIS, SDL_Window *window)
slime73@9532
   433
{
slime73@9532
   434
    @autoreleasepool {
slime73@9532
   435
        SDL_uikitviewcontroller *vc = GetWindowViewController(window);
slime73@9532
   436
        [vc hideKeyboard];
slime73@9532
   437
    }
slime73@9532
   438
}
slime73@9532
   439
slime73@9532
   440
SDL_bool
slime73@9532
   441
UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window)
slime73@9532
   442
{
slime73@9532
   443
    @autoreleasepool {
slime73@9532
   444
        SDL_uikitviewcontroller *vc = GetWindowViewController(window);
slime73@9532
   445
        if (vc != nil) {
slime73@9532
   446
            return vc.isKeyboardVisible;
slime73@9532
   447
        }
slime73@9532
   448
        return SDL_FALSE;
slime73@9532
   449
    }
slime73@9532
   450
}
slime73@9532
   451
slime73@9532
   452
void
slime73@9532
   453
UIKit_SetTextInputRect(_THIS, SDL_Rect *rect)
slime73@9532
   454
{
slime73@9532
   455
    if (!rect) {
slime73@9532
   456
        SDL_InvalidParamError("rect");
slime73@9532
   457
        return;
slime73@9532
   458
    }
slime73@9532
   459
slime73@9532
   460
    @autoreleasepool {
slime73@9532
   461
        SDL_uikitviewcontroller *vc = GetWindowViewController(SDL_GetFocusWindow());
slime73@9532
   462
        if (vc != nil) {
slime73@9532
   463
            vc.textInputRect = *rect;
slime73@9532
   464
slime73@9532
   465
            if (vc.keyboardVisible) {
slime73@9532
   466
                [vc updateKeyboard];
slime73@9532
   467
            }
slime73@9532
   468
        }
slime73@9532
   469
    }
slime73@9532
   470
}
slime73@9532
   471
slime73@9532
   472
slime73@9532
   473
#endif /* SDL_IPHONE_KEYBOARD */
slime73@9532
   474
slouken@6044
   475
#endif /* SDL_VIDEO_DRIVER_UIKIT */
slouken@6044
   476
slouken@6440
   477
/* vi: set ts=4 sw=4 expandtab: */