static PyObject *Icn_PlotIcon(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; Rect theRect; Handle theIcon; #ifndef PlotIcon PyMac_PRECHECK(PlotIcon); #endif if (!PyArg_ParseTuple(_args, "O&O&", PyMac_GetRect, &theRect, ResObj_Convert, &theIcon)) return NULL; PlotIcon(&theRect, theIcon); Py_INCREF(Py_None); _res = Py_None; return _res; }
boolean ploticon (const Rect *r, short id) { /* plot the icon with the given id in rect r. if a color icon is available, and the machine supports color, use the color version */ #ifdef MACVERSION Handle hicon; CIconHandle hcicn; if (systemhascolor ()) { hcicn = GetCIcon (id); if (hcicn != nil) { PlotCIcon (r, hcicn); DisposeCIcon (hcicn); return (true); } } hicon = GetResource ('ICON', id); if (hicon != nil) { PlotIcon (r, hicon); return (true); } return (false); #endif #ifdef WIN95VERSION return (ploticonresource (r, 0, 0, id)); #endif } /*ploticon*/
Pixmap TkpCreateNativeBitmap( Display *display, CONST char *source) /* Info about the icon to build. */ { Pixmap pix; Rect destRect; CGrafPtr savePort; Boolean portChanged; const NativeIcon *nativeIconPtr; pix = Tk_GetPixmap(display, None, 32, 32, 0); portChanged = QDSwapPort(TkMacOSXGetDrawablePort(pix), &savePort); nativeIconPtr = (const NativeIcon *) source; SetRect(&destRect, 0, 0, 32, 32); if (nativeIconPtr->type == TYPE1) { RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF}; RGBForeColor(&white); PaintRect(&destRect); PlotIconID(&destRect, atAbsoluteCenter, ttNone, nativeIconPtr->id); } else if (nativeIconPtr->type == TYPE2) { Handle icon = GetIcon(nativeIconPtr->id); if (icon != NULL) { RGBColor black = {0, 0, 0}; RGBForeColor(&black); PlotIcon(&destRect, icon); ReleaseResource(icon); } } if (portChanged) { QDSwapPort(savePort, NULL); } return pix; }
boolean ploticonresource (const Rect *r, short align, short transform, short resid) { /* 1.0b20 dmb: try plotting cicn if icon family isn't found. This allows all of the stand system icons to be used. 1.0b21 dmb: try geting normal b&w icon if all else fails 5.0a8 dmb: use srccopy, not srcand for win blits Note that the Windows version does NOT use the transform parameter */ #ifdef MACVERSION OSErr ec; CIconHandle hcicon; Handle hicon; Rect rlocal = *r; #ifdef SWAP_BYTE_ORDER /* For some unknown reason the Intel OS X builds shift the icon displays */ rlocal.top += 3; rlocal.bottom += 3; rlocal.left += 6; rlocal.right += 6; #endif ec = PlotIconID (&rlocal, align, transform, resid); if (ec == noErr) return (true); hcicon = GetCIcon (resid); if (hcicon != nil) { PlotCIcon (&rlocal, hcicon); DisposeCIcon (hcicon); return (true); } hicon = GetIcon (resid); if (hicon != nil) { PlotIcon (&rlocal, hicon); /*ReleaseResource (hicon);*/ /*dmb 1.0b21 - don't need to*/ return (true); } return (false); #endif #ifdef WIN95VERSION HBITMAP hbm, oldbm; BITMAP bm; HDC hdcsrc, hdc; boolean flprinting; HDC hdcmask; HBITMAP hbmmask, oldmaskbm; COLORREF oldclr, oldclr2; hbm = LoadBitmap (shellinstance, MAKEINTRESOURCE (resid)); if (hbm) { hdc = getcurrentDC(); flprinting = iscurrentportprintport (); if (hdc) { hdcsrc = CreateCompatibleDC (hdc); if (hdcsrc) { GetObject (hbm, sizeof (BITMAP), &bm); oldbm = (HBITMAP) SelectObject (hdcsrc, hbm); if (flprinting) { // StretchBlt (hdc, r->left, r->top, r->right-r->left, r->bottom - r->top, hdcsrc, 0,0, bm.bmWidth, bm.bmHeight, SRCCOPY); } else { hdcmask = CreateCompatibleDC (hdc); hbmmask = CreateBitmap (bm.bmWidth, bm.bmHeight, 1, 1, NULL); if (hdcmask && hbmmask) { oldmaskbm = (HBITMAP) SelectObject (hdcmask, hbmmask); oldclr = SetBkColor (hdcsrc, RGB(255,255,255)); BitBlt (hdcmask, 0,0,bm.bmWidth, bm.bmHeight, hdcsrc, 0,0, SRCCOPY); SetBkColor (hdcsrc,oldclr); eraserect (*r); oldclr = SetBkColor (hdc, RGB(255,255,255)); oldclr2 = SetTextColor (hdc, RGB(0,0,0)); BitBlt (hdc, r->left, r->bottom - bm.bmHeight, bm.bmWidth, bm.bmHeight, hdcsrc, 0,0, SRCINVERT); BitBlt (hdc, r->left, r->bottom - bm.bmHeight, bm.bmWidth, bm.bmHeight, hdcmask, 0,0, SRCAND); BitBlt (hdc, r->left, r->bottom - bm.bmHeight, bm.bmWidth, bm.bmHeight, hdcsrc, 0,0, SRCINVERT); SetBkColor (hdc,oldclr); SetTextColor (hdc,oldclr2); SelectObject (hdcmask, oldmaskbm); // BitBlt (hdc, r->left, r->bottom - bm.bmHeight, bm.bmWidth, bm.bmHeight, hdcsrc, 0,0, SRCAND); } DeleteObject (hbmmask); DeleteDC (hdcmask); } SelectObject (hdcsrc, oldbm); DeleteDC (hdcsrc); } } DeleteObject (hbm); } return (true); #endif } /*ploticonresource*/
/* VARARGS ARGSUSED */ void TclpPanic TCL_VARARGS_DEF(CONST char *, format) { va_list varg; char msg[256]; WindowRef macWinPtr, foundWinPtr; Rect macRect; Rect buttonRect = PANIC_BUTTON_RECT; Rect iconRect = PANIC_ICON_RECT; Rect textRect = PANIC_TEXT_RECT; ControlHandle okButtonHandle; EventRecord event; Handle stopIconHandle; int part; Boolean done = false; va_start(varg, format); vsprintf(msg, format, varg); va_end(varg); /* * Put up an alert without using the Resource Manager (there may * be no resources to load). Use the Window and Control Managers instead. * We want the window centered on the main monitor. The following * should be tested with multiple monitors. Look and see if there is a way * not using qd.screenBits. */ macRect.top = (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom) / 2 - (PANICHEIGHT / 2); macRect.bottom = (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom) / 2 + (PANICHEIGHT / 2); macRect.left = (qd.screenBits.bounds.left + qd.screenBits.bounds.right) / 2 - (PANICWIDTH / 2); macRect.right = (qd.screenBits.bounds.left + qd.screenBits.bounds.right) / 2 + (PANICWIDTH / 2); macWinPtr = NewWindow(NULL, &macRect, "\p", true, dBoxProc, (WindowRef) -1, false, 0); if (macWinPtr == NULL) { goto exitNow; } okButtonHandle = NewControl(macWinPtr, &buttonRect, "\pOK", true, 0, 0, 1, pushButProc, 0); if (okButtonHandle == NULL) { CloseWindow(macWinPtr); goto exitNow; } SelectWindow(macWinPtr); SetCursor(&qd.arrow); stopIconHandle = GetIcon(kStopIcon); while (!done) { if (WaitNextEvent(mDownMask | keyDownMask | updateMask, &event, 0, NULL)) { switch(event.what) { case mouseDown: part = FindWindow(event.where, &foundWinPtr); if ((foundWinPtr != macWinPtr) || (part != inContent)) { SysBeep(1); } else { SetPortWindowPort(macWinPtr); GlobalToLocal(&event.where); part = FindControl(event.where, macWinPtr, &okButtonHandle); if ((kControlButtonPart == part) && (TrackControl(okButtonHandle, event.where, NULL))) { done = true; } } break; case keyDown: switch (event.message & charCodeMask) { case ENTERCODE: case RETURNCODE: HiliteControl(okButtonHandle, 1); HiliteControl(okButtonHandle, 0); done = true; } break; case updateEvt: SetPortWindowPort(macWinPtr); TextFont(systemFont); BeginUpdate(macWinPtr); if (stopIconHandle != NULL) { PlotIcon(&iconRect, stopIconHandle); } TETextBox(msg, strlen(msg), &textRect, teFlushDefault); DrawControls(macWinPtr); EndUpdate(macWinPtr); } } } CloseWindow(macWinPtr); exitNow: #ifdef TCL_DEBUG Debugger(); #else abort(); #endif }
Pixmap TkpGetNativeAppBitmap( Display *display, /* The display. */ CONST char *name, /* The name of the bitmap. */ int *width, /* The width & height of the bitmap. */ int *height) { Pixmap pix; CGrafPtr savePort; Boolean portChanged; Rect destRect; Handle resource; int type = -1, destWrote; Str255 nativeName; Tcl_Encoding encoding; /* * macRoman is the encoding that the resource fork uses. */ encoding = Tcl_GetEncoding(NULL, "macRoman"); Tcl_UtfToExternal(NULL, encoding, name, strlen(name), 0, NULL, (char *) &nativeName[1], 255, NULL, &destWrote, NULL); nativeName[0] = destWrote; Tcl_FreeEncoding(encoding); resource = GetNamedResource('cicn', nativeName); if (resource != NULL) { type = TYPE3; } else { resource = GetNamedResource('ICON', nativeName); if (resource != NULL) { type = TYPE2; } } if (resource == NULL) { return (Pixmap) NULL; } pix = Tk_GetPixmap(display, None, 32, 32, 0); portChanged = QDSwapPort(TkMacOSXGetDrawablePort(pix), &savePort); SetRect(&destRect, 0, 0, 32, 32); if (type == TYPE2) { RGBColor black = {0, 0, 0}; RGBForeColor(&black); PlotIcon(&destRect, resource); ReleaseResource(resource); } else if (type == TYPE3) { RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF}; short id; ResType theType; Str255 dummy; /* * We need to first paint the background white. Also, for some reason * we *must* use GetCIcon instead of GetNamedResource for PlotCIcon to * work - so we use GetResInfo to get the id. */ RGBForeColor(&white); PaintRect(&destRect); GetResInfo(resource, &id, &theType, dummy); ReleaseResource(resource); resource = (Handle) GetCIcon(id); PlotCIcon(&destRect, (CIconHandle) resource); DisposeCIcon((CIconHandle) resource); } *width = 32; *height = 32; if (portChanged) { QDSwapPort(savePort, NULL); } return pix; }