2 * Copyright (C) 2012-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "XBMCController.h"
22 #include "IOSKeyboard.h"
23 #include "IOSKeyboardView.h"
24 #include "XBMCDebugHelpers.h"
28 KeyboardView *g_pIosKeyboard = nil;
30 bool CIOSKeyboard::ShowAndGetInput(char_callback_t pCallback, const std::string &initialString, std::string &typedString, const std::string &heading, bool bHiddenInput)
32 // we are in xbmc main thread or python module thread.
36 @synchronized([KeyboardView class])
38 // in case twice open keyboard.
42 // assume we are only drawn on the mainscreen ever!
43 UIScreen *pCurrentScreen = [UIScreen mainScreen];
44 CGRect keyboardFrame = CGRectMake(0, 0, pCurrentScreen.bounds.size.height, pCurrentScreen.bounds.size.width);
45 // LOG(@"kb: kb frame: %@", NSStringFromCGRect(keyboardFrame));
47 //create the keyboardview
48 g_pIosKeyboard = [[KeyboardView alloc] initWithFrame:keyboardFrame];
53 m_pCharCallback = pCallback;
55 // init keyboard stuff
56 [g_pIosKeyboard setDefault:[NSString stringWithUTF8String:initialString.c_str()]];
57 [g_pIosKeyboard setHidden:bHiddenInput];
58 [g_pIosKeyboard setHeading:[NSString stringWithUTF8String:heading.c_str()]];
59 [g_pIosKeyboard registerKeyboard:this]; // for calling back
60 bool confirmed = false;
63 [g_pIosKeyboard setCancelFlag:&m_bCanceled];
64 [g_pIosKeyboard activate]; // blocks and loops our application loop (like a modal dialog)
65 // user is done - get resulted text and confirmation
66 confirmed = g_pIosKeyboard.isConfirmed;
68 typedString = [g_pIosKeyboard.text UTF8String];
70 [g_pIosKeyboard release]; // bye bye native keyboard
71 @synchronized([KeyboardView class])
78 void CIOSKeyboard::Cancel()
83 //wrap our callback between objc and c++
84 void CIOSKeyboard::fireCallback(const std::string &str)
88 m_pCharCallback(this, str);