Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcocoaintrospection.mm
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4/****************************************************************************
5**
6** Copyright (c) 2007-2008, Apple, Inc.
7**
8** All rights reserved.
9**
10** Redistribution and use in source and binary forms, with or without
11** modification, are permitted provided that the following conditions are met:
12**
13** * Redistributions of source code must retain the above copyright notice,
14** this list of conditions and the following disclaimer.
15**
16** * Redistributions in binary form must reproduce the above copyright notice,
17** this list of conditions and the following disclaimer in the documentation
18** and/or other materials provided with the distribution.
19**
20** * Neither the name of Apple, Inc. nor the names of its contributors
21** may be used to endorse or promote products derived from this software
22** without specific prior written permission.
23**
24** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35**
36****************************************************************************/
37
38#include "qcocoaintrospection.h"
39
41
42void qt_cocoa_change_implementation(Class baseClass, SEL originalSel, Class proxyClass, SEL replacementSel, SEL backupSel)
43{
44 // The following code replaces the _implementation_ for the selector we want to hack
45 // (originalSel) with the implementation found in proxyClass. Then it creates
46 // a new 'backup' method inside baseClass containing the old, original,
47 // implementation (fakeSel). You can let the proxy implementation of originalSel
48 // call fakeSel if needed (similar approach to calling a super class implementation).
49 // fakeSel must also be implemented in proxyClass, as the signature is used
50 // as template for the method one we add into baseClass.
51 // NB: You will typically never create any instances of proxyClass; we use it
52 // only for stealing its contents and put it into baseClass.
53 if (!replacementSel)
54 replacementSel = originalSel;
55
56 Method originalMethod = class_getInstanceMethod(baseClass, originalSel);
57 Method replacementMethod = class_getInstanceMethod(proxyClass, replacementSel);
58 IMP originalImp = method_setImplementation(originalMethod, method_getImplementation(replacementMethod));
59
60 if (backupSel) {
61 Method backupMethod = class_getInstanceMethod(proxyClass, backupSel);
62 class_addMethod(baseClass, backupSel, originalImp, method_getTypeEncoding(backupMethod));
63 }
64}
65
66void qt_cocoa_change_back_implementation(Class baseClass, SEL originalSel, SEL backupSel)
67{
68 Method originalMethod = class_getInstanceMethod(baseClass, originalSel);
69 Method backupMethodInBaseClass = class_getInstanceMethod(baseClass, backupSel);
70 method_setImplementation(originalMethod, method_getImplementation(backupMethodInBaseClass));
71}
72
Combined button and popup list for selecting options.
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)