gdkwindow-quartz.c 38.3 KB
Newer Older
Anders Carlsson's avatar
Anders Carlsson committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/* gdkwindow-quartz.c
 *
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 * Copyright (C) 2005 Imendio AB
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <config.h>

#include "gdk.h"
#include "gdkprivate-quartz.h"

static gpointer parent_class;

29 30 31 32 33 34 35 36
NSView *
gdk_quartz_window_get_nsview (GdkWindow *window)
{
  GdkWindowObject *private = (GdkWindowObject *)window;

  return ((GdkWindowImplQuartz *)private->impl)->view;
}

Anders Carlsson's avatar
Anders Carlsson committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
static void
gdk_window_impl_quartz_get_size (GdkDrawable *drawable,
				gint        *width,
				gint        *height)
{
  g_return_if_fail (GDK_IS_WINDOW_IMPL_QUARTZ (drawable));

  if (width)
    *width = GDK_WINDOW_IMPL_QUARTZ (drawable)->width;
  if (height)
    *height = GDK_WINDOW_IMPL_QUARTZ (drawable)->height;
}

static GdkRegion*
gdk_window_impl_quartz_get_visible_region (GdkDrawable *drawable)
{
  GdkWindowObject *private = GDK_WINDOW_OBJECT (GDK_DRAWABLE_IMPL_QUARTZ (drawable)->wrapper);
  GdkRectangle rect;
  GdkWindowImplQuartz *impl;
  GList *windows = NULL, *l;

  /* FIXME: The clip rectangle should really be cached
   * and recalculated when the window rectangle changes.
   */
  while (private)
    {
      windows = g_list_prepend (windows, private);

      if (private->parent == GDK_WINDOW_OBJECT (_gdk_root))
	break;

      private = private->parent;
    }

  /* Get rectangle for toplevel window */
  private = GDK_WINDOW_OBJECT (windows->data);
  impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
  
  rect.x = 0;
  rect.y = 0;
  rect.width = impl->width;
  rect.height = impl->height;

  /* Skip toplevel window since we have its rect */
  for (l = windows->next; l; l = l->next)
    {
      private = GDK_WINDOW_OBJECT (l->data);
      impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
      GdkRectangle tmp_rect;

      tmp_rect.x = -MIN (0, private->x - rect.x);
      tmp_rect.y = -MIN (0, private->y - rect.y);
      tmp_rect.width = MIN (rect.width, impl->width + private->x - rect.x) - MAX (0, private->x - rect.x);
      tmp_rect.height = MIN (rect.height, impl->height + private->y - rect.y) - MAX (0, private->y - rect.y);

      rect = tmp_rect;
    }
  
  g_list_free (windows);
  
  return gdk_region_rectangle (&rect);
}

static void
gdk_window_impl_quartz_finalize (GObject *object)
{
  GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (object);

  if (impl->nscursor)
    [impl->nscursor release];

108 109 110
  if (impl->paint_clip_region)
    gdk_region_destroy (impl->paint_clip_region);

Anders Carlsson's avatar
Anders Carlsson committed
111 112 113 114 115 116 117
  G_OBJECT_CLASS (parent_class)->finalize (object);
}

static void
gdk_window_impl_quartz_class_init (GdkWindowImplQuartzClass *klass)
{
  GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
118
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
Anders Carlsson's avatar
Anders Carlsson committed
119 120 121

  parent_class = g_type_class_peek_parent (klass);

122 123
  object_class->finalize = gdk_window_impl_quartz_finalize;

Anders Carlsson's avatar
Anders Carlsson committed
124 125 126 127 128 129 130 131 132 133 134 135
  drawable_class->get_size = gdk_window_impl_quartz_get_size;

  /* Visible and clip regions are the same */
  drawable_class->get_clip_region = gdk_window_impl_quartz_get_visible_region;
  drawable_class->get_visible_region = gdk_window_impl_quartz_get_visible_region;
}

static void
gdk_window_impl_quartz_init (GdkWindowImplQuartz *impl)
{
  impl->width = 1;
  impl->height = 1;
136
  impl->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
Anders Carlsson's avatar
Anders Carlsson committed
137 138
}

139 140 141 142 143
static void
gdk_window_impl_quartz_begin_paint_region (GdkPaintable *paintable,
					   GdkRegion    *region)
{
  GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (paintable);
144
  CGContextRef context = gdk_quartz_drawable_get_context (GDK_DRAWABLE (impl), FALSE);
145 146 147 148 149 150 151 152 153 154 155 156 157
  int i, n_rects;
  GdkRectangle *rects;

  if (impl->begin_paint_count == 0)
    impl->paint_clip_region = gdk_region_copy (region);
  else
    gdk_region_union (impl->paint_clip_region, region);

  impl->begin_paint_count ++;

  gdk_region_get_rectangles (region, &rects, &n_rects);
  for (i = 0; i < n_rects; i++) 
    {
158 159
      gdk_quartz_set_context_fill_color_from_pixel (context, gdk_drawable_get_colormap (GDK_DRAWABLE_IMPL_QUARTZ (impl)->wrapper),
						    GDK_WINDOW_OBJECT (GDK_DRAWABLE_IMPL_QUARTZ (impl)->wrapper)->bg_color.pixel);
160 161 162 163 164 165
      
      CGContextFillRect (context, CGRectMake (rects[i].x, rects[i].y, rects[i].width, rects[i].height));
      
    }
  g_free (rects);

166
  gdk_quartz_drawable_release_context (GDK_DRAWABLE (impl), context);
167 168 169 170 171 172 173 174
}

static void
gdk_window_impl_quartz_end_paint (GdkPaintable *paintable)
{
  GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (paintable);

  impl->begin_paint_count --;
175 176 177 178 179 180

  if (impl->begin_paint_count == 0)
    {
      gdk_region_destroy (impl->paint_clip_region);
      impl->paint_clip_region = NULL;
    }
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
}

static void
gdk_window_impl_quartz_invalidate_maybe_recurse (GdkPaintable *paintable,
						 GdkRegion    *region,
						 gboolean    (*child_func) (GdkWindow *, gpointer),
						 gpointer      user_data)
{
  GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (paintable);
  int i, n_rects;
  GdkRectangle *rects;

  gdk_region_get_rectangles (region, &rects, &n_rects);

  for (i = 0; i < n_rects; i++) 
    {
      [impl->view setNeedsDisplayInRect:NSMakeRect (rects[i].x, rects[i].y,
						    rects[i].width, rects[i].height)];
    }

  g_free (rects);

  /* FIXME: Check if we need to traverse the children */
}

static void
gdk_window_impl_quartz_process_updates (GdkPaintable *paintable,
					gboolean      update_children)
{
  GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (paintable);

  [impl->view display];

  /* FIXME: Check if display actually updates the children too */
}

static void
gdk_window_impl_quartz_paintable_init (GdkPaintableIface *iface)
{
  iface->begin_paint_region = gdk_window_impl_quartz_begin_paint_region;
  iface->end_paint = gdk_window_impl_quartz_end_paint;

  iface->invalidate_maybe_recurse = gdk_window_impl_quartz_invalidate_maybe_recurse;
  iface->process_updates = gdk_window_impl_quartz_process_updates;
}


Anders Carlsson's avatar
Anders Carlsson committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
GType
_gdk_window_impl_quartz_get_type (void)
{
  static GType object_type = 0;

  if (!object_type)
    {
      static const GTypeInfo object_info =
      {
        sizeof (GdkWindowImplQuartzClass),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) gdk_window_impl_quartz_class_init,
        NULL,           /* class_finalize */
        NULL,           /* class_data */
        sizeof (GdkWindowImplQuartz),
        0,              /* n_preallocs */
        (GInstanceInitFunc) gdk_window_impl_quartz_init,
      };
      
248 249 250 251 252 253 254
      static const GInterfaceInfo paintable_info = 
      {
	(GInterfaceInitFunc) gdk_window_impl_quartz_paintable_init,
	NULL,
	NULL
      };

Anders Carlsson's avatar
Anders Carlsson committed
255 256 257
      object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_QUARTZ,
                                            "GdkWindowImplQuartz",
                                            &object_info, 0);
258 259 260
      g_type_add_interface_static (object_type,
				   GDK_TYPE_PAINTABLE,
				   &paintable_info);
Anders Carlsson's avatar
Anders Carlsson committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
    }
  
  return object_type;
}

GType
_gdk_window_impl_get_type (void)
{
  return _gdk_window_impl_quartz_get_type ();
}

static const gchar *
get_default_title (void)
{
  const char *title;

  title = g_get_application_name ();
  if (!title)
    title = g_get_prgname ();

  return title;
}

gint 
_gdk_quartz_get_inverted_screen_y (gint y)
{
  NSRect rect = [[NSScreen mainScreen] frame];

  return rect.size.height - y;
}

292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
static GdkWindow *
find_child_window_by_point_helper (GdkWindow *window,
				   int        x,
				   int        y,
				   int        x_offset,
				   int        y_offset,
				   int       *x_ret,
				   int       *y_ret)
{
  GList *l;

  for (l = GDK_WINDOW_OBJECT (window)->children; l; l = l->next)
    {
      GdkWindowObject *private = GDK_WINDOW_OBJECT (l->data);
      GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
      int temp_x, temp_y;

      if (!GDK_WINDOW_IS_MAPPED (private))
	continue;

      temp_x = x_offset + private->x;
      temp_y = y_offset + private->y;
      
      /* FIXME: Are there off by one errors here? */
      if (x >= temp_x && y >= temp_y &&
	  x < temp_x + impl->width && y < temp_y + impl->height) 
	{
	  *x_ret = x - x_offset - private->x;
	  *y_ret = y - y_offset - private->y;
	  
	  /* Look for child windows */
	  return find_child_window_by_point_helper (GDK_WINDOW (l->data),
						    x, y,
						    temp_x, temp_y,
						    x_ret, y_ret);
	}
    }

  return window;
}

/* Given a toplevel window and coordinates, returns the window
 * in which the point is. Note that x and y should be non-flipped
 * (and relative the toplevel), while the returned positions are
 * flipped.
 */
GdkWindow *
_gdk_quartz_find_child_window_by_point (GdkWindow *toplevel,
					int        x,
					int        y,
					int       *x_ret,
					int       *y_ret)
{
  GdkWindowObject *private = (GdkWindowObject *)toplevel;
  GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);

  /* If the point is in the title bar, ignore it */
  if (y > impl->height)
    return NULL;

  /* First flip the y coordinate */
  y = impl->height - y;

  return find_child_window_by_point_helper (toplevel, x, y, 0, 0, x_ret, y_ret);
}

Anders Carlsson's avatar
Anders Carlsson committed
358 359 360 361 362 363 364 365 366 367 368 369
GdkWindow *
gdk_window_new (GdkWindow     *parent,
		GdkWindowAttr *attributes,
		gint           attributes_mask)
{
  GdkWindow *window;
  GdkWindowObject *private;
  GdkWindowImplQuartz *impl;
  GdkDrawableImplQuartz *draw_impl;
  GdkVisual *visual;

  if (parent && GDK_WINDOW_DESTROYED (parent))
370 371 372
    return NULL;

  GDK_QUARTZ_ALLOC_POOL;
Anders Carlsson's avatar
Anders Carlsson committed
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435

  if (!parent)
    parent = _gdk_root;

  window = g_object_new (GDK_TYPE_WINDOW, NULL);
  private = (GdkWindowObject *)window;
  impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
  draw_impl = GDK_DRAWABLE_IMPL_QUARTZ (private->impl);
  draw_impl->wrapper = GDK_DRAWABLE (window);

  private->parent = (GdkWindowObject *)parent;

  if (attributes_mask & GDK_WA_X)
    private->x = attributes->x;
  else
    private->x = 0;
  
  if (attributes_mask & GDK_WA_Y)
    private->y = attributes->y;
  else if (attributes_mask & GDK_WA_X)
    private->y = 100;
  else
    private->y = 0;

  private->event_mask = attributes->event_mask;

  impl->width = attributes->width > 1 ? attributes->width : 1;
  impl->height = attributes->height > 1 ? attributes->height : 1;

  if (attributes_mask & GDK_WA_VISUAL)
    visual = attributes->visual;
  else
    visual = gdk_screen_get_system_visual (_gdk_screen);

  if (attributes->wclass == GDK_INPUT_ONLY)
    {
      /* Backwards compatiblity - we've always ignored
       * attributes->window_type for input-only windows
       * before
       */
      if (parent == _gdk_root)
	private->window_type = GDK_WINDOW_TEMP;
      else
	private->window_type = GDK_WINDOW_CHILD;
    }
  else
    private->window_type = attributes->window_type;

  /* Sanity checks */
  switch (private->window_type)
    {
    case GDK_WINDOW_TOPLEVEL:
    case GDK_WINDOW_DIALOG:
    case GDK_WINDOW_TEMP:
      if (GDK_WINDOW_TYPE (parent) != GDK_WINDOW_ROOT)
	{
	  g_warning (G_STRLOC "Toplevel windows must be created as children of\n"
		     "of a window of type GDK_WINDOW_ROOT or GDK_WINDOW_FOREIGN");
	}
    case GDK_WINDOW_CHILD:
      break;
    default:
      g_warning (G_STRLOC "cannot make windows of type %d", private->window_type);
436
      GDK_QUARTZ_RELEASE_POOL;
Anders Carlsson's avatar
Anders Carlsson committed
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
      return NULL;
    }

  if (attributes->wclass == GDK_INPUT_OUTPUT)
    {
      private->input_only = FALSE;
      private->depth = visual->depth;

      if (attributes_mask & GDK_WA_COLORMAP)
	{
	  draw_impl->colormap = attributes->colormap;
	  g_object_ref (attributes->colormap);
	}
      else
	{
	  if (visual == gdk_screen_get_system_visual (_gdk_screen))
	    {
	      draw_impl->colormap = gdk_screen_get_system_colormap (_gdk_screen);
	      g_object_ref (draw_impl->colormap);
	    }
	  else if (visual == gdk_screen_get_rgba_visual (_gdk_screen))
	    {
	      draw_impl->colormap = gdk_screen_get_rgba_colormap (_gdk_screen);
	      g_object_ref (draw_impl->colormap);
	    }
	  else
	    {
	      draw_impl->colormap = gdk_colormap_new (visual, FALSE);
	    }
	}

      private->bg_color.pixel = 0;
      private->bg_color.red = private->bg_color.green = private->bg_color.blue = 0;
    }
  else
    {
      private->depth = 0;
      private->input_only = TRUE;
      draw_impl->colormap = gdk_screen_get_system_colormap (_gdk_screen);
Anders Carlsson's avatar
Anders Carlsson committed
476
      g_object_ref (draw_impl->colormap);
Anders Carlsson's avatar
Anders Carlsson committed
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
    }

  if (private->parent)
    private->parent->children = g_list_prepend (private->parent->children, window);

  gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
				  (attributes->cursor) :
				  NULL));

  switch (attributes->window_type) 
    {
    case GDK_WINDOW_TOPLEVEL:
    case GDK_WINDOW_DIALOG:
    case GDK_WINDOW_TEMP:
      {
	NSRect content_rect = NSMakeRect (private->x, 
					  _gdk_quartz_get_inverted_screen_y (private->y) - impl->height,
					  impl->width, impl->height);
	const char *title;
Anders Carlsson's avatar
Anders Carlsson committed
496 497 498 499 500 501 502
	int style_mask;

	switch (attributes->window_type) {
	case GDK_WINDOW_TEMP:
	  style_mask = NSBorderlessWindowMask;
	  break;
	default:
503 504 505 506
	  style_mask = (NSTitledWindowMask |
			NSClosableWindowMask |
			NSMiniaturizableWindowMask |
			NSResizableWindowMask);
Anders Carlsson's avatar
Anders Carlsson committed
507
	} 
Anders Carlsson's avatar
Anders Carlsson committed
508 509

	impl->toplevel = [[GdkQuartzWindow alloc] initWithContentRect:content_rect 
Anders Carlsson's avatar
Anders Carlsson committed
510 511
			                                    styleMask:style_mask
			                                      backing:NSBackingStoreBuffered defer:NO];
Anders Carlsson's avatar
Anders Carlsson committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
	if (attributes_mask & GDK_WA_TITLE)
	  title = attributes->title;
	else
	  title = get_default_title ();

	gdk_window_set_title (window, title);
	  
	if (draw_impl->colormap == gdk_screen_get_rgba_colormap (_gdk_screen))
	  {
	    [impl->toplevel setOpaque:NO];
	    [impl->toplevel setBackgroundColor:[NSColor clearColor]];
	  }

	impl->view = [[GdkQuartzView alloc] initWithFrame:content_rect];
	[impl->view setGdkWindow:window];
	[impl->toplevel setContentView:impl->view];

	/* Add a tracking rect */
	impl->tracking_rect = [impl->view addTrackingRect:NSMakeRect(0, 0, impl->width, impl->height) 
			                            owner:impl->view
			                         userData:nil
			                     assumeInside:NO];
      }
      break;
    case GDK_WINDOW_CHILD:
      {
	GdkWindowImplQuartz *parent_impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (parent)->impl);

	if (attributes->wclass == GDK_INPUT_OUTPUT)
	  {
	    NSRect frame_rect = NSMakeRect (private->x, private->y, impl->width, impl->height);
	
	    impl->view = [[GdkQuartzView alloc] initWithFrame:frame_rect];
	    
	    [impl->view setGdkWindow:window];

	    /* GdkWindows should be hidden by default */
	    [impl->view setHidden:YES];
	    [parent_impl->view addSubview:impl->view];
	  }
      }
      break;
    default:
      g_assert_not_reached ();
    }

  GDK_QUARTZ_RELEASE_POOL;

  return window;
}

void
_gdk_windowing_window_init (void)
{
  GdkWindowObject *private;

  g_assert (_gdk_root == NULL);

  _gdk_root = g_object_new (GDK_TYPE_WINDOW, NULL);
Anders Carlsson's avatar
Anders Carlsson committed
571

Anders Carlsson's avatar
Anders Carlsson committed
572
  private = (GdkWindowObject *)_gdk_root;
Anders Carlsson's avatar
Anders Carlsson committed
573 574

  private->state = 0; /* We don't want GDK_WINDOW_STATE_WITHDRAWN here */
Anders Carlsson's avatar
Anders Carlsson committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
  private->window_type = GDK_WINDOW_ROOT;
  private->depth = 24;
}

void
_gdk_windowing_window_destroy (GdkWindow *window,
			       gboolean   recursing,
			       gboolean   foreign_destroy)
{
  if (!recursing && ! foreign_destroy)
    {
      GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (window)->impl);

      if (window == _gdk_quartz_get_mouse_window ()) 
	{
	  _gdk_quartz_update_mouse_window (_gdk_root);
	}

      if (impl->toplevel)
	[impl->toplevel close];
      else if (impl->view)
	[impl->view release];
      
    }
}

void
_gdk_windowing_window_destroy_foreign (GdkWindow *window)
{
604
  /* Foreign windows aren't supported in OSX. */
Anders Carlsson's avatar
Anders Carlsson committed
605 606
}

Anders Carlsson's avatar
Anders Carlsson committed
607 608 609 610 611 612 613 614 615 616 617 618 619 620
static gboolean
all_parents_shown (GdkWindowObject *private)
{
  while (GDK_WINDOW_IS_MAPPED (private))
    {
      if (private->parent)
	private = (GdkWindowObject *)private->parent;
      else
	return TRUE;
    }

  return FALSE;
}

Anders Carlsson's avatar
Anders Carlsson committed
621 622 623 624 625 626
static void
show_window_internal (GdkWindow *window, gboolean raise)
{
  GdkWindowObject *private;
  GdkWindowImplQuartz *impl;

627
  if (GDK_WINDOW_DESTROYED (window))
Anders Carlsson's avatar
Anders Carlsson committed
628 629 630 631
    return;

  GDK_QUARTZ_ALLOC_POOL;

632
  private = (GdkWindowObject *)window;
Anders Carlsson's avatar
Anders Carlsson committed
633 634 635 636 637 638 639 640 641 642 643 644 645
  impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);

  if (impl->toplevel)
    {
      [impl->toplevel orderFront:nil];
      [impl->view setNeedsDisplay:YES];
    }
  else
    {
      [impl->view setHidden:NO];
      [impl->view setNeedsDisplay:YES];
    }

Anders Carlsson's avatar
Anders Carlsson committed
646 647 648
  if (all_parents_shown (private->parent))
    _gdk_quartz_send_map_events (window);

Anders Carlsson's avatar
Anders Carlsson committed
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
  gdk_synthesize_window_state (window, GDK_WINDOW_STATE_WITHDRAWN, 0);

  GDK_QUARTZ_RELEASE_POOL;
}

void
gdk_window_show_unraised (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  show_window_internal (window, FALSE);
}

void
gdk_window_show (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  show_window_internal (window, TRUE);
}

void
gdk_window_hide (GdkWindow *window)
{
  GdkWindowObject *private = (GdkWindowObject *)window;
  GdkWindowImplQuartz *impl;

  g_return_if_fail (GDK_IS_WINDOW (window));

  if (GDK_WINDOW_DESTROYED (window))
    return;

  if (GDK_WINDOW_IS_MAPPED (window))
    gdk_synthesize_window_state (window,
				 0,
				 GDK_WINDOW_STATE_WITHDRAWN);
  
  _gdk_window_clear_update_area (window);

  impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);

  if (impl->toplevel) 
    {
Anders Carlsson's avatar
Anders Carlsson committed
692
      [impl->toplevel orderOut:nil];
Anders Carlsson's avatar
Anders Carlsson committed
693 694 695 696 697
    }
  else if (impl->view)
    {
      [impl->view setHidden:YES];
    }
Anders Carlsson's avatar
Anders Carlsson committed
698

Anders Carlsson's avatar
Anders Carlsson committed
699 700
  if (window == _gdk_quartz_pointer_grab_window)
    gdk_pointer_ungrab (0);
Anders Carlsson's avatar
Anders Carlsson committed
701

Anders Carlsson's avatar
Anders Carlsson committed
702 703
  if (window == _gdk_quartz_keyboard_grab_window)
    gdk_keyboard_ungrab (0);
Anders Carlsson's avatar
Anders Carlsson committed
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
}

void
gdk_window_withdraw (GdkWindow *window)
{
  gdk_window_hide (window);
}

static void
move_resize_window_internal (GdkWindow *window,
			     gint       x,
			     gint       y,
			     gint       width,
			     gint       height)
{
  GdkWindowObject *private = (GdkWindowObject *)window;
  GdkWindowImplQuartz *impl;

  if (GDK_WINDOW_DESTROYED (window))
723
    return;
Anders Carlsson's avatar
Anders Carlsson committed
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738

  impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);

  if (x != -1)
    private->x = x;

  if (y != -1)
    private->y = y;

  if (width != -1)
    impl->width = width;

  if (height != -1)
    impl->height = height;

739 740
  GDK_QUARTZ_ALLOC_POOL;

Anders Carlsson's avatar
Anders Carlsson committed
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
  if (impl->toplevel)
    {
      NSRect content_rect = NSMakeRect (private->x, 
					_gdk_quartz_get_inverted_screen_y (private->y) ,
					impl->width, impl->height);
      NSRect frame_rect = [impl->toplevel frameRectForContentRect:content_rect];
      
      frame_rect.origin.y -= frame_rect.size.height;

      [impl->toplevel setFrame:frame_rect display:YES];
    }
  else 
    {
      if (!private->input_only)
	{
	  [impl->view setFrame:NSMakeRect (private->x, private->y, 
					   impl->width, impl->height)];
758

Anders Carlsson's avatar
Anders Carlsson committed
759 760 761 762
	  /* FIXME: Maybe we should use setNeedsDisplayInRect instead */
	  [impl->view setNeedsDisplay:YES];
	}
    }
763 764

  GDK_QUARTZ_RELEASE_POOL;
Anders Carlsson's avatar
Anders Carlsson committed
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
}

void
gdk_window_move (GdkWindow *window,
		 gint       x,
		 gint       y)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  move_resize_window_internal (window, x, y, -1, -1);
}

void
gdk_window_resize (GdkWindow *window,
		   gint       width,
		   gint       height)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  if (width < 1)
    width = 1;
  if (height < 1)
    height = 1;

  move_resize_window_internal (window, -1, -1, width, height);
}

void
gdk_window_move_resize (GdkWindow *window,
			gint       x,
			gint       y,
			gint       width,
			gint       height)
{
  if (width < 1)
    width = 1;
  if (height < 1)
    height = 1;

  move_resize_window_internal (window, x, y, width, height);
}

void
gdk_window_reparent (GdkWindow *window,
		     GdkWindow *new_parent,
		     gint       x,
		     gint       y)
{
  g_warning ("gdk_window_reparent: %p %p (%d, %d)", 
	     window, new_parent, x, y);

  /* FIXME: Implement */
}

void
_gdk_windowing_window_clear_area (GdkWindow *window,
				  gint       x,
				  gint       y,
				  gint       width,
				  gint       height)
{
  /* FIXME: Implement */
}

void
_gdk_windowing_window_clear_area_e (GdkWindow *window,
				    gint       x,
				    gint       y,
				    gint       width,
				    gint       height)
{
  /* FIXME: Implement */
}

void
gdk_window_raise (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));
  
  /* FIXME: Implement */
}

void
gdk_window_lower (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));
  
  /* FIXME: Implement */
}

void
gdk_window_set_background (GdkWindow      *window,
			   const GdkColor *color)
{
  GdkWindowObject *private = (GdkWindowObject *)window;
  GdkWindowImplQuartz *impl;

  g_return_if_fail (GDK_IS_WINDOW (window));

  if (GDK_WINDOW_DESTROYED (window))
      return;

  impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);

  private->bg_color = *color;

  if (private->bg_pixmap &&
      private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
      private->bg_pixmap != GDK_NO_BG)
    g_object_unref (private->bg_pixmap);
  
  private->bg_pixmap = NULL;
}

void
gdk_window_set_back_pixmap (GdkWindow *window,
			    GdkPixmap *pixmap,
			    gboolean   parent_relative)
{
Richard Hult's avatar
Richard Hult committed
884 885
  GdkWindowObject *private = (GdkWindowObject *)window;

Anders Carlsson's avatar
Anders Carlsson committed
886 887 888 889
  g_return_if_fail (GDK_IS_WINDOW (window));
  g_return_if_fail (pixmap == NULL || !parent_relative);
  g_return_if_fail (pixmap == NULL || gdk_drawable_get_depth (window) == gdk_drawable_get_depth (pixmap));

Richard Hult's avatar
Richard Hult committed
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
  if (GDK_WINDOW_DESTROYED (window))
    return;

  if (private->bg_pixmap &&
      private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
      private->bg_pixmap != GDK_NO_BG)
    g_object_unref (private->bg_pixmap);

  if (parent_relative)
    {
      private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
      GDK_NOTE (MISC, g_print (G_STRLOC ": setting background pixmap to parent_relative\n"));
    }
  else
    {
      if (pixmap)
	{
	  g_object_ref (pixmap);
	  private->bg_pixmap = pixmap;
	}
      else
	{
	  private->bg_pixmap = GDK_NO_BG;
	}
    }
Anders Carlsson's avatar
Anders Carlsson committed
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
}

void
gdk_window_set_cursor (GdkWindow *window,
		       GdkCursor *cursor)
{
  GdkWindowImplQuartz *impl;
  GdkCursorPrivate *cursor_private;
  NSCursor *nscursor;

  g_return_if_fail (GDK_IS_WINDOW (window));

  impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (window)->impl);
  cursor_private = (GdkCursorPrivate *)cursor;

  if (GDK_WINDOW_DESTROYED (window))
    return;

  if (!cursor)
    nscursor = NULL;
  else 
    nscursor = [cursor_private->nscursor retain];

  if (impl->nscursor)
    [impl->nscursor release];

  impl->nscursor = nscursor;

  _gdk_quartz_update_cursor (_gdk_quartz_get_mouse_window ());
}

void
gdk_window_get_geometry (GdkWindow *window,
			 gint      *x,
			 gint      *y,
			 gint      *width,
			 gint      *height,
			 gint      *depth)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

gboolean
gdk_window_get_origin (GdkWindow *window,
		       gint      *x,
		       gint      *y)
{
Anders Carlsson's avatar
Anders Carlsson committed
964 965 966 967 968 969
  GdkWindowObject *private;
  int tmp_x = 0, tmp_y = 0;
  GdkWindow *toplevel;
  NSRect content_rect;
  GdkWindowImplQuartz *impl;

Anders Carlsson's avatar
Anders Carlsson committed
970 971
  g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);

Anders Carlsson's avatar
Anders Carlsson committed
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
  if (GDK_WINDOW_DESTROYED (window)) 
    {
      if (x) 
	*x = 0;
      if (y) 
	*y = 0;
      
      return FALSE;
    }
  
  private = GDK_WINDOW_OBJECT (window);

  toplevel = gdk_window_get_toplevel (window);
  impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl);

  content_rect = [impl->toplevel contentRectForFrameRect:[impl->toplevel frame]];

  tmp_x = content_rect.origin.x;
  tmp_y = _gdk_quartz_get_inverted_screen_y (content_rect.origin.y + content_rect.size.height);

  while (private != GDK_WINDOW_OBJECT (toplevel))
    {
      tmp_x += private->x;
      tmp_y += private->y;

      private = private->parent;
    }

  if (x)
    *x = tmp_x;
  if (y)
    *y = tmp_y;

  return TRUE;
Anders Carlsson's avatar
Anders Carlsson committed
1006 1007 1008 1009 1010 1011 1012 1013 1014
}

gboolean
gdk_window_get_deskrelative_origin (GdkWindow *window,
				    gint      *x,
				    gint      *y)
{
  g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);

1015
  return gdk_window_get_origin (window, x, y);
Anders Carlsson's avatar
Anders Carlsson committed
1016 1017 1018 1019 1020 1021 1022
}

void
gdk_window_get_root_origin (GdkWindow *window,
			    gint      *x,
			    gint      *y)
{
1023 1024
  GdkRectangle rect;

Anders Carlsson's avatar
Anders Carlsson committed
1025 1026
  g_return_if_fail (GDK_IS_WINDOW (window));

1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
  rect.x = 0;
  rect.y = 0;
  
  gdk_window_get_frame_extents (window, &rect);

  if (x)
    *x = rect.x;

  if (y)
    *y = rect.y;
Anders Carlsson's avatar
Anders Carlsson committed
1037 1038 1039 1040 1041 1042 1043 1044 1045
}

void
_gdk_windowing_get_pointer (GdkDisplay       *display,
			    GdkScreen       **screen,
			    gint             *x,
			    gint             *y,
			    GdkModifierType  *mask)
{
1046 1047 1048 1049
  g_return_if_fail (display == _gdk_display);
  
  *screen = _gdk_screen;
  _gdk_windowing_window_get_pointer (_gdk_display, _gdk_root, x, y, mask);
Anders Carlsson's avatar
Anders Carlsson committed
1050 1051
}

1052
/* Returns coordinates relative to the upper left corner of window. */
Anders Carlsson's avatar
Anders Carlsson committed
1053 1054 1055 1056 1057 1058 1059
GdkWindow *
_gdk_windowing_window_get_pointer (GdkDisplay      *display,
				   GdkWindow       *window,
				   gint            *x,
				   gint            *y,
				   GdkModifierType *mask)
{
1060 1061 1062
  GdkWindow *toplevel;
  GdkWindowImplQuartz *impl;
  GdkWindowObject *private;
1063
  NSPoint point;
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
  gint x_tmp, y_tmp;

  if (GDK_WINDOW_DESTROYED (window))
    {
      *x = 0;
      *y = 0;
      *mask = 0;
      return NULL;
    }
  
  toplevel = gdk_window_get_toplevel (window);
  impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl);
  private = GDK_WINDOW_OBJECT (window);
1077

1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
  /* Must flip the y coordinate. */
  if (window == _gdk_root)
    {
      point = [NSEvent mouseLocation];
      y_tmp = _gdk_quartz_get_inverted_screen_y (point.y);
    }
  else
    {
      NSWindow *nswindow = impl->toplevel;
      point = [nswindow mouseLocationOutsideOfEventStream];
      y_tmp = impl->height - point.y;
    }
1090
  x_tmp = point.x;
1091

1092 1093 1094 1095
  while (private != GDK_WINDOW_OBJECT (toplevel))
    {
      x_tmp -= private->x;
      y_tmp -= private->y;
1096
    
1097 1098
      private = private->parent;
    }
Anders Carlsson's avatar
Anders Carlsson committed
1099

1100
  /* FIXME: Implement mask. */
1101 1102 1103
  *x = x_tmp;
  *y = y_tmp;
  *mask = 0;
Anders Carlsson's avatar
Anders Carlsson committed
1104

1105 1106 1107
  return _gdk_quartz_find_child_window_by_point (window,
						 point.x, point.y,
						 &x_tmp, &y_tmp);
Anders Carlsson's avatar
Anders Carlsson committed
1108 1109
}

1110 1111 1112 1113 1114 1115 1116 1117 1118
void
gdk_display_warp_pointer (GdkDisplay *display,
			  GdkScreen  *screen,
			  gint        x,
			  gint        y)
{
  CGDisplayMoveCursorToPoint (CGMainDisplayID (), CGPointMake (x, y));
}

Anders Carlsson's avatar
Anders Carlsson committed
1119 1120 1121 1122 1123
GdkWindow *
_gdk_windowing_window_at_pointer (GdkDisplay *display,
				  gint       *win_x,
				  gint       *win_y)
{
1124 1125 1126 1127 1128 1129
  GdkModifierType mask;

  return _gdk_windowing_window_get_pointer (display,
					    _gdk_root,
					    win_x, win_y,
					    &mask);
Anders Carlsson's avatar
Anders Carlsson committed
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
}

GdkEventMask  
gdk_window_get_events (GdkWindow *window)
{
  g_return_val_if_fail (GDK_IS_WINDOW (window), 0);

  if (GDK_WINDOW_DESTROYED (window))
    return 0;
  else
    return GDK_WINDOW_OBJECT (window)->event_mask;
}

void          
gdk_window_set_events (GdkWindow       *window,
		       GdkEventMask     event_mask)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  if (!GDK_WINDOW_DESTROYED (window))
    {
      GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
    }
}

void
gdk_window_set_urgency_hint (GdkWindow *window,
			     gboolean   urgent)
{
  /* FIXME: Implement */
}

void 
gdk_window_set_geometry_hints (GdkWindow      *window,
			       GdkGeometry    *geometry,
			       GdkWindowHints  geom_mask)
{
  /* FIXME: Implement */
}

void
gdk_window_set_title (GdkWindow   *window,
		      const gchar *title)
{
  GdkWindowImplQuartz *impl;

  g_return_if_fail (GDK_IS_WINDOW (window));
  g_return_if_fail (title != NULL);

  if (GDK_WINDOW_DESTROYED (window))
    return;

  impl = GDK_WINDOW_IMPL_QUARTZ (((GdkWindowObject *)window)->impl);

  if (impl->toplevel)
    {
1186
      GDK_QUARTZ_ALLOC_POOL;
Anders Carlsson's avatar
Anders Carlsson committed
1187
      [impl->toplevel setTitle:[NSString stringWithUTF8String:title]];
1188
      GDK_QUARTZ_RELEASE_POOL;
Anders Carlsson's avatar
Anders Carlsson committed
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224
    }
}

void          
gdk_window_set_role (GdkWindow   *window,
		     const gchar *role)
{
  /* FIXME: Implement */
}

void          
gdk_window_set_transient_for (GdkWindow *window, 
			      GdkWindow *parent)
{
  /* FIXME: Implement */
}

void
gdk_window_shape_combine_region (GdkWindow *window,
                                 GdkRegion *shape,
                                 gint       x,
                                 gint       y)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_shape_combine_mask (GdkWindow *window,
			       GdkBitmap *mask,
			       gint x, gint y)
{
  /* FIXME: Implement */
}

1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
void 
gdk_window_input_shape_combine_mask (GdkWindow *window,
				     GdkBitmap *mask,
				     gint       x,
				     gint       y)
{
  /* FIXME: Implement */
}

void 
gdk_window_input_shape_combine_region (GdkWindow *window,
				       GdkRegion *shape_region,
				       gint       offset_x,
				       gint       offset_y)
{
  /* FIXME: Implement */
}

void 
gdk_window_set_child_input_shapes (GdkWindow *window)
{
  /* FIXME: IMplement */
}

Richard Hult's avatar
Richard Hult committed
1249 1250 1251 1252 1253 1254 1255
void
gdk_window_set_override_redirect (GdkWindow *window,
				  gboolean override_redirect)
{
  /* FIXME: Implement */
}

Anders Carlsson's avatar
Anders Carlsson committed
1256 1257 1258 1259 1260 1261 1262
void
gdk_window_set_accept_focus (GdkWindow *window,
			     gboolean accept_focus)
{
  /* FIXME: Implement */
}

Richard Hult's avatar
Richard Hult committed
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
void
gdk_window_set_child_shapes (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_merge_child_shapes (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

1279 1280 1281 1282 1283 1284
void 
gdk_window_merge_child_input_shapes (GdkWindow *window)
{
  /* FIXME: Implement */
}

Richard Hult's avatar
Richard Hult committed
1285 1286 1287 1288 1289 1290 1291 1292
gboolean 
gdk_window_set_static_gravities (GdkWindow *window,
				 gboolean   use_static)
{
  /* FIXME: Implement */
  return FALSE;
}

Anders Carlsson's avatar
Anders Carlsson committed
1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
void
gdk_window_set_focus_on_map (GdkWindow *window,
			     gboolean focus_on_map)
{
  /* FIXME: Implement */
}

void          
gdk_window_set_icon (GdkWindow *window, 
		     GdkWindow *icon_window,
		     GdkPixmap *pixmap,
		     GdkBitmap *mask)
{
  g_return_if_fail (window != NULL);
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void          
gdk_window_set_icon_name (GdkWindow   *window, 
			  const gchar *name)
{
  g_return_if_fail (window != NULL);
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_focus (GdkWindow *window,
                  guint32    timestamp)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

Richard Hult's avatar
Richard Hult committed
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
void
gdk_window_set_hints (GdkWindow *window,
		      gint       x,
		      gint       y,
		      gint       min_width,
		      gint       min_height,
		      gint       max_width,
		      gint       max_height,
		      gint       flags)
{
  /* FIXME: Implement */
}

Anders Carlsson's avatar
Anders Carlsson committed
1344 1345 1346 1347
void
gdk_window_set_type_hint (GdkWindow        *window,
			  GdkWindowTypeHint hint)
{
1348 1349 1350 1351
  GdkWindowImplQuartz *impl;
  gint                 level;
  gboolean             shadow;
  
Anders Carlsson's avatar
Anders Carlsson committed
1352 1353
  g_return_if_fail (GDK_IS_WINDOW (window));

1354 1355 1356
  if (GDK_WINDOW_DESTROYED (window))
    return;

1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368
  impl = GDK_WINDOW_IMPL_QUARTZ (((GdkWindowObject *) window)->impl);

  impl->type_hint = hint;

  /* Match the documentation, only do something if we're not mapped yet. */
  if (GDK_WINDOW_IS_MAPPED (window))
    return;

  switch (hint)
    {
    case GDK_WINDOW_TYPE_HINT_NORMAL:  /* Normal toplevel window */
    case GDK_WINDOW_TYPE_HINT_DIALOG:  /* Dialog window */
1369 1370 1371 1372
      level = NSNormalWindowLevel;
      shadow = TRUE;
      break;

1373 1374 1375
    case GDK_WINDOW_TYPE_HINT_TOOLBAR: /* Window used to implement toolbars */
    case GDK_WINDOW_TYPE_HINT_DESKTOP: /* N/A */
      level = NSNormalWindowLevel;
1376
      shadow = FALSE;
1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
      break;

    case GDK_WINDOW_TYPE_HINT_DOCK:
    case GDK_WINDOW_TYPE_HINT_UTILITY:
      level = NSFloatingWindowLevel;
      shadow = TRUE;
      break;

    case GDK_WINDOW_TYPE_HINT_MENU: /* Torn-off menu */
      level = NSTornOffMenuWindowLevel;
      shadow = TRUE;
      break;
      
    case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU: /* Menu from menubar */
      level = NSSubmenuWindowLevel;
      shadow = TRUE;
      break;
      
    case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
      level = NSPopUpMenuWindowLevel;
      shadow = TRUE;
      break;
      
    case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
    case GDK_WINDOW_TYPE_HINT_COMBO:
      level = NSPopUpMenuWindowLevel;
      shadow = TRUE;
      break;
      
    case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
    case GDK_WINDOW_TYPE_HINT_TOOLTIP:
      level = NSStatusWindowLevel;
      shadow = TRUE;
      break;

    case GDK_WINDOW_TYPE_HINT_DND:
      level = NSPopUpMenuWindowLevel;
      shadow = FALSE;
      break;

    default:
      level = NSNormalWindowLevel;
      shadow = FALSE;
      break;
    }

1423
  [impl->toplevel setHasShadow:shadow];
1424
  [impl->toplevel setLevel:level];
Anders Carlsson's avatar
Anders Carlsson committed
1425 1426
}

1427 1428 1429
GdkWindowTypeHint
gdk_window_get_type_hint (GdkWindow *window)
{
1430 1431 1432 1433
  if (GDK_WINDOW_DESTROYED (window))
    return GDK_WINDOW_TYPE_HINT_NORMAL;
  
  return GDK_WINDOW_IMPL_QUARTZ (((GdkWindowObject *) window)->impl)->type_hint;
1434 1435
}

Anders Carlsson's avatar
Anders Carlsson committed
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498
void
gdk_window_set_modal_hint (GdkWindow *window,
			   gboolean   modal)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_set_skip_taskbar_hint (GdkWindow *window,
				  gboolean   skips_taskbar)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_set_skip_pager_hint (GdkWindow *window,
				gboolean   skips_pager)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_begin_resize_drag (GdkWindow     *window,
                              GdkWindowEdge  edge,
                              gint           button,
                              gint           root_x,
                              gint           root_y,
                              guint32        timestamp)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */  
}

void
gdk_window_begin_move_drag (GdkWindow *window,
                            gint       button,
                            gint       root_x,
                            gint       root_y,
                            guint32    timestamp)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_set_icon_list (GdkWindow *window,
			  GList     *pixbufs)
{
  /* FIXME: Implement */
}

void
gdk_window_get_frame_extents (GdkWindow    *window,
                              GdkRectangle *rect)
{
1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
  GdkWindowObject *private;
  GdkWindow *toplevel;
  GdkWindowImplQuartz *impl;
  NSRect ns_rect;

  g_return_if_fail (GDK_IS_WINDOW (window));
  g_return_if_fail (rect != NULL);

  private = GDK_WINDOW_OBJECT (window);

  rect->x = 0;
  rect->y = 0;
  rect->width = 1;
  rect->height = 1;
  
  if (GDK_WINDOW_DESTROYED (window))
    return;

  toplevel = gdk_window_get_toplevel (window);
  impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl);

  ns_rect = [impl->toplevel frame];

  rect->x = ns_rect.origin.x;
  rect->y = _gdk_quartz_get_inverted_screen_y (ns_rect.origin.y + ns_rect.size.height);
  rect->width = ns_rect.size.width;
  rect->height = ns_rect.size.height;
Anders Carlsson's avatar
Anders Carlsson committed
1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536
}

void
gdk_window_set_decorations (GdkWindow      *window,
			    GdkWMDecoration decorations)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

Richard Hult's avatar
Richard Hult committed
1537
gboolean
1538 1539
gdk_window_get_decorations (GdkWindow       *window,
			    GdkWMDecoration *decorations)
Richard Hult's avatar
Richard Hult committed
1540 1541 1542 1543 1544
{
  /* FIXME: Implement */
  return FALSE;
}

Anders Carlsson's avatar
Anders Carlsson committed
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
void
gdk_window_set_functions (GdkWindow    *window,
			  GdkWMFunction functions)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
_gdk_windowing_window_get_offsets (GdkWindow  *window,
				   gint       *x_offset,
				   gint       *y_offset)
{
  *x_offset = *y_offset = 0;
}

gboolean
_gdk_windowing_window_queue_antiexpose (GdkWindow  *window,
					GdkRegion  *area)
{
  return FALSE;
}

void
gdk_window_stick (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));
}

void
gdk_window_unstick (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));
}

void
gdk_window_maximize (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_unmaximize (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_iconify (GdkWindow *window)
{
  GdkWindowImplQuartz *impl;

  g_return_if_fail (GDK_IS_WINDOW (window));
  
  if (GDK_WINDOW_DESTROYED (window))
    return;
1606
  
Anders Carlsson's avatar
Anders Carlsson committed
1607 1608 1609
  impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (window)->impl);
  if (!impl->toplevel)
    return;
1610 1611
  
  GDK_QUARTZ_ALLOC_POOL;
Anders Carlsson's avatar
Anders Carlsson committed
1612
  [impl->toplevel miniaturize:nil];
1613
  GDK_QUARTZ_RELEASE_POOL;
Anders Carlsson's avatar
Anders Carlsson committed
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629
}

void
gdk_window_deiconify (GdkWindow *window)
{
  GdkWindowImplQuartz *impl;

  g_return_if_fail (GDK_IS_WINDOW (window));
  
  if (GDK_WINDOW_DESTROYED (window))
    return;

  impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (window)->impl);
  if (!impl->toplevel)
    return;

1630
  GDK_QUARTZ_ALLOC_POOL;
Anders Carlsson's avatar
Anders Carlsson committed
1631
  [impl->toplevel deminiaturize:nil];
1632
  GDK_QUARTZ_RELEASE_POOL;
Anders Carlsson's avatar
Anders Carlsson committed
1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666
}

void
gdk_window_fullscreen (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_unfullscreen (GdkWindow *window)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_set_keep_above (GdkWindow *window, gboolean setting)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

void
gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  /* FIXME: Implement */
}

Richard Hult's avatar
Richard Hult committed
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684
GdkWindow *
gdk_window_get_group (GdkWindow *window)
{
  g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
  g_return_val_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD, NULL);

  /* FIXME: Implement */

  return NULL;
}

void          
gdk_window_set_group (GdkWindow *window, 
		      GdkWindow *leader)
{
  /* FIXME: Implement */	
}

Anders Carlsson's avatar
Anders Carlsson committed
1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715
GdkWindow*
gdk_window_foreign_new_for_display (GdkDisplay      *display,
				    GdkNativeWindow  anid)
{
  /* Foreign windows aren't supported in Mac OS X */
  return NULL;
}

GdkWindow*
gdk_window_lookup (GdkNativeWindow anid)
{
  /* Foreign windows aren't supported in Mac OS X */
  return NULL;
}

GdkWindow *
gdk_window_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
{
  /* Foreign windows aren't supported in Mac OS X */
  return NULL;
}

void
gdk_window_enable_synchronized_configure (GdkWindow *window)
{
}

void
gdk_window_configure_finished (GdkWindow *window)
{
}
1716 1717 1718 1719 1720 1721 1722 1723

void
gdk_window_destroy_notify (GdkWindow *window)
{
  /* FIXME: Implement. We should call this from -[GdkQuartzWindow dealloc] or
   * -[GdkQuartzView dealloc], although I suspect that currently they leak
   * anyway. */
}