iOS: Allow settings custom input and accessory views through ImPlatformData
Change-Id: Ib802c73f9c9e27853fa0dd25c304d77df570309e Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
This commit is contained in:
parent
6910b8a552
commit
e98b5cddeb
@ -48,6 +48,9 @@
|
||||
#include <QtGui/qtransform.h>
|
||||
#include <qpa/qplatforminputcontext.h>
|
||||
|
||||
const char kImePlatformDataInputView[] = "inputView";
|
||||
const char kImePlatformDataInputAccessoryView[] = "inputAccessoryView";
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@class QIOSKeyboardListener;
|
||||
|
@ -420,10 +420,10 @@ void QIOSInputContext::focusWindowChanged(QWindow *focusWindow)
|
||||
void QIOSInputContext::update(Qt::InputMethodQueries updatedProperties)
|
||||
{
|
||||
// Mask for properties that we are interested in and see if any of them changed
|
||||
updatedProperties &= (Qt::ImEnabled | Qt::ImHints | Qt::ImQueryInput);
|
||||
updatedProperties &= (Qt::ImEnabled | Qt::ImHints | Qt::ImQueryInput | Qt::ImPlatformData);
|
||||
|
||||
Qt::InputMethodQueries changedProperties = m_imeState.update(updatedProperties);
|
||||
if (changedProperties & (Qt::ImEnabled | Qt::ImHints)) {
|
||||
if (changedProperties & (Qt::ImEnabled | Qt::ImHints | Qt::ImPlatformData)) {
|
||||
// Changes to enablement or hints require virtual keyboard reconfigure
|
||||
[m_textResponder release];
|
||||
m_textResponder = [[QIOSTextInputResponder alloc] initWithInputContext:this];
|
||||
|
@ -58,6 +58,9 @@ class QIOSInputContext;
|
||||
- (id)initWithInputContext:(QIOSInputContext *)context;
|
||||
- (void)notifyInputDelegate:(Qt::InputMethodQueries)updatedProperties;
|
||||
|
||||
@property(readwrite, retain) UIView *inputView;
|
||||
@property(readwrite, retain) UIView *inputAccessoryView;
|
||||
|
||||
// UITextInputTraits
|
||||
@property(nonatomic) UITextAutocapitalizationType autocapitalizationType;
|
||||
@property(nonatomic) UITextAutocorrectionType autocorrectionType;
|
||||
|
@ -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];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user