summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/qiostextresponder.mm
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2014-09-18 12:48:29 +0200
committerTor Arne Vestbø <tor.arne.vestbo@digia.com>2014-09-20 11:53:43 +0200
commite98b5cddeb09e24373371af190dfcd92c9292aaf (patch)
treed55ec2d4f22eb467613444bfe40e2679bdc6422c /src/plugins/platforms/ios/qiostextresponder.mm
parent6910b8a552de6f0cd98fdfa50620825d59d63363 (diff)
iOS: Allow settings custom input and accessory views through ImPlatformData
Change-Id: Ib802c73f9c9e27853fa0dd25c304d77df570309e Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src/plugins/platforms/ios/qiostextresponder.mm')
-rw-r--r--src/plugins/platforms/ios/qiostextresponder.mm57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm
index ea6b5ffb94..54362cde7a 100644
--- a/src/plugins/platforms/ios/qiostextresponder.mm
+++ b/src/plugins/platforms/ios/qiostextresponder.mm
@@ -114,6 +114,55 @@
// -------------------------------------------------------------------------
+@interface WrapperView : UIView
+@end
+
+@implementation WrapperView
+
+-(id)initWithView:(UIView *)view
+{
+ if (self = [self init]) {
+ [self addSubview:view];
+
+ self.autoresizingMask = view.autoresizingMask;
+
+ [self sizeToFit];
+ }
+
+ return self;
+}
+
+- (void)layoutSubviews
+{
+ UIView* view = [self.subviews firstObject];
+ view.frame = self.bounds;
+
+ // FIXME: During orientation changes the size and position
+ // of the view is not respected by the host view, even if
+ // we call sizeToFit or setNeedsLayout on the superview.
+}
+
+- (CGSize)sizeThatFits:(CGSize)size
+{
+ return [[self.subviews firstObject] sizeThatFits:size];
+}
+
+// By keeping the responder (QIOSTextInputResponder in this case)
+// retained, we ensure that all messages sent to the view during
+// its lifetime in a window hierarcy will be able to traverse the
+// responder chain.
+-(void)willMoveToWindow:(UIWindow *)window
+{
+ if (window)
+ [[self nextResponder] retain];
+ else
+ [[self nextResponder] autorelease];
+}
+
+@end
+
+// -------------------------------------------------------------------------
+
@implementation QIOSTextInputResponder
- (id)initWithInputContext:(QIOSInputContext *)inputContext
@@ -153,11 +202,19 @@
else
self.keyboardType = UIKeyboardTypeDefault;
+ QVariantMap platformData = [self imValue:Qt::ImPlatformData].toMap();
+ if (UIView *inputView = static_cast<UIView *>(platformData.value(kImePlatformDataInputView).value<void *>()))
+ self.inputView = [[[WrapperView alloc] initWithView:inputView] autorelease];
+ if (UIView *accessoryView = static_cast<UIView *>(platformData.value(kImePlatformDataInputAccessoryView).value<void *>()))
+ self.inputAccessoryView = [[[WrapperView alloc] initWithView:accessoryView] autorelease];
+
return self;
}
- (void)dealloc
{
+ self.inputView = 0;
+ self.inputAccessoryView = 0;
[super dealloc];
}