diff options
author | Ivo Hinkelmann <ihi@openoffice.org> | 2007-07-11 09:57:16 +0000 |
---|---|---|
committer | Ivo Hinkelmann <ihi@openoffice.org> | 2007-07-11 09:57:16 +0000 |
commit | 3f9354c601a9962ab85f35288d460bf4e65df0b3 (patch) | |
tree | 13a62705d10e289925b8f80aab246d7b94be4300 /fpicker/source/aqua | |
parent | fde61dccd94d0a535924d5c0470604782d4f4925 (diff) |
INTEGRATION: CWS aquafilepicker01 (1.1.2); FILE ADDED
2007/06/16 11:38:16 pjanik 1.1.2.6: #i74798#: Add license header, whitespace cleanup.
2007/05/09 06:12:05 fheckl 1.1.2.5: some cleanup and last changes
2007/05/03 07:28:30 fheckl 1.1.2.4: change implementation of CFStringToOUString
2007/04/28 14:03:52 fheckl 1.1.2.3: Several debug logging changes
2007/04/13 18:25:58 fheckl 1.1.2.2: Adding new files and general update
2007/02/20 23:57:38 fheckl 1.1.2.1: Next phase of aqua file picker after some refactoring
Diffstat (limited to 'fpicker/source/aqua')
-rw-r--r-- | fpicker/source/aqua/CFStringUtilities.cxx | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/fpicker/source/aqua/CFStringUtilities.cxx b/fpicker/source/aqua/CFStringUtilities.cxx new file mode 100644 index 000000000000..ede93c1cb72c --- /dev/null +++ b/fpicker/source/aqua/CFStringUtilities.cxx @@ -0,0 +1,121 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: CFStringUtilities.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: ihi $ $Date: 2007-07-11 10:57:16 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +#include "CFStringUtilities.hxx" + +rtl::OUString CFStringToOUString(const CFStringRef sOrig) { + //DBG_PRINT_ENTRY("CFStringUtilities", __func__, "sOrig", sOrig); + + if (NULL == sOrig) { + return rtl::OUString(); + } + + CFRetain(sOrig); + CFIndex nFileNameLength = CFStringGetLength(sOrig); + //OSL_TRACE("FH: string length: %d", (int)(nFileNameLength)); + UniChar unichars[nFileNameLength+1]; + //'close' the string buffer correctly + unichars[nFileNameLength] = '\0'; + + CFStringGetCharacters (sOrig, CFRangeMake(0,nFileNameLength), unichars); + + //we no longer need the original string + CFRelease(sOrig); + + //DBG_PRINT_EXIT("CFStringUtilities", __func__, unichars); + + return rtl::OUString(unichars); +} + +CFStringRef CFStringCreateWithOUString(const rtl::OUString& aString) { + //DBG_PRINT_ENTRY("CFStringUtilities", __func__); + + CFStringRef ref = CFStringCreateWithCharacters(kCFAllocatorDefault, aString.getStr(), aString.getLength()); + + //DBG_PRINT_EXIT("CFStringUtilities", __func__, ref); + + return ref; +} + +rtl::OUString FSRefToOUString(FSRef fsRef, InfoType info) +{ + //DBG_PRINT_ENTRY("CFStringUtilities", __func__); + + CFURLRef aUrlRef = CFURLCreateFromFSRef(NULL, &fsRef); + + CFStringRef sURLString = NULL; + + switch(info) { + case FULLPATH: + OSL_TRACE("Extracting the full path of an item"); + sURLString = CFURLGetString(aUrlRef); + CFRetain(sURLString); + break; + case FILENAME: + OSL_TRACE("Extracting the file name of an item"); + CFStringRef fullString = CFURLGetString(aUrlRef); + CFURLRef dirRef = CFURLCreateCopyDeletingLastPathComponent(NULL,aUrlRef); + CFIndex dirLength = CFStringGetLength(CFURLGetString(dirRef)); + CFRelease(dirRef); + CFIndex fullLength = CFStringGetLength(fullString); + CFRange substringRange = CFRangeMake(dirLength, fullLength - dirLength); + sURLString = CFStringCreateWithSubstring(NULL, fullString, substringRange); + break; + case PATHWITHOUTLASTCOMPONENT: + OSL_TRACE("Extracting the last but one component of an item's path"); + CFURLRef directoryRef = CFURLCreateCopyDeletingLastPathComponent(NULL,aUrlRef); + sURLString = CFURLGetString(directoryRef); + CFRetain(sURLString); + CFRelease(directoryRef); + break; + default: + break; + } + + rtl::OUString sResult = CFStringToOUString(sURLString); + + CFRelease(sURLString); + + //we no longer need the CFURLRef + CFRelease(aUrlRef); + + //DBG_PRINT_EXIT("CFStringUtilities", __func__, OUStringToOString(sResult, RTL_TEXTENCODING_UTF8).getStr()); + + return sResult; +} |