merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / macab / macabutilities.hxx
blob7d89e0aba0e6e68ff20c3bbb5876ecea583adcd6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: macabutilities.hxx,v $
10 * $Revision: 1.3.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _CONNECTIVITY_MACAB_UTILITIES_HXX_
32 #define _CONNECTIVITY_MACAB_UTILITIES_HXX_
34 #include <com/sun/star/util/DateTime.hpp>
35 #include <com/sun/star/sdbc/DataType.hpp>
37 #include <time.h>
38 #include <premac.h>
39 #include <Carbon/Carbon.h>
40 #include <AddressBook/ABAddressBookC.h>
41 #include <postmac.h>
43 namespace connectivity
45 namespace macab
47 // -------------------------------------------------------------------------
48 inline ::rtl::OUString CFStringToOUString(const CFStringRef sOrig)
50 /* Copied all-but directly from code by Florian Heckl in
51 * cws_src680_aquafilepicker01
52 * File was: fpicker/source/aqua/CFStringUtilities
53 * I only removed commented debugging lines and changed variable
54 * names.
56 if (NULL == sOrig) {
57 return rtl::OUString();
60 CFRetain(sOrig);
61 CFIndex nStringLength = CFStringGetLength(sOrig);
63 UniChar unichars[nStringLength+1];
65 //'close' the string buffer correctly
66 unichars[nStringLength] = '\0';
68 CFStringGetCharacters (sOrig, CFRangeMake(0,nStringLength), unichars);
69 CFRelease(sOrig);
71 return rtl::OUString(unichars);
74 // -------------------------------------------------------------------------
75 inline CFStringRef OUStringToCFString(const ::rtl::OUString& aString)
77 /* Copied directly from code by Florian Heckl in
78 * cws_src680_aquafilepicker01
79 * File was: fpicker/source/aqua/CFStringUtilities
82 CFStringRef ref = CFStringCreateWithCharacters(kCFAllocatorDefault, aString.getStr(), aString.getLength());
84 return ref;
87 // -------------------------------------------------------------------------
88 inline com::sun::star::util::DateTime CFDateToDateTime(const CFDateRef _cfDate)
90 /* Carbon can give us the time since 2001 of any CFDateRef,
91 * and it also stores the time since 1970 as a constant,
92 * basically allowing us to get the unixtime of any
93 * CFDateRef. From there, it is just a matter of choosing what
94 * we want to do with it.
96 com::sun::star::util::DateTime nRet;
97 double timeSince2001 = CFDateGetAbsoluteTime(_cfDate);
98 time_t unixtime = timeSince2001+kCFAbsoluteTimeIntervalSince1970;
99 struct tm *ptm = localtime(&unixtime);
100 nRet.Year = ptm->tm_year+1900;
101 nRet.Month = ptm->tm_mon+1;
102 nRet.Day = ptm->tm_mday;
103 nRet.Hours = ptm->tm_hour;
104 nRet.Minutes = ptm->tm_min;
105 nRet.Seconds = ptm->tm_sec;
106 nRet.HundredthSeconds = 0;
107 return nRet;
110 // -------------------------------------------------------------------------
111 inline ::rtl::OUString fixLabel(const ::rtl::OUString _originalLabel)
113 /* Get the length, and make sure that there is actually a string
114 * here.
116 if(_originalLabel.indexOf(::rtl::OUString::createFromAscii("_$!<")) == 0)
118 return _originalLabel.copy(4,_originalLabel.getLength()-8);
121 return _originalLabel;
124 // -------------------------------------------------------------------------
125 inline sal_Int32 ABTypeToDataType(const ABPropertyType _abType)
127 sal_Int32 dataType;
128 switch(_abType)
130 case kABStringProperty:
131 dataType = ::com::sun::star::sdbc::DataType::CHAR;
132 break;
133 case kABDateProperty:
134 dataType = ::com::sun::star::sdbc::DataType::TIMESTAMP;
135 break;
136 case kABIntegerProperty:
137 dataType = ::com::sun::star::sdbc::DataType::INTEGER;
138 break;
139 case kABRealProperty:
140 dataType = ::com::sun::star::sdbc::DataType::FLOAT;
141 break;
142 default:
143 dataType = -1;
145 return dataType;
148 void impl_throwError(sal_uInt16 _nErrorId);
152 #endif // _ CONNECTIVITY_MACAB_UTILITIES_HXX_