// -----------------------------------------------------------------------------
static HIPoint  
QDGlobalToHIViewLocal( const Point inGlobalPoint, const HIViewRef inDestView)
{                               
    HIPoint viewPoint = CGPointMake(inGlobalPoint.h, inGlobalPoint.v);

    HIPointConvert(&viewPoint, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceView, inDestView);
    return viewPoint;
}
예제 #2
0
void PluginView::eventPointToPluginCarbonPointUsingHIPoint(const IntPoint& eventPoint, WindowRef const carbonWindow, Point* carbonPoint)
{
    ASSERT(carbonPoint);
    IntRect const frameGeom(frameGeometry());
    IntPoint const frameLocation(frameGeom.location());
    IntSize const frameOffset(IntPoint(m_npWindow.x, m_npWindow.y) - frameLocation);
    IntPoint const pluginPoint(eventPoint + frameOffset);
    
    HIPoint mouseHIPoint;
    mouseHIPoint.x = pluginPoint.x();
    mouseHIPoint.y = pluginPoint.y();
    
    if (m_isWindowed) {
        ASSERT(carbonWindow);
        if (carbonWindow) {
            // ** EVIL **
            // In apollo, the HTML rendering can be rotated,
            // blurred, etc.  This means the relation ship between
            // the coordinate space of the plugin and the screen is not straight forward.
            // Fortunately, we are already making the carbon event from whole cloth.
            // The FlashPlayer uses HIPointConvert to convert the coordinates of the
            // carbon event to the coordinates of the plugin by calling HIPointConvert.
            // We just call HIPointConvert to convert the mouse point the opposite direction
            // so the FlashPlayer will end up with the correct coordinates for the mouse point.
            HIPointConvert(&mouseHIPoint
                          , kHICoordSpaceWindow
                          , carbonWindow
                          , kHICoordSpaceScreenPixel
                          , 0);
            
        }
    }
    
    carbonPoint->h = static_cast<short>(mouseHIPoint.x);
    carbonPoint->v = static_cast<short>(mouseHIPoint.y);
}
예제 #3
0
// static
pascal OSStatus IGraphicsCarbon::MainEventHandler(EventHandlerCallRef pHandlerCall, EventRef pEvent, void* pGraphicsCarbon)
{
  IGraphicsCarbon* _this = (IGraphicsCarbon*) pGraphicsCarbon;
  IGraphicsMac* pGraphicsMac = _this->mGraphicsMac;
  UInt32 eventClass = GetEventClass(pEvent);
  UInt32 eventKind = GetEventKind(pEvent);

  switch (eventClass)
  {
    case kEventClassKeyboard:
    {
      switch (eventKind)
      {
        case kEventRawKeyDown:
        {
          if (_this->mTextEntryView)
            return eventNotHandledErr;

          bool handle = true;
          int key;
          UInt32 k;
          GetEventParameter(pEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &k);

          char c;
          GetEventParameter(pEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &c);

          if (k == 49) key = KEY_SPACE;
          else if (k == 125) key = KEY_DOWNARROW;
          else if (k == 126) key = KEY_UPARROW;
          else if (k == 123) key = KEY_LEFTARROW;
          else if (k == 124) key = KEY_RIGHTARROW;
          else if (c >= '0' && c <= '9') key = KEY_DIGIT_0+c-'0';
          else if (c >= 'A' && c <= 'Z') key = KEY_ALPHA_A+c-'A';
          else if (c >= 'a' && c <= 'z') key = KEY_ALPHA_A+c-'a';
          else handle = false;

          if(handle)
            handle = pGraphicsMac->OnKeyDown(_this->mPrevX, _this->mPrevY, key);

          if(handle)
            return noErr;
          else
            return eventNotHandledErr;

        }
      }
    }
    case kEventClassControl:
    {
      switch (eventKind)
      {
        case kEventControlDraw:
        {
          int gfxW = pGraphicsMac->Width(), gfxH = pGraphicsMac->Height();

          IRECT r = GetRegionRect(pEvent, gfxW, gfxH);

          CGrafPtr port = 0;

          if (_this->mIsComposited)
          {
            GetEventParameter(pEvent, kEventParamCGContextRef, typeCGContextRef, 0, sizeof(CGContextRef), 0, &(_this->mCGC));
            CGContextTranslateCTM(_this->mCGC, 0, gfxH);
            CGContextScaleCTM(_this->mCGC, 1.0, -1.0);
            pGraphicsMac->Draw(&r);
          }
          else
          {
            GetEventParameter(pEvent, kEventParamGrafPort, typeGrafPtr, 0, sizeof(CGrafPtr), 0, &port);
            QDBeginCGContext(port, &(_this->mCGC));
            
            //RgnHandle clipRegion = NewRgn();
            //GetPortClipRegion(port, clipRegion);
            
            Rect portBounds;
            GetPortBounds(port, &portBounds);

            int offsetW = 0;
            int offsetH = -portBounds.top;
            //int offsetH = (portBounds.bottom - portBounds.top) - gfxH; // this almost works with AS, but clip rect seems wrong when previewing/breaks RTAS
            
            if ((portBounds.right - portBounds.left) >= gfxW)
            {
              offsetW = 0.5 * ((portBounds.right - portBounds.left) - gfxW);
            }
            
            CGContextTranslateCTM(_this->mCGC, portBounds.left + offsetW, offsetH);
            
            r = IRECT(0, 0, pGraphicsMac->Width(), pGraphicsMac->Height());
            pGraphicsMac->Draw(&r); // Carbon non-composited will redraw everything, the IRECT passed here is the entire plugin-gui
            
            QDEndCGContext(port, &(_this->mCGC));
            
            //DisposeRgn(clipRegion);
          }
          return noErr;
        }
      }
      break;
    }
    case kEventClassMouse:
    {
      HIPoint hp;
      GetEventParameter(pEvent, kEventParamWindowMouseLocation, typeHIPoint, 0, sizeof(HIPoint), 0, &hp);

      #ifdef RTAS_API
      // Header offset
      hp.x -= _this->GetLeftOffset();
      hp.y -= _this->GetTopOffset();

      Rect bounds;
      GetWindowBounds(_this->mWindow, kWindowTitleBarRgn, &bounds);

      // adjust x mouse coord if the gui is less wide than the window
//      int windowWidth = (bounds.right - bounds.left);
//
//      if (windowWidth > pGraphicsMac->Width())
//      {
//        hp.x -= (int) floor((windowWidth - pGraphicsMac->Width()) / 2.);
//      }

      // Title bar Y offset
      hp.y -= bounds.bottom - bounds.top;

      int x = (int) hp.x;
      int y = (int) hp.y;

      #else // NOT RTAS
      HIPointConvert(&hp, kHICoordSpaceWindow, _this->mWindow, kHICoordSpaceView, _this->mView);
      int x = (int) hp.x - 2;
      int y = (int) hp.y - 3;
      #endif

      UInt32 mods;
      GetEventParameter(pEvent, kEventParamKeyModifiers, typeUInt32, 0, sizeof(UInt32), 0, &mods);
      EventMouseButton button;
      GetEventParameter(pEvent, kEventParamMouseButton, typeMouseButton, 0, sizeof(EventMouseButton), 0, &button);
      if (button == kEventMouseButtonPrimary && (mods & cmdKey)) button = kEventMouseButtonSecondary;
      IMouseMod mmod(true, button == kEventMouseButtonSecondary, (mods & shiftKey), (mods & controlKey), (mods & optionKey));

      switch (eventKind)
      {
        case kEventMouseDown:
        {
          if (_this->mTextEntryView)
          {
            #if !(USE_MLTE)
            HIViewRef view;
            HIViewGetViewForMouseEvent(_this->mView, pEvent, &view);
            if (view == _this->mTextEntryView) break;
            #endif
            _this->EndUserInput(true);
          }

          #ifdef RTAS_API // RTAS triple click
          if (mmod.L && mmod.R && mmod.C && (pGraphicsMac->GetParamIdxForPTAutomation(x, y) > -1))
          {
            return CallNextEventHandler(pHandlerCall, pEvent);
          }
          #endif

          CallNextEventHandler(pHandlerCall, pEvent);

          UInt32 clickCount = 0;
          GetEventParameter(pEvent, kEventParamClickCount, typeUInt32, 0, sizeof(UInt32), 0, &clickCount);

          if (clickCount > 1)
          {
            pGraphicsMac->OnMouseDblClick(x, y, &mmod);
          }
          else
          {
            pGraphicsMac->OnMouseDown(x, y, &mmod);
          }

          return noErr;
        }

        case kEventMouseUp:
        {
          pGraphicsMac->OnMouseUp(x, y, &mmod);
          return noErr;
        }

        case kEventMouseMoved:
        {
          _this->mPrevX = x;
          _this->mPrevY = y;
          pGraphicsMac->OnMouseOver(x, y, &mmod);
          return noErr;
        }

        case kEventMouseDragged:
        {
          if (!_this->mTextEntryView)
            pGraphicsMac->OnMouseDrag(x, y, &mmod);
          return noErr;
        }

        case kEventMouseWheelMoved:
        {
          EventMouseWheelAxis axis;
          GetEventParameter(pEvent, kEventParamMouseWheelAxis, typeMouseWheelAxis, 0, sizeof(EventMouseWheelAxis), 0, &axis);

          if (axis == kEventMouseWheelAxisY)
          {
            int d;
            GetEventParameter(pEvent, kEventParamMouseWheelDelta, typeSInt32, 0, sizeof(SInt32), 0, &d);

            if (_this->mTextEntryView) _this->EndUserInput(false);

            pGraphicsMac->OnMouseWheel(x, y, &mmod, d);
            return noErr;
          }
        }
      }

      break;
    }

    case kEventClassWindow:
    {
      WindowRef window;

      if (GetEventParameter(pEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof (WindowRef), NULL, &window) != noErr)
        break;

      switch (eventKind)
      {
        case kEventWindowDeactivated:
        {
          if (_this->mTextEntryView)
            _this->EndUserInput(false);
          break;
        }
      }
      break;
    }
  }

  return eventNotHandledErr;
}