aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2011-01-03 22:26:22 +0100
committerJan Djärv2011-01-03 22:26:22 +0100
commit0ad254447b7542284a2eb3c63b0732edb9409af7 (patch)
tree09481b752b098e6f79ba91c715d561e873a25de9 /src
parentfb724e553757e9d3344be443ab5f329afc9bf91c (diff)
downloademacs-0ad254447b7542284a2eb3c63b0732edb9409af7.tar.gz
emacs-0ad254447b7542284a2eb3c63b0732edb9409af7.zip
Backport bug 7517 fixes from trunk.
* coding.h (ENCODE_UTF_8): Remove "Used by ..." comment. * nsfns.m (ns_set_name_iconic): Remove. (ns_get_screen): Don't assign integer to f. (ns_set_name_internal): New function. (Vicon_title_format): Extern declare. (ns_set_name): Call ns_set_name_internal. (x_explicitly_set_name): Remove call to ns_set_name_iconic. (x_implicitly_set_name): Ditto. (x_set_title): Remove commet about EXPLICIT. Call ns_set_name_internal. (ns_set_name_as_filename): Encode name with ENCODE_UTF_8. Always use buffer name for title and buffer filename only for RepresentedFilename. Handle bad UTF-8 in buffer name (Bug#7517).
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog16
-rw-r--r--src/coding.h3
-rw-r--r--src/nsfns.m176
3 files changed, 101 insertions, 94 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index f947b5aeef6..2b22a2e07ff 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,19 @@
12011-01-03 Jan Djärv <jan.h.d@swipnet.se>
2
3 * coding.h (ENCODE_UTF_8): Remove "Used by ..." comment.
4
5 * nsfns.m (ns_set_name_iconic): Remove.
6 (ns_get_screen): Don't assign integer to f.
7 (ns_set_name_internal): New function (Bug#7517).
8 (Vicon_title_format): Extern declare.
9 (ns_set_name): Call ns_set_name_internal.
10 (x_explicitly_set_name): Remove call to ns_set_name_iconic.
11 (x_implicitly_set_name): Ditto.
12 (x_set_title): Remove commet about EXPLICIT. Call ns_set_name_internal.
13 (ns_set_name_as_filename): Encode name with ENCODE_UTF_8.
14 Always use buffer name for title and buffer filename only for
15 RepresentedFilename. Handle bad UTF-8 in buffer name (Bug#7517).
16
12011-01-03 Eli Zaretskii <eliz@gnu.org> 172011-01-03 Eli Zaretskii <eliz@gnu.org>
2 18
3 * image.c (png_jmpbuf): Remove definition. 19 * image.c (png_jmpbuf): Remove definition.
diff --git a/src/coding.h b/src/coding.h
index 22944091896..c2884a559d6 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -686,8 +686,7 @@ struct coding_system
686 ? code_convert_string_norecord (str, Vlocale_coding_system, 0) \ 686 ? code_convert_string_norecord (str, Vlocale_coding_system, 0) \
687 : str) 687 : str)
688 688
689/* Used by the gtk menu code. Note that this encodes utf-8, not 689/* Note that this encodes utf-8, not utf-8-emacs, so it's not a no-op. */
690 utf-8-emacs, so it's not a no-op. */
691#define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, 1) 690#define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, 1)
692 691
693/* Extern declarations. */ 692/* Extern declarations. */
diff --git a/src/nsfns.m b/src/nsfns.m
index 1ab12979578..10ce80dd480 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -81,7 +81,7 @@ extern Lisp_Object Qunderline, Qundefined;
81extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth; 81extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth;
82extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle; 82extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle;
83extern Lisp_Object Qnone; 83extern Lisp_Object Qnone;
84extern Lisp_Object Vframe_title_format; 84extern Lisp_Object Vframe_title_format, Vicon_title_format;
85 85
86Lisp_Object Qbuffered; 86Lisp_Object Qbuffered;
87Lisp_Object Qfontsize; 87Lisp_Object Qfontsize;
@@ -224,7 +224,8 @@ ns_get_screen (Lisp_Object screen)
224 else 224 else
225 { 225 {
226 struct ns_display_info *dpyinfo = terminal->display_info.ns; 226 struct ns_display_info *dpyinfo = terminal->display_info.ns;
227 f = (dpyinfo->x_focus_frame || dpyinfo->x_highlight_frame); 227 f = dpyinfo->x_focus_frame
228 ? dpyinfo->x_focus_frame : dpyinfo->x_highlight_frame;
228 } 229 }
229 230
230 return ((f && FRAME_NS_P (f)) ? [[FRAME_NS_VIEW (f) window] screen] 231 return ((f && FRAME_NS_P (f)) ? [[FRAME_NS_VIEW (f) window] screen]
@@ -468,55 +469,37 @@ x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
468 [NSString stringWithUTF8String: SDATA (arg)]]; 469 [NSString stringWithUTF8String: SDATA (arg)]];
469} 470}
470 471
471
472static void 472static void
473ns_set_name_iconic (struct frame *f, Lisp_Object name, int explicit) 473ns_set_name_internal (FRAME_PTR f, Lisp_Object name)
474{ 474{
475 struct gcpro gcpro1;
476 Lisp_Object encoded_name, encoded_icon_name;
477 NSString *str;
475 NSView *view = FRAME_NS_VIEW (f); 478 NSView *view = FRAME_NS_VIEW (f);
476 NSTRACE (ns_set_name_iconic);
477 479
478 if (ns_in_resize) 480 GCPRO1 (name);
479 return; 481 encoded_name = ENCODE_UTF_8 (name);
480 482 UNGCPRO;
481 /* Make sure that requests from lisp code override requests from
482 Emacs redisplay code. */
483 if (explicit)
484 {
485 /* If we're switching from explicit to implicit, we had better
486 update the mode lines and thereby update the title. */
487 if (f->explicit_name && NILP (name))
488 update_mode_lines = 1;
489 483
490 f->explicit_name = ! NILP (name); 484 str = [NSString stringWithUTF8String: SDATA (encoded_name)];
491 }
492 else if (f->explicit_name)
493 name = f->name;
494 485
495 /* title overrides explicit name */ 486 /* Don't change the name if it's already NAME. */
496 if (! NILP (f->title)) 487 if (! [[[view window] title] isEqualToString: str])
497 name = f->title; 488 [[view window] setTitle: str];
498
499 /* icon_name overrides title and explicit name */
500 if (! NILP (f->icon_name))
501 name = f->icon_name;
502 489
503 if (NILP (name)) 490 if (!STRINGP (f->icon_name))
504 name = build_string([ns_app_name UTF8String]); 491 encoded_icon_name = encoded_name;
505 else 492 else
506 CHECK_STRING (name); 493 encoded_icon_name = ENCODE_UTF_8 (f->icon_name);
494
495 str = [NSString stringWithUTF8String: SDATA (encoded_icon_name)];
507 496
508 /* Don't change the name if it's already NAME. */
509 if ([[view window] miniwindowTitle] && 497 if ([[view window] miniwindowTitle] &&
510 ([[[view window] miniwindowTitle] 498 ! [[[view window] miniwindowTitle] isEqualToString: str])
511 isEqualToString: [NSString stringWithUTF8String: 499 [[view window] setMiniwindowTitle: str];
512 SDATA (name)]]))
513 return;
514 500
515 [[view window] setMiniwindowTitle:
516 [NSString stringWithUTF8String: SDATA (name)]];
517} 501}
518 502
519
520static void 503static void
521ns_set_name (struct frame *f, Lisp_Object name, int explicit) 504ns_set_name (struct frame *f, Lisp_Object name, int explicit)
522{ 505{
@@ -542,6 +525,12 @@ ns_set_name (struct frame *f, Lisp_Object name, int explicit)
542 525
543 if (NILP (name)) 526 if (NILP (name))
544 name = build_string([ns_app_name UTF8String]); 527 name = build_string([ns_app_name UTF8String]);
528 else
529 CHECK_STRING (name);
530
531 /* Don't change the name if it's already NAME. */
532 if (! NILP (Fstring_equal (name, f->name)))
533 return;
545 534
546 f->name = name; 535 f->name = name;
547 536
@@ -549,17 +538,7 @@ ns_set_name (struct frame *f, Lisp_Object name, int explicit)
549 if (! NILP (f->title)) 538 if (! NILP (f->title))
550 name = f->title; 539 name = f->title;
551 540
552 CHECK_STRING (name); 541 ns_set_name_internal (f, name);
553
554 view = FRAME_NS_VIEW (f);
555
556 /* Don't change the name if it's already NAME. */
557 if ([[[view window] title]
558 isEqualToString: [NSString stringWithUTF8String:
559 SDATA (name)]])
560 return;
561 [[view window] setTitle: [NSString stringWithUTF8String:
562 SDATA (name)]];
563} 542}
564 543
565 544
@@ -570,7 +549,6 @@ static void
570x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) 549x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
571{ 550{
572 NSTRACE (x_explicitly_set_name); 551 NSTRACE (x_explicitly_set_name);
573 ns_set_name_iconic (f, arg, 1);
574 ns_set_name (f, arg, 1); 552 ns_set_name (f, arg, 1);
575} 553}
576 554
@@ -582,9 +560,10 @@ void
582x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) 560x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
583{ 561{
584 NSTRACE (x_implicitly_set_name); 562 NSTRACE (x_implicitly_set_name);
585 if (FRAME_ICONIFIED_P (f)) 563
586 ns_set_name_iconic (f, arg, 0); 564 /* Deal with NS specific format t. */
587 else if (FRAME_NS_P (f) && EQ (Vframe_title_format, Qt)) 565 if (FRAME_NS_P (f) && ((FRAME_ICONIFIED_P (f) && EQ (Vicon_title_format, Qt))
566 || EQ (Vframe_title_format, Qt)))
588 ns_set_name_as_filename (f); 567 ns_set_name_as_filename (f);
589 else 568 else
590 ns_set_name (f, arg, 0); 569 ns_set_name (f, arg, 0);
@@ -592,15 +571,8 @@ x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
592 571
593 572
594/* Change the title of frame F to NAME. 573/* Change the title of frame F to NAME.
595 If NAME is nil, use the frame name as the title. 574 If NAME is nil, use the frame name as the title. */
596
597 If EXPLICIT is non-zero, that indicates that lisp code is setting the
598 name; if NAME is a string, set F's name to NAME and set
599 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
600 575
601 If EXPLICIT is zero, that indicates that Emacs redisplay code is
602 suggesting a new name, which lisp code should override; if
603 F->explicit_name is set, ignore the new name; otherwise, set it. */
604static void 576static void
605x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name) 577x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
606{ 578{
@@ -612,6 +584,13 @@ x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
612 update_mode_lines = 1; 584 update_mode_lines = 1;
613 585
614 f->title = name; 586 f->title = name;
587
588 if (NILP (name))
589 name = f->name;
590 else
591 CHECK_STRING (name);
592
593 ns_set_name_internal (f, name);
615} 594}
616 595
617 596
@@ -619,10 +598,13 @@ void
619ns_set_name_as_filename (struct frame *f) 598ns_set_name_as_filename (struct frame *f)
620{ 599{
621 NSView *view; 600 NSView *view;
622 Lisp_Object name; 601 Lisp_Object name, filename;
623 Lisp_Object buf = XWINDOW (f->selected_window)->buffer; 602 Lisp_Object buf = XWINDOW (f->selected_window)->buffer;
624 const char *title; 603 const char *title;
625 NSAutoreleasePool *pool; 604 NSAutoreleasePool *pool;
605 struct gcpro gcpro1;
606 Lisp_Object encoded_name, encoded_filename;
607 NSString *str;
626 NSTRACE (ns_set_name_as_filename); 608 NSTRACE (ns_set_name_as_filename);
627 609
628 if (f->explicit_name || ! NILP (f->title) || ns_in_resize) 610 if (f->explicit_name || ! NILP (f->title) || ns_in_resize)
@@ -630,56 +612,66 @@ ns_set_name_as_filename (struct frame *f)
630 612
631 BLOCK_INPUT; 613 BLOCK_INPUT;
632 pool = [[NSAutoreleasePool alloc] init]; 614 pool = [[NSAutoreleasePool alloc] init];
633 name = XBUFFER (buf)->filename; 615 filename = XBUFFER (buf)->filename;
634 if (NILP (name) || FRAME_ICONIFIED_P (f)) name =XBUFFER (buf)->name; 616 name = XBUFFER (buf)->name;
635
636 if (FRAME_ICONIFIED_P (f) && !NILP (f->icon_name))
637 name = f->icon_name;
638 617
639 if (NILP (name)) 618 if (NILP (name))
640 name = build_string ([ns_app_name UTF8String]); 619 {
641 else 620 if (! NILP (filename))
642 CHECK_STRING (name); 621 name = Ffile_name_nondirectory (filename);
622 else
623 name = build_string ([ns_app_name UTF8String]);
624 }
625
626 GCPRO1 (name);
627 encoded_name = ENCODE_UTF_8 (name);
628 UNGCPRO;
643 629
644 view = FRAME_NS_VIEW (f); 630 view = FRAME_NS_VIEW (f);
645 631
646 title = FRAME_ICONIFIED_P (f) ? [[[view window] miniwindowTitle] UTF8String] 632 title = FRAME_ICONIFIED_P (f) ? [[[view window] miniwindowTitle] UTF8String]
647 : [[[view window] title] UTF8String]; 633 : [[[view window] title] UTF8String];
648 634
649 if (title && (! strcmp (title, SDATA (name)))) 635 if (title && (! strcmp (title, SDATA (encoded_name))))
650 { 636 {
651 [pool release]; 637 [pool release];
652 UNBLOCK_INPUT; 638 UNBLOCK_INPUT;
653 return; 639 return;
654 } 640 }
655 641
656 if (! FRAME_ICONIFIED_P (f)) 642 str = [NSString stringWithUTF8String: SDATA (encoded_name)];
643 if (str == nil) str = @"Bad coding";
644
645 if (FRAME_ICONIFIED_P (f))
646 [[view window] setMiniwindowTitle: str];
647 else
657 { 648 {
658#ifdef NS_IMPL_COCOA 649 NSString *fstr;
659 /* work around a bug observed on 10.3 where 650
660 setTitleWithRepresentedFilename does not clear out previous state 651 if (! NILP (filename))
661 if given filename does not exist */
662 NSString *str = [NSString stringWithUTF8String: SDATA (name)];
663 if (![[NSFileManager defaultManager] fileExistsAtPath: str])
664 { 652 {
665 [[view window] setTitleWithRepresentedFilename: @""]; 653 GCPRO1 (filename);
666 [[view window] setTitle: str]; 654 encoded_filename = ENCODE_UTF_8 (filename);
655 UNGCPRO;
656
657 fstr = [NSString stringWithUTF8String: SDATA (encoded_filename)];
658 if (fstr == nil) fstr = @"";
659#ifdef NS_IMPL_COCOA
660 /* work around a bug observed on 10.3 and later where
661 setTitleWithRepresentedFilename does not clear out previous state
662 if given filename does not exist */
663 if (! [[NSFileManager defaultManager] fileExistsAtPath: fstr])
664 [[view window] setRepresentedFilename: @""];
665#endif
667 } 666 }
668 else 667 else
669 { 668 fstr = @"";
670 [[view window] setTitleWithRepresentedFilename: str]; 669
671 } 670 [[view window] setRepresentedFilename: fstr];
672#else 671 [[view window] setTitle: str];
673 [[view window] setTitleWithRepresentedFilename:
674 [NSString stringWithUTF8String: SDATA (name)]];
675#endif
676 f->name = name; 672 f->name = name;
677 } 673 }
678 else 674
679 {
680 [[view window] setMiniwindowTitle:
681 [NSString stringWithUTF8String: SDATA (name)]];
682 }
683 [pool release]; 675 [pool release];
684 UNBLOCK_INPUT; 676 UNBLOCK_INPUT;
685} 677}