macOS: Copy QNSWindowProtocol without referencing it by name

The protocol may be namespaced, in which case the string lookup would
fail, so we iterate the protocols of QNSWindow instead (of which there
is only one, QNSWindowProtocol).

Change-Id: Ic45752c9e3a40f5d42ec82c4287402a3d7a47b09
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
This commit is contained in:
Tor Arne Vestbø 2018-01-15 12:15:39 +01:00
parent 6e5edb5a15
commit 0be8f59d72

View File

@ -99,18 +99,25 @@ static bool isMouseEvent(NSEvent *ev)
const Class windowClass = [self class];
const Class panelClass = [QNSPanel class];
unsigned int methodDescriptionsCount;
objc_method_description *methods = protocol_copyMethodDescriptionList(
objc_getProtocol("QNSWindowProtocol"), NO, YES, &methodDescriptionsCount);
unsigned int protocolCount;
Protocol **protocols = class_copyProtocolList(windowClass, &protocolCount);
for (unsigned int i = 0; i < protocolCount; ++i) {
Protocol *protocol = protocols[i];
for (unsigned int i = 0; i < methodDescriptionsCount; ++i) {
objc_method_description method = methods[i];
class_addMethod(panelClass, method.name,
class_getMethodImplementation(windowClass, method.name),
method.types);
unsigned int methodDescriptionsCount;
objc_method_description *methods = protocol_copyMethodDescriptionList(
protocol, NO, YES, &methodDescriptionsCount);
for (unsigned int j = 0; j < methodDescriptionsCount; ++j) {
objc_method_description method = methods[j];
class_addMethod(panelClass, method.name,
class_getMethodImplementation(windowClass, method.name),
method.types);
}
free(methods);
}
free(methods);
free(protocols);
}
- (QCocoaWindow *)platformWindow