]> code.delx.au - gnu-emacs/commitdiff
* macterm.h (cfstring_create_with_utf8_cstring): Added prototype.
authorSteven Tamm <steventamm@mac.com>
Fri, 3 Dec 2004 17:00:11 +0000 (17:00 +0000)
committerSteven Tamm <steventamm@mac.com>
Fri, 3 Dec 2004 17:00:11 +0000 (17:00 +0000)
* image.c (image_load_quartz2d): Use
cfstring_create_with_utf8_cstring
* macmenu.c (add_menu_item): Use
cfstring_create_with_utf8_cstring
* macfns.c (x_set_name, x_set_title): Use
cfstring_create_with_utf8_cstring
(Fx_file_dialog): Use cfstring_create_with_utf8_cstring and use
constant CFRefs instead of creating them each time for labels.
* mac.c (cfstring_create_with_utf8_cstring): Added to prevent
crashes with invalid characters.

src/ChangeLog
src/image.c
src/mac.c
src/macfns.c
src/macmenu.c
src/macterm.h

index f6ebe27ebfb484f12139921a24dcca7c93858321..5d3e621a5683859c5364d869e194efdff26d506f 100644 (file)
@@ -1,3 +1,17 @@
+2004-12-03  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+       * macterm.h (cfstring_create_with_utf8_cstring): Added prototype.
+       * image.c (image_load_quartz2d): Use
+       cfstring_create_with_utf8_cstring
+       * macmenu.c (add_menu_item): Use
+       cfstring_create_with_utf8_cstring
+       * macfns.c (x_set_name, x_set_title): Use
+       cfstring_create_with_utf8_cstring
+       (Fx_file_dialog): Use cfstring_create_with_utf8_cstring and use
+       constant CFRefs instead of creating them each time for labels.
+       * mac.c (cfstring_create_with_utf8_cstring): Added to prevent
+       crashes with invalid characters.
+
 2004-12-02  Richard M. Stallman  <rms@gnu.org>
 
        * config.in (RE_TRANSLATE_P): If make_number is not a macro,
index 4ab672ca58ee959bf7db037de83292fd1df3d57b..d1925cf36e48793fdf5b1b8fbbfdf020afa59cf9 100644 (file)
@@ -2416,8 +2416,7 @@ image_load_quartz2d (f, img, png_p)
          UNGCPRO;
          return 0;
        }
-      path = CFStringCreateWithCString (NULL, SDATA (file),
-                                       kCFStringEncodingUTF8);
+      path = cfstring_create_with_utf8_cstring (SDATA (file));
       url = CFURLCreateWithFileSystemPath (NULL, path,
                                           kCFURLPOSIXPathStyle, 0);
       CFRelease (path);
index 91d073725780ba906330a30fc35c32237cb6bd68..53e56cfb54176766d7d3a6f98e341d4a82107272 100644 (file)
--- a/src/mac.c
+++ b/src/mac.c
@@ -262,6 +262,22 @@ posix_to_mac_pathname (const char *ufn, char *mfn, int mfnbuflen)
   return 1;
 }
 
+#if TARGET_API_MAC_CARBON
+CFStringRef
+cfstring_create_with_utf8_cstring (c_str)
+     const char *c_str;
+{
+  CFStringRef str;
+
+  str = CFStringCreateWithCString (NULL, c_str, kCFStringEncodingUTF8);
+  if (str == NULL)
+    /* Failed to interpret as UTF 8.  Fall back on Mac Roman.  */
+    str = CFStringCreateWithCString (NULL, c_str, kCFStringEncodingMacRoman);
+
+  return str;
+}
+#endif
+
 #ifndef MAC_OSX
 
 /* The following functions with "sys_" prefix are stubs to Unix
index 9220bdd2798d2ca9f7ce80012734dbaeb467b171..fdfe7a524164828ef7ede6cd567d26f25d8e84e8 100644 (file)
@@ -1932,8 +1932,7 @@ x_set_name (f, name, explicit)
       {
 #if TARGET_API_MAC_CARBON
        CFStringRef windowTitle =
-         CFStringCreateWithCString (NULL, SDATA (name),
-                                    kCFStringEncodingUTF8);
+         cfstring_create_with_utf8_cstring (SDATA (name));
 
        SetWindowTitleWithCFString (FRAME_MAC_WINDOW (f), windowTitle);
        CFRelease (windowTitle);
@@ -2015,8 +2014,7 @@ x_set_title (f, name, old_name)
       {
 #if TARGET_API_MAC_CARBON
        CFStringRef windowTitle =
-         CFStringCreateWithCString (NULL, SDATA (name),
-                                    kCFStringEncodingUTF8);
+         cfstring_create_with_utf8_cstring (SDATA (name));
 
        SetWindowTitleWithCFString (FRAME_MAC_WINDOW (f), windowTitle);
        CFRelease (windowTitle);
@@ -4246,8 +4244,7 @@ If ONLY-DIR-P is non-nil, the user can only select directories.  */)
     NavDialogRef dialogRef;
     NavTypeListHandle fileTypes = NULL;
     NavUserAction userAction;
-    CFStringRef message=NULL, client=NULL, saveName = NULL, ok = NULL;
-    CFStringRef title = NULL;
+    CFStringRef message=NULL, saveName = NULL;
     
     BLOCK_INPUT;
     /* No need for a callback function because we are modal */
@@ -4259,15 +4256,11 @@ If ONLY-DIR-P is non-nil, the user can only select directories.  */)
     options.optionFlags |= kNavSelectAllReadableItem;
     if (!NILP(prompt))
       {
-       message = CFStringCreateWithCStringNoCopy(NULL, SDATA(prompt),
-                                                 kCFStringEncodingUTF8, 
-                                                 kCFAllocatorNull);
+       message = cfstring_create_with_utf8_cstring (SDATA (prompt));
        options.message = message;
       }
     /* Don't set the application, let it use default.
-    client = CFStringCreateWithCStringNoCopy(NULL, "Emacs", 
-                                            kCFStringEncodingMacRoman, NULL);
-    options.clientName = client;
+    options.clientName = CFSTR ("Emacs");
     */
 
     if (!NILP (only_dir_p))
@@ -4276,17 +4269,14 @@ If ONLY-DIR-P is non-nil, the user can only select directories.  */)
     else if (NILP (mustmatch)) 
       { 
        /* This is a save dialog */
-       ok = CFStringCreateWithCString (NULL, "Ok", kCFStringEncodingUTF8);
-       title = CFStringCreateWithCString (NULL, "Enter name",
-                                          kCFStringEncodingUTF8);
        options.optionFlags |= kNavDontConfirmReplacement;
-       options.actionButtonLabel = ok;
-       options.windowTitle = title;
+       options.actionButtonLabel = CFSTR ("Ok");
+       options.windowTitle = CFSTR ("Enter name");
 
        if (!NILP(default_filename))
          {
-           saveName = CFStringCreateWithCString(NULL, SDATA(default_filename),
-                                                kCFStringEncodingUTF8);
+           saveName =
+             cfstring_create_with_utf8_cstring (SDATA (default_filename));
            options.saveFileName = saveName;
            options.optionFlags |= kNavSelectDefaultLocation;
          }
@@ -4320,10 +4310,7 @@ If ONLY-DIR-P is non-nil, the user can only select directories.  */)
     }
 
     if (saveName) CFRelease(saveName);
-    if (client) CFRelease(client);
     if (message) CFRelease(message);
-    if (ok) CFRelease(ok);
-    if (title) CFRelease(title);
 
     if (status == noErr) {
       userAction = NavDialogGetUserAction(dialogRef);
index af24cfe237c18e4096098e52c4b7c6aa074f0723..f0696a497740962d58cf1b415fccd4223e7193d0 100644 (file)
@@ -2264,17 +2264,8 @@ add_menu_item (MenuHandle menu, widget_value *wv, int submenu,
       item_name[255] = 0;
 #if TARGET_API_MAC_CARBON
       {
-       CFStringRef string =
-         CFStringCreateWithCString (NULL, item_name, kCFStringEncodingUTF8);
-
-       if (string == NULL)
-         {
-           /* Failed to interpret as UTF8.  Fall back to Mac Roman.
-              Maybe wv->name is corrupted?  */
-           string = CFStringCreateWithCString (NULL, item_name,
-                                               kCFStringEncodingMacRoman);
-         }
-       
+       CFStringRef string = cfstring_create_with_utf8_cstring (item_name);
+
        SetMenuItemTextWithCFString (menu, pos, string);
        CFRelease (string);
       }
index f9bde772fcdc92a05ae18a00def26ed5ede74d5a..ff7110828b19cdffe7923ec99e3aa1f1618475fc 100644 (file)
@@ -600,5 +600,9 @@ extern void mac_draw_line_to_pixmap P_ ((Display *, Pixmap, GC, int, int,
 #define FONT_TYPE_FOR_UNIBYTE(font, ch) 0
 #define FONT_TYPE_FOR_MULTIBYTE(font, ch) 0
 
+#if TARGET_API_MAC_CARBON
+extern CFStringRef cfstring_create_with_utf8_cstring P_ ((const char *));
+#endif
+
 /* arch-tag: 6b4ca125-5bef-476d-8ee8-31ed808b7e79
    (do not change this comment) */