void OpenUserDataRec::EventProcCBEventMouseDown(NavCBRecPtr callBackParms) { EventRecord *evt = callBackParms->eventData.eventDataParms.event; Point where = evt->where; QDGlobalToLocalPoint(GetWindowPort(callBackParms->window), &where); ControlRef whichControl = FindControlUnderMouse(where, callBackParms->window, NULL); if (whichControl != NULL) { ControlKind theKind; GetControlKind(whichControl, &theKind); // Moving the focus if we clicked in an focusable control if ((theKind.kind == kControlKindEditUnicodeText) || (theKind.kind == kControlKindEditText) || (theKind.kind == kControlKindDataBrowser) || (theKind.kind == kControlKindListBox)) { ControlRef currentlyFocusedControl; GetKeyboardFocus(callBackParms->window, ¤tlyFocusedControl); if (currentlyFocusedControl != whichControl) SetKeyboardFocus(callBackParms->window, whichControl, kControlFocusNextPart); } HandleControlClick(whichControl, where, evt->modifiers, NULL); } }
int TkGenerateButtonEvent( int x, /* X location of mouse */ int y, /* Y location of mouse */ Window window, /* X Window containing button event. */ unsigned int state) /* Button Key state suitable for X event */ { MouseEventData med; bzero(&med, sizeof(MouseEventData)); med.state = state; med.window = window; med.global.h = x; med.global.v = y; FindWindow(med.global, &med.whichWin); med.activeNonFloating = ActiveNonFloatingWindow(); med.local = med.global; QDGlobalToLocalPoint(GetWindowPort(med.whichWin), &med.local); return GenerateButtonEvent(&med); }
// ----------------------------------------------------------------------------- // HITestViewTrack // ----------------------------------------------------------------------------- // This is overkill, and probably #ifdef'd out, but is here as an example of // a custom tracking handler. // OSStatus HITestViewTrack( EventRef inEvent, HITestViewData* inData ) { OSStatus err; HIRect bounds; HIPoint where; ControlPartCode part; Boolean inside; Boolean wasInside; Point qdPt; MouseTrackingResult mouseResult; PixMapHandle portPixMap; // Extract the mouse location err = GetEventParameter( inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof( HIPoint ), NULL, &where ); require_noerr( err, ParameterMissing ); // Is the mouse location in the view? err = HIViewGetBounds( inData->view, &bounds ); if ( CGRectContainsPoint( bounds, where ) ) part = 1; else part = kControlNoPart; HiliteControl( inData->view, part ); wasInside = true; // Need the port's pixMap's bounds to convert the mouse location portPixMap = GetPortPixMap( GetWindowPort( GetControlOwner( inData->view ) ) ); // The tracking loop while ( true ) { // Check again to see if the mouse is in the view if ( CGRectContainsPoint( bounds, where ) ) part = 1; else part = kControlNoPart; inside = ( part != kControlNoPart ); // If that changed, update if ( inside != wasInside ) HiliteControl( inData->view, part ); wasInside = inside; // Watch the mouse for change err = TrackMouseLocation( (GrafPtr)-1L, &qdPt, &mouseResult ); // Need to convert from global QDGlobalToLocalPoint( GetWindowPort( GetControlOwner( inData->view ) ), &qdPt ); where.x = qdPt.h - (**portPixMap).bounds.left; where.y = qdPt.v - (**portPixMap).bounds.top; HIViewConvertPoint( &where, NULL, inData->view ); // Bail out when the mouse is released if ( mouseResult == kMouseTrackingMouseReleased ) break; } // Restore the original highlight HiliteControl( inData->view, kControlNoPart ); // Send back the part upon which the mouse was released err = SetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode, sizeof( ControlPartCode ), &part ); ParameterMissing: return err; }
Bool XQueryPointer( Display* display, Window w, Window* root_return, Window* child_return, int* root_x_return, int* root_y_return, int* win_x_return, int* win_y_return, unsigned int* mask_return) { int getGlobal = (root_x_return && root_y_return); int getLocal = (win_x_return && win_y_return); if (getGlobal || getLocal) { Point where, local; OSStatus err = noErr; int gotMouseLoc = 0; EventRef ev = GetCurrentEvent(); if (ev && getLocal) { err = ChkErr(GetEventParameter, ev, kEventParamWindowMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &local); gotMouseLoc = (err == noErr); } if (getGlobal || !gotMouseLoc) { if (ev) { err = ChkErr(GetEventParameter, ev, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &where); } if (!ev || err != noErr) { GetGlobalMouse(&where); } } if (getLocal) { WindowRef whichWin; if (ev) { err = ChkErr(GetEventParameter, ev, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, &whichWin); } if (!ev || err != noErr) { FindWindow(where, &whichWin); } if (gotMouseLoc) { if (whichWin) { Rect widths; ChkErr(GetWindowStructureWidths, whichWin, &widths); local.h -= widths.left; local.v -= widths.top; } } else { local = where; if (whichWin) { QDGlobalToLocalPoint(GetWindowPort(whichWin), &local); } } } if (getGlobal) { *root_x_return = where.h; *root_y_return = where.v; } if (getLocal) { *win_x_return = local.h; *win_y_return = local.v; } } if (mask_return) { *mask_return = TkMacOSXButtonKeyState(); } return True; }
MODULE_SCOPE int TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) { Tk_Window tkwin; Point where, where2; int result; TkDisplay * dispPtr; OSStatus err; MouseEventData mouseEventData, * medPtr = &mouseEventData; int isFrontProcess; switch (eventPtr->eKind) { case kEventMouseDown: case kEventMouseUp: case kEventMouseMoved: case kEventMouseDragged: case kEventMouseWheelMoved: break; default: return false; break; } err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(where), NULL, &where); if (err != noErr) { GetGlobalMouse(&where); } err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, &medPtr->whichWin); if (err == noErr) { err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamWindowPartCode, typeWindowPartCode, NULL, sizeof(WindowPartCode), NULL, &medPtr->windowPart); } if (err != noErr) { medPtr->windowPart = FindWindow(where, &medPtr->whichWin); } medPtr->window = TkMacOSXGetXWindow(medPtr->whichWin); if (medPtr->whichWin != NULL && medPtr->window == None) { return false; } if (eventPtr->eKind == kEventMouseDown) { if (IsWindowActive(medPtr->whichWin) && IsWindowPathSelectEvent( medPtr->whichWin, eventPtr->eventRef)) { ChkErr(WindowPathSelect, medPtr->whichWin, NULL, NULL); return false; } if (medPtr->windowPart == inProxyIcon) { TkMacOSXTrackingLoop(1); err = ChkErr(TrackWindowProxyDrag, medPtr->whichWin, where); TkMacOSXTrackingLoop(0); if (err == errUserWantsToDragWindow) { medPtr->windowPart = inDrag; } else { return false; } } } isFrontProcess = Tk_MacOSXIsAppInFront(); if (isFrontProcess) { medPtr->state = ButtonModifiers2State(GetCurrentEventButtonState(), GetCurrentEventKeyModifiers()); } else { medPtr->state = ButtonModifiers2State(GetCurrentButtonState(), GetCurrentKeyModifiers()); } medPtr->global = where; err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamWindowMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &medPtr->local); if (err == noErr) { if (medPtr->whichWin) { Rect widths; GetWindowStructureWidths(medPtr->whichWin, &widths); medPtr->local.h -= widths.left; medPtr->local.v -= widths.top; } } else { medPtr->local = where; if (medPtr->whichWin) { QDGlobalToLocalPoint(GetWindowPort(medPtr->whichWin), &medPtr->local); } } medPtr->activeNonFloating = ActiveNonFloatingWindow(); dispPtr = TkGetDisplayList(); tkwin = Tk_IdToWindow(dispPtr->display, medPtr->window); if (eventPtr->eKind != kEventMouseDown) { int res = false; switch (eventPtr->eKind) { case kEventMouseUp: /* * The window manager only needs to know about mouse down * events and sometimes we need to "eat" the mouse up. * Otherwise, we just pass the event to Tk. */ if (TkMacOSXGetEatButtonUp()) { TkMacOSXSetEatButtonUp(false); } else { res = GenerateButtonEvent(medPtr); } break; case kEventMouseWheelMoved: err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(long), NULL, &medPtr->delta); if (err != noErr ) { statusPtr->err = 1; } else { EventMouseWheelAxis axis; err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(EventMouseWheelAxis), NULL, &axis); if (err == noErr && axis == kEventMouseWheelAxisX) { medPtr->state |= ShiftMask; } res = GenerateMouseWheelEvent(medPtr); } break; case kEventMouseMoved: case kEventMouseDragged: res = GeneratePollingEvents(medPtr); break; default: Tcl_Panic("Unknown mouse event !"); } if (res) { statusPtr->stopProcessing = 1; } return res; } TkMacOSXSetEatButtonUp(false); if (medPtr->whichWin) { /* * We got a mouse down in a window * See if this is the activate click * This click moves the window forward. We don't want * the corresponding mouse-up to be reported to the application * or else it will mess up some Tk scripts. */ if (!(TkpIsWindowFloating(medPtr->whichWin)) && (medPtr->whichWin != medPtr->activeNonFloating || !isFrontProcess)) { int frontWindowOnly = 1; int cmdDragGrow = ((medPtr->windowPart == inDrag || medPtr->windowPart == inGrow) && medPtr->state & Mod1Mask); if (!cmdDragGrow) { Tk_Window grabWin = GetGrabWindowForWindow(tkwin); frontWindowOnly = !grabWin; if (grabWin && grabWin != tkwin) { TkMacOSXSetEatButtonUp(true); BringWindowForward(TkMacOSXDrawableWindow( ((TkWindow*)grabWin)->window), isFrontProcess, frontWindowOnly); return false; } } /* * Clicks in the titlebar widgets are handled without bringing the * window forward. */ if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) { statusPtr->stopProcessing = 1; return result; } else { /* * Only windows with the kWindowNoActivatesAttribute can * receive mouse events in the background. */ if (!(((TkWindow *)tkwin)->wmInfoPtr->attributes & kWindowNoActivatesAttribute)) { /* * Allow background window dragging & growing with Command * down. */ if (!cmdDragGrow) { TkMacOSXSetEatButtonUp(true); BringWindowForward(medPtr->whichWin, isFrontProcess, frontWindowOnly); } /* * Allow dragging & growing of windows that were/are in the * background. */ if (!(medPtr->windowPart == inDrag || medPtr->windowPart == inGrow)) { return false; } } } } else { if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) { statusPtr->stopProcessing = 1; return result; } } switch (medPtr->windowPart) { case inDrag: { WindowAttributes attributes; GetWindowAttributes(medPtr->whichWin, &attributes); if (!(attributes & kWindowAsyncDragAttribute)) { TkMacOSXTrackingLoop(1); DragWindow(medPtr->whichWin, where, NULL); TkMacOSXTrackingLoop(0); where2.h = where2.v = 0; QDLocalToGlobalPoint(GetWindowPort(medPtr->whichWin), &where2); if (EqualPt(where, where2)) { return false; } return true; } break; } case inGrow: /* * Generally the content region is the domain of Tk * sub-windows. However, one exception is the grow * region. A button down in this area will be handled * by the window manager. Note: this means that Tk * may not get button down events in this area! */ if (TkMacOSXGrowToplevel(medPtr->whichWin, where) == true) { statusPtr->stopProcessing = 1; return true; } else { return GenerateButtonEvent(medPtr); } break; case inContent: return GenerateButtonEvent(medPtr); break; default: return false; break; } } return false; }
// static pascal OSStatus IGraphicsCarbon::TextEntryHandler(EventHandlerCallRef pHandlerCall, EventRef pEvent, void* pGraphicsCarbon) { IGraphicsCarbon* _this = (IGraphicsCarbon*) pGraphicsCarbon; UInt32 eventClass = GetEventClass(pEvent); UInt32 eventKind = GetEventKind(pEvent); switch (eventClass) { case kEventClassKeyboard: switch (eventKind) { case kEventRawKeyDown: case kEventRawKeyRepeat: { // Get the keys and modifiers char c; UInt32 k; UInt32 modifiers; GetEventParameter(pEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &c); GetEventParameter(pEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &k); GetEventParameter(pEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); // paste if (c == 118 && modifiers == 256) { if (TXNIsScrapPastable()) { TXNPaste(_this->mTextEntryView); return eventNotHandledErr; } } // trap enter keys if (c == 3 || c == 13) { _this->EndUserInput(true); return noErr; } // trap escape key if (c == 27) { _this->EndUserInput(false); return noErr; } // pass arrow keys if (k == 125 || k == 126 || k == 123 || k == 124) return eventNotHandledErr; // pass delete keys if (c == 8 || c == 127) return eventNotHandledErr; if (_this->mEdParam) { switch ( _this->mEdParam->Type() ) { case IParam::kTypeEnum: case IParam::kTypeInt: case IParam::kTypeBool: if (c >= '0' && c <= '9') break; else if (c == '-') break; else if (c == '+') break; else return noErr; case IParam::kTypeDouble: if (c >= '0' && c <= '9') break; else if (c == '.') break; else if (c == '-') break; else if (c == '+') break; else return noErr; default: break; } } // Get the text CharsHandle textHandle; long textLength = 0; TXNGetDataEncoded(_this->mTextEntryView, kTXNStartOffset, kTXNEndOffset, &textHandle, kTXNTextData); // Check that we have some worthwhile data if (textHandle != NULL && GetHandleSize(textHandle) > 0) { textLength = GetHandleSize(textHandle); } if(textLength >= _this->mEdControl->GetTextEntryLength()) { return noErr; } else { EventRecord eventRecord; if (ConvertEventRefToEventRecord(pEvent, &eventRecord)) { TXNKeyDown(_this->mTextEntryView, &eventRecord); return noErr; } } } break; } break; case kEventClassMouse: { switch (eventKind) { case kEventMouseDown: case kEventMouseUp: { // Get the window handle WindowRef window; GetEventParameter(pEvent, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); // Determine the point HIPoint p; GetEventParameter(pEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &p); Point point = { (short)p.y, (short)p.x }; QDGlobalToLocalPoint(GetWindowPort (window), &point); // Get the viewable area Rect rect; TXNGetViewRect (_this->mTextEntryView, &rect); //swell collision #undef PtInRect #define MacPtInRect PtInRect // Handle the click as necessary if (PtInRect(point, &rect)) { #define PtInRect(r,p) SWELL_PtInRect(r,p) EventRecord eventRecord; if (eventKind == kEventMouseDown && ConvertEventRefToEventRecord(pEvent, &eventRecord)) { TXNClick(_this->mTextEntryView, &eventRecord); } return noErr; } else { CallNextEventHandler(pHandlerCall, pEvent); ClearKeyboardFocus(window); _this->EndUserInput(false); return noErr; } } break; case kEventMouseMoved: TXNAdjustCursor(_this->mTextEntryView, NULL); return noErr; case kEventMouseWheelMoved: return noErr; } break; } case kEventClassWindow: { WindowRef window; GetEventParameter (pEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); switch (eventKind) { case kEventWindowFocusRelinquish: case kEventWindowClosed: case kEventWindowDeactivated: CallNextEventHandler(pHandlerCall, pEvent); ClearKeyboardFocus(window); _this->EndUserInput(false); return noErr; } break; } } return eventNotHandledErr; }
pascal OSStatus TextControlProc(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData) { OSStatus result = eventNotHandledErr; UInt32 eventClass = GetEventClass(inEvent); UInt32 eventKind = GetEventKind(inEvent); cBitmapFontEditable* control = (cBitmapFontEditable*)inUserData; switch(eventClass) { case kEventClassKeyboard: { switch(eventKind) { case kEventRawKeyDown: case kEventRawKeyRepeat: { char macCharCode; UInt32 keyCode; UInt32 modifiers; GetEventParameter(inEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof (char), NULL, &macCharCode); GetEventParameter(inEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof (UInt32), NULL, &keyCode); GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof (UInt32), NULL, &modifiers); VstKeyCode key; key.character = macCharCode; ((cBitmapFontEditable*)control)->onKeyDown(key); break; } } break; } case kEventClassMouse: { switch (eventKind) { case kEventMouseDown: { WindowRef window; GetEventParameter(inEvent, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); HIPoint p; GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &p); Point point = { (short)p.y, (short)p.x }; QDGlobalToLocalPoint(GetWindowPort(window), &point); CRect crect; control->getViewSize(crect); Rect rect; rect.top = crect.top; rect.left = crect.left; rect.right = crect.right; rect.bottom = crect.bottom; //TXNGetViewRect((cBitmap)textEdit->platformControl, &rect); if(PtInRect(point, &rect)) { EventRecord eventRecord; if(eventKind == kEventMouseDown && ConvertEventRefToEventRecord(inEvent, &eventRecord)) { // Mouse click received } else { VstKeyCode key; key.character = KEY_ESC; control->onKeyDown(key); } result = noErr; } break; } } break; } case kEventClassWindow: { WindowRef window; if(GetEventParameter(inEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof (WindowRef), NULL, &window) != noErr) { break; } switch(eventKind) { case kEventWindowDeactivated: { result = CallNextEventHandler(inHandlerCallRef, inEvent); ClearKeyboardFocus(window); // set up the correct drawing port for the window GrafPtr savedPort; bool portChanged = QDSwapPort(GetWindowPort (window), &savedPort); // remember the current resource map ID short currentResID = CurResFile(); short vstResFileID = control->pluginResID; // if it's different (and if it's valid), set the current resource map ID to our plugin's resource map if((vstResFileID != currentResID) && (vstResFileID > 0)) { UseResFile(vstResFileID); } VstKeyCode key; key.character = KEY_ESC; ((cBitmapFontEditable*)control)->onKeyDown(key); // revert the window port, if we changed it if(portChanged) { QDSwapPort(savedPort, NULL); } // revert the current resource map, if we changed it if((currentResID > 0) && (vstResFileID != currentResID) && (vstResFileID > 0)) { UseResFile(currentResID); } break; } } break; } } return result; }