diff options
Diffstat (limited to 'macosx/tkMacOSXSubwindows.c')
-rw-r--r-- | macosx/tkMacOSXSubwindows.c | 522 |
1 files changed, 199 insertions, 323 deletions
diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index ca72bd5..9b01178 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -4,13 +4,13 @@ * Implements subwindows for the macintosh version of Tk. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. - * Copyright 2001, Apple Computer, Inc. - * Copyright (c) 2006-2008 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright 2001-2009, Apple Inc. + * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> * - * See the file "license.terms" for information on usage and redistribution of - * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXSubwindows.c,v 1.29 2008/10/27 11:55:45 dkf Exp $ + * RCS: @(#) $Id: tkMacOSXSubwindows.c,v 1.30 2009/06/29 14:35:01 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -33,32 +33,7 @@ static void GenerateConfigureNotify(TkWindow *winPtr, static void UpdateOffsets(TkWindow *winPtr, int deltaX, int deltaY); static void NotifyVisibility(TkWindow *winPtr, XEvent *eventPtr); - -/* - *---------------------------------------------------------------------- - * - * AllocGWorld -- - * Simplifies the allocation of new drawable ports. - * - *---------------------------------------------------------------------- - */ - -static inline void -AllocGWorld( - int width, - int height, - int mono, - CGrafPtr *grafPtrPtr) -{ - Rect bounds = {0, 0, height, width}; -#ifdef __LITTLE_ENDIAN__ - ChkErr(NewGWorld, grafPtrPtr, mono ? 1 : 0, &bounds, NULL, NULL, - kNativeEndianPixMap); -#else - ChkErr(NewGWorld, grafPtrPtr, mono ? 1 : 0, &bounds, NULL, NULL, 0); -#endif -} /* *---------------------------------------------------------------------- @@ -82,7 +57,6 @@ XDestroyWindow( Window window) /* Window. */ { MacDrawable *macWin = (MacDrawable *) window; - WindowRef winRef; /* * Remove any dangling pointers that may exist if the window we are @@ -90,6 +64,7 @@ XDestroyWindow( */ TkPointerDeadWindow(macWin->winPtr); + TkMacOSXSelDeadWindow(macWin->winPtr); macWin->toplevel->referenceCount--; if (!Tk_IsTopLevel(macWin->winPtr)) { @@ -103,6 +78,9 @@ XDestroyWindow( if (macWin->aboveVisRgn) { CFRelease(macWin->aboveVisRgn); } + if (macWin->drawRgn) { + CFRelease(macWin->drawRgn); + } if (macWin->toplevel->referenceCount == 0) { ckfree((char *) macWin->toplevel); @@ -110,107 +88,16 @@ XDestroyWindow( ckfree((char *) macWin); return; } - - /* - * We are relying on the Activate Mac OS event to pass the focus away from - * a window that is getting Destroyed to the Front non-floating window. BUT - * we don't get activate events when a floating window is destroyed, since - * the front non-floating window doesn't in fact get activated... So maybe - * we can check here and if we are destroying a floating window, we can - * pass the focus back to the front non-floating window... - */ - - if (macWin->grafPtr != NULL) { - TkWindow *focusPtr = TkGetFocusWin(macWin->winPtr); - - if (focusPtr == NULL - || (focusPtr->mainPtr->winPtr == macWin->winPtr)) { - winRef = TkMacOSXDrawableWindow(window); - if (TkpIsWindowFloating (winRef)) { - Window window = TkMacOSXGetXWindow(ActiveNonFloatingWindow()); - - if (window != None) { - TkMacOSXGenerateFocusEvent(window, 1); - } - } - } - } if (macWin->visRgn) { CFRelease(macWin->visRgn); } if (macWin->aboveVisRgn) { CFRelease(macWin->aboveVisRgn); } - - /* - * Delete the Mac window and remove it from the windowTable. The window - * could be NULL if the window was never mapped. However, we don't do this - * for embedded windows, they don't go in the window list, and they do not - * own their portPtr's. - */ - - if (!Tk_IsEmbedded(macWin->winPtr)) { - WindowRef winRef = TkMacOSXDrawableWindow(window); - - if (winRef) { - TkMacOSXWindowList *listPtr, *prevPtr; - WindowGroupRef group; - - if (GetWindowProperty(winRef, 'Tk ', 'TsGp', sizeof(group), NULL, - &group) == noErr) { - TkDisplay *dispPtr = TkGetDisplayList(); - ItemCount i = CountWindowGroupContents(group, - kWindowGroupContentsReturnWindows); - WindowRef macWin; - WindowGroupRef newGroup; - Window window; - - while (i > 0) { - ChkErr(GetIndexedWindow, group, i--, 0, &macWin); - if (!macWin) { - continue; - } - - window = TkMacOSXGetXWindow(macWin); - newGroup = NULL; - if (window != None) { - TkWindow *winPtr = (TkWindow *) - Tk_IdToWindow(dispPtr->display, window); - - if (winPtr && winPtr->wmInfoPtr) { - newGroup = GetWindowGroupOfClass( - winPtr->wmInfoPtr->macClass); - } - } - if (!newGroup) { - newGroup = - GetWindowGroupOfClass(kDocumentWindowClass); - } - ChkErr(SetWindowGroup, macWin, newGroup); - } - ChkErr(SetWindowGroupOwner, group, NULL); - ChkErr(ReleaseWindowGroup, group); - } - TkMacOSXUnregisterMacWindow(winRef); - DisposeWindow(winRef); - - for (listPtr=tkMacOSXWindowListPtr, prevPtr=NULL; - tkMacOSXWindowListPtr != NULL; - prevPtr=listPtr, listPtr=listPtr->nextPtr) { - if (listPtr->winPtr == macWin->winPtr) { - if (prevPtr == NULL) { - tkMacOSXWindowListPtr = listPtr->nextPtr; - } else { - prevPtr->nextPtr = listPtr->nextPtr; - } - ckfree((char *) listPtr); - break; - } - } - } + if (macWin->drawRgn) { + CFRelease(macWin->drawRgn); } - - macWin->grafPtr = NULL; + macWin->view = nil; /* * Delay deletion of a toplevel data structure untill all children have @@ -263,20 +150,11 @@ XMapWindow( macWin->winPtr->flags |= TK_MAPPED; if (Tk_IsTopLevel(macWin->winPtr)) { if (!Tk_IsEmbedded(macWin->winPtr)) { - /* - * XXX This should be ShowSheetWindow for kSheetWindowClass - * XXX windows that have a wmPtr->master parent set. - */ + NSWindow *win = TkMacOSXDrawableWindow(window); - WindowRef wRef = TkMacOSXDrawableWindow(window); - - if ((macWin->winPtr->wmInfoPtr->macClass == kSheetWindowClass) - && (macWin->winPtr->wmInfoPtr->master != None)) { - ShowSheetWindow(wRef, TkMacOSXDrawableWindow( - macWin->winPtr->wmInfoPtr->master)); - } else { - ShowWindow(wRef); - } + [win makeKeyAndOrderFront:NSApp]; + [win windowRef]; + TkMacOSXApplyWindowAttributes(macWin->winPtr, win); } TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr); @@ -284,7 +162,7 @@ XMapWindow( * We only need to send the MapNotify event for toplevel windows. */ - event.xany.serial = display->request; + event.xany.serial = LastKnownRequestProcessed(display); event.xany.send_event = False; event.xany.display = display; @@ -319,7 +197,7 @@ XMapWindow( * NotifyVisibility -- * * Recursively called helper proc for XMapWindow(). - + * * Results: * None. * @@ -377,18 +255,11 @@ XUnmapWindow( if (Tk_IsTopLevel(macWin->winPtr)) { if (!Tk_IsEmbedded(macWin->winPtr) && macWin->winPtr->wmInfoPtr->hints.initial_state!=IconicState) { - /* - * XXX This should be HideSheetWindow for kSheetWindowClass - * XXX windows that have a wmPtr->master parent set. - */ - - WindowRef wref = TkMacOSXDrawableWindow(window); + NSWindow *win = TkMacOSXDrawableWindow(window); - if ((macWin->winPtr->wmInfoPtr->macClass == kSheetWindowClass) - && (macWin->winPtr->wmInfoPtr->master != None)) { - HideSheetWindow(wref); - } else { - HideWindow(wref); + if ([win isVisible]) { + [[win parentWindow] removeChildWindow:win]; + [win orderOut:NSApp]; } } TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr); @@ -397,7 +268,7 @@ XUnmapWindow( * We only need to send the UnmapNotify event for toplevel windows. */ - event.xany.serial = display->request; + event.xany.serial = LastKnownRequestProcessed(display); event.xany.send_event = False; event.xany.display = display; @@ -444,15 +315,14 @@ XResizeWindow( display->request++; if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { - WindowRef w = TkMacOSXDrawableWindow(window); + NSWindow *w = macWin->winPtr->wmInfoPtr->window; if (w) { - Rect bounds; - - ChkErr(GetWindowBounds, w, kWindowContentRgn, &bounds); - bounds.right = bounds.left + width; - bounds.bottom = bounds.top + height; - ChkErr(SetWindowBounds, w, kWindowContentRgn, &bounds); + NSRect r = [w contentRectForFrameRect:[w frame]]; + r.origin.y += r.size.height - height; + r.size.width = width; + r.size.height = height; + [w setFrame:[w frameRectForContentRect:r] display:YES]; } } else { MoveResizeWindow(macWin); @@ -488,16 +358,14 @@ XMoveResizeWindow( display->request++; if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { - WindowRef w = TkMacOSXDrawableWindow(window); + NSWindow *w = macWin->winPtr->wmInfoPtr->window; if (w) { - Rect bounds; - - bounds.left = x + macWin->winPtr->wmInfoPtr->xInParent; - bounds.right = bounds.left + width; - bounds.top = y + macWin->winPtr->wmInfoPtr->yInParent; - bounds.bottom = bounds.top + height; - ChkErr(SetWindowBounds, w, kWindowContentRgn, &bounds); + NSRect r = NSMakeRect(x + macWin->winPtr->wmInfoPtr->xInParent, + tkMacOSXZeroScreenHeight - (y + + macWin->winPtr->wmInfoPtr->yInParent + height), + width, height); + [w setFrame:[w frameRectForContentRect:r] display:YES]; } } else { MoveResizeWindow(macWin); @@ -531,10 +399,10 @@ XMoveWindow( display->request++; if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { - WindowRef w = TkMacOSXDrawableWindow(window); + NSWindow *w = macWin->winPtr->wmInfoPtr->window; if (w) { - ChkErr(MoveWindowStructure, w, x, y); + [w setFrameTopLeftPoint:NSMakePoint(x, tkMacOSXZeroScreenHeight - y)]; } } else { MoveResizeWindow(macWin); @@ -563,7 +431,7 @@ MoveResizeWindow( { int deltaX = 0, deltaY = 0, parentBorderwidth = 0; MacDrawable *macParent = NULL; - CGrafPtr destPort = TkMacOSXGetDrawablePort((Drawable) macWin); + NSWindow *macWindow = TkMacOSXDrawableWindow((Drawable) macWin); /* * Find the Parent window, for an embedded window it will be its container. @@ -597,14 +465,14 @@ MoveResizeWindow( deltaY = macParent->yOff + parentBorderwidth + macWin->winPtr->changes.y - macWin->yOff; } - if (destPort) { + if (macWindow) { TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); if (macParent) { TkMacOSXInvalClipRgns((Tk_Window) macParent->winPtr); } } UpdateOffsets(macWin->winPtr, deltaX, deltaY); - if (destPort) { + if (macWindow) { TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); } GenerateConfigureNotify(macWin->winPtr, 0); @@ -762,13 +630,17 @@ XConfigureWindow( */ if (value_mask & CWStackMode) { + NSView *view = TkMacOSXDrawableView(macWin); Rect bounds; - WindowRef wRef = TkMacOSXDrawableWindow(w); + NSRect r; - if (wRef) { + if (view) { TkMacOSXInvalClipRgns((Tk_Window) winPtr->parentPtr); TkMacOSXWinBounds(winPtr, &bounds); - InvalWindowRect(wRef, &bounds); + r = NSMakeRect(bounds.left, + [view bounds].size.height - bounds.bottom, + bounds.right - bounds.left, bounds.bottom - bounds.top); + [view setNeedsDisplayInRect:r]; } } @@ -808,6 +680,9 @@ TkMacOSXUpdateClipRgn( if (macWin && macWin->flags & TK_CLIP_INVALID) { TkWindow *win2Ptr; +#ifdef TK_MAC_DEBUG_CLIP_REGIONS + TkMacOSXDbgMsg("%s", winPtr->pathName); +#endif if (Tk_IsMapped(winPtr)) { int rgnChanged = 0; CGRect bounds; @@ -852,14 +727,14 @@ TkMacOSXUpdateClipRgn( ChkErr(HIShapeIntersect, win2Ptr->privatePtr->aboveVisRgn, rgn, rgn); } else if (tkMacOSXEmbedHandler != NULL) { + TkRegion r = TkCreateRegion(); HIShapeRef visRgn; - TkMacOSXCheckTmpQdRgnEmpty(); - tkMacOSXEmbedHandler->getClipProc((Tk_Window) winPtr, - tkMacOSXtmpQdRgn); - visRgn = HIShapeCreateWithQDRgn(tkMacOSXtmpQdRgn); - SetEmptyRgn(tkMacOSXtmpQdRgn); + tkMacOSXEmbedHandler->getClipProc((Tk_Window) winPtr, r); + visRgn = TkMacOSXGetNativeRegion(r); ChkErr(HIShapeIntersect, visRgn, rgn, rgn); + CFRelease(visRgn); + TkpReleaseRegion(r); } /* @@ -867,16 +742,13 @@ TkMacOSXUpdateClipRgn( */ } else if (winPtr->wmInfoPtr->attributes & kWindowResizableAttribute) { - HIViewRef growBoxView; - OSErr err = HIViewFindByID(HIViewGetRoot( - TkMacOSXDrawableWindow(winPtr->window)), - kHIViewWindowGrowBoxID, &growBoxView); - - if (err == noErr) { - ChkErr(HIViewGetFrame, growBoxView, &bounds); - bounds = CGRectOffset(bounds, - -winPtr->wmInfoPtr->xInParent, - -winPtr->wmInfoPtr->yInParent); + NSWindow *w = TkMacOSXDrawableWindow(winPtr->window); + + if (w) { + bounds = NSRectToCGRect([w _growBoxRect]); + bounds.origin.y = [w contentRectForFrameRect: + [w frame]].size.height - bounds.size.height - + bounds.origin.y; ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds); } } @@ -947,10 +819,6 @@ TkMacOSXUpdateClipRgn( macWin->visRgn = HIShapeCreateCopy(macWin->aboveVisRgn); } macWin->flags &= ~TK_CLIP_INVALID; - -#ifdef TK_MAC_DEBUG_CLIP_REGIONS - TkMacOSXDebugFlashRegion((Drawable) macWin, macWin->visRgn); -#endif /* TK_MAC_DEBUG_CLIP_REGIONS */ } } @@ -959,8 +827,9 @@ TkMacOSXUpdateClipRgn( * * TkMacOSXVisableClipRgn -- * - * This function returnd the Macintosh cliping region for the given - * window. A NULL Rgn means the window is not visible. + * This function returns the Macintosh cliping region for the given + * window. The caller is responsible for disposing of the returned + * region via TkDestroyRegion(). * * Results: * The region. @@ -971,20 +840,63 @@ TkMacOSXUpdateClipRgn( *---------------------------------------------------------------------- */ -RgnHandle +TkRegion TkMacOSXVisableClipRgn( TkWindow *winPtr) { - static RgnHandle visQdRgn = NULL; - - if (visQdRgn == NULL) { - visQdRgn = NewRgn(); - } if (winPtr->privatePtr->flags & TK_CLIP_INVALID) { TkMacOSXUpdateClipRgn(winPtr); } - ChkErr(HIShapeGetAsQDRgn, winPtr->privatePtr->visRgn, visQdRgn); - return visQdRgn; + return (TkRegion)HIShapeCreateMutableCopy(winPtr->privatePtr->visRgn); +} + +/* + *---------------------------------------------------------------------- + * + * TkMacOSXInvalidateViewRegion -- + * + * This function invalidates the given region of a view. + * + * Results: + * None. + * + * Side effects: + * Damage is created. + * + *---------------------------------------------------------------------- + */ + +static OSStatus +InvalViewRect(int msg, HIShapeRef rgn, const CGRect *rect, void *ref) { + static CGAffineTransform t; + NSView *view = ref; + + if (!view) { + return paramErr; + } + switch (msg) { + case kHIShapeEnumerateInit: + t = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, + NSHeight([view bounds])); + break; + case kHIShapeEnumerateRect: + [view setNeedsDisplayInRect:NSRectFromCGRect( + CGRectApplyAffineTransform(*rect, t))]; + break; + } + return noErr; +} + +void +TkMacOSXInvalidateViewRegion( + NSView *view, + HIShapeRef rgn) +{ + if (view && !HIShapeIsEmpty(rgn)) { + ChkErr(HIShapeEnumerate, rgn, + kHIShapeParseFromBottom|kHIShapeParseFromLeft, + InvalViewRect, view); + } } /* @@ -992,8 +904,7 @@ TkMacOSXVisableClipRgn( * * TkMacOSXInvalidateWindow -- * - * This function makes the window as invalid will generate damage for the - * window. + * This function invalidates a window and (optionally) its children. * * Results: * None. @@ -1006,38 +917,29 @@ TkMacOSXVisableClipRgn( void TkMacOSXInvalidateWindow( - MacDrawable *macWin, /* Make window that's causing damage. */ + MacDrawable *macWin, /* Window to be invalidated. */ int flag) /* Should be TK_WINDOW_ONLY or * TK_PARENT_WINDOW */ { - WindowRef windowRef; - HIShapeRef rgn; - - windowRef = TkMacOSXDrawableWindow((Drawable)macWin); +#ifdef TK_MAC_DEBUG_CLIP_REGIONS + TkMacOSXDbgMsg("%s", winPtr->pathName); +#endif if (macWin->flags & TK_CLIP_INVALID) { TkMacOSXUpdateClipRgn(macWin->winPtr); } - rgn = (flag == TK_WINDOW_ONLY) ? macWin->visRgn : macWin->aboveVisRgn; - if (!HIShapeIsEmpty(rgn)) { - TkMacOSXCheckTmpQdRgnEmpty(); - ChkErr(HIShapeGetAsQDRgn, rgn, tkMacOSXtmpQdRgn); - InvalWindowRgn(windowRef, tkMacOSXtmpQdRgn); - SetEmptyRgn(tkMacOSXtmpQdRgn); - } -#ifdef TK_MAC_DEBUG_CLIP_REGIONS - TkMacOSXDebugFlashRegion((Drawable) macWin, rgn); -#endif /* TK_MAC_DEBUG_CLIP_REGIONS */ + TkMacOSXInvalidateViewRegion(TkMacOSXDrawableView(macWin), + (flag == TK_WINDOW_ONLY) ? macWin->visRgn : macWin->aboveVisRgn); } /* *---------------------------------------------------------------------- * - * TkMacOSXGetDrawableWindow -- + * TkMacOSXDrawableWindow -- * - * This function returns the WindowRef for a given X drawable. + * This function returns the NSWindow for a given X drawable. * * Results: - * A WindowRef, or NULL for off screen pixmaps. + * A NSWindow, or nil for off screen pixmaps. * * Side effects: * None. @@ -1045,17 +947,27 @@ TkMacOSXInvalidateWindow( *---------------------------------------------------------------------- */ -WindowRef +NSWindow* TkMacOSXDrawableWindow( Drawable drawable) { MacDrawable *macWin = (MacDrawable *) drawable; - WindowRef result = NULL; + NSWindow *result = nil; if (!macWin || macWin->flags & TK_IS_PIXMAP) { - result = NULL; - } else { - result = GetWindowFromPort(TkMacOSXGetDrawablePort(drawable)); + result = nil; + } else if (macWin->toplevel && macWin->toplevel->winPtr && + macWin->toplevel->winPtr->wmInfoPtr && + macWin->toplevel->winPtr->wmInfoPtr->window) { + result = macWin->toplevel->winPtr->wmInfoPtr->window; + } else if (macWin->winPtr && macWin->winPtr->wmInfoPtr && + macWin->winPtr->wmInfoPtr->window) { + result = macWin->winPtr->wmInfoPtr->window; + } else if (macWin->toplevel && (macWin->toplevel->flags & TK_EMBEDDED)) { + TkWindow *contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr); + if (contWinPtr) { + result = TkMacOSXDrawableWindow((Drawable) contWinPtr->privatePtr); + } } return result; } @@ -1068,7 +980,7 @@ TkMacOSXDrawableWindow( * This function returns the Graphics Port for a given X drawable. * * Results: - * A CGrafPort. Either an off screen pixmap or a Window. + * NULL. * * Side effects: * None. @@ -1076,74 +988,48 @@ TkMacOSXDrawableWindow( *---------------------------------------------------------------------- */ -CGrafPtr +void * TkMacOSXGetDrawablePort( Drawable drawable) { - MacDrawable *macWin = (MacDrawable *) drawable; - CGrafPtr resultPort = NULL; - - if (!macWin) { - return NULL; - } - - /* - * Handle toplevel windows. - */ - - if (macWin->toplevel) { - TkWindow *contWinPtr; - - if (!(macWin->toplevel->flags & TK_EMBEDDED)) { - return macWin->toplevel->grafPtr; - } - - /* - * If the Drawable is in an embedded window, use the Port of its - * container. - * - * TRICKY POINT: we can have cases when a toplevel is being destroyed - * where the winPtr for the toplevel has been freed, but the children - * are not all the way destroyed. The children will call this function - * as they are being destroyed, but Tk_IsEmbedded will return garbage. - * So we check the copy of the TK_EMBEDDED flag we put into the - * toplevel's macWin flags. - */ - - contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr); - - resultPort = NULL; - if (contWinPtr != NULL) { - resultPort = TkMacOSXGetDrawablePort((Drawable) - contWinPtr->privatePtr); - } else if (tkMacOSXEmbedHandler != NULL) { - resultPort = tkMacOSXEmbedHandler->getPortProc((Tk_Window) - macWin->winPtr); - } + return NULL; +} + +/* + *---------------------------------------------------------------------- + * + * TkMacOSXDrawableView -- + * + * This function returns the NSView for a given X drawable. + * + * Results: + * A NSView* or nil. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ - if (!resultPort) { - /* - * FIXME: So far as I can tell, the only time that this happens is - * when we are tearing down an embedded child interpreter, and most - * of the time, this is harmless... However, we really need to find - * why the embedding loses. - */ +NSView* +TkMacOSXDrawableView( + MacDrawable *macWin) +{ + NSView *result = nil; - TkMacOSXDbgMsg("Couldn't find container"); + if (!macWin) { + result = nil; + } else if (!macWin->toplevel) { + result = macWin->view; + } else if (!(macWin->toplevel->flags & TK_EMBEDDED)) { + result = macWin->toplevel->view; + } else { + TkWindow *contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr); + if (contWinPtr) { + result = TkMacOSXDrawableView(contWinPtr->privatePtr); } - - /* - * TODO: Here we should handle out of process embedding. - */ - - return resultPort; - } - - if ((macWin->flags & TK_IS_PIXMAP) && !macWin->grafPtr) { - AllocGWorld(macWin->size.width, macWin->size.height, - macWin->flags & TK_IS_BW_PIXMAP, &macWin->grafPtr); } - return macWin->grafPtr; + return result; } /* @@ -1151,10 +1037,10 @@ TkMacOSXGetDrawablePort( * * TkMacOSXGetRootControl -- * - * This function returns the Root Control for a given X drawable. + * This function returns the NSView for a given X drawable. * * Results: - * A ControlRef . + * A NSView* . * * Side effects: * None. @@ -1162,7 +1048,7 @@ TkMacOSXGetDrawablePort( *---------------------------------------------------------------------- */ -ControlRef +void * TkMacOSXGetRootControl( Drawable drawable) { @@ -1170,23 +1056,7 @@ TkMacOSXGetRootControl( * will probably need to fix this up for embedding */ - MacDrawable *macWin = (MacDrawable *) drawable; - TkWindow *contWinPtr; - - if (macWin == NULL) { - return NULL; - } - - if (!(macWin->toplevel->flags & TK_EMBEDDED)) { - return macWin->toplevel->rootControl; - } - - contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr); - if (contWinPtr == NULL) { - return NULL; - } - - return TkMacOSXGetRootControl((Drawable) contWinPtr->privatePtr); + return TkMacOSXDrawableView((MacDrawable *) drawable); } /* @@ -1235,6 +1105,10 @@ TkMacOSXInvalClipRgns( CFRelease(macWin->aboveVisRgn); macWin->aboveVisRgn = NULL; } + if (macWin->drawRgn) { + CFRelease(macWin->drawRgn); + macWin->drawRgn = NULL; + } /* * Invalidate clip regions for all children & their descendants, unless the @@ -1288,12 +1162,13 @@ TkMacOSXInvalClipRgns( void TkMacOSXWinBounds( TkWindow *winPtr, - Rect *bounds) + void *bounds) { - bounds->left = winPtr->privatePtr->xOff; - bounds->top = winPtr->privatePtr->yOff; - bounds->right = bounds->left + winPtr->changes.width; - bounds->bottom = bounds->top + winPtr->changes.height; + Rect *b = (Rect *)bounds; + b->left = winPtr->privatePtr->xOff; + b->top = winPtr->privatePtr->yOff; + b->right = b->left + winPtr->changes.width; + b->bottom = b->top + winPtr->changes.height; } /* @@ -1421,14 +1296,13 @@ Tk_GetPixmap( macPix->yOff = 0; macPix->visRgn = NULL; macPix->aboveVisRgn = NULL; - macPix->drawRect = CGRectNull; + macPix->drawRgn = NULL; macPix->referenceCount = 0; macPix->toplevel = NULL; macPix->flags = TK_IS_PIXMAP | (depth == 1 ? TK_IS_BW_PIXMAP : 0); - macPix->grafPtr = NULL; + macPix->view = nil; macPix->context = NULL; macPix->size = CGSizeMake(width, height); - AllocGWorld(width, height, depth==1, &macPix->grafPtr); return (Pixmap) macPix; } @@ -1457,11 +1331,13 @@ Tk_FreePixmap( MacDrawable *macPix = (MacDrawable *) pixmap; display->request++; - if (macPix->grafPtr) { - DisposeGWorld(macPix->grafPtr); - } if (macPix->context) { - TkMacOSXDbgMsg("Cannot free CG backed Pixmap"); + char *data = CGBitmapContextGetData(macPix->context); + + if (data) { + ckfree(data); + } + CFRelease(macPix->context); } ckfree((char *) macPix); } |