From 0e3a8dd74e3e0c78529eac6cba419bfbb92e750e Mon Sep 17 00:00:00 2001 From: das Date: Thu, 19 Jun 2008 00:13:10 +0000 Subject: * macosx/tkMacOSXInit.c: add helper to efficiently convert from * macosx/tkMacOSXPrivate.h: CFString to Tcl_Obj. --- macosx/tkMacOSXInit.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++-- macosx/tkMacOSXPrivate.h | 3 ++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index f9b67f5..e54938b 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -6,12 +6,12 @@ * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. - * Copyright (c) 2005-2007 Daniel A. Steffen + * Copyright (c) 2005-2008 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXInit.c,v 1.34.2.1 2008/05/03 21:09:16 das Exp $ + * RCS: @(#) $Id: tkMacOSXInit.c,v 1.34.2.2 2008/06/19 00:13:10 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -553,3 +553,52 @@ TkMacOSXGetNamedSymbol( } return NSAddressOfSymbol(nsSymbol); } + +/* + *---------------------------------------------------------------------- + * + * TkMacOSXGetStringObjFromCFString -- + * + * Get a string object from a CFString as efficiently as possible. + * + * Results: + * New string object or NULL if conversion failed. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +MODULE_SCOPE Tcl_Obj* +TkMacOSXGetStringObjFromCFString( + CFStringRef str) +{ + Tcl_Obj *obj = NULL; + const char *c = CFStringGetCStringPtr(str, kCFStringEncodingUTF8); + + if (c) { + obj = Tcl_NewStringObj(c, -1); + } else { + CFRange all = CFRangeMake(0, CFStringGetLength(str)); + CFIndex len; + + if (CFStringGetBytes(str, all, kCFStringEncodingUTF8, 0, false, NULL, + 0, &len) > 0) { + obj = Tcl_NewObj(); + Tcl_SetObjLength(obj, len); + CFStringGetBytes(str, all, kCFStringEncodingUTF8, 0, false, + (UInt8*) obj->bytes, len, NULL); + } + } + return obj; +} + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 79 + * coding: utf-8 + * End: + */ diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index b1ca8c4..544621c 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXPrivate.h,v 1.6 2007/12/15 15:55:38 das Exp $ + * RCS: @(#) $Id: tkMacOSXPrivate.h,v 1.6.2.1 2008/06/19 00:13:10 das Exp $ */ #ifndef _TKMACPRIV @@ -335,5 +335,6 @@ MODULE_SCOPE void TkMacOSXBringWindowForward(WindowRef wRef); MODULE_SCOPE WindowRef TkMacOSXDrawableWindow(Drawable drawable); MODULE_SCOPE void TkMacOSXWinCGBounds(TkWindow *winPtr, CGRect *bounds); MODULE_SCOPE HIShapeRef TkMacOSXGetClipRgn(Drawable drawable); +MODULE_SCOPE Tcl_Obj* TkMacOSXGetStringObjFromCFString(CFStringRef str); #endif /* _TKMACPRIV */ -- cgit v0.12