tdf#150789 - FILEOPEN PPTX: fix text in SmartArt vertically off
[LibreOffice.git] / connectivity / source / drivers / macab / macabutilities.hxx
blob7e0f6b091085a7b645ad5672c857b5442c374eda
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 #pragma once
22 #include <sal/config.h>
24 #include <memory>
26 #include <com/sun/star/util/DateTime.hpp>
27 #include <com/sun/star/sdbc/DataType.hpp>
28 #include <unotools/resmgr.hxx>
30 #include <time.h>
31 #include <premac.h>
32 #include <Carbon/Carbon.h>
33 #include <AddressBook/ABAddressBookC.h>
34 #include <postmac.h>
36 namespace connectivity::macab
39 inline OUString CFStringToOUString(const CFStringRef sOrig)
41 /* Copied all-but directly from code by Florian Heckl in
42 * cws_src680_aquafilepicker01
43 * File was: fpicker/source/aqua/CFStringUtilities
44 * I only removed commented debugging lines and changed variable
45 * names.
47 if (nullptr == sOrig) {
48 return OUString();
51 CFRetain(sOrig);
52 CFIndex nStringLength = CFStringGetLength(sOrig);
54 auto const unichars = std::make_unique<UniChar[]>(nStringLength+1);
56 //'close' the string buffer correctly
57 unichars[nStringLength] = '\0';
59 CFStringGetCharacters (sOrig, CFRangeMake(0,nStringLength), unichars.get());
60 CFRelease(sOrig);
62 return OUString(reinterpret_cast<sal_Unicode *>(unichars.get()));
66 inline CFStringRef OUStringToCFString(const OUString& aString)
68 /* Copied directly from code by Florian Heckl in
69 * cws_src680_aquafilepicker01
70 * File was: fpicker/source/aqua/CFStringUtilities
73 CFStringRef ref = CFStringCreateWithCharacters(kCFAllocatorDefault, reinterpret_cast<UniChar const *>(aString.getStr()), aString.getLength());
75 return ref;
79 inline css::util::DateTime CFDateToDateTime(const CFDateRef _cfDate)
81 /* Carbon can give us the time since 2001 of any CFDateRef,
82 * and it also stores the time since 1970 as a constant,
83 * basically allowing us to get the unixtime of any
84 * CFDateRef. From there, it is just a matter of choosing what
85 * we want to do with it.
87 css::util::DateTime nRet;
88 double timeSince2001 = CFDateGetAbsoluteTime(_cfDate);
89 time_t unixtime = timeSince2001+kCFAbsoluteTimeIntervalSince1970;
90 struct tm *ptm = localtime(&unixtime);
91 nRet.Year = ptm->tm_year+1900;
92 nRet.Month = ptm->tm_mon+1;
93 nRet.Day = ptm->tm_mday;
94 nRet.Hours = ptm->tm_hour;
95 nRet.Minutes = ptm->tm_min;
96 nRet.Seconds = ptm->tm_sec;
97 nRet.NanoSeconds = 0;
98 return nRet;
102 inline OUString fixLabel(const OUString& _originalLabel)
104 /* Get the length, and make sure that there is actually a string
105 * here.
107 if(_originalLabel.startsWith("_$!<"))
109 return _originalLabel.copy(4,_originalLabel.getLength()-8);
112 return _originalLabel;
116 inline sal_Int32 ABTypeToDataType(const ABPropertyType _abType)
118 sal_Int32 dataType;
119 switch(_abType)
121 case kABStringProperty:
122 dataType = css::sdbc::DataType::CHAR;
123 break;
124 case kABDateProperty:
125 dataType = css::sdbc::DataType::TIMESTAMP;
126 break;
127 case kABIntegerProperty:
128 dataType = css::sdbc::DataType::INTEGER;
129 break;
130 case kABRealProperty:
131 dataType = css::sdbc::DataType::FLOAT;
132 break;
133 default:
134 dataType = -1;
136 return dataType;
139 void impl_throwError(TranslateId pErrorId);
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */