📄 tkmacwindowmgr.c
字号:
/* *---------------------------------------------------------------------- * * TkMacConvertEvent -- * * This function converts a Macintosh event into zero or more * Tcl events. * * Results: * Returns 1 if event added to Tcl queue, 0 otherwse. * * Side effects: * May add events to Tcl's event queue. * *---------------------------------------------------------------------- */intTkMacConvertEvent( EventRecord *eventPtr){ WindowRef whichWindow; Window window; int eventFound = false; switch (eventPtr->what) { case nullEvent: case adjustCursorEvent: if (GeneratePollingEvents()) { eventFound = true; } break; case updateEvt: whichWindow = (WindowRef)eventPtr->message; window = TkMacGetXWindow(whichWindow); if (GenerateUpdateEvent(eventPtr, window)) { eventFound = true; } break; case mouseDown: case mouseUp: FindWindow(eventPtr->where, &whichWindow); window = TkMacGetXWindow(whichWindow); if (WindowManagerMouse(eventPtr, window)) { eventFound = true; } break; case autoKey: case keyDown: /* * Handle menu-key events here. If it is *not* * a menu key - just fall through to handle as a * normal key event. */ if ((eventPtr->modifiers & cmdKey) == cmdKey) { long menuResult; int oldMode; oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL); menuResult = MenuKey(eventPtr->message & charCodeMask); Tcl_SetServiceMode(oldMode); if (HiWord(menuResult) != 0) { TkMacHandleMenuSelect(menuResult, false); break; } } case keyUp: whichWindow = FrontWindow(); window = TkMacGetXWindow(whichWindow); eventFound |= GenerateKeyEvent(eventPtr, window); break; case activateEvt: window = TkMacGetXWindow((WindowRef) eventPtr->message); eventFound |= GenerateActivateEvents(eventPtr, window); eventFound |= GenerateFocusEvent(eventPtr, window); break; case getFocusEvent: eventPtr->modifiers |= activeFlag; window = TkMacGetXWindow((WindowRef) eventPtr->message); eventFound |= GenerateFocusEvent(eventPtr, window); break; case loseFocusEvent: eventPtr->modifiers &= ~activeFlag; window = TkMacGetXWindow((WindowRef) eventPtr->message); eventFound |= GenerateFocusEvent(eventPtr, window); break; case kHighLevelEvent: TkMacDoHLEvent(eventPtr); /* TODO: should return true if events were placed on event queue. */ break; case osEvt: /* * Do clipboard conversion. */ switch ((eventPtr->message & osEvtMessageMask) >> 24) { case mouseMovedMessage: if (GeneratePollingEvents()) { eventFound = true; } break; case suspendResumeMessage: if (!(eventPtr->message & resumeFlag)) { TkSuspendClipboard(); } tkMacAppInFront = (eventPtr->message & resumeFlag); break; } break; case diskEvt: /* * Disk insertion. */ if (HiWord(eventPtr->message) != noErr) { Point pt; DILoad(); pt.v = pt.h = 120; /* parameter ignored in sys 7 */ DIBadMount(pt, eventPtr->message); DIUnload(); } break; } return eventFound;}/* *---------------------------------------------------------------------- * * TkMacConvertTkEvent -- * * This function converts a Macintosh event into zero or more * Tcl events. It is intended for use in Netscape-style embedding. * * Results: * Returns 1 if event added to Tcl queue, 0 otherwse. * * Side effects: * May add events to Tcl's event queue. * *---------------------------------------------------------------------- */intTkMacConvertTkEvent( EventRecord *eventPtr, Window window){ int eventFound = false; Point where; /* * By default, assume it is legal for us to set the cursor */ Tk_MacTkOwnsCursor(1); switch (eventPtr->what) { case nullEvent: /* * We get NULL events only when the cursor is NOT over * the plugin. Otherwise we get updateCursor events. * We will not generate polling events or move the cursor * in this case. */ eventFound = false; break; case adjustCursorEvent: if (GeneratePollingEvents2(window, 1)) { eventFound = true; } break; case updateEvt: /* * It is possibly not legal for us to set the cursor */ Tk_MacTkOwnsCursor(0); if (GenerateUpdateEvent(eventPtr, window)) { eventFound = true; } break; case mouseDown: case mouseUp: GetMouse(&where); LocalToGlobal(&where); eventFound |= TkGenerateButtonEvent(where.h, where.v, window, TkMacButtonKeyState()); break; case autoKey: case keyDown: /* * Handle menu-key events here. If it is *not* * a menu key - just fall through to handle as a * normal key event. */ if ((eventPtr->modifiers & cmdKey) == cmdKey) { long menuResult = MenuKey(eventPtr->message & charCodeMask); if (HiWord(menuResult) != 0) { TkMacHandleMenuSelect(menuResult, false); break; } } case keyUp: eventFound |= GenerateKeyEvent(eventPtr, window); break; case activateEvt: /* * It is probably not legal for us to set the cursor * here, since we don't know where the mouse is in the * window that is being activated. */ Tk_MacTkOwnsCursor(0); eventFound |= GenerateActivateEvents(eventPtr, window); eventFound |= GenerateFocusEvent(eventPtr, window); break; case getFocusEvent: eventPtr->modifiers |= activeFlag; eventFound |= GenerateFocusEvent(eventPtr, window); break; case loseFocusEvent: eventPtr->modifiers &= ~activeFlag; eventFound |= GenerateFocusEvent(eventPtr, window); break; case kHighLevelEvent: TkMacDoHLEvent(eventPtr); /* TODO: should return true if events were placed on event queue. */ break; case osEvt: /* * Do clipboard conversion. */ switch ((eventPtr->message & osEvtMessageMask) >> 24) { /* * It is possibly not legal for us to set the cursor. * Netscape sends us these events all the time... */ Tk_MacTkOwnsCursor(0); case mouseMovedMessage: /* if (GeneratePollingEvents2(window, 0)) { eventFound = true; } NEXT LINE IS TEMPORARY */ eventFound = false; break; case suspendResumeMessage: if (!(eventPtr->message & resumeFlag)) { TkSuspendClipboard(); } tkMacAppInFront = (eventPtr->message & resumeFlag); break; } break; case diskEvt: /* * Disk insertion. */ if (HiWord(eventPtr->message) != noErr) { Point pt; DILoad(); pt.v = pt.h = 120; /* parameter ignored in sys 7 */ DIBadMount(pt, eventPtr->message); DIUnload(); } break; } return eventFound;}/* *---------------------------------------------------------------------- * * CheckEventsAvail -- * * Checks to see if events are available on the Macintosh queue. * This function looks for both queued events (eg. key & button) * and generated events (update). * * Results: * True is events exist, false otherwise. * * Side effects: * None. * *---------------------------------------------------------------------- */static intCheckEventsAvail(){ QHdrPtr evPtr; WindowPeek macWinPtr; evPtr = GetEvQHdr(); if (evPtr->qHead != NULL) { return true; } macWinPtr = (WindowPeek) FrontWindow(); while (macWinPtr != NULL) { if (!EmptyRgn(macWinPtr->updateRgn)) { return true; } macWinPtr = macWinPtr->nextWindow; } return false;}/* *---------------------------------------------------------------------- * * TkpSetCapture -- * * This function captures the mouse so that all future events * will be reported to this window, even if the mouse is outside * the window. If the specified window is NULL, then the mouse * is released. * * Results: * None. * * Side effects: * Sets the capture flag and captures the mouse. * *---------------------------------------------------------------------- */voidTkpSetCapture( TkWindow *winPtr) /* Capture window, or NULL. */{ while ((winPtr != NULL) && !Tk_IsTopLevel(winPtr)) { winPtr = winPtr->parentPtr; } gGrabWinPtr = (Tk_Window) winPtr;}/* *---------------------------------------------------------------------- * * TkMacWindowOffset -- * * Determines the x and y offset from the orgin of the toplevel * window dressing (the structure region, ie. title bar) and the * orgin of the content area. * * Results: * The x & y offset in pixels. * * Side effects: * None. * *---------------------------------------------------------------------- */voidTkMacWindowOffset( WindowRef wRef, int *xOffset, int *yOffset){ OSErr err = noErr; WindowPeek wPeek = (WindowPeek) wRef; RgnHandle strucRgn = wPeek->strucRgn; RgnHandle contRgn = wPeek->contRgn; Rect strucRect, contRect; if (!EmptyRgn(strucRgn) && !EmptyRgn(contRgn)) { strucRect = (**strucRgn).rgnBBox; contRect = (**contRgn).rgnBBox; } else { /* * The current window's regions are not up to date. * Probably because the window isn't visable. What we * will do is save the old regions, have the window calculate * what the regions should be, and then restore it self. */ strucRgn = NewRgn( ); contRgn = NewRgn( ); if (!strucRgn || !contRgn) { err = MemError( ); } else { CopyRgn(wPeek->strucRgn, strucRgn); CopyRgn(wPeek->contRgn, contRgn); if (!(err = TellWindowDefProcToCalcRegions(wRef))) { strucRect = (**(wPeek->strucRgn)).rgnBBox; contRect = (**(wPeek->contRgn)).rgnBBox; } CopyRgn(strucRgn, wPeek->strucRgn); CopyRgn(contRgn, wPeek->contRgn); } if (contRgn) { DisposeRgn(contRgn); } if (strucRgn) { DisposeRgn(strucRgn); } } if (!err) { *xOffset = contRect.left - strucRect.left; *yOffset = contRect.top - strucRect.top; } else { *xOffset = 0; *yOffset = 0; } return;}/* *---------------------------------------------------------------------- * * TellWindowDefProcToCalcRegions -- * * Force a Macintosh window to recalculate it's content and * structure regions. * * Results: * An OS error. * * Side effects: * The windows content and structure regions may be updated. * *---------------------------------------------------------------------- */static OSErr TellWindowDefProcToCalcRegions( WindowRef wRef){ OSErr err = noErr; SInt8 hState; Handle wdef = ((WindowPeek) wRef)->windowDefProc; /* * Load and lock the window definition procedure for * the window. */ hState = HGetState(wdef); if (!(err = MemError())) { LoadResource(wdef); if (!(err = ResError())) { MoveHHi(wdef); err = MemError(); if (err == memLockedErr) { err = noErr; } else if (!err) { HLock(wdef); err = MemError(); } } } /* * Assuming there are no errors we now call the window definition * procedure to tell it to calculate the regions for the window. */ if (err == noErr) { (void) CallWindowDefProc((UniversalProcPtr) *wdef, GetWVariant(wRef), wRef, wCalcRgns, 0); HSetState(wdef, hState); if (!err) { err = MemError(); } } return err;}/* *---------------------------------------------------------------------- * * BringWindowForward -- * * Bring this background window to the front. We also set state * so Tk thinks the button is currently up. * * Results: * None. * * Side effects: * The window is brought forward. * *---------------------------------------------------------------------- */static void BringWindowForward( WindowRef wRef){ SelectWindow(wRef);}/* *---------------------------------------------------------------------- * * TkpGetMS -- * * Return a relative time in milliseconds. It doesn't matter * when the epoch was. * * Results: * Number of milliseconds. * * Side effects: * None. * *---------------------------------------------------------------------- */unsigned longTkpGetMS(){ long long * int64Ptr; UnsignedWide micros; Microseconds(µs); int64Ptr = (long long *) µs; /* * We need 64 bit math to do this. This is available in CW 11 * and on. Other's will need to use a different scheme. */ *int64Ptr /= 1000; return (long) *int64Ptr;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -