diff options
author | Tor Lillqvist <tml@iki.fi> | 2013-04-14 01:41:28 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@iki.fi> | 2013-04-14 01:52:28 +0300 |
commit | e3e040f671097e1675be80e2db294ad208e0b13c (patch) | |
tree | f05aa1029f0e1424f94ab5fbc139d616960ab237 /ios | |
parent | 6b89688829fa2758419361b1ac0598b72a3e3423 (diff) |
Add text input to the iOS app
Don't have our View class implement the UIKeyInput protocol any
more. It won't work properly anyway. The docs say: "Only a small
subset of the available keyboards and languages are available to
classes that adopt this protocol".
Instead, use a transparent UITextView on top of our View to accept
keyboard input.
Seems to work as expected.
Change-Id: I3093ea7fbfa0ecab0dc5d0a38e5695723e8ed4ad
Diffstat (limited to 'ios')
4 files changed, 35 insertions, 35 deletions
diff --git a/ios/experimental/LibreOffice/LibreOffice/AppDelegate.h b/ios/experimental/LibreOffice/LibreOffice/AppDelegate.h index c5c4560a6c57..ebc7f69d25c6 100644 --- a/ios/experimental/LibreOffice/LibreOffice/AppDelegate.h +++ b/ios/experimental/LibreOffice/LibreOffice/AppDelegate.h @@ -10,12 +10,13 @@ #import "View.h" -@interface AppDelegate : UIResponder <UIApplicationDelegate> +@interface AppDelegate : UIResponder <UIApplicationDelegate, UITextViewDelegate> @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) View *view; -- (void) threadMainMethod: (id) argument; +- (void)threadMainMethod: (id) argument; +- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text; @end diff --git a/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m b/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m index 223ccf56b4ba..a12585b4ef0f 100644 --- a/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m +++ b/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m @@ -16,7 +16,7 @@ #import "lo.h" -static UIView *theView; +static View *theView; @implementation AppDelegate @@ -41,6 +41,12 @@ static UIView *theView; vc.view = self.view; theView = self.view; + self.view->textView = [[UITextView alloc] initWithFrame: r]; + self.view->textView.autocapitalizationType = UITextAutocapitalizationTypeNone; + self.view->textView.alpha = 0; + [self.view addSubview: self.view->textView]; + self.view->textView.delegate = self; + UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self.view action:@selector(tapGesture:)]; [self.window addGestureRecognizer: tapRecognizer]; @@ -68,6 +74,17 @@ static UIView *theView; } } +- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text +{ + NSLog(@"textView: %@ shouldChangeTextInRange:[%u,%u] replacementText:%@", textView, range.location, range.length, text); + assert(textView == theView->textView); + + for (NSUInteger i = 0; i < [text length]; i++) + lo_keyboard_input([text characterAtIndex: i]); + + return NO; +} + - (void)applicationWillResignActive:(UIApplication *)application { (void) application; @@ -101,16 +118,17 @@ static UIView *theView; [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&frameBegin]; [[info objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&frameEnd]; + + NSLog(@"keyboardWillShow: frame:%dx%d@(%d,%d)", + (int) frameEnd.size.width, (int) frameEnd.size.height, + (int) frameEnd.origin.x, (int) frameEnd.origin.y); } - (void)keyboardDidHide:(NSNotification *)note { - NSDictionary *info = [note userInfo]; - CGRect frameBegin; - CGRect frameEnd; + (void) note; - [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&frameBegin]; - [[info objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&frameEnd]; + NSLog(@"keyboardDidHide"); lo_keyboard_did_hide(); } @@ -129,14 +147,14 @@ void lo_damaged(CGRect rect) void lo_show_keyboard() { dispatch_async(dispatch_get_main_queue(), ^{ - [theView becomeFirstResponder]; + [theView->textView becomeFirstResponder]; }); } void lo_hide_keyboard() { dispatch_async(dispatch_get_main_queue(), ^{ - [theView resignFirstResponder]; + [theView->textView resignFirstResponder]; }); } diff --git a/ios/experimental/LibreOffice/LibreOffice/View.h b/ios/experimental/LibreOffice/LibreOffice/View.h index a50b8f3e0d9b..b0e8394809b2 100644 --- a/ios/experimental/LibreOffice/LibreOffice/View.h +++ b/ios/experimental/LibreOffice/LibreOffice/View.h @@ -9,8 +9,11 @@ #import <UIKit/UIKit.h> -@interface View : UIView <UIKeyInput> - +@interface View : UIView +{ +@public + UITextView* textView; +} - (void)drawRect:(CGRect)rect; - (void)tapGesture:(UIGestureRecognizer *)gestureRecognizer; diff --git a/ios/experimental/LibreOffice/LibreOffice/View.m b/ios/experimental/LibreOffice/LibreOffice/View.m index 43edc2f62c93..2dd4ab899cc3 100644 --- a/ios/experimental/LibreOffice/LibreOffice/View.m +++ b/ios/experimental/LibreOffice/LibreOffice/View.m @@ -34,33 +34,11 @@ CGPoint location = [gestureRecognizer locationInView: self]; NSLog(@"tapGesture: at: (%d,%d)", (int)location.x, (int)location.y); lo_tap(location.x, location.y); + [self->textView becomeFirstResponder]; } else NSLog(@"tapGesture: %@", gestureRecognizer); } -- (void)insertText:(NSString *)text -{ - (void) text; - // Do something with the typed character -} - -- (void)deleteBackward -{ - // Handle the delete key -} - -- (BOOL)hasText -{ - // Return whether there's any text present - return YES; -} - -- (BOOL)canBecomeFirstResponder -{ - return YES; -} - - @end // vim:set shiftwidth=4 softtabstop=4 expandtab: |