static OSStatus CarbonEventHandlerProc( EventHandlerCallRef callRef, EventRef event, void *userData) { OSStatus err = eventNotHandledErr; TkMacOSXEvent macEvent; MacEventStatus eventStatus; macEvent.eventRef = event; macEvent.eClass = GetEventClass(event); macEvent.eKind = GetEventKind(event); macEvent.interp = (Tcl_Interp *) userData; macEvent.callRef = callRef; bzero(&eventStatus, sizeof(eventStatus)); #ifdef TK_MAC_DEBUG_CARBON_EVENTS if (!(macEvent.eClass == kEventClassMouse && ( macEvent.eKind == kEventMouseMoved || macEvent.eKind == kEventMouseDragged))) { TkMacOSXDbgMsg("Started handling %s", TkMacOSXCarbonEventToAscii(event)); TkMacOSXInitNamedDebugSymbol(HIToolbox, void, _DebugPrintEvent, EventRef inEvent); if (_DebugPrintEvent) { /* * Carbon-internal event debugging (c.f. Technote 2124) */ _DebugPrintEvent(event); } } #endif /* TK_MAC_DEBUG_CARBON_EVENTS */ TkMacOSXProcessEvent(&macEvent,&eventStatus); if (eventStatus.stopProcessing) { err = noErr; } #ifdef TK_MAC_DEBUG_CARBON_EVENTS if (macEvent.eKind != kEventMouseMoved && macEvent.eKind != kEventMouseDragged) { TkMacOSXDbgMsg("Finished handling %s: %s handled", TkMacOSXCarbonEventToAscii(event), eventStatus.stopProcessing ? " " : "not"); } #endif /* TK_MAC_DEBUG_CARBON_EVENTS */ return err; }
MODULE_SCOPE void TkMacOSXPrintRect(char * tag, Rect * r ) { TkMacOSXDbgMsg("%s %4d %4d %4d %4d (%dx%d)", tag, r->left, r->top, r->right, r->bottom, r->right - r->left + 1, r->bottom - r->top + 1); }
static void MacScaleEventProc( ClientData clientData, /* Information about window. */ XEvent *eventPtr) /* Information about event. */ { MacScale *macScalePtr = (MacScale *) clientData; Point where; Rect bounds; int part; CGrafPtr destPort, savePort; Boolean portChanged; #ifdef TK_MAC_DEBUG_SCALE fprintf(stderr,"MacScaleEventProc\n" ); #endif /* * To call Macintosh control routines we must have the port * set to the window containing the control. We will then test * which part of the control was hit and act accordingly. */ destPort = TkMacOSXGetDrawablePort(Tk_WindowId(macScalePtr->info.tkwin)); portChanged = QDSwapPort(destPort, &savePort); TkMacOSXSetUpClippingRgn(Tk_WindowId(macScalePtr->info.tkwin)); TkMacOSXWinBounds((TkWindow *) macScalePtr->info.tkwin, &bounds); where.h = eventPtr->xbutton.x + bounds.left; where.v = eventPtr->xbutton.y + bounds.top; #ifdef TK_MAC_DEBUG_SCALE TkMacOSXDbgMsg("calling TestControl"); #endif part = TestControl(macScalePtr->scaleHandle, where); if (part == 0) { return; } TkMacOSXTrackingLoop(1); part = HandleControlClick(macScalePtr->scaleHandle, where, TkMacOSXModifierState(), scaleActionProc); TkMacOSXTrackingLoop(0); /* * Update the value for the widget. */ macScalePtr->info.value = GetControlValue(macScalePtr->scaleHandle); /* TkScaleSetValue(&macScalePtr->info, macScalePtr->info.value, 1, 0); */ /* * The HandleControlClick call will "eat" the ButtonUp event. We now * generate a ButtonUp event so Tk will unset implicit grabs etc. */ TkGenerateButtonEventForXPointer(Tk_WindowId(macScalePtr->info.tkwin)); if (portChanged) { QDSwapPort(savePort, NULL); } }
static OSStatus InstallStandardApplicationEventHandler(void) { OSStatus err = memFullErr; TK_IF_HI_TOOLBOX(5, /* * The approach below does not work correctly in Leopard, it leads to * crashes in [NSView unlockFocus] whenever HIToolbox uses Cocoa (Help * menu, Nav Services, Color Picker). While it is now possible to * install the standard app handler with InstallStandardEventHandler(), * to fully replicate RAEL the standard menubar event handler also needs * to be installed. Unfortunately there appears to be no public API to * obtain the menubar event target. As a workaround, for now we resort * to calling the HIToolbox-internal GetMenuBarEventTarget() directly * (symbol acquired via TkMacOSXInitNamedSymbol() from HIToolbox * version 343, may not exist in later versions). */ err = ChkErr(InstallStandardEventHandler, GetApplicationEventTarget()); TkMacOSXInitNamedSymbol(HIToolbox, EventTargetRef, GetMenuBarEventTarget, void); if (GetMenuBarEventTarget) { ChkErr(InstallStandardEventHandler, GetMenuBarEventTarget()); } else { TkMacOSXDbgMsg("Unable to install standard menubar event handler"); } ) TK_ELSE_HI_TOOLBOX (5,
MODULE_SCOPE void TkMacOSXPrintWindowTitle(char * tag, WindowRef window ) { Str255 title; GetWTitle(window,title); title [title[0] + 1] = 0; TkMacOSXDbgMsg("%s %s", tag, title +1 ); }
int TkpScaleElement( TkScale *scalePtr, /* Widget record for scale. */ int x, int y) /* Coordinates within scalePtr's window. */ { MacScale *macScalePtr = (MacScale *) scalePtr; ControlPartCode part; Point where; Rect bounds; CGrafPtr destPort, savePort; Boolean portChanged; #ifdef TK_MAC_DEBUG_SCALE TkMacOSXDbgMsg("TkpScaleElement"); #endif destPort = TkMacOSXGetDrawablePort(Tk_WindowId(scalePtr->tkwin)); portChanged = QDSwapPort(destPort, &savePort); /* * All of the calculations in this procedure mirror those in * DisplayScrollbar. Be sure to keep the two consistent. */ TkMacOSXWinBounds((TkWindow *) scalePtr->tkwin, &bounds); where.h = x + bounds.left; where.v = y + bounds.top; part = TestControl(macScalePtr->scaleHandle, where); if (portChanged) { QDSwapPort(savePort, NULL); } #ifdef TK_MAC_DEBUG_SCALE fprintf (stderr,"ScalePart %d, pos ( %d %d )\n", part, where.h, where.v ); #endif switch (part) { case inSlider: return SLIDER; case inInc: if (scalePtr->orient == ORIENT_VERTICAL) { return TROUGH1; } else { return TROUGH2; } case inDecr: if (scalePtr->orient == ORIENT_VERTICAL) { return TROUGH2; } else { return TROUGH1; } default: return OTHER; } }
void Tk_FreePixmap( Display *display, /* Display. */ Pixmap pixmap) /* Pixmap to destroy */ { MacDrawable *macPix = (MacDrawable *) pixmap; display->request++; if (macPix->grafPtr) { DisposeGWorld(macPix->grafPtr); } if (macPix->context) { TkMacOSXDbgMsg("Cannot free CG backed Pixmap"); } ckfree((char *) macPix); }
static pascal void ScaleActionProc( ControlRef theControl, /* Handle to scrollbat control */ ControlPartCode partCode) /* Part of scrollbar that was "hit" */ { int value; TkScale *scalePtr = (TkScale *) GetControlReference(theControl); #ifdef TK_MAC_DEBUG_SCALE TkMacOSXDbgMsg("ScaleActionProc"); #endif value = GetControlValue(theControl); TkScaleSetValue(scalePtr, value, 1, 1); Tcl_Preserve((ClientData) scalePtr); TkMacOSXRunTclEventLoop(); Tcl_Release((ClientData) scalePtr); }
CGrafPtr 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); } 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. */ TkMacOSXDbgMsg("Couldn't find container"); } /* * 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; }
MODULE_SCOPE void TkMacOSXPrintPoint(char * tag, Point * p ) { TkMacOSXDbgMsg("%s %4d %4d", tag,p->h,p->v ); }
void TkpDisplayScale( ClientData clientData) /* Widget record for scale. */ { TkScale *scalePtr = (TkScale *) clientData; Tk_Window tkwin = scalePtr->tkwin; Tcl_Interp *interp = scalePtr->interp; int result; char string[TCL_DOUBLE_SPACE]; MacScale *macScalePtr = (MacScale *) clientData; Rect r; WindowRef windowRef; CGrafPtr destPort, savePort; Boolean portChanged; MacDrawable *macDraw; SInt32 initialValue, minValue, maxValue; UInt16 numTicks; #ifdef TK_MAC_DEBUG_SCALE TkMacOSXDbgMsg("TkpDisplayScale"); #endif scalePtr->flags &= ~REDRAW_PENDING; if ((scalePtr->tkwin == NULL) || !Tk_IsMapped(scalePtr->tkwin)) { goto done; } /* * Invoke the scale's command if needed. */ Tcl_Preserve((ClientData) scalePtr); if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { Tcl_Preserve((ClientData) interp); sprintf(string, scalePtr->format, scalePtr->value); result = Tcl_VarEval(interp, scalePtr->command, " ", string, NULL); if (result != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (command executed by scale)"); Tcl_BackgroundError(interp); } Tcl_Release((ClientData) interp); } scalePtr->flags &= ~INVOKE_COMMAND; if (scalePtr->flags & SCALE_DELETED) { Tcl_Release((ClientData) scalePtr); return; } Tcl_Release((ClientData) scalePtr); /* * Now handle the part of redisplay that is the same for * horizontal and vertical scales: border and traversal * highlight. */ if (scalePtr->highlightWidth != 0) { GC gc = Tk_GCForColor(scalePtr->highlightColorPtr, Tk_WindowId(tkwin)); Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth, Tk_WindowId(tkwin)); } Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), scalePtr->bgBorder, scalePtr->highlightWidth, scalePtr->highlightWidth, Tk_Width(tkwin) - 2*scalePtr->highlightWidth, Tk_Height(tkwin) - 2*scalePtr->highlightWidth, scalePtr->borderWidth, scalePtr->relief); /* * Set up port for drawing Macintosh control. */ macDraw = (MacDrawable *) Tk_WindowId(tkwin); destPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin)); windowRef = TkMacOSXDrawableWindow(Tk_WindowId(tkwin)); portChanged = QDSwapPort(destPort, &savePort); TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin)); /* * Create Macintosh control. */ #define MAC_OSX_SCROLL_WIDTH 10 if (scalePtr->orient == ORIENT_HORIZONTAL) { int offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH)/2; if (offset < 0) { offset = 0; } r.left = macDraw->xOff + scalePtr->inset; r.top = macDraw->yOff + offset; r.right = macDraw->xOff+Tk_Width(tkwin) - scalePtr->inset; r.bottom = macDraw->yOff + offset + MAC_OSX_SCROLL_WIDTH/2; } else { int offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH)/2; if (offset < 0) { offset = 0; } r.left = macDraw->xOff + offset; r.top = macDraw->yOff + scalePtr->inset; r.right = macDraw->xOff + offset + MAC_OSX_SCROLL_WIDTH/2; r.bottom = macDraw->yOff+Tk_Height(tkwin) - scalePtr->inset; } if (macScalePtr->scaleHandle == NULL) { #ifdef TK_MAC_DEBUG_SCALE TkMacOSXDbgMsg("Initialising scale"); #endif initialValue = scalePtr->value; if (scalePtr->orient == ORIENT_HORIZONTAL) { minValue = scalePtr->fromValue; maxValue = scalePtr->toValue; } else { minValue = scalePtr->fromValue; maxValue = scalePtr->toValue; } if (scalePtr->tickInterval == 0) { numTicks = 0; } else { numTicks = (maxValue - minValue)/scalePtr->tickInterval; } CreateSliderControl(windowRef, &r, initialValue, minValue, maxValue, kControlSliderPointsDownOrRight, numTicks, 1, scaleActionProc, &(macScalePtr->scaleHandle)); SetControlReference(macScalePtr->scaleHandle, (UInt32) scalePtr); if (IsWindowActive(windowRef)) { macScalePtr->flags |= ACTIVE; } } else { SetControlBounds(macScalePtr->scaleHandle, &r); SetControl32BitValue(macScalePtr->scaleHandle, scalePtr->value); SetControl32BitMinimum(macScalePtr->scaleHandle, scalePtr->fromValue); SetControl32BitMaximum(macScalePtr->scaleHandle, scalePtr->toValue); } /* * Finally draw the control. */ SetControlVisibility(macScalePtr->scaleHandle,true,true); HiliteControl(macScalePtr->scaleHandle,0); Draw1Control(macScalePtr->scaleHandle); if (portChanged) { QDSwapPort(savePort, NULL); } done: scalePtr->flags &= ~REDRAW_ALL; }
static int TkMacOSXInitControl( MacButton *mbPtr, /* Mac button. */ GWorldPtr destPort, GC gc, Pixmap pixmap, Rect *paneRect, Rect *cntrRect) { TkButton *butPtr = (TkButton *) mbPtr; ControlRef rootControl; SInt16 procID, initialValue, minValue, maxValue; Boolean initiallyVisible; SInt32 controlReference; rootControl = TkMacOSXGetRootControl(Tk_WindowId(butPtr->tkwin)); mbPtr->windowRef = TkMacOSXDrawableWindow(Tk_WindowId(butPtr->tkwin)); /* * Set up the user pane. */ initiallyVisible = false; initialValue = kControlSupportsEmbedding|kControlHasSpecialBackground; minValue = 0; maxValue = 1; procID = kControlUserPaneProc; controlReference = (SInt32)mbPtr; mbPtr->userPane = NewControl(mbPtr->windowRef, paneRect, "\p", initiallyVisible, initialValue, minValue, maxValue, procID, controlReference); if (!mbPtr->userPane) { TkMacOSXDbgMsg("Failed to create user pane control"); return 1; } if (ChkErr(EmbedControl, mbPtr->userPane,rootControl) != noErr) { return 1; } SetUserPaneSetUpSpecialBackgroundProc(mbPtr->userPane, UserPaneBackgroundProc); SetUserPaneDrawProc(mbPtr->userPane,UserPaneDraw); initiallyVisible = false; TkMacOSXComputeControlParams(butPtr,&mbPtr->params); mbPtr->control = NewControl(mbPtr->windowRef, cntrRect, "\p", initiallyVisible, mbPtr->params.initialValue, mbPtr->params.minValue, mbPtr->params.maxValue, mbPtr->params.procID, controlReference); if (!mbPtr->control) { TkMacOSXDbgMsg("Failed to create control of type %d\n", procID); return 1; } if (ChkErr(EmbedControl, mbPtr->control,mbPtr->userPane) != noErr ) { return 1; } mbPtr->flags |= (CONTROL_INITIALIZED | FIRST_DRAW); if (IsWindowActive(mbPtr->windowRef)) { mbPtr->flags |= ACTIVE; } return 0; }
void SetupBevelButton( MacButton *mbPtr, /* Mac button. */ ControlRef controlHandle, /* The control to set this picture to. */ GWorldPtr destPort, /* Off screen GWorld. */ GC gc, /* The GC we are drawing into - needed for the * bevel button. */ Pixmap pixmap) /* The pixmap we are drawing into - needed for * the bevel button. */ { TkButton *butPtr = (TkButton *) mbPtr; int height, width; ControlButtonGraphicAlignment theAlignment; CGrafPtr savePort; Boolean portChanged = false; if (butPtr->image != None) { Tk_SizeOfImage(butPtr->image, &width, &height); } else { Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); } if ((butPtr->width > 0) && (butPtr->width < width)) { width = butPtr->width; } if ((butPtr->height > 0) && (butPtr->height < height)) { height = butPtr->height; } { portChanged = QDSwapPort(destPort, &savePort); mbPtr->picParams.version = -2; mbPtr->picParams.hRes = 0x00480000; mbPtr->picParams.vRes = 0x00480000; mbPtr->picParams.srcRect.top = 0; mbPtr->picParams.srcRect.left = 0; mbPtr->picParams.srcRect.bottom = height; mbPtr->picParams.srcRect.right = width; mbPtr->picParams.reserved1 = 0; mbPtr->picParams.reserved2 = 0; mbPtr->bevelButtonContent.contentType = kControlContentPictHandle; mbPtr->bevelButtonContent.u.picture = OpenCPicture(&mbPtr->picParams); if (!mbPtr->bevelButtonContent.u.picture) { TkMacOSXDbgMsg("OpenCPicture failed"); } tkPictureIsOpen = 1; /* * TO DO - There is one case where XCopyPlane calls CopyDeepMask, * which does not get recorded in the picture. So the bitmap code * will fail in that case. */ } if (butPtr->selectImage != NULL && (butPtr->flags & SELECTED)) { Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height, pixmap, 0, 0); #if 0 } else if (butPtr->tristateImage != NULL && (butPtr->flags & TRISTATED)) { Tk_RedrawImage(butPtr->tristateImage, 0, 0, width, height, pixmap, 0, 0); #endif } else if (butPtr->image != NULL) { Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, 0, 0); } else { XSetClipOrigin(butPtr->display, gc, 0, 0); XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0, width, height, 0, 0, 1); } { ClosePicture(); tkPictureIsOpen = 0; if (portChanged) { QDSwapPort(savePort, NULL); } } ChkErr(SetControlData, controlHandle, kControlButtonPart, kControlBevelButtonContentTag, sizeof(ControlButtonContentInfo), (char *) &mbPtr->bevelButtonContent); if (butPtr->anchor == TK_ANCHOR_N) { theAlignment = kControlBevelButtonAlignTop; } else if (butPtr->anchor == TK_ANCHOR_NE) { theAlignment = kControlBevelButtonAlignTopRight; } else if (butPtr->anchor == TK_ANCHOR_E) { theAlignment = kControlBevelButtonAlignRight; } else if (butPtr->anchor == TK_ANCHOR_SE) { theAlignment = kControlBevelButtonAlignBottomRight; } else if (butPtr->anchor == TK_ANCHOR_S) { theAlignment = kControlBevelButtonAlignBottom; } else if (butPtr->anchor == TK_ANCHOR_SW) { theAlignment = kControlBevelButtonAlignBottomLeft; } else if (butPtr->anchor == TK_ANCHOR_W) { theAlignment = kControlBevelButtonAlignLeft; } else if (butPtr->anchor == TK_ANCHOR_NW) { theAlignment = kControlBevelButtonAlignTopLeft; } else if (butPtr->anchor == TK_ANCHOR_CENTER) { theAlignment = kControlBevelButtonAlignCenter; } ChkErr(SetControlData, controlHandle, kControlButtonPart, kControlBevelButtonGraphicAlignTag, sizeof(ControlButtonGraphicAlignment), (char *) &theAlignment); if (butPtr->compound != COMPOUND_NONE) { ControlButtonTextPlacement thePlacement = kControlBevelButtonPlaceNormally; if (butPtr->compound == COMPOUND_TOP) { thePlacement = kControlBevelButtonPlaceBelowGraphic; } else if (butPtr->compound == COMPOUND_BOTTOM) { thePlacement = kControlBevelButtonPlaceAboveGraphic; } else if (butPtr->compound == COMPOUND_LEFT) { thePlacement = kControlBevelButtonPlaceToRightOfGraphic; } else if (butPtr->compound == COMPOUND_RIGHT) { thePlacement = kControlBevelButtonPlaceToLeftOfGraphic; } ChkErr(SetControlData, controlHandle, kControlButtonPart, kControlBevelButtonTextPlaceTag, sizeof(ControlButtonTextPlacement), (char *) &thePlacement); } }