diff options
author | Kevin Walzer <kw@codebykevin.com> | 2017-11-11 04:02:41 (GMT) |
---|---|---|
committer | Kevin Walzer <kw@codebykevin.com> | 2017-11-11 04:02:41 (GMT) |
commit | d5df7df7c8c66da6af400db30f3561061140647c (patch) | |
tree | c01bdc632bdee1086a399bb436c3aa30c87d6016 /macosx | |
parent | 8640ffb2f18ad6d88fffa87459e16b7578f4bab5 (diff) | |
download | tk-d5df7df7c8c66da6af400db30f3561061140647c.zip tk-d5df7df7c8c66da6af400db30f3561061140647c.tar.gz tk-d5df7df7c8c66da6af400db30f3561061140647c.tar.bz2 |
Implement wm_iconphoto command for macOS
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/tkMacOSXNotify.c | 6 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 48 |
2 files changed, 24 insertions, 30 deletions
diff --git a/macosx/tkMacOSXNotify.c b/macosx/tkMacOSXNotify.c index b78d7ff..ac0c0ec 100644 --- a/macosx/tkMacOSXNotify.c +++ b/macosx/tkMacOSXNotify.c @@ -276,15 +276,15 @@ TkMacOSXEventsCheckProc( inMode:GetRunLoopMode(modalSession) dequeue:NO]; /* We must not steal any events during LiveResize. */ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (testEvent && [[testEvent window] inLiveResize]) { break; } -#else + #else if (testEvent && [[[testEvent window] contentView] inLiveResize]) { break; } -#endif + #endif currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:GetRunLoopMode(modalSession) diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index e9b38b5..829c796 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -2329,8 +2329,7 @@ WmIconnameCmd( * WmIconphotoCmd -- * * This procedure is invoked to process the "wm iconphoto" Tcl command. - * See the user documentation for details on what it does. Not yet - * implemented for OS X. + * See the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2338,6 +2337,7 @@ WmIconnameCmd( * Side effects: * See the user documentation. * + * *---------------------------------------------------------------------- */ static int @@ -2348,45 +2348,39 @@ WmIconphotoCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - Tk_PhotoHandle photo; + Tk_Image tk_icon; int i, width, height, isDefault = 0; if (objc < 4) { Tcl_WrongNumArgs(interp, 2, objv, - "window ?-default? image1 ?image2 ...?"); + "window ?-default? image1 ?image2 ...?"); return TCL_ERROR; } + if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) { isDefault = 1; if (objc == 4) { Tcl_WrongNumArgs(interp, 2, objv, - "window ?-default? image1 ?image2 ...?"); - return TCL_ERROR; - } - } - - /* - * Iterate over all images to retrieve their sizes, in order to allocate a - * buffer large enough to hold all images. - */ - - for (i = 3 + isDefault; i < objc; i++) { - photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i])); - if (photo == NULL) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "can't use \"%s\" as iconphoto: not a photo image", - Tcl_GetString(objv[i]))); - Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "PHOTO", NULL); + "window ?-default? image1 ?image2 ...?"); return TCL_ERROR; } - Tk_PhotoGetSize(photo, &width, &height); } - /* - * TODO: This requires implementation for OS X, but we silently return for - * now. - */ - + char *icon; + if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) { + icon = Tcl_GetString(objv[4]); + } else { + icon = Tcl_GetString(objv[3]); + } + + tk_icon = Tk_GetImage(interp, winPtr, icon, NULL, NULL); + Tk_SizeOfImage(tk_icon, &width, &height); + + NSImage *newIcon; + newIcon = TkMacOSXGetNSImageWithTkImage(winPtr->display, tk_icon, width, height); + [NSApp setApplicationIconImage: newIcon]; + + Tk_FreeImage(tk_icon); return TCL_OK; } |