* nsfns.m: Declare image_cache_refcount if GLYPH_DEBUG.
[bpt/emacs.git] / src / nsterm.m
index 582e53e..3d3723f 100644 (file)
@@ -164,7 +164,7 @@ static Lisp_Object last_mouse_motion_frame;
 static EmacsScroller *last_mouse_scroll_bar = nil;
 static struct frame *ns_updating_frame;
 static NSView *focus_view = NULL;
-static int ns_window_num =0;
+static int ns_window_num = 0;
 static NSRect uRect;
 static BOOL gsaved = NO;
 BOOL ns_in_resize = NO;
@@ -1123,12 +1123,10 @@ x_iconify_frame (struct frame *f)
   [[view window] miniaturize: NSApp];
 }
 
+/* Free X resources of frame F.  */
 
 void
-x_destroy_window (struct frame *f)
-/* --------------------------------------------------------------------------
-     External: Delete the window
-   -------------------------------------------------------------------------- */
+x_free_frame_resources (struct frame *f)
 {
   NSView *view = FRAME_NS_VIEW (f);
   struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f);
@@ -1163,10 +1161,21 @@ x_destroy_window (struct frame *f)
   [[view window] close];
   [view release];
 
-  ns_window_num--;
   UNBLOCK_INPUT;
 }
 
+void
+x_destroy_window (struct frame *f)
+/* --------------------------------------------------------------------------
+     External: Delete the window
+   -------------------------------------------------------------------------- */
+{
+  NSTRACE (x_destroy_window);
+  check_ns ();
+  x_free_frame_resources (f);
+  ns_window_num--;
+}
+
 
 void
 x_set_offset (struct frame *f, int xoff, int yoff, int change_grav)
@@ -1341,7 +1350,7 @@ unsigned long
 ns_index_color (NSColor *color, struct frame *f)
 {
   struct ns_color_table *color_table = FRAME_NS_DISPLAY_INFO (f)->color_table;
-  int idx;
+  ptrdiff_t idx;
   NSNumber *index;
 
   if (!color_table->colors)
@@ -1356,7 +1365,7 @@ ns_index_color (NSColor *color, struct frame *f)
 
   /* do we already have this color ? */
   {
-    int i;
+    ptrdiff_t i;
     for (i = 1; i < color_table->avail; i++)
       {
         if (color_table->colors[i] && [color_table->colors[i] isEqual: color])
@@ -1371,17 +1380,14 @@ ns_index_color (NSColor *color, struct frame *f)
     {
       index = [color_table->empty_indices anyObject];
       [color_table->empty_indices removeObject: index];
-      idx = [index unsignedIntValue];
+      idx = [index unsignedLongValue];
     }
   else
     {
       if (color_table->avail == color_table->size)
-        {
-          color_table->size += NS_COLOR_CAPACITY;
-          color_table->colors
-           = (NSColor **)xrealloc (color_table->colors,
-                                   color_table->size * sizeof (NSColor *));
-        }
+       color_table->colors =
+         xpalloc (color_table->colors, &color_table->size, 1,
+                  min (ULONG_MAX, PTRDIFF_MAX), sizeof *color_table->colors);
       idx = color_table->avail++;
     }
 
@@ -2321,7 +2327,7 @@ ns_draw_fringe_bitmap (struct window *w, struct glyph_row *row,
       if (!img)
         {
           unsigned short *bits = p->bits + p->dh;
-          int len = 8 * p->h/8;
+          int len = p->h;
           int i;
           unsigned char *cbits = xmalloc (len);
 
@@ -4867,7 +4873,7 @@ ns_term_shutdown (int sig)
         }
     }
 
-  
+
 #if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
   /* if we get here we should send the key for input manager processing */
   if (firstTime && [[NSInputManager currentInputManager]
@@ -5319,7 +5325,7 @@ ns_term_shutdown (int sig)
             strcpy (old_title, t);
           }
         size_title = xmalloc (strlen (old_title) + 40);
-        sprintf (size_title, "%s  —  (%d x %d)", old_title, cols, rows);
+       esprintf (size_title, "%s  —  (%d x %d)", old_title, cols, rows);
         [window setTitle: [NSString stringWithUTF8String: size_title]];
         [window display];
         xfree (size_title);
@@ -5360,7 +5366,23 @@ ns_term_shutdown (int sig)
      a "windowDidResize" which calls x_set_window_size).  */
 #ifndef NS_IMPL_GNUSTEP
   if (cols > 0 && rows > 0)
-    x_set_window_size (emacsframe, 0, cols, rows);
+    {
+      if (ns_in_resize)
+        x_set_window_size (emacsframe, 0, cols, rows);
+      else
+        {
+          NSWindow *window = [self window];
+          NSRect wr = [window frame];
+          FRAME_PIXEL_WIDTH (emacsframe) = (int)wr.size.width
+            - emacsframe->border_width;
+          FRAME_PIXEL_HEIGHT (emacsframe) = (int)wr.size.height
+            - FRAME_NS_TITLEBAR_HEIGHT (emacsframe)
+            - FRAME_TOOLBAR_HEIGHT (emacsframe);
+          change_frame_size (emacsframe, rows, cols, 0, 0, 1);
+          SET_FRAME_GARBAGED (emacsframe);
+          cancel_mouse_face (emacsframe);
+        }
+    }
 #endif
 
   ns_send_appdefined (-1);