Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcocoaintrospection.mm
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (c) 2007-2008, Apple, Inc.
3// SPDX-License-Identifier: BSD-3-Clause
4// Qt-Security score:significant reason:default
5
7
9
10void qt_cocoa_change_implementation(Class baseClass, SEL originalSel, Class proxyClass, SEL replacementSel, SEL backupSel)
11{
12 // The following code replaces the _implementation_ for the selector we want to hack
13 // (originalSel) with the implementation found in proxyClass. Then it creates
14 // a new 'backup' method inside baseClass containing the old, original,
15 // implementation (fakeSel). You can let the proxy implementation of originalSel
16 // call fakeSel if needed (similar approach to calling a super class implementation).
17 // fakeSel must also be implemented in proxyClass, as the signature is used
18 // as template for the method one we add into baseClass.
19 // NB: You will typically never create any instances of proxyClass; we use it
20 // only for stealing its contents and put it into baseClass.
21 if (!replacementSel)
22 replacementSel = originalSel;
23
24 Method originalMethod = class_getInstanceMethod(baseClass, originalSel);
25 Method replacementMethod = class_getInstanceMethod(proxyClass, replacementSel);
26 IMP originalImp = method_setImplementation(originalMethod, method_getImplementation(replacementMethod));
27
28 if (backupSel) {
29 Method backupMethod = class_getInstanceMethod(proxyClass, backupSel);
30 class_addMethod(baseClass, backupSel, originalImp, method_getTypeEncoding(backupMethod));
31 }
32}
33
34void qt_cocoa_change_back_implementation(Class baseClass, SEL originalSel, SEL backupSel)
35{
36 Method originalMethod = class_getInstanceMethod(baseClass, originalSel);
37 Method backupMethodInBaseClass = class_getInstanceMethod(baseClass, backupSel);
38 method_setImplementation(originalMethod, method_getImplementation(backupMethodInBaseClass));
39}
40
41QT_END_NAMESPACE
QT_BEGIN_NAMESPACE void qt_cocoa_change_implementation(Class baseClass, SEL originalSel, Class proxyClass, SEL replacementSel, SEL backupSel)
void qt_cocoa_change_back_implementation(Class baseClass, SEL originalSel, SEL backupSel)