4 * Implements subwindows for the macintosh version of Tk.
6 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
8 * See the file "license.terms" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
20 #include <QDOffscreen.h>
24 * Temporary region that can be reused.
26 static RgnHandle tmpRgn = NULL;
28 static void UpdateOffsets _ANSI_ARGS_((TkWindow *winPtr, int deltaX, int deltaY));
30 void tkMacMoveWindow _ANSI_ARGS_((WindowRef window, int x, int y));
33 *----------------------------------------------------------------------
37 * Dealocates the given X Window.
40 * The window id is returned.
45 *----------------------------------------------------------------------
50 Display* display, /* Display. */
51 Window window) /* Window. */
53 MacDrawable *macWin = (MacDrawable *) window;
57 * Remove any dangling pointers that may exist if
58 * the window we are deleting is being tracked by
62 TkPointerDeadWindow(macWin->winPtr);
63 macWin->toplevel->referenceCount--;
66 if (Tk_IsTopLevel(macWin->winPtr)) {
67 DisposeRgn(macWin->clipRgn);
68 DisposeRgn(macWin->aboveClipRgn);
71 * Delete the Mac window and remove it from the windowTable.
72 * The window could be NULL if the window was never mapped.
73 * However, we don't do this for embedded windows, they don't
74 * go in the window list, and they do not own their portPtr's.
77 if (!(Tk_IsEmbedded(macWin->winPtr))) {
78 destPort = TkMacGetDrawablePort(window);
79 if (destPort != NULL) {
80 TkMacWindowList *listPtr, *prevPtr;
82 TkMacUnregisterMacWindow(destPort);
83 DisposeWindow((WindowRef) destPort);
85 for (listPtr = tkMacWindowListPtr, prevPtr = NULL;
86 tkMacWindowListPtr != NULL;
87 prevPtr = listPtr, listPtr = listPtr->nextPtr) {
88 if (listPtr->winPtr == macWin->winPtr) {
89 if (prevPtr == NULL) {
90 tkMacWindowListPtr = listPtr->nextPtr;
92 prevPtr->nextPtr = listPtr->nextPtr;
94 ckfree((char *) listPtr);
101 macWin->portPtr = NULL;
104 * Delay deletion of a toplevel data structure untill all
105 * children have been deleted.
107 if (macWin->toplevel->referenceCount == 0) {
108 ckfree((char *) macWin->toplevel);
111 destPort = TkMacGetDrawablePort(window);
112 if (destPort != NULL) {
113 SetGWorld(destPort, NULL);
114 TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);
116 if (macWin->winPtr->parentPtr != NULL) {
117 TkMacInvalClipRgns(macWin->winPtr->parentPtr);
119 DisposeRgn(macWin->clipRgn);
120 DisposeRgn(macWin->aboveClipRgn);
122 if (macWin->toplevel->referenceCount == 0) {
123 ckfree((char *) macWin->toplevel);
125 ckfree((char *) macWin);
130 *----------------------------------------------------------------------
134 * Map the given X Window to the screen. See X window documentation
141 * The subwindow or toplevel may appear on the screen.
143 *----------------------------------------------------------------------
148 Display* display, /* Display. */
149 Window window) /* Window. */
151 MacDrawable *macWin = (MacDrawable *) window;
156 * Under certain situations it's possible for this function to be
157 * called before the toplevel window it's associated with has actually
158 * been mapped. In that case we need to create the real Macintosh
159 * window now as this function as well as other X functions assume that
160 * the portPtr is valid.
162 if (!TkMacHostToplevelExists(macWin->toplevel->winPtr)) {
163 TkMacMakeRealWindowExist(macWin->toplevel->winPtr);
165 destPort = TkMacGetDrawablePort(window);
168 macWin->winPtr->flags |= TK_MAPPED;
169 if (Tk_IsTopLevel(macWin->winPtr)) {
170 if (!Tk_IsEmbedded(macWin->winPtr)) {
171 ShowWindow((WindowRef) destPort);
175 * We only need to send the MapNotify event
176 * for toplevel windows.
178 event.xany.serial = display->request;
179 event.xany.send_event = False;
180 event.xany.display = display;
182 event.xmap.window = window;
183 event.xmap.type = MapNotify;
184 event.xmap.event = window;
185 event.xmap.override_redirect = macWin->winPtr->atts.override_redirect;
186 Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
188 TkMacInvalClipRgns(macWin->winPtr->parentPtr);
192 * Generate damage for that area of the window
194 SetGWorld(destPort, NULL);
195 TkMacUpdateClipRgn(macWin->winPtr);
196 TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);
200 *----------------------------------------------------------------------
204 * Unmap the given X Window to the screen. See X window
205 * documentation for more details.
211 * The subwindow or toplevel may be removed from the screen.
213 *----------------------------------------------------------------------
218 Display* display, /* Display. */
219 Window window) /* Window. */
221 MacDrawable *macWin = (MacDrawable *) window;
225 destPort = TkMacGetDrawablePort(window);
228 macWin->winPtr->flags &= ~TK_MAPPED;
229 if (Tk_IsTopLevel(macWin->winPtr)) {
230 if (!Tk_IsEmbedded(macWin->winPtr)) {
231 HideWindow((WindowRef) destPort);
235 * We only need to send the UnmapNotify event
236 * for toplevel windows.
238 event.xany.serial = display->request;
239 event.xany.send_event = False;
240 event.xany.display = display;
242 event.xunmap.type = UnmapNotify;
243 event.xunmap.window = window;
244 event.xunmap.event = window;
245 event.xunmap.from_configure = false;
246 Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
249 * Generate damage for that area of the window.
251 SetGWorld(destPort, NULL);
252 TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW); /* TODO: may not be valid */
253 TkMacInvalClipRgns(macWin->winPtr->parentPtr);
258 *----------------------------------------------------------------------
262 * Resize a given X window. See X windows documentation for
271 *----------------------------------------------------------------------
276 Display* display, /* Display. */
277 Window window, /* Window. */
281 MacDrawable *macWin = (MacDrawable *) window;
284 destPort = TkMacGetDrawablePort(window);
285 if (destPort == NULL) {
290 SetPort((GrafPtr) destPort);
291 if (Tk_IsTopLevel(macWin->winPtr)) {
292 if (!Tk_IsEmbedded(macWin->winPtr)) {
294 * NOTE: we are not adding the new space to the update
295 * region. It is currently assumed that Tk will need
296 * to completely redraw anway.
298 SizeWindow((WindowRef) destPort,
299 (short) width, (short) height, false);
300 TkMacInvalidateWindow(macWin, TK_WINDOW_ONLY);
301 TkMacInvalClipRgns(macWin->winPtr);
306 * Find the Parent window -
307 * For an embedded window this will be its container.
309 TkWindow *contWinPtr;
311 contWinPtr = TkpGetOtherWindow(macWin->winPtr);
313 if (contWinPtr != NULL) {
314 MacDrawable *macParent = contWinPtr->privatePtr;
316 TkMacInvalClipRgns(macParent->winPtr);
317 TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);
319 deltaX = macParent->xOff +
320 macWin->winPtr->changes.x - macWin->xOff;
321 deltaY = macParent->yOff +
322 macWin->winPtr->changes.y - macWin->yOff;
324 UpdateOffsets(macWin->winPtr, deltaX, deltaY);
327 * This is the case where we are embedded in
328 * another app. At this point, we are assuming that
329 * the changes.x,y is not maintained, if you need
330 * the info get it from Tk_GetRootCoords,
331 * and that the toplevel sits at 0,0 when it is drawn.
334 TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);
335 UpdateOffsets(macWin->winPtr, 0, 0);
340 /* TODO: update all xOff & yOffs */
341 int deltaX, deltaY, parentBorderwidth;
342 MacDrawable *macParent = macWin->winPtr->parentPtr->privatePtr;
344 if (macParent == NULL) {
345 return; /* TODO: Probably should be a panic */
348 TkMacInvalClipRgns(macParent->winPtr);
349 TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);
351 deltaX = - macWin->xOff;
352 deltaY = - macWin->yOff;
354 parentBorderwidth = macWin->winPtr->parentPtr->changes.border_width;
356 deltaX += macParent->xOff + parentBorderwidth +
357 macWin->winPtr->changes.x;
358 deltaY += macParent->yOff + parentBorderwidth +
359 macWin->winPtr->changes.y;
361 UpdateOffsets(macWin->winPtr, deltaX, deltaY);
366 *----------------------------------------------------------------------
368 * XMoveResizeWindow --
370 * Move or resize a given X window. See X windows documentation
371 * for further details.
379 *----------------------------------------------------------------------
384 Display* display, /* Display. */
385 Window window, /* Window. */
390 MacDrawable *macWin = (MacDrawable *) window;
393 destPort = TkMacGetDrawablePort(window);
394 if (destPort == NULL) {
398 SetPort((GrafPtr) destPort);
399 if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
401 * NOTE: we are not adding the new space to the update
402 * region. It is currently assumed that Tk will need
403 * to completely redraw anway.
406 SizeWindow((WindowRef) destPort,
407 (short) width, (short) height, false);
408 tkMacMoveWindow((WindowRef) destPort, x, y);
410 /* TODO: is the following right? */
411 TkMacInvalidateWindow(macWin, TK_WINDOW_ONLY);
412 TkMacInvalClipRgns(macWin->winPtr);
414 int deltaX, deltaY, parentBorderwidth;
416 MacDrawable *macParent;
419 * Find the Parent window -
420 * For an embedded window this will be its container.
423 if (Tk_IsEmbedded(macWin->winPtr)) {
424 TkWindow *contWinPtr;
426 contWinPtr = TkpGetOtherWindow(macWin->winPtr);
427 if (contWinPtr == NULL) {
428 panic("XMoveResizeWindow could not find container");
430 macParent = contWinPtr->privatePtr;
433 * NOTE: Here we should handle out of process embedding.
438 macParent = macWin->winPtr->parentPtr->privatePtr;
439 if (macParent == NULL) {
440 return; /* TODO: Probably should be a panic */
444 TkMacInvalClipRgns(macParent->winPtr);
445 TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);
447 deltaX = - macWin->xOff;
448 deltaY = - macWin->yOff;
451 * If macWin->winPtr is an embedded window, don't offset by its
452 * parent's borderwidth...
455 if (!Tk_IsEmbedded(macWin->winPtr)) {
456 parentBorderwidth = macWin->winPtr->parentPtr->changes.border_width;
458 parentBorderwidth = 0;
460 deltaX += macParent->xOff + parentBorderwidth +
461 macWin->winPtr->changes.x;
462 deltaY += macParent->yOff + parentBorderwidth +
463 macWin->winPtr->changes.y;
465 UpdateOffsets(macWin->winPtr, deltaX, deltaY);
466 TkMacWinBounds(macWin->winPtr, &bounds);
472 *----------------------------------------------------------------------
476 * Move a given X window. See X windows documentation for further
485 *----------------------------------------------------------------------
490 Display* display, /* Display. */
491 Window window, /* Window. */
495 MacDrawable *macWin = (MacDrawable *) window;
498 destPort = TkMacGetDrawablePort(window);
499 if (destPort == NULL) {
503 SetPort((GrafPtr) destPort);
504 if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
506 * NOTE: we are not adding the new space to the update
507 * region. It is currently assumed that Tk will need
508 * to completely redraw anway.
510 tkMacMoveWindow((WindowRef) destPort, x, y);
512 /* TODO: is the following right? */
513 TkMacInvalidateWindow(macWin, TK_WINDOW_ONLY);
514 TkMacInvalClipRgns(macWin->winPtr);
516 int deltaX, deltaY, parentBorderwidth;
518 MacDrawable *macParent;
521 * Find the Parent window -
522 * For an embedded window this will be its container.
525 if (Tk_IsEmbedded(macWin->winPtr)) {
526 TkWindow *contWinPtr;
528 contWinPtr = TkpGetOtherWindow(macWin->winPtr);
529 if (contWinPtr == NULL) {
530 panic("XMoveWindow could not find container");
532 macParent = contWinPtr->privatePtr;
535 * NOTE: Here we should handle out of process embedding.
539 macParent = macWin->winPtr->parentPtr->privatePtr;
540 if (macParent == NULL) {
541 return; /* TODO: Probably should be a panic */
545 TkMacInvalClipRgns(macParent->winPtr);
546 TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);
548 deltaX = - macWin->xOff;
549 deltaY = - macWin->yOff;
552 * If macWin->winPtr is an embedded window, don't offset by its
553 * parent's borderwidth...
556 if (!Tk_IsEmbedded(macWin->winPtr)) {
557 parentBorderwidth = macWin->winPtr->parentPtr->changes.border_width;
559 parentBorderwidth = 0;
561 deltaX += macParent->xOff + parentBorderwidth +
562 macWin->winPtr->changes.x;
563 deltaY += macParent->yOff + parentBorderwidth +
564 macWin->winPtr->changes.y;
566 UpdateOffsets(macWin->winPtr, deltaX, deltaY);
567 TkMacWinBounds(macWin->winPtr, &bounds);
573 *----------------------------------------------------------------------
577 * Change the stacking order of a window.
583 * Changes the stacking order of the specified window.
585 *----------------------------------------------------------------------
590 Display* display, /* Display. */
591 Window window) /* Window. */
593 MacDrawable *macWin = (MacDrawable *) window;
596 if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
597 TkWmRestackToplevel(macWin->winPtr, Above, NULL);
599 /* TODO: this should generate damage */
604 *----------------------------------------------------------------------
606 * XConfigureWindow --
608 * Change the size, position, stacking, or border of the specified
615 * Changes the attributes of the specified window. Note that we
616 * ignore the passed in values and use the values stored in the
617 * TkWindow data structure.
619 *----------------------------------------------------------------------
624 Display* display, /* Display. */
625 Window w, /* Window. */
626 unsigned int value_mask,
627 XWindowChanges* values)
629 MacDrawable *macWin = (MacDrawable *) w;
630 TkWindow *winPtr = macWin->winPtr;
635 * Change the shape and/or position of the window.
638 if (value_mask & (CWX|CWY|CWWidth|CWHeight)) {
639 XMoveResizeWindow(display, w, winPtr->changes.x, winPtr->changes.y,
640 winPtr->changes.width, winPtr->changes.height);
644 * Change the stacking order of the window. Tk actuall keeps all
645 * the information we need for stacking order. All we need to do
646 * is make sure the clipping regions get updated and generate damage
647 * that will ensure things get drawn correctly.
650 if (value_mask & CWStackMode) {
654 destPort = TkMacGetDrawablePort(w);
655 if (destPort != NULL) {
656 SetPort((GrafPtr) destPort);
657 TkMacInvalClipRgns(winPtr->parentPtr);
658 TkMacWinBounds(winPtr, &bounds);
663 /* TkGenWMMoveRequestEvent(macWin->winPtr,
664 macWin->winPtr->changes.x, macWin->winPtr->changes.y); */
668 *----------------------------------------------------------------------
670 * TkMacUpdateClipRgn --
672 * This function updates the cliping regions for a given window
673 * and all of its children. Once updated the TK_CLIP_INVALID flag
674 * in the subwindow data structure is unset. The TK_CLIP_INVALID
675 * flag should always be unset before any drawing is attempted.
681 * The clip regions for the window and its children are updated.
683 *----------------------------------------------------------------------
694 if (winPtr == NULL) {
698 if (winPtr->privatePtr->flags & TK_CLIP_INVALID) {
699 rgn = winPtr->privatePtr->aboveClipRgn;
700 if (tmpRgn == NULL) {
705 * Start with a region defined by the window bounds.
708 x = winPtr->privatePtr->xOff;
709 y = winPtr->privatePtr->yOff;
710 SetRectRgn(rgn, (short) x, (short) y,
711 (short) (winPtr->changes.width + x),
712 (short) (winPtr->changes.height + y));
715 * Clip away the area of any windows that may obscure this
717 * For a non-toplevel window, first, clip to the parents visable
719 * Second, clip away any siblings that are higher in the
721 * For an embedded toplevel, just clip to the container's visible
722 * clip region. Remember, we only allow one contained window
723 * in a frame, and don't support any other widgets in the frame either.
724 * This is not currently enforced, however.
727 if (!Tk_IsTopLevel(winPtr)) {
728 TkMacUpdateClipRgn(winPtr->parentPtr);
730 winPtr->parentPtr->privatePtr->aboveClipRgn, rgn);
732 win2Ptr = winPtr->nextPtr;
733 while (win2Ptr != NULL) {
734 if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) {
735 win2Ptr = win2Ptr->nextPtr;
738 x = win2Ptr->privatePtr->xOff;
739 y = win2Ptr->privatePtr->yOff;
740 SetRectRgn(tmpRgn, (short) x, (short) y,
741 (short) (win2Ptr->changes.width + x),
742 (short) (win2Ptr->changes.height + y));
743 DiffRgn(rgn, tmpRgn, rgn);
745 win2Ptr = win2Ptr->nextPtr;
747 } else if (Tk_IsEmbedded(winPtr)) {
748 TkWindow *contWinPtr;
750 contWinPtr = TkpGetOtherWindow(winPtr);
752 if (contWinPtr != NULL) {
753 TkMacUpdateClipRgn(contWinPtr);
755 contWinPtr->privatePtr->aboveClipRgn, rgn);
756 } else if (gMacEmbedHandler != NULL) {
757 gMacEmbedHandler->getClipProc((Tk_Window) winPtr, tmpRgn);
758 SectRgn(rgn, tmpRgn, rgn);
762 * NOTE: Here we should handle out of process embedding.
768 * The final clip region is the aboveClip region (or visable
769 * region) minus all the children of this window.
770 * Alternatively, if the window is a container, we must also
771 * subtract the region of the embedded window.
774 rgn = winPtr->privatePtr->clipRgn;
775 CopyRgn(winPtr->privatePtr->aboveClipRgn, rgn);
777 win2Ptr = winPtr->childList;
778 while (win2Ptr != NULL) {
779 if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) {
780 win2Ptr = win2Ptr->nextPtr;
783 x = win2Ptr->privatePtr->xOff;
784 y = win2Ptr->privatePtr->yOff;
785 SetRectRgn(tmpRgn, (short) x, (short) y,
786 (short) (win2Ptr->changes.width + x),
787 (short) (win2Ptr->changes.height + y));
788 DiffRgn(rgn, tmpRgn, rgn);
790 win2Ptr = win2Ptr->nextPtr;
793 if (Tk_IsContainer(winPtr)) {
794 win2Ptr = TkpGetOtherWindow(winPtr);
795 if (win2Ptr != NULL) {
796 if (Tk_IsMapped(win2Ptr)) {
797 x = win2Ptr->privatePtr->xOff;
798 y = win2Ptr->privatePtr->yOff;
799 SetRectRgn(tmpRgn, (short) x, (short) y,
800 (short) (win2Ptr->changes.width + x),
801 (short) (win2Ptr->changes.height + y));
802 DiffRgn(rgn, tmpRgn, rgn);
807 * NOTE: Here we should handle out of process embedding.
812 winPtr->privatePtr->flags &= ~TK_CLIP_INVALID;
817 *----------------------------------------------------------------------
819 * TkMacVisableClipRgn --
821 * This function returnd the Macintosh cliping region for the
822 * given window. A NULL Rgn means the window is not visable.
830 *----------------------------------------------------------------------
837 if (winPtr->privatePtr->flags & TK_CLIP_INVALID) {
838 TkMacUpdateClipRgn(winPtr);
841 return winPtr->privatePtr->clipRgn;
845 *----------------------------------------------------------------------
847 * TkMacInvalidateWindow --
849 * This function makes the window as invalid will generate damage
858 *----------------------------------------------------------------------
862 TkMacInvalidateWindow(
863 MacDrawable *macWin, /* Make window that's causing damage. */
864 int flag) /* Should be TK_WINDOW_ONLY or
865 * TK_PARENT_WINDOW */
868 if (flag == TK_WINDOW_ONLY) {
869 InvalRgn(macWin->clipRgn);
871 if (!EmptyRgn(macWin->aboveClipRgn)) {
872 InvalRgn(macWin->aboveClipRgn);
878 *----------------------------------------------------------------------
880 * TkMacGetDrawablePort --
882 * This function returns the Graphics Port for a given X drawable.
885 * A GWorld pointer. Either an off screen pixmap or a Window.
890 *----------------------------------------------------------------------
894 TkMacGetDrawablePort(
897 MacDrawable *macWin = (MacDrawable *) drawable;
898 GWorldPtr resultPort = NULL;
900 if (macWin == NULL) {
905 * This is NULL for off-screen pixmaps. Then the portPtr
906 * always points to the off-screen port, and we don't
907 * have to worry about containment
910 if (macWin->clipRgn == NULL) {
911 return macWin->portPtr;
915 * If the Drawable is in an embedded window, use the Port of its container.
917 * TRICKY POINT: we can have cases when a toplevel is being destroyed
918 * where the winPtr for the toplevel has been freed, but the children
919 * are not all the way destroyed. The children will call this function
920 * as they are being destroyed, but Tk_IsEmbedded will return garbage.
921 * So we check the copy of the TK_EMBEDDED flag we put into the
922 * toplevel's macWin flags.
925 if (!(macWin->toplevel->flags & TK_EMBEDDED)) {
926 return macWin->toplevel->portPtr;
928 TkWindow *contWinPtr;
930 contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr);
932 if (contWinPtr != NULL) {
933 resultPort = TkMacGetDrawablePort((Drawable) contWinPtr->privatePtr);
934 } else if (gMacEmbedHandler != NULL) {
935 resultPort = gMacEmbedHandler->getPortProc(
936 (Tk_Window) macWin->winPtr);
939 if (resultPort == NULL) {
940 panic("TkMacGetDrawablePort couldn't find container");
945 * NOTE: Here we should handle out of process embedding.
953 *----------------------------------------------------------------------
955 * TkMacInvalClipRgns --
957 * This function invalidates the clipping regions for a given
958 * window and all of its children. This function should be
959 * called whenever changes are made to subwindows that would
960 * effect the size or position of windows.
966 * The cliping regions for the window and its children are
967 * mark invalid. (Make sure they are valid before drawing.)
969 *----------------------------------------------------------------------
979 * If already marked we can stop because all
980 * decendants will also already be marked.
982 if (winPtr->privatePtr->flags & TK_CLIP_INVALID) {
986 winPtr->privatePtr->flags |= TK_CLIP_INVALID;
989 * Invalidate clip regions for all children &
990 * their decendants - unless the child is a toplevel.
992 childPtr = winPtr->childList;
993 while (childPtr != NULL) {
994 if (!Tk_IsTopLevel(childPtr) && Tk_IsMapped(childPtr)) {
995 TkMacInvalClipRgns(childPtr);
997 childPtr = childPtr->nextPtr;
1001 * Also, if the window is a container, mark its embedded window
1004 if (Tk_IsContainer(winPtr)) {
1005 childPtr = TkpGetOtherWindow(winPtr);
1007 if (childPtr != NULL && Tk_IsMapped(childPtr)) {
1008 TkMacInvalClipRgns(childPtr);
1012 * NOTE: Here we should handle out of process embedding.
1019 *----------------------------------------------------------------------
1023 * Given a Tk window this function determines the windows
1024 * bounds in relation to the Macintosh window's coordinate
1025 * system. This is also the same coordinate system as the
1026 * Tk toplevel window in which this window is contained.
1034 *----------------------------------------------------------------------
1042 bounds->left = (short) winPtr->privatePtr->xOff;
1043 bounds->top = (short) winPtr->privatePtr->yOff;
1044 bounds->right = (short) (winPtr->privatePtr->xOff +
1045 winPtr->changes.width);
1046 bounds->bottom = (short) (winPtr->privatePtr->yOff +
1047 winPtr->changes.height);
1051 *----------------------------------------------------------------------
1053 * tkMacMoveWindow --
1055 * A replacement for the Macintosh MoveWindow function. This
1056 * function adjusts the inputs to MoveWindow to offset the root of
1057 * the window system. This has the effect of making the coords
1058 * refer to the window dressing rather than the top of the content.
1064 * Moves the Macintosh window.
1066 *----------------------------------------------------------------------
1075 int xOffset, yOffset;
1077 TkMacWindowOffset(window, &xOffset, &yOffset);
1078 MoveWindow((WindowRef) window,
1079 (short) (x + xOffset), (short) (y + yOffset), false);
1083 *----------------------------------------------------------------------
1087 * Updates the X & Y offsets of the given TkWindow from the
1088 * TopLevel it is a decendant of.
1094 * The xOff & yOff fields for the Mac window datastructure
1095 * is updated to the proper offset.
1097 *----------------------------------------------------------------------
1108 if (winPtr->privatePtr == NULL) {
1110 * We havn't called Tk_MakeWindowExist for this window yet. The
1111 * offset information will be postponed and calulated at that
1112 * time. (This will usually only happen when a mapped parent is
1113 * being moved but has child windows that have yet to be mapped.)
1118 winPtr->privatePtr->xOff += deltaX;
1119 winPtr->privatePtr->yOff += deltaY;
1121 childPtr = winPtr->childList;
1122 while (childPtr != NULL) {
1123 if (!Tk_IsTopLevel(childPtr)) {
1124 UpdateOffsets(childPtr, deltaX, deltaY);
1126 childPtr = childPtr->nextPtr;
1129 if (Tk_IsContainer(winPtr)) {
1130 childPtr = TkpGetOtherWindow(winPtr);
1131 if (childPtr != NULL) {
1132 UpdateOffsets(childPtr,deltaX,deltaY);
1136 * NOTE: Here we should handle out of process embedding.
1143 *----------------------------------------------------------------------
1147 * Creates an in memory drawing surface.
1150 * Returns a handle to a new pixmap.
1153 * Allocates a new Macintosh GWorld.
1155 *----------------------------------------------------------------------
1160 Display *display, /* Display for new pixmap (can be null). */
1161 Drawable d, /* Drawable where pixmap will be used (ignored). */
1162 int width, /* Dimensions of pixmap. */
1164 int depth) /* Bits per pixel for pixmap. */
1169 MacDrawable *macPix;
1170 PixMapHandle pixels;
1172 if (display != NULL) {
1175 macPix = (MacDrawable *) ckalloc(sizeof(MacDrawable));
1176 macPix->winPtr = NULL;
1179 macPix->clipRgn = NULL;
1180 macPix->aboveClipRgn = NULL;
1181 macPix->referenceCount = 0;
1182 macPix->toplevel = NULL;
1185 bounds.top = bounds.left = 0;
1186 bounds.right = (short) width;
1187 bounds.bottom = (short) height;
1193 * Allocate memory for the off screen pixmap. If we fail
1194 * try again from system memory. Eventually, we may have
1197 err = NewGWorld(&gWorld, depth, &bounds, NULL, NULL, 0);
1199 err = NewGWorld(&gWorld, depth, &bounds, NULL, NULL, useTempMem);
1202 panic("Out of memory: NewGWorld failed in Tk_GetPixmap");
1206 * Lock down the pixels so they don't move out from under us.
1208 pixels = GetGWorldPixMap(gWorld);
1210 macPix->portPtr = gWorld;
1212 return (Pixmap) macPix;
1216 *----------------------------------------------------------------------
1220 * Release the resources associated with a pixmap.
1226 * Deletes the Macintosh GWorld created by Tk_GetPixmap.
1228 *----------------------------------------------------------------------
1233 Display *display, /* Display. */
1234 Pixmap pixmap) /* Pixmap to destroy */
1236 MacDrawable *macPix = (MacDrawable *) pixmap;
1237 PixMapHandle pixels;
1240 pixels = GetGWorldPixMap(macPix->portPtr);
1241 UnlockPixels(pixels);
1242 DisposeGWorld(macPix->portPtr);
1243 ckfree((char *) macPix);