Mercurial > emacs
comparison src/nsfns.m @ 112033:a80c1e8d9df4
Encode frame title and icon name before setting.
* coding.h (ENCODE_UTF_8): Remove "Used by ..." comment.
* nsfns.m (ns_set_name_iconic): Remove.
(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 (Bug#7517).
author | Jan D. <jan.h.d@swipnet.se> |
---|---|
date | Thu, 30 Dec 2010 12:30:55 +0100 |
parents | ca0d9a916432 |
children | 9c611deb66fa |
comparison
equal
deleted
inserted
replaced
112032:209df3f0dcc6 | 112033:a80c1e8d9df4 |
---|---|
80 extern Lisp_Object Qface_set_after_frame_default; | 80 extern Lisp_Object Qface_set_after_frame_default; |
81 extern Lisp_Object Qunderline, Qundefined; | 81 extern Lisp_Object Qunderline, Qundefined; |
82 extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth; | 82 extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth; |
83 extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle; | 83 extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle; |
84 extern Lisp_Object Qnone; | 84 extern Lisp_Object Qnone; |
85 extern Lisp_Object Vframe_title_format; | 85 extern Lisp_Object Vframe_title_format, Vicon_title_format; |
86 | 86 |
87 /* The below are defined in frame.c. */ | 87 /* The below are defined in frame.c. */ |
88 | 88 |
89 extern Lisp_Object Vmenu_bar_mode, Vtool_bar_mode; | 89 extern Lisp_Object Vmenu_bar_mode, Vtool_bar_mode; |
90 | 90 |
471 | 471 |
472 [[view window] setMiniwindowTitle: | 472 [[view window] setMiniwindowTitle: |
473 [NSString stringWithUTF8String: SDATA (arg)]]; | 473 [NSString stringWithUTF8String: SDATA (arg)]]; |
474 } | 474 } |
475 | 475 |
476 | |
477 static void | 476 static void |
478 ns_set_name_iconic (struct frame *f, Lisp_Object name, int explicit) | 477 ns_set_name_internal (FRAME_PTR f, Lisp_Object name) |
479 { | 478 { |
479 struct gcpro gcpro1; | |
480 Lisp_Object encoded_name, encoded_icon_name; | |
481 NSString *str; | |
480 NSView *view = FRAME_NS_VIEW (f); | 482 NSView *view = FRAME_NS_VIEW (f); |
481 NSTRACE (ns_set_name_iconic); | 483 |
484 GCPRO1 (name); | |
485 encoded_name = ENCODE_UTF_8 (name); | |
486 UNGCPRO; | |
487 | |
488 str = [NSString stringWithUTF8String: SDATA (encoded_name)]; | |
489 | |
490 /* Don't change the name if it's already NAME. */ | |
491 if (! [[[view window] title] isEqualToString: str]) | |
492 [[view window] setTitle: str]; | |
493 | |
494 if (!STRINGP (f->icon_name)) | |
495 encoded_icon_name = encoded_name; | |
496 else | |
497 encoded_icon_name = ENCODE_UTF_8 (f->icon_name); | |
498 | |
499 str = [NSString stringWithUTF8String: SDATA (encoded_icon_name)]; | |
500 | |
501 if ([[view window] miniwindowTitle] && | |
502 ! [[[view window] miniwindowTitle] isEqualToString: str]) | |
503 [[view window] setMiniwindowTitle: str]; | |
504 | |
505 } | |
506 | |
507 static void | |
508 ns_set_name (struct frame *f, Lisp_Object name, int explicit) | |
509 { | |
510 NSView *view; | |
511 NSTRACE (ns_set_name); | |
482 | 512 |
483 if (ns_in_resize) | 513 if (ns_in_resize) |
484 return; | 514 return; |
485 | 515 |
486 /* Make sure that requests from lisp code override requests from | 516 /* Make sure that requests from lisp code override requests from |
493 update_mode_lines = 1; | 523 update_mode_lines = 1; |
494 | 524 |
495 f->explicit_name = ! NILP (name); | 525 f->explicit_name = ! NILP (name); |
496 } | 526 } |
497 else if (f->explicit_name) | 527 else if (f->explicit_name) |
498 name = f->name; | 528 return; |
529 | |
530 if (NILP (name)) | |
531 name = build_string([ns_app_name UTF8String]); | |
532 else | |
533 CHECK_STRING (name); | |
534 | |
535 /* Don't change the name if it's already NAME. */ | |
536 if (! NILP (Fstring_equal (name, f->name))) | |
537 return; | |
538 | |
539 f->name = name; | |
499 | 540 |
500 /* title overrides explicit name */ | 541 /* title overrides explicit name */ |
501 if (! NILP (f->title)) | 542 if (! NILP (f->title)) |
502 name = f->title; | 543 name = f->title; |
503 | 544 |
504 /* icon_name overrides title and explicit name */ | 545 ns_set_name_internal (f, name); |
505 if (! NILP (f->icon_name)) | |
506 name = f->icon_name; | |
507 | |
508 if (NILP (name)) | |
509 name = build_string([ns_app_name UTF8String]); | |
510 else | |
511 CHECK_STRING (name); | |
512 | |
513 /* Don't change the name if it's already NAME. */ | |
514 if ([[view window] miniwindowTitle] && | |
515 ([[[view window] miniwindowTitle] | |
516 isEqualToString: [NSString stringWithUTF8String: | |
517 SDATA (name)]])) | |
518 return; | |
519 | |
520 [[view window] setMiniwindowTitle: | |
521 [NSString stringWithUTF8String: SDATA (name)]]; | |
522 } | |
523 | |
524 | |
525 static void | |
526 ns_set_name (struct frame *f, Lisp_Object name, int explicit) | |
527 { | |
528 NSView *view; | |
529 NSTRACE (ns_set_name); | |
530 | |
531 if (ns_in_resize) | |
532 return; | |
533 | |
534 /* Make sure that requests from lisp code override requests from | |
535 Emacs redisplay code. */ | |
536 if (explicit) | |
537 { | |
538 /* If we're switching from explicit to implicit, we had better | |
539 update the mode lines and thereby update the title. */ | |
540 if (f->explicit_name && NILP (name)) | |
541 update_mode_lines = 1; | |
542 | |
543 f->explicit_name = ! NILP (name); | |
544 } | |
545 else if (f->explicit_name) | |
546 return; | |
547 | |
548 if (NILP (name)) | |
549 name = build_string([ns_app_name UTF8String]); | |
550 | |
551 f->name = name; | |
552 | |
553 /* title overrides explicit name */ | |
554 if (! NILP (f->title)) | |
555 name = f->title; | |
556 | |
557 CHECK_STRING (name); | |
558 | |
559 view = FRAME_NS_VIEW (f); | |
560 | |
561 /* Don't change the name if it's already NAME. */ | |
562 if ([[[view window] title] | |
563 isEqualToString: [NSString stringWithUTF8String: | |
564 SDATA (name)]]) | |
565 return; | |
566 [[view window] setTitle: [NSString stringWithUTF8String: | |
567 SDATA (name)]]; | |
568 } | 546 } |
569 | 547 |
570 | 548 |
571 /* This function should be called when the user's lisp code has | 549 /* This function should be called when the user's lisp code has |
572 specified a name for the frame; the name will override any set by the | 550 specified a name for the frame; the name will override any set by the |
573 redisplay code. */ | 551 redisplay code. */ |
574 static void | 552 static void |
575 x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) | 553 x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) |
576 { | 554 { |
577 NSTRACE (x_explicitly_set_name); | 555 NSTRACE (x_explicitly_set_name); |
578 ns_set_name_iconic (f, arg, 1); | |
579 ns_set_name (f, arg, 1); | 556 ns_set_name (f, arg, 1); |
580 } | 557 } |
581 | 558 |
582 | 559 |
583 /* This function should be called by Emacs redisplay code to set the | 560 /* This function should be called by Emacs redisplay code to set the |
585 lisp code. */ | 562 lisp code. */ |
586 void | 563 void |
587 x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) | 564 x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) |
588 { | 565 { |
589 NSTRACE (x_implicitly_set_name); | 566 NSTRACE (x_implicitly_set_name); |
590 if (FRAME_ICONIFIED_P (f)) | 567 |
591 ns_set_name_iconic (f, arg, 0); | 568 /* Deal with NS specific format t. */ |
592 else if (FRAME_NS_P (f) && EQ (Vframe_title_format, Qt)) | 569 if (FRAME_NS_P (f) && ((FRAME_ICONIFIED_P (f) && EQ (Vicon_title_format, Qt)) |
570 || EQ (Vframe_title_format, Qt))) | |
593 ns_set_name_as_filename (f); | 571 ns_set_name_as_filename (f); |
594 else | 572 else |
595 ns_set_name (f, arg, 0); | 573 ns_set_name (f, arg, 0); |
596 } | 574 } |
597 | 575 |
598 | 576 |
599 /* Change the title of frame F to NAME. | 577 /* Change the title of frame F to NAME. |
600 If NAME is nil, use the frame name as the title. | 578 If NAME is nil, use the frame name as the title. */ |
601 | 579 |
602 If EXPLICIT is non-zero, that indicates that lisp code is setting the | |
603 name; if NAME is a string, set F's name to NAME and set | |
604 F->explicit_name; if NAME is Qnil, then clear F->explicit_name. | |
605 | |
606 If EXPLICIT is zero, that indicates that Emacs redisplay code is | |
607 suggesting a new name, which lisp code should override; if | |
608 F->explicit_name is set, ignore the new name; otherwise, set it. */ | |
609 static void | 580 static void |
610 x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name) | 581 x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name) |
611 { | 582 { |
612 NSTRACE (x_set_title); | 583 NSTRACE (x_set_title); |
613 /* Don't change the title if it's already NAME. */ | 584 /* Don't change the title if it's already NAME. */ |
615 return; | 586 return; |
616 | 587 |
617 update_mode_lines = 1; | 588 update_mode_lines = 1; |
618 | 589 |
619 f->title = name; | 590 f->title = name; |
591 | |
592 if (NILP (name)) | |
593 name = f->name; | |
594 else | |
595 CHECK_STRING (name); | |
596 | |
597 ns_set_name_internal (f, name); | |
620 } | 598 } |
621 | 599 |
622 | 600 |
623 void | 601 void |
624 ns_set_name_as_filename (struct frame *f) | 602 ns_set_name_as_filename (struct frame *f) |
626 NSView *view; | 604 NSView *view; |
627 Lisp_Object name; | 605 Lisp_Object name; |
628 Lisp_Object buf = XWINDOW (f->selected_window)->buffer; | 606 Lisp_Object buf = XWINDOW (f->selected_window)->buffer; |
629 const char *title; | 607 const char *title; |
630 NSAutoreleasePool *pool; | 608 NSAutoreleasePool *pool; |
609 struct gcpro gcpro1; | |
610 Lisp_Object encoded_name; | |
631 NSTRACE (ns_set_name_as_filename); | 611 NSTRACE (ns_set_name_as_filename); |
632 | 612 |
633 if (f->explicit_name || ! NILP (f->title) || ns_in_resize) | 613 if (f->explicit_name || ! NILP (f->title) || ns_in_resize) |
634 return; | 614 return; |
635 | 615 |
636 BLOCK_INPUT; | 616 BLOCK_INPUT; |
637 pool = [[NSAutoreleasePool alloc] init]; | 617 pool = [[NSAutoreleasePool alloc] init]; |
638 name = XBUFFER (buf)->filename; | 618 name = XBUFFER (buf)->filename; |
639 if (NILP (name) || FRAME_ICONIFIED_P (f)) name =XBUFFER (buf)->name; | 619 if (NILP (name) || FRAME_ICONIFIED_P (f)) name = XBUFFER (buf)->name; |
640 | 620 |
641 if (FRAME_ICONIFIED_P (f) && !NILP (f->icon_name)) | 621 if (FRAME_ICONIFIED_P (f) && !NILP (f->icon_name)) |
642 name = f->icon_name; | 622 name = f->icon_name; |
643 | 623 |
644 if (NILP (name)) | 624 if (NILP (name)) |
645 name = build_string ([ns_app_name UTF8String]); | 625 name = build_string ([ns_app_name UTF8String]); |
646 else | 626 else |
647 CHECK_STRING (name); | 627 CHECK_STRING (name); |
648 | 628 |
629 GCPRO1 (name); | |
630 encoded_name = ENCODE_UTF_8 (name); | |
631 UNGCPRO; | |
632 | |
649 view = FRAME_NS_VIEW (f); | 633 view = FRAME_NS_VIEW (f); |
650 | 634 |
651 title = FRAME_ICONIFIED_P (f) ? [[[view window] miniwindowTitle] UTF8String] | 635 title = FRAME_ICONIFIED_P (f) ? [[[view window] miniwindowTitle] UTF8String] |
652 : [[[view window] title] UTF8String]; | 636 : [[[view window] title] UTF8String]; |
653 | 637 |
654 if (title && (! strcmp (title, SDATA (name)))) | 638 if (title && (! strcmp (title, SDATA (encoded_name)))) |
655 { | 639 { |
656 [pool release]; | 640 [pool release]; |
657 UNBLOCK_INPUT; | 641 UNBLOCK_INPUT; |
658 return; | 642 return; |
659 } | 643 } |
662 { | 646 { |
663 #ifdef NS_IMPL_COCOA | 647 #ifdef NS_IMPL_COCOA |
664 /* work around a bug observed on 10.3 where | 648 /* work around a bug observed on 10.3 where |
665 setTitleWithRepresentedFilename does not clear out previous state | 649 setTitleWithRepresentedFilename does not clear out previous state |
666 if given filename does not exist */ | 650 if given filename does not exist */ |
667 NSString *str = [NSString stringWithUTF8String: SDATA (name)]; | 651 NSString *str = [NSString stringWithUTF8String: SDATA (encoded_name)]; |
668 if (![[NSFileManager defaultManager] fileExistsAtPath: str]) | 652 if (![[NSFileManager defaultManager] fileExistsAtPath: str]) |
669 { | 653 { |
670 [[view window] setTitleWithRepresentedFilename: @""]; | 654 [[view window] setTitleWithRepresentedFilename: @""]; |
671 [[view window] setTitle: str]; | 655 [[view window] setTitle: str]; |
672 } | 656 } |
674 { | 658 { |
675 [[view window] setTitleWithRepresentedFilename: str]; | 659 [[view window] setTitleWithRepresentedFilename: str]; |
676 } | 660 } |
677 #else | 661 #else |
678 [[view window] setTitleWithRepresentedFilename: | 662 [[view window] setTitleWithRepresentedFilename: |
679 [NSString stringWithUTF8String: SDATA (name)]]; | 663 [NSString stringWithUTF8String: SDATA (encoded_name)]]; |
680 #endif | 664 #endif |
681 f->name = name; | 665 f->name = name; |
682 } | 666 } |
683 else | 667 else |
684 { | 668 { |
685 [[view window] setMiniwindowTitle: | 669 [[view window] setMiniwindowTitle: |
686 [NSString stringWithUTF8String: SDATA (name)]]; | 670 [NSString stringWithUTF8String: SDATA (encoded_name)]]; |
687 } | 671 } |
688 [pool release]; | 672 [pool release]; |
689 UNBLOCK_INPUT; | 673 UNBLOCK_INPUT; |
690 } | 674 } |
691 | 675 |