diff src/macterm.c @ 90072:cb67264d6096

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-2 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-83 - miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-84 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-3 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-4 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-5 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-6 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-11 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-12 Remove "-face" suffix from lazy-highlight face name * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-13 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-16 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-17 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-18 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-21 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-22 <no summary provided> * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-23 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-39 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-40 Fix regressions from latest reftex update * miles@gnu.org--gnu-2005/gnus--rel--5.10--base-0 tag of miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-82 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-1 Merge from emacs--cvs-trunk--0 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-2 Merge from miles@gnu.org--gnu-2004 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-3 Merge from emacs--cvs-trunk--0
author Miles Bader <miles@gnu.org>
date Sun, 16 Jan 2005 03:40:12 +0000
parents 95879cc1ed20 10f083976969
children 6d92d69fae33
line wrap: on
line diff
--- a/src/macterm.c	Sun Jan 02 09:21:32 2005 +0000
+++ b/src/macterm.c	Sun Jan 16 03:40:12 2005 +0000
@@ -69,6 +69,7 @@
 #include <errno.h>
 #include <setjmp.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 
 #include "keyboard.h"
 #include "frame.h"
@@ -102,6 +103,10 @@
 
 Lisp_Object Vx_toolkit_scroll_bars;
 
+/* If Non-nil, the text will be rendered using Core Graphics text rendering which may anti-alias the text.  */
+Lisp_Object Vmac_use_core_graphics;
+
+
 /* Non-zero means that a HELP_EVENT has been generated since Emacs
    start.  */
 
@@ -726,6 +731,13 @@
      int nchars, mode, bytes_per_char;
 {
   SetPortWindowPort (w);
+#ifdef MAC_OSX
+  UInt32 textFlags, savedFlags;
+  if (!NILP(Vmac_use_core_graphics)) {
+    textFlags = kQDUseCGTextRendering;
+    savedFlags = SwapQDTextFlags(textFlags);
+  }
+#endif
 
   mac_set_colors (gc);
 
@@ -736,6 +748,10 @@
 
   MoveTo (x, y);
   DrawText (buf, 0, nchars * bytes_per_char);
+#ifdef MAC_OSX
+  if (!NILP(Vmac_use_core_graphics))
+    SwapQDTextFlags(savedFlags);
+#endif
 }
 
 
@@ -1092,6 +1108,62 @@
 }
 
 
+/* Mac replacement for XSetBackground.  */
+
+void
+XSetBackground (display, gc, color)
+     Display *display;
+     GC gc;
+     unsigned long color;
+{
+  gc->background = color;
+}
+
+
+/* Mac replacement for XSetWindowBackground.  */
+
+void
+XSetWindowBackground (display, w, color)
+     Display *display;
+     WindowPtr w;
+     unsigned long color;
+{
+#if !TARGET_API_MAC_CARBON
+  AuxWinHandle aw_handle;
+  CTabHandle ctab_handle;
+  ColorSpecPtr ct_table;
+  short ct_size;
+#endif
+  RGBColor bg_color;
+
+  bg_color.red = RED16_FROM_ULONG (color);
+  bg_color.green = GREEN16_FROM_ULONG (color);
+  bg_color.blue = BLUE16_FROM_ULONG (color);
+
+#if TARGET_API_MAC_CARBON
+  SetWindowContentColor (w, &bg_color);
+#else
+  if (GetAuxWin (w, &aw_handle))
+    {
+      ctab_handle = (*aw_handle)->awCTable;
+      HandToHand ((Handle *) &ctab_handle);
+      ct_table = (*ctab_handle)->ctTable;
+      ct_size = (*ctab_handle)->ctSize;
+      while (ct_size > -1)
+	{
+	  if (ct_table->value == 0)
+	    {
+	      ct_table->rgb = bg_color;
+	      CTabChanged (ctab_handle);
+	      SetWinColor (w, (WCTabHandle) ctab_handle);
+	    }
+	  ct_size--;
+	}
+    }
+#endif
+}
+
+
 /* Mac replacement for XSetFont.  */
 
 static void
@@ -4963,7 +5035,8 @@
   FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset;
   FRAME_FONTSET (f) = -1;
 
-  FRAME_COLUMN_WIDTH (f) = FONT_WIDTH (FRAME_FONT (f));
+  FRAME_COLUMN_WIDTH (f) = fontp->average_width;
+  FRAME_SPACE_WIDTH (f) = fontp->space_width;
   FRAME_LINE_HEIGHT (f) = FONT_HEIGHT (FRAME_FONT (f));
 
   compute_fringe_widths (f, 1);
@@ -6499,12 +6572,8 @@
      MacFontStruct *font;
      int *w, *h;
 {
-  /*
-   * TODO: Windows does not appear to offer min bound, only
-   * average and maximum width, and maximum height.
-   */
   *h = FONT_HEIGHT (font);
-  *w = FONT_WIDTH (font);
+  *w = font->min_bounds.width;
 }
 
 
@@ -6732,17 +6801,28 @@
       font->per_char = (XCharStruct *)
 	xmalloc (sizeof (XCharStruct) * (0xff - 0x20 + 1));
       {
-        int c;
-
+        int c, min_width, max_width;
+
+	min_width = max_width = char_width;
         for (c = 0x20; c <= 0xff; c++)
           {
-            font->per_char[c - 0x20] = font->max_bounds;
-            font->per_char[c - 0x20].width =
-	      font->per_char[c - 0x20].rbearing = CharWidth (c);
-          }
+	    font->per_char[c - 0x20] = font->max_bounds;
+	    char_width = CharWidth (c);
+	    font->per_char[c - 0x20].width = char_width;
+	    font->per_char[c - 0x20].rbearing = char_width;
+	    /* Some Japanese fonts (in SJIS encoding) return 0 as the
+	       character width of 0x7f.  */
+	    if (char_width > 0)
+	      {
+		min_width = min (min_width, char_width);
+		max_width = max (max_width, char_width);
+	      }
+            }
+	font->min_bounds.width = min_width;
+	font->max_bounds.width = max_width;
       }
     }
-
+  
   TextFont (old_fontnum);  /* restore previous font number, size and face */
   TextSize (old_fontsize);
   TextFace (old_fontface);
@@ -6847,6 +6927,35 @@
     fontp->name = (char *) xmalloc (strlen (font->fontname) + 1);
     bcopy (font->fontname, fontp->name, strlen (font->fontname) + 1);
 
+    if (font->min_bounds.width == font->max_bounds.width)
+      {
+	/* Fixed width font.  */
+	fontp->average_width = fontp->space_width = font->min_bounds.width;
+      }
+    else
+      {
+	XChar2b char2b;
+	XCharStruct *pcm;
+
+	char2b.byte1 = 0x00, char2b.byte2 = 0x20;
+	pcm = mac_per_char_metric (font, &char2b, 0);
+	if (pcm)
+	  fontp->space_width = pcm->width;
+	else
+	  fontp->space_width = FONT_WIDTH (font);
+
+	if (pcm)
+	  {
+	    int width = pcm->width;
+	    for (char2b.byte2 = 33; char2b.byte2 <= 126; char2b.byte2++)
+	      if ((pcm = mac_per_char_metric (font, &char2b, 0)) != NULL)
+		width += pcm->width;
+	    fontp->average_width = width / 95;
+	  }
+	else
+	  fontp->average_width = FONT_WIDTH (font);
+      }
+
     fontp->full_name = fontp->name;
 
     fontp->size = font->max_bounds.width;
@@ -7861,6 +7970,14 @@
 
   switch (GetEventKind (event))
     {
+    case kEventWindowUpdate:
+      result = CallNextEventHandler (next_handler, event);
+      if (result != eventNotHandledErr)
+	return result;
+
+      do_window_update (wp);
+      break;
+
     case kEventWindowBoundsChanging:
       result = CallNextEventHandler (next_handler, event);
       if (result != eventNotHandledErr)
@@ -7918,7 +8035,8 @@
 {
   OSErr err = noErr;
 #if USE_CARBON_EVENTS
-  EventTypeSpec specs[] = {{kEventClassWindow, kEventWindowBoundsChanging}};
+  EventTypeSpec specs[] = {{kEventClassWindow, kEventWindowUpdate},
+			   {kEventClassWindow, kEventWindowBoundsChanging}};
   static EventHandlerUPP handle_window_event_UPP = NULL;
 
   if (handle_window_event_UPP == NULL)
@@ -8013,24 +8131,28 @@
         int i;
 
         /* AE file list is one based so just use that for indexing here.  */
-        for (i = 1; (err == noErr) && (i <= num_files_to_open); i++)
+        for (i = 1; i <= num_files_to_open; i++)
 	  {
+#ifdef MAC_OSX
+	    FSRef fref;
+	    char unix_path_name[MAXPATHLEN];
+
+	    err = AEGetNthPtr (&the_desc, i, typeFSRef, &keyword,
+			       &actual_type, &fref, sizeof (FSRef),
+			       &actual_size);
+	    if (err != noErr || actual_type != typeFSRef)
+	      continue;
+
+	    if (FSRefMakePath (&fref, unix_path_name, sizeof (unix_path_name))
+		== noErr)
+#else
 	    FSSpec fs;
 	    Str255 path_name, unix_path_name;
-#ifdef MAC_OSX
-	    FSRef fref;
-#endif
 
 	    err = AEGetNthPtr(&the_desc, i, typeFSS, &keyword, &actual_type,
 			      (Ptr) &fs, sizeof (fs), &actual_size);
-	    if (err != noErr) break;
-
-#ifdef MAC_OSX
-	    err = FSpMakeFSRef (&fs, &fref);
-	    if (err != noErr) break;
-
-	    if (FSRefMakePath (&fref, unix_path_name, 255) == noErr)
-#else
+	    if (err != noErr) continue;
+
 	    if (path_from_vol_dir_name (path_name, 255, fs.vRefNum, fs.parID,
 					fs.name) &&
 		mac_to_posix_pathname (path_name, unix_path_name, 255))
@@ -8066,18 +8188,21 @@
   FlavorFlags theFlags;
   OSErr result;
 
+  if (GetFrontWindowOfClass (kMovableModalWindowClass, false))
+    return dragNotAcceptedErr;
+
   switch (message)
     {
     case kDragTrackingEnterHandler:
       CountDragItems (theDrag, &items);
-      can_accept = 1;
+      can_accept = 0;
       for (index = 1; index <= items; index++)
 	{
 	  GetDragItemReferenceNumber (theDrag, index, &theItem);
 	  result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags);
-	  if (result != noErr)
+	  if (result == noErr)
 	    {
-	      can_accept = 0;
+	      can_accept = 1;
 	      break;
 	    }
 	}
@@ -8088,7 +8213,9 @@
 	{
 	  RgnHandle hilite_rgn = NewRgn ();
 	  Rect r;
-
+	  struct frame *f = mac_window_to_frame (window);
+
+	  mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f));
 	  GetWindowPortBounds (window, &r);
 	  OffsetRect (&r, -r.left, -r.top);
 	  RectRgn (hilite_rgn, &r);
@@ -8104,6 +8231,9 @@
     case kDragTrackingLeaveWindow:
       if (can_accept)
 	{
+	  struct frame *f = mac_window_to_frame (window);
+
+	  mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f));
 	  HideDragHilite (theDrag);
 	  SetThemeCursor (kThemeArrowCursor);
 	}
@@ -8127,9 +8257,11 @@
   OSErr result;
   ItemReference theItem;
   HFSFlavor data;
-  FSRef fref;
   Size size = sizeof (HFSFlavor);
 
+  if (GetFrontWindowOfClass (kMovableModalWindowClass, false))
+    return dragNotAcceptedErr;
+
   drag_and_drop_file_list = Qnil;
   GetDragMouse (theDrag, &mouse, 0L);
   CountDragItems (theDrag, &items);
@@ -8141,11 +8273,11 @@
       if (result == noErr)
 	{
 #ifdef MAC_OSX
-	  FSRef frref;
+	  FSRef fref;
+	  char unix_path_name[MAXPATHLEN];
 #else
-	  Str255 path_name;
-#endif
-	  Str255 unix_path_name;
+	  Str255 path_name, unix_path_name;
+#endif
 	  GetFlavorData (theDrag, theItem, flavorTypeHFS, &data, &size, 0L);
 #ifdef MAC_OSX
 	  /* Use Carbon routines, otherwise it converts the file name
@@ -8163,8 +8295,6 @@
 					  strlen (unix_path_name)),
 		     drag_and_drop_file_list);
 	}
-      else
-	continue;
     }
   /* If there are items in the list, construct an event and post it to
      the queue like an interrupt using kbd_buffer_store_event.  */
@@ -8724,8 +8854,9 @@
 	  if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
 	      != eventNotHandledErr)
 	    break;
-#endif
+#else
 	  do_window_update ((WindowPtr) er.message);
+#endif
 	  break;
 
 	case osEvt:
@@ -9811,7 +9942,16 @@
    doc: /* If non-nil, the Mac \"Control\" key is passed on to the Mac
 Toolbox for processing before Emacs sees it.  */);
   Vmac_pass_control_to_system = Qt;
-#endif
+
+  DEFVAR_LISP ("mac-pass-control-to-system", &Vmac_pass_control_to_system,
+   doc: /* If non-nil, the Mac \"Control\" key is passed on to the Mac
+Toolbox for processing before Emacs sees it.  */);
+  Vmac_pass_control_to_system = Qt;
+#endif
+
+  DEFVAR_LISP ("mac-allow-anti-aliasing", &Vmac_use_core_graphics,
+   doc: /* If non-nil, the text will be rendered using Core Graphics text rendering which may anti-alias the text.  */);
+  Vmac_use_core_graphics = Qnil;
 
   DEFVAR_INT ("mac-keyboard-text-encoding", &mac_keyboard_text_encoding,
     doc: /* One of the Text Encoding Base constant values defined in the