在移动OS X"Carbon"时,可以使用哪个API捕获鼠标.视窗? [英] Which API can be used to _capture_ the mouse when moving OS X "Carbon" windows?

查看:77
本文介绍了在移动OS X"Carbon"时,可以使用哪个API捕获鼠标.视窗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据要求,我已经实现了对移动OS X窗口的支持,方法是使用该窗口的内容部分内的区域进行拖动,即,将标题栏的拖动和移动功能复制到另一个区域.

On request I have implemented support for moving an OS X window by dragging it using an area within the content part of the window, i.e replicating the drag and move functionality of the title bar but in another area.

我尚未解决的问题是,如果用户快速拖动鼠标,它可能会离开窗口区域,因此不再接收到任何鼠标移动事件.

The problem I have yet to resolve is the fact that if the user drags the mouse quickly it can leave the window area and then no more mouse move events are received.

在Windows上,可以通过调用win32方法SetCapture()来解决此类型的问题,相应的OSX方法是什么?

On windows this type of problem can simply be fixed by calling the win32 method SetCapture(), what's the corresponding OSX method?

此应用程序是跨平台C ++应用程序,使用Carbon来安装OS X特定部分. (是的,我知道所有有关Cocoa的好处,但这是一个较旧的代码库,并且在这个时间点上没有时间和金钱来购买Cocoa港口.)

This application is a cross platform C++ application using Carbon for the OS X specific parts. (And yes, I know all about the Cocoa benefits but this is an older code base and there no time nor money for a Cocoa port at this point in time.)

我发现了Carbon API方法,例如TrackMouseLocation(),但实际上看不到如何在此应用程序中使用它们.在清单2-7中,此处 http: //developer.apple.com/legacy/mac/library/documentation/Carbon/Conceptual/Carbon_Event_Manager/Tasks/CarbonEventsTasks.html 鼠标被捕获,但问题是TrackMouseLocation()阻止了等待输入.阻塞是该应用程序无法执行的操作,因为它还托管了必须每秒调用多次的Flash Player.

I have found Carbon API methods like for example TrackMouseLocation() but can't really see how I could use them for this application. In listing 2-7 here http://developer.apple.com/legacy/mac/library/documentation/Carbon/Conceptual/Carbon_Event_Manager/Tasks/CarbonEventsTasks.html the mouse is captured but the problem is that TrackMouseLocation() blocks waiting for input. Blocking is something this application can not do since it also host a flash player that must be called many times per second.

我试图弄清这个原型时组装的原型基本上是这样的:

The protototype I have assembled when trying to figure this out basically looks like this:

switch(GetEventKind(inEvent))
{
  case kEventMouseDown:
    // A silly test to make parts of the window border "draggable"
    dragging = local_loc.v < 25 || local_loc.h < 25; 
    last_screen_loc = screen_loc;
    break;
  case kEventMouseUp:
    dragging = false;
    break;
  case kEventMouseMoved:
    break;
  case kEventMouseDragged:
    if (dragging) {
      Rect rect;
      GetWindowBounds (windowRef, kWindowContentRgn, &rect);
      int dx = screen_loc.h - last_screen_loc.h;
      int dy = screen_loc.v - last_screen_loc.v;
      rect.left += dx;
      rect.right += dx;
      rect.top += dy;
      rect.bottom += dy;
      SetWindowBounds (windowRef, kWindowContentRgn, &rect);
    }
    last_screen_loc = screen_loc;
    break;

有什么想法值得赞赏吗?

Any ideas appreciated?

推荐答案

我觉得您应该在Window以及窗口之外跟踪鼠标.以下代码可以解决您的问题,

I feel you should track mouse in Window as well as out of window. Following code should solve your problem,

EventHandlerRef     m_ApplicationMouseDragEventHandlerRef;          
EventHandlerRef     m_MonitorMouseDragEventHandlerRef;

{
    OSStatus ErrStatus;

    static const EventTypeSpec kMouseDragEvents[] =
      {
        { kEventClassMouse, kEventMouseDragged }
      };

    ErrStatus = InstallEventHandler(GetEventMonitorTarget(), NewEventHandlerUPP(MouseHasDragged), GetEventTypeCount(kMouseDragEvents), kMouseDragEvents, this, &m_MonitorMouseDragEventHandlerRef);

    ErrStatus = InstallApplicationEventHandler(NewEventHandlerUPP(MouseHasDragged), GetEventTypeCount(kMouseDragEvents), kMouseDragEvents, this, &m_ApplicationMouseDragEventHandlerRef);

    return true;
}

//implement these functions
OSStatus MouseHasDragged(EventHandlerCallRef inCaller, EventRef inEvent, void *pUserData){}

希望有帮助!

这篇关于在移动OS X"Carbon"时,可以使用哪个API捕获鼠标.视窗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆