tdf#137105: crash in table with Style Inspector active
[LibreOffice.git] / vcl / quartz / utils.cxx
blob0e0ac8f4d90a6a05c9d25f127fd4c5f7321db9ea
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <iostream>
23 #include <iomanip>
25 #include <rtl/alloc.h>
26 #include <rtl/ustrbuf.hxx>
28 #include <quartz/utils.h>
30 OUString GetOUString( CFStringRef rStr )
32 if( rStr == nullptr )
34 return OUString();
37 CFIndex nLength = CFStringGetLength( rStr );
38 if( nLength == 0 )
40 return OUString();
43 const UniChar* pConstStr = CFStringGetCharactersPtr( rStr );
44 if( pConstStr )
46 return OUString( reinterpret_cast<sal_Unicode const *>(pConstStr), nLength );
49 std::unique_ptr<UniChar[]> pStr(new UniChar[nLength]);
50 CFRange aRange = { 0, nLength };
51 CFStringGetCharacters( rStr, aRange, pStr.get() );
53 OUString aRet( reinterpret_cast<sal_Unicode *>(pStr.get()), nLength );
54 return aRet;
57 OUString GetOUString( const NSString* pStr )
59 if( ! pStr )
61 return OUString();
64 int nLen = [pStr length];
65 if( nLen == 0 )
67 return OUString();
70 OUStringBuffer aBuf( nLen+1 );
71 aBuf.setLength( nLen );
72 [pStr getCharacters:
73 reinterpret_cast<unichar *>(const_cast<sal_Unicode*>(aBuf.getStr()))];
75 return aBuf.makeStringAndClear();
78 CFStringRef CreateCFString( const OUString& rStr )
80 return CFStringCreateWithCharacters(kCFAllocatorDefault, reinterpret_cast<UniChar const *>(rStr.getStr()), rStr.getLength() );
83 NSString* CreateNSString( const OUString& rStr )
85 return [[NSString alloc] initWithCharacters: reinterpret_cast<unichar const *>(rStr.getStr()) length: rStr.getLength()];
88 std::ostream &operator <<(std::ostream& s, const CGRect &rRect)
90 #ifndef SAL_LOG_INFO
91 (void) rRect;
92 #else
93 if (CGRectIsNull(rRect))
95 s << "NULL";
97 else
99 s << rRect.size << "@" << rRect.origin;
101 #endif
102 return s;
105 std::ostream &operator <<(std::ostream& s, const CGPoint &rPoint)
107 #ifndef SAL_LOG_INFO
108 (void) rPoint;
109 #else
110 s << "(" << rPoint.x << "," << rPoint.y << ")";
111 #endif
112 return s;
115 std::ostream &operator <<(std::ostream& s, const CGSize &rSize)
117 #ifndef SAL_LOG_INFO
118 (void) rSize;
119 #else
120 s << rSize.width << "x" << rSize.height;
121 #endif
122 return s;
125 std::ostream &operator <<(std::ostream& s, CGColorRef pColor)
127 #ifndef SAL_LOG_INFO
128 (void) pColor;
129 #else
130 CFStringRef colorString = CFCopyDescription(pColor);
131 if (colorString)
133 s << GetOUString(colorString);
134 CFRelease(colorString);
136 else
138 s << "NULL";
140 #endif
141 return s;
144 std::ostream &operator <<(std::ostream& s, const CGAffineTransform &aXform)
146 #ifndef SAL_LOG_INFO
147 (void) aXform;
148 #else
149 if (CGAffineTransformIsIdentity(aXform))
151 s << "IDENT";
153 else
155 s << "[" << aXform.a << "," << aXform.b << "," << aXform.c << "," << aXform.d << "," << aXform.tx << "," << aXform.ty << "]";
157 #endif
158 return s;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */