1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <private/qcore_mac_p.h>
#include <new>
QT_BEGIN_NAMESPACE
QString QCFString::toQString(CFStringRef str)
{
if (!str)
return QString();
CFIndex length = CFStringGetLength(str);
if (length == 0)
return QString();
QString string(length, Qt::Uninitialized);
CFStringGetCharacters(str, CFRangeMake(0, length), reinterpret_cast<UniChar *>(const_cast<QChar *>(string.unicode())));
return string;
}
QCFString::operator QString() const
{
if (string.isEmpty() && type)
const_cast<QCFString*>(this)->string = toQString(type);
return string;
}
CFStringRef QCFString::toCFStringRef(const QString &string)
{
return CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(string.unicode()),
string.length());
}
QCFString::operator CFStringRef() const
{
if (!type) {
if (string.d->data != string.d->array)
const_cast<QCFString*>(this)->string.realloc(); // ### Qt5: do we really need this stupid user protection?
const_cast<QCFString*>(this)->type =
CFStringCreateWithCharactersNoCopy(0,
reinterpret_cast<const UniChar *>(string.unicode()),
string.length(),
kCFAllocatorNull);
}
return type;
}
#ifndef QT_NO_CORESERVICES
void qt_mac_to_pascal_string(const QString &s, Str255 str, TextEncoding encoding, int len)
{
if(len == -1)
len = s.length();
#if 0
UnicodeMapping mapping;
mapping.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault,
kTextEncodingDefaultVariant,
kUnicode16BitFormat);
mapping.otherEncoding = (encoding ? encoding : );
mapping.mappingVersion = kUnicodeUseLatestMapping;
UnicodeToTextInfo info;
OSStatus err = CreateUnicodeToTextInfo(&mapping, &info);
if(err != noErr) {
qDebug("Qt: internal: Unable to create pascal string '%s'::%d [%ld]",
s.left(len).latin1(), (int)encoding, err);
return;
}
const int unilen = len * 2;
const UniChar *unibuf = (UniChar *)s.unicode();
ConvertFromUnicodeToPString(info, unilen, unibuf, str);
DisposeUnicodeToTextInfo(&info);
#else
Q_UNUSED(encoding);
CFStringGetPascalString(QCFString(s), str, 256, CFStringGetSystemEncoding());
#endif
}
QString qt_mac_from_pascal_string(const Str255 pstr)
{
return QCFString(CFStringCreateWithPascalString(0, pstr, CFStringGetSystemEncoding()));
}
OSErr qt_mac_create_fsref(const QString &file, FSRef *fsref)
{
return FSPathMakeRef(reinterpret_cast<const UInt8 *>(file.toUtf8().constData()), fsref, 0);
}
// Don't use this function, it won't work in 10.5 (Leopard) and up
OSErr qt_mac_create_fsspec(const QString &file, FSSpec *spec)
{
FSRef fsref;
OSErr ret = qt_mac_create_fsref(file, &fsref);
if (ret == noErr)
ret = FSGetCatalogInfo(&fsref, kFSCatInfoNone, 0, 0, spec, 0);
return ret;
}
#endif // QT_NO_CORESERVICES
QT_END_NAMESPACE
|