Example #1
0
pascal OSErr wxMacWindowDragReceiveHandler(
    WindowPtr theWindow,
    void *handlerRefCon,
    DragReference theDrag)
{
    MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*)handlerRefCon;
    if ( trackingGlobals->m_currentTarget )
    {
        Point mouse, localMouse;
        int localx, localy;

        trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
        GetDragMouse( theDrag, &mouse, 0L );
        localMouse = mouse;
        wxMacGlobalToLocal( theWindow, &localMouse );
        localx = localMouse.h;
        localy = localMouse.v;

        // TODO : should we use client coordinates?
        if ( trackingGlobals->m_currentTargetWindow )
            trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx, &localy );
        if ( trackingGlobals->m_currentTarget->OnDrop( localx, localy ) )
        {
            bool optionDown = GetCurrentKeyModifiers() & optionKey;
            wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
            trackingGlobals->m_currentTarget->OnData( localx, localy, result );
        }
    }

    return noErr;
}
Example #2
0
KeyModifierMask
OSXKeyState::pollActiveModifiers() const
{
	// falsely assumed that the mask returned by GetCurrentKeyModifiers()
	// was the same as a CGEventFlags (which is what mapModifiersFromOSX
	// expects). patch by Marc
	UInt32 mask = GetCurrentKeyModifiers();
	KeyModifierMask outMask = 0;

	if ((mask & shiftKey) != 0) {
		outMask |= KeyModifierShift;
	}
	if ((mask & controlKey) != 0) {
		outMask |= KeyModifierControl;
	}
	if ((mask & optionKey) != 0) {
		outMask |= KeyModifierAlt;
	}
	if ((mask & cmdKey) != 0) {
		outMask |= KeyModifierSuper;
	}
	if ((mask & alphaLock) != 0) {
		outMask |= KeyModifierCapsLock;
	}
	if ((mask & s_osxNumLock) != 0) {
		outMask |= KeyModifierNumLock;
	}

	LOG((CLOG_DEBUG1 "mask=%04x outMask=%04x", mask, outMask));
	return outMask;
}
Example #3
0
File: app.cpp Project: hgwells/tive
wxMouseState wxGetMouseState()
{
    wxMouseState ms;

    wxPoint pt = wxGetMousePosition();
    ms.SetX(pt.x);
    ms.SetY(pt.y);

#if TARGET_API_MAC_OSX
    UInt32 buttons = GetCurrentButtonState();
    ms.SetLeftDown( (buttons & 0x01) != 0 );
    ms.SetMiddleDown( (buttons & 0x04) != 0 );
    ms.SetRightDown( (buttons & 0x02) != 0 );
#else
    ms.SetLeftDown( Button() );
    ms.SetMiddleDown( 0 );
    ms.SetRightDown( 0 );
#endif

    UInt32 modifiers = GetCurrentKeyModifiers();
    ms.SetControlDown(modifiers & controlKey);
    ms.SetShiftDown(modifiers & shiftKey);
    ms.SetAltDown(modifiers & optionKey);
    ms.SetMetaDown(modifiers & cmdKey);

    return ms;
}
Example #4
0
static pascal OSStatus MyMainThreadYielder(void)
{
	OSStatus err;
	static UInt32 gTimeLastPrinted;
	
	if ( TickCount() > (gTimeLastPrinted + 30) ) {
		printf(".");
		fflush(stdout);
		gTimeLastPrinted = TickCount();
	}

	#if TARGET_API_MAC_CARBON
		{
			err = noErr;
			if (GetCurrentKeyModifiers() & alphaLock) {
				err = kOTCanceledErr;
			}
		}
	#else
		{
			EventRecord event;
			
			err = noErr;
			(void) OSEventAvail(0, &event);
			if (event.modifiers & alphaLock) {
				err = kOTCanceledErr;
			}
		}
	#endif
	return err;
}
Example #5
0
// MW-2008-06-12: Updated to use more modern GetCurrentKeyModifiers function
//   to fetch the modifier state.
uint2 MCScreenDC::querymods()
{
	if (lockmods)
		return MCmodifierstate;
		
	UInt32 t_modifiers;
	t_modifiers = GetCurrentKeyModifiers();
	
	uint2 state;
	state = 0;
	
	if ((t_modifiers & (1 << shiftKeyBit)) != 0)
		state |= MS_SHIFT;
	
	if ((t_modifiers & (1 << cmdKeyBit)) != 0)
		state |= MS_CONTROL;
		
	if ((t_modifiers & (1 << optionKeyBit)) != 0)
		state |= MS_MOD1;
		
	if ((t_modifiers & (1 << controlKeyBit)) != 0)
		state |= MS_MOD2;
		
	if ((t_modifiers & (1 << alphaLockBit)) != 0)
		state |= MS_CAPS_LOCK;
		
	return state;
}
Example #6
0
static bool ForceOpen()
{
#if TARGET_API_MAC_CARBON
    //UInt32 keys = GetCurrentEventKeyModifiers();
	UInt32 keys = GetCurrentKeyModifiers();
	
	return ( (keys & shiftKey) || (keys & rightShiftKey) || (keys & optionKey) || (keys & rightOptionKey) );
#else
	return false;
#endif
}
Example #7
0
EventModifiers
TkMacOSXModifierState(void)
{
    UInt32 keyModifiers;
    int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront());

    keyModifiers = isFrontProcess ? GetCurrentEventKeyModifiers() :
	    GetCurrentKeyModifiers();

    return (EventModifiers)(keyModifiers & USHRT_MAX);
}
bool PlatformKeyboardEvent::currentCapsLockState()
{
#if PLATFORM(WIN_OS)
    // FIXME: Does this even work inside the sandbox?
    return GetKeyState(VK_CAPITAL) & 1;
#elif PLATFORM(DARWIN)
    return GetCurrentKeyModifiers() & alphaLock;
#else
    notImplemented();
    return false;
#endif
}
Example #9
0
bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below
{
    wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key !=
        WXK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons"));

//if OS X > 10.2 (i.e. 10.2.x)
//a known apple bug prevents the system from determining led
//states with GetKeys... can only determine caps lock led
   return !!(GetCurrentKeyModifiers() & wxMacKeyCodeToModifier(key)); 
//else
//  KeyMapByteArray keymap; 
//  GetKeys((BigEndianLong*)keymap);
//  return !!(BitTst(keymap, (sizeof(KeyMapByteArray)*8) - iKey));
}
Example #10
0
static PyObject *Evt_GetCurrentKeyModifiers(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    UInt32 _rv;
#ifndef GetCurrentKeyModifiers
    PyMac_PRECHECK(GetCurrentKeyModifiers);
#endif
    if (!PyArg_ParseTuple(_args, ""))
        return NULL;
    _rv = GetCurrentKeyModifiers();
    _res = Py_BuildValue("l",
                         _rv);
    return _res;
}
Example #11
0
unsigned int
TkMacOSXButtonKeyState(void)
{
    UInt32 buttonState = 0, keyModifiers;
    int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront());

    if (!TkMacOSXGetEatButtonUp()) {
	buttonState = isFrontProcess ? GetCurrentEventButtonState() :
		GetCurrentButtonState();
    }
    keyModifiers = isFrontProcess ? GetCurrentEventKeyModifiers() :
	    GetCurrentKeyModifiers();

    return ButtonModifiers2State(buttonState, keyModifiers);
}
wchar_t InputHandler_MacOSX_HID::DeviceButtonToChar( DeviceButton button, bool bUseCurrentKeyModifiers )
{
	// KeyTranslate maps these keys to a character.  They shouldn't be mapped to any character.
	switch( button )
	{
		default:
			if( (button >= KEY_F1 && button <= KEY_F16) )
				return L'\0';
			break;
		case KEY_UP:
		case KEY_DOWN:
		case KEY_LEFT:
		case KEY_RIGHT:
		case KEY_ESC:
		case KEY_TAB:
		case KEY_ENTER:
		case KEY_PRTSC:
		case KEY_SCRLLOCK:
		case KEY_PAUSE:
		case KEY_DEL:
		case KEY_HOME:
		case KEY_END:
		case KEY_PGUP:
		case KEY_PGDN:
		case KEY_NUMLOCK:
		case KEY_KP_ENTER:
			return L'\0';
	}

	// Use Text Input Source services to convert the key code to character code.
	UInt8 iMacVirtualKey;
	if( KeyboardDevice::DeviceButtonToMacVirtualKey( button, iMacVirtualKey ) )
	{
		UInt32 nModifiers = bUseCurrentKeyModifiers ? GetCurrentKeyModifiers() : 0;
		wchar_t sCharCode = KeyCodeToChar( iMacVirtualKey, nModifiers );
		if( sCharCode != 0 )
		{
			return sCharCode;
		}
	}

	return InputHandler::DeviceButtonToChar( button, bUseCurrentKeyModifiers );
}
Example #13
0
pascal OSErr wxMacWindowDragReceiveHandler(
    WindowPtr theWindow,
    void *handlerRefCon,
    DragReference theDrag)
{
    MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*)handlerRefCon;
    if ( trackingGlobals->m_currentTarget )
    {
        Point mouse, localMouse;
        int localx, localy;

        PasteboardRef   pasteboard = 0;
        GetDragPasteboard( theDrag, &pasteboard );
        trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
        GetDragMouse( theDrag, &mouse, 0L );
        localMouse = mouse;
        localx = localMouse.h;
        localy = localMouse.v;
        wxNonOwnedWindow* tlw = wxNonOwnedWindow::GetFromWXWindow((WXWindow) theWindow);
        if ( tlw )
            tlw->GetNonOwnedPeer()->ScreenToWindow( &localx, &localy );

        // TODO : should we use client coordinates?
        if ( trackingGlobals->m_currentTargetWindow )
            trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx, &localy );
        if ( trackingGlobals->m_currentTarget->OnDrop( localx, localy ) )
        {
            // the option key indicates copy in Mac UI, if it's not pressed do
            // move by default if it's allowed at all
            wxDragResult
                result = !(trackingGlobals->m_flags & wxDrag_AllowMove) ||
                            (GetCurrentKeyModifiers() & optionKey)
                            ? wxDragCopy
                            : wxDragMove;
            trackingGlobals->m_result =
                trackingGlobals->m_currentTarget->OnData( localx, localy, result );
        }
    }

    return noErr;
}
Example #14
0
void PlatformKeyboardEvent::getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey)
{
#if OS(WIN)
    shiftKey = GetKeyState(VK_SHIFT) & HIGHBITMASKSHORT;
    ctrlKey = GetKeyState(VK_CONTROL) & HIGHBITMASKSHORT;
    altKey = GetKeyState(VK_MENU) & HIGHBITMASKSHORT;
    metaKey = false;
#elif OS(MACOSX)
    UInt32 currentModifiers = GetCurrentKeyModifiers();
    shiftKey = currentModifiers & ::shiftKey;
    ctrlKey = currentModifiers & ::controlKey;
    altKey = currentModifiers & ::optionKey;
    metaKey = currentModifiers & ::cmdKey;
#else
    shiftKey = false;
    ctrlKey = false;
    altKey = false;
    metaKey = false;
    notImplemented();
#endif
}
Example #15
0
KeyModifierMask
COSXKeyState::pollActiveModifiers() const
{
	return mapModifiersFromOSX(GetCurrentKeyModifiers());
}
Example #16
0
pascal OSErr wxMacWindowDragTrackingHandler(
    DragTrackingMessage theMessage, WindowPtr theWindow,
    void *handlerRefCon, DragReference theDrag )
{
    MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;

    Point mouse, localMouse;
    DragAttributes attributes;

    GetDragAttributes( theDrag, &attributes );
    PasteboardRef   pasteboard = 0;
    GetDragPasteboard( theDrag, &pasteboard );
    wxNonOwnedWindow* toplevel = wxNonOwnedWindow::GetFromWXWindow( (WXWindow) theWindow );

    bool optionDown = GetCurrentKeyModifiers() & optionKey;
    wxDragResult result = optionDown ? wxDragCopy : wxDragMove;

    switch (theMessage)
    {
        case kDragTrackingEnterHandler:
        case kDragTrackingLeaveHandler:
            break;

        case kDragTrackingEnterWindow:
            if (trackingGlobals != NULL)
            {
                trackingGlobals->m_currentTargetWindow = NULL;
                trackingGlobals->m_currentTarget = NULL;
            }
            break;

        case kDragTrackingInWindow:
            if (trackingGlobals == NULL)
                break;
            if (toplevel == NULL)
                break;

            GetDragMouse( theDrag, &mouse, 0L );
            {
                int x = mouse.h ;
                int y = mouse.v ;
                toplevel->GetNonOwnedPeer()->ScreenToWindow( &x, &y );
                localMouse.h = x;
                localMouse.v = y;

                {
                    wxWindow *win = NULL;
                    ControlPartCode controlPart;
                    ControlRef control = FindControlUnderMouse( localMouse, theWindow, &controlPart );
                    if ( control )
                        win = wxFindWindowFromWXWidget( (WXWidget) control );
                    else
                        win = toplevel;

                    int localx, localy;
                    localx = localMouse.h;
                    localy = localMouse.v;

                    if ( win )
                        win->MacRootWindowToWindow( &localx, &localy );
                    if ( win != trackingGlobals->m_currentTargetWindow )
                    {
                        if ( trackingGlobals->m_currentTargetWindow )
                        {
                            // this window is left
                            if ( trackingGlobals->m_currentTarget )
                            {
                                HideDragHilite( theDrag );
                                trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
                                trackingGlobals->m_currentTarget->OnLeave();
                                trackingGlobals->m_currentTarget = NULL;
                                trackingGlobals->m_currentTargetWindow = NULL;
                            }
                        }

                        if ( win )
                        {
                            // this window is entered
                            trackingGlobals->m_currentTargetWindow = win;
                            trackingGlobals->m_currentTarget = win->GetDropTarget();
                            {
                                if ( trackingGlobals->m_currentTarget )
                                {
                                    trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
                                    result = trackingGlobals->m_currentTarget->OnEnter( localx, localy, result );
                                }

                                if ( result != wxDragNone )
                                {
                                    int x, y;

                                    x = y = 0;
                                    win->MacWindowToRootWindow( &x, &y );
                                    RgnHandle hiliteRgn = NewRgn();
                                    Rect r = { y, x, y + win->GetSize().y, x + win->GetSize().x };
                                    RectRgn( hiliteRgn, &r );
                                    ShowDragHilite( theDrag, hiliteRgn, true );
                                    DisposeRgn( hiliteRgn );
                                }
                            }
                        }
                    }
                    else
                    {
                        if ( trackingGlobals->m_currentTarget )
                        {
                            trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
                            result = trackingGlobals->m_currentTarget->OnDragOver( localx, localy, result );
                        }
                    }

                    // set cursor for OnEnter and OnDragOver
                    if ( trackingGlobals->m_currentSource && !trackingGlobals->m_currentSource->GiveFeedback( result ) )
                    {
                        if ( !trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) )
                        {
                            wxStockCursor cursorID = wxCURSOR_NONE;

                            switch (result)
                            {
                                case wxDragCopy:
                                    cursorID = wxCURSOR_COPY_ARROW;
                                    break;

                                case wxDragMove:
                                    cursorID = wxCURSOR_ARROW;
                                    break;

                                case wxDragNone:
                                    cursorID = wxCURSOR_NO_ENTRY;
                                    break;

                                case wxDragError:
                                case wxDragLink:
                                case wxDragCancel:
                                default:
                                    // put these here to make gcc happy
                                    ;
                            }

                            if (cursorID != wxCURSOR_NONE)
                            {
                                wxCursor cursor( cursorID );
                                cursor.MacInstall();
                            }
                        }
                    }
                }
            }
            break;

        case kDragTrackingLeaveWindow:
            if (trackingGlobals == NULL)
                break;

            if (trackingGlobals->m_currentTarget)
            {
                trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
                trackingGlobals->m_currentTarget->OnLeave();
                HideDragHilite( theDrag );
                trackingGlobals->m_currentTarget = NULL;
            }
            trackingGlobals->m_currentTargetWindow = NULL;
            break;

        default:
            break;
    }

    return noErr;
}
Example #17
0
// ---------------------------------------------------------------------------
OSStatus OSXWindowImpl::windowHandler(EventHandlerCallRef next, EventRef e) {
  EventClass clazz = GetEventClass(e);
  EventKind kind = GetEventKind(e);
  switch( clazz ) {
    case kEventClassWindow:
      {
        switch( kind ) {
          case kEventWindowDrawContent:
            on_paint();
            break;
          case kEventWindowClosed:
            on_dispose();
            break;
          case kEventWindowBoundsChanged:
            {
              aglUpdateContext(mGLContext);
              GetWindowBounds(mWindowRef,kWindowContentRgn,&mRect);
              if (window)
                window->resize( mRect.right - mRect.left, mRect.bottom - mRect.top );
            }
            break; 
        }
      }
      break;
    case kEventClassMouse:
      {
        EventMouseButton button;
        GetEventParameter(e,kEventParamMouseButton,   typeMouseButton, NULL, sizeof(button), NULL, &button);
        Point location;
        GetEventParameter(e,kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &location);
        int mouseX = location.h - mRect.left;
        int mouseY = location.v - mRect.top;
        switch( kind ) {
          case kEventMouseDown:
            {
          
              UInt32 mod = GetCurrentKeyModifiers();
              if (mod & EMULATE_RIGHT_KEYMOD) {
                mButtonDown = GUI_ButtonRight;
                mMouseDownMod = EMULATE_RIGHT_KEYMOD;
              } else if (mod & EMULATE_MIDDLE_KEYMOD) {
                mButtonDown = GUI_ButtonMiddle;
                mMouseDownMod = EMULATE_MIDDLE_KEYMOD;
              } else {
                mButtonDown = button;
                mMouseDownMod = 0;
              }
              window->buttonPress( mButtonDown,mouseX,mouseY);
            }
            break;
          case kEventMouseUp:
            if ( (mButtonDown) && ( (mMouseDownMod) || (mButtonDown == button) ) ) {
              window->buttonRelease( mButtonDown,mouseX,mouseY);
              mMouseDownMod = 0;
              mButtonDown   = 0;
            }
            break;
          case kEventMouseMoved:
          case kEventMouseDragged:
            window->mouseMove(mouseX,mouseY);
            break;
          case kEventMouseWheelMoved:
            UInt16 axis;
            GetEventParameter(e,kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(axis), NULL, &axis);
            if (axis == kEventMouseWheelAxisY) {
              int delta;
              GetEventParameter(e,kEventParamMouseWheelDelta, typeSInt32, NULL, sizeof(delta), NULL, &delta);
              if (delta != 0)
                window->wheelRotate( (delta > 0) ? GUI_WheelForward : GUI_WheelBackward );
            }
        }
      }
      break;
    case kEventClassKeyboard:
      {
        UInt32 keycode;
        GetEventParameter(e,kEventParamKeyCode, typeUInt32, NULL, sizeof(keycode), NULL, &keycode);
        switch( kind ) {
          case kEventRawKeyDown:
            break;
          case kEventRawKeyUp:
            break;
          case kEventRawKeyModifiersChanged:
            
            break;
          default:
            break;
        }
      }
      break;
    default:
      break;
  }   
  return CallNextEventHandler(next,e);
}
Example #18
0
wxDragResult wxDropSource::DoDragDrop(int flags)
{
    wxASSERT_MSG( m_data, wxT("Drop source: no data") );

    if ((m_data == NULL) || (m_data->GetFormatCount() == 0))
        return (wxDragResult)wxDragNone;

    DragReference theDrag;
    RgnHandle dragRegion;

    if (NewDrag( &theDrag ) != noErr)
        return wxDragNone;

    // add data to drag
    size_t formatCount = m_data->GetFormatCount();
    wxDataFormat *formats = new wxDataFormat[formatCount];
    m_data->GetAllFormats( formats );
    ItemReference theItem = (ItemReference) 1;

    for ( size_t i = 0; i < formatCount; ++i )
    {
        size_t dataSize = m_data->GetDataSize( formats[i] );
        Ptr dataPtr = new char[dataSize];
        m_data->GetDataHere( formats[i], dataPtr );
        OSType type = formats[i].GetFormatId();
        if ( type == 'TEXT' || type == 'utxt' )
        {
            if ( dataSize > 0 )
                dataSize--;
            dataPtr[ dataSize ] = 0;
            if ( type == 'utxt' )
            {
                if ( dataSize > 0 )
                    dataSize--;
                dataPtr[ dataSize ] = 0;
            }

            AddDragItemFlavor( theDrag, theItem, type, dataPtr, dataSize, 0 );
        }
        else if (type == kDragFlavorTypeHFS )
        {
            HFSFlavor  theFlavor;
            OSErr err = noErr;
#ifndef __LP64__
            CInfoPBRec cat;

            wxMacFilename2FSSpec( wxString( dataPtr, *wxConvCurrent ), &theFlavor.fileSpec );

            memset( &cat, 0, sizeof(cat) );
            cat.hFileInfo.ioNamePtr = theFlavor.fileSpec.name;
            cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum;
            cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
            cat.hFileInfo.ioFDirIndex = 0;
            err = PBGetCatInfoSync( &cat );
#endif
          if (err == noErr)
            {
#ifndef __LP64__
                theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags;
                if (theFlavor.fileSpec.parID == fsRtParID)
                {
                    theFlavor.fileCreator = 'MACS';
                    theFlavor.fileType = 'disk';
                }
                else if ((cat.hFileInfo.ioFlAttrib & ioDirMask) != 0)
                {
                    theFlavor.fileCreator = 'MACS';
                    theFlavor.fileType = 'fold';
                }
                else
                {
                    theFlavor.fileCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator;
                    theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
                }
#endif
                AddDragItemFlavor( theDrag, theItem, type, &theFlavor, sizeof(theFlavor), 0 );
            }
        }
        else
        {
            AddDragItemFlavor( theDrag, theItem, type, dataPtr, dataSize, 0 );
        }

        delete [] dataPtr;
    }

    delete [] formats;

    dragRegion = NewRgn();
    RgnHandle tempRgn = NewRgn();

    EventRecord* ev = NULL;

#if !TARGET_CARBON // TODO
    ev = (EventRecord*) wxTheApp->MacGetCurrentEvent();
#else
    EventRecord rec;
    ev = &rec;
    wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent(), &rec );
#endif

    const short dragRegionOuterBoundary = 10;
    const short dragRegionInnerBoundary = 9;

    SetRectRgn(
        dragRegion,
        ev->where.h - dragRegionOuterBoundary,
        ev->where.v  - dragRegionOuterBoundary,
        ev->where.h + dragRegionOuterBoundary,
        ev->where.v + dragRegionOuterBoundary );

    SetRectRgn(
        tempRgn,
        ev->where.h - dragRegionInnerBoundary,
        ev->where.v - dragRegionInnerBoundary,
        ev->where.h + dragRegionInnerBoundary,
        ev->where.v + dragRegionInnerBoundary );

    DiffRgn( dragRegion, tempRgn, dragRegion );
    DisposeRgn( tempRgn );

    // TODO: work with promises in order to return data
    // only when drag was successfully completed

    gTrackingGlobals.m_currentSource = this;
    TrackDrag( theDrag, ev, dragRegion );
    DisposeRgn( dragRegion );
    DisposeDrag( theDrag );
    gTrackingGlobals.m_currentSource = NULL;

    bool optionDown = GetCurrentKeyModifiers() & optionKey;
    wxDragResult dndresult = wxDragCopy;
    if ( flags != wxDrag_CopyOnly )
        // on mac the option key is always the indication for copy
        dndresult = optionDown ? wxDragCopy : wxDragMove;

    return dndresult;
}
Example #19
0
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;
}
Example #20
0
pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
  void *handlerRefCon, DragReference theDrag)
{ 
    MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
    Point mouse, localMouse;
    DragAttributes attributes;
    GetDragAttributes(theDrag, &attributes);
    wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ; 

    bool optionDown = GetCurrentKeyModifiers() & optionKey ;
    wxDragResult result = optionDown ? wxDragCopy : wxDragMove;

    switch(theMessage) 
    {
        case kDragTrackingEnterHandler:
            break;
        case kDragTrackingLeaveHandler:
            break;
        case kDragTrackingEnterWindow:
            trackingGlobals->m_currentTargetWindow = NULL ;
            trackingGlobals->m_currentTarget = NULL ;
            break;
        case kDragTrackingInWindow:
            if (toplevel == NULL)
                break;

            GetDragMouse(theDrag, &mouse, 0L);
            localMouse = mouse;
            GlobalToLocal(&localMouse);


            
            {
                wxWindow *win = NULL ;
                ControlPartCode controlPart ;
                ControlRef control = wxMacFindControlUnderMouse( toplevel , localMouse ,
                    theWindow , &controlPart ) ;
                if ( control )
                    win = wxFindControlFromMacControl( control ) ;
                else
                    win = toplevel ;
                
                int localx , localy ;
                localx = localMouse.h ;
                localy = localMouse.v ;

                if ( win )
                    win->MacRootWindowToWindow( &localx , &localy ) ;
                if ( win != trackingGlobals->m_currentTargetWindow )
                {
                    if ( trackingGlobals->m_currentTargetWindow )
                    {
                        // this window is left
                        if ( trackingGlobals->m_currentTarget )
                        {
                            HideDragHilite(theDrag);
                            trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                            trackingGlobals->m_currentTarget->OnLeave() ;
                            trackingGlobals->m_currentTarget = NULL;
                            trackingGlobals->m_currentTargetWindow = NULL ;
                        }
                    }
                    if ( win )
                    {
                        // this window is entered
                        trackingGlobals->m_currentTargetWindow = win ;
                        trackingGlobals->m_currentTarget = win->GetDropTarget() ;
                        {

                        	if ( trackingGlobals->m_currentTarget )
                        	{
                            	trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                            	result = trackingGlobals->m_currentTarget->OnEnter(
                                	localx , localy , result ) ;
                            }
                                
                           
                            if ( result != wxDragNone )
                            {
                                int x , y ;
                                x = y = 0 ;
                                win->MacWindowToRootWindow( &x , &y ) ;
                                RgnHandle hiliteRgn = NewRgn() ;
                                Rect r = { y , x , y+win->GetSize().y , x+win->GetSize().x } ;
                                RectRgn( hiliteRgn , &r ) ;
                                ShowDragHilite(theDrag, hiliteRgn, true);
                                DisposeRgn( hiliteRgn ) ;
                            }
                        }
                    }
                }
                else
                {
                    if( trackingGlobals->m_currentTarget )
                    {
                        trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                        trackingGlobals->m_currentTarget->OnDragOver(
                            localx , localy , result ) ;
                    }
                }

                // set cursor for OnEnter and OnDragOver
                if ( trackingGlobals->m_currentSource && trackingGlobals->m_currentSource->GiveFeedback( result ) == FALSE )
                {
                  if ( trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) == FALSE )
                  {
                      switch( result )
                      {
                          case wxDragCopy :
                              {
                                  wxCursor cursor(wxCURSOR_COPY_ARROW) ;
                                  cursor.MacInstall() ;
                              }
                              break ;
                          case wxDragMove :
                              {
                                  wxCursor cursor(wxCURSOR_ARROW) ;
                                  cursor.MacInstall() ;
                              }
                              break ;
                          case wxDragNone :
                              {
                                  wxCursor cursor(wxCURSOR_NO_ENTRY) ;
                                  cursor.MacInstall() ;
                              }
                              break ;

                          case wxDragError:
                          case wxDragLink:
                          case wxDragCancel:
                              // put these here to make gcc happy
                              ;
                      }
                  }
                }
                
            }
            break;
        case kDragTrackingLeaveWindow:
            if (trackingGlobals->m_currentTarget) 
            {
                trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                trackingGlobals->m_currentTarget->OnLeave() ;
                HideDragHilite(theDrag);
                trackingGlobals->m_currentTarget = NULL ;
            }
            trackingGlobals->m_currentTargetWindow = NULL ;
            break;
    }
    return(noErr);
}