From d8e16ccc068807f0763c20072e76c426825ad4fe Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Wed, 17 Feb 2010 10:12:46 +0000 Subject: [PATCH] Converted some internal ComponentPeer methods to use Point and Rectangle rather than raw ints. --- .../src/ui/jucer_EditingPanelBase.cpp | 15 +- juce_amalgamated.cpp | 492 ++++++++---------- juce_amalgamated.h | 20 +- src/gui/components/juce_Component.cpp | 5 + src/gui/components/juce_Component.h | 11 + .../special/juce_MagnifierComponent.cpp | 20 +- .../components/windows/juce_ComponentPeer.cpp | 84 ++- .../components/windows/juce_ComponentPeer.h | 18 +- src/native/linux/juce_linux_Windowing.cpp | 189 ++++--- .../mac/juce_iphone_UIViewComponentPeer.mm | 77 +-- .../mac/juce_mac_NSViewComponentPeer.mm | 65 +-- .../windows/juce_win32_ActiveXComponent.cpp | 12 +- .../windows/juce_win32_OpenGLComponent.cpp | 5 +- src/native/windows/juce_win32_Windowing.cpp | 38 +- 14 files changed, 459 insertions(+), 592 deletions(-) diff --git a/extras/the jucer/src/ui/jucer_EditingPanelBase.cpp b/extras/the jucer/src/ui/jucer_EditingPanelBase.cpp index 65c005126c..2a424b05a4 100644 --- a/extras/the jucer/src/ui/jucer_EditingPanelBase.cpp +++ b/extras/the jucer/src/ui/jucer_EditingPanelBase.cpp @@ -208,25 +208,24 @@ void EditingPanelBase::setZoom (double newScale) void EditingPanelBase::setZoom (double newScale, int anchorX, int anchorY) { - const int oldAnchorX = anchorX; - const int oldAnchorY = anchorY; - - viewport->relativePositionToOtherComponent (editor, anchorX, anchorY); + Point anchor (viewport->relativePositionToOtherComponent (editor, Point (anchorX, anchorY))); magnifier->setScaleFactor (newScale); resized(); - editor->relativePositionToOtherComponent (viewport, anchorX, anchorY); + anchor = editor->relativePositionToOtherComponent (viewport, anchor); viewport->setViewPosition (jlimit (0, jmax (0, viewport->getViewedComponent()->getWidth() - viewport->getViewWidth()), - viewport->getViewPositionX() + anchorX - oldAnchorX), + viewport->getViewPositionX() + anchor.getX() - anchorX), jlimit (0, jmax (0, viewport->getViewedComponent()->getHeight() - viewport->getViewHeight()), - viewport->getViewPositionY() + anchorY - oldAnchorY)); + viewport->getViewPositionY() + anchor.getY() - anchorY)); } void EditingPanelBase::xyToTargetXY (int& x, int& y) const { - relativePositionToOtherComponent (editor, x, y); + Point pos (relativePositionToOtherComponent (editor, Point (x, y))); + x = pos.getX(); + y = pos.getY(); } void EditingPanelBase::dragKeyHeldDown (bool isKeyDown) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 11921531a8..17d1566822 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -39550,6 +39550,11 @@ bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChil return (c == this) || (returnTrueIfWithinAChild && isParentOf (c)); } +Component* Component::getComponentAt (const Point& position) +{ + return getComponentAt (position.getX(), position.getY()); +} + Component* Component::getComponentAt (const int x, const int y) { if (flags.visibleFlag @@ -73904,12 +73909,10 @@ public: peer->textInputRequired (position); } - void getBounds (int& x, int& y, int& w, int& h) const + const Rectangle getBounds() const { - x = magnifierComp->getScreenX(); - y = magnifierComp->getScreenY(); - w = component->getWidth(); - h = component->getHeight(); + return Rectangle (magnifierComp->getScreenX(), magnifierComp->getScreenY(), + component->getWidth(), component->getHeight()); } const Point getScreenPosition() const @@ -74106,37 +74109,37 @@ void MagnifierComponent::childBoundsChanged (Component* c) void MagnifierComponent::mouseDown (const MouseEvent& e) { if (peer != 0) - peer->handleMouseDown (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseDown (Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseUp (const MouseEvent& e) { if (peer != 0) - peer->handleMouseUp (e.mods.getRawFlags(), scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseUp (e.mods.getRawFlags(), Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseDrag (const MouseEvent& e) { if (peer != 0) - peer->handleMouseDrag (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseDrag (Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseMove (const MouseEvent& e) { if (peer != 0) - peer->handleMouseMove (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseMove (Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseEnter (const MouseEvent& e) { if (peer != 0) - peer->handleMouseEnter (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseEnter (Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseExit (const MouseEvent& e) { if (peer != 0) - peer->handleMouseExit (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseExit (Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy) @@ -76161,38 +76164,38 @@ void ComponentPeer::updateCurrentModifiers() throw() ModifierKeys::updateCurrentModifiers(); } -void ComponentPeer::handleMouseEnter (int x, int y, const int64 time) +void ComponentPeer::handleMouseEnter (const Point& position, const int64 time) { jassert (component->isValidComponent()); updateCurrentModifiers(); - Component* c = component->getComponentAt (x, y); + Component* c = component->getComponentAt (position); const ComponentDeletionWatcher deletionChecker (component); if (c != Component::componentUnderMouse && Component::componentUnderMouse != 0) { jassert (Component::componentUnderMouse->isValidComponent()); - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; if (deletionChecker.hasBeenDeleted()) return; - c = component->getComponentAt (x, y); + c = component->getComponentAt (position); } Component::componentUnderMouse = c; if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time); } } -void ComponentPeer::handleMouseMove (int x, int y, const int64 time) +void ComponentPeer::handleMouseMove (const Point& position, const int64 time) { jassert (component->isValidComponent()); updateCurrentModifiers(); @@ -76200,27 +76203,27 @@ void ComponentPeer::handleMouseMove (int x, int y, const int64 time) fakeMouseMessageSent = false; const ComponentDeletionWatcher deletionChecker (component); - Component* c = component->getComponentAt (x, y); + Component* c = component->getComponentAt (position); if (c != Component::componentUnderMouse) { if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; if (deletionChecker.hasBeenDeleted()) return; // if this window has just been deleted.. - c = component->getComponentAt (x, y); + c = component->getComponentAt (position); } Component::componentUnderMouse = c; if (c != 0) { - const Point relPos (component->relativePositionToOtherComponent (c, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (c, position)); c->internalMouseEnter (relPos.getX(), relPos.getY(), time); if (deletionChecker.hasBeenDeleted()) @@ -76230,53 +76233,53 @@ void ComponentPeer::handleMouseMove (int x, int y, const int64 time) if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseMove (relPos.getX(), relPos.getY(), time); } } -void ComponentPeer::handleMouseDown (int x, int y, const int64 time) +void ComponentPeer::handleMouseDown (const Point& position, const int64 time) { Desktop::getInstance().incrementMouseClickCounter(); updateCurrentModifiers(); if (ModifierKeys::getCurrentModifiers().getNumMouseButtonsDown() == 1) { - Component::componentUnderMouse = component->getComponentAt (x, y); + Component::componentUnderMouse = component->getComponentAt (position); if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseDown (relPos.getX(), relPos.getY(), time); } } } -void ComponentPeer::handleMouseDrag (int x, int y, const int64 time) +void ComponentPeer::handleMouseDrag (const Point& position, const int64 time) { updateCurrentModifiers(); if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseDrag (relPos.getX(), relPos.getY(), time); } } -void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const int64 time) +void ComponentPeer::handleMouseUp (const int oldModifiers, const Point& position, const int64 time) { updateCurrentModifiers(); if (ModifierKeys (oldModifiers).getNumMouseButtonsDown() == 1) { const ComponentDeletionWatcher deletionChecker (component); - Component* c = component->getComponentAt (x, y); + Component* c = component->getComponentAt (position); if (c != Component::componentUnderMouse) { if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time); if (Component::componentUnderMouse != 0) @@ -76285,14 +76288,14 @@ void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const i if (deletionChecker.hasBeenDeleted()) return; - c = component->getComponentAt (x, y); + c = component->getComponentAt (position); } Component::componentUnderMouse = c; if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time); } } @@ -76300,21 +76303,21 @@ void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const i { if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time); } } } } -void ComponentPeer::handleMouseExit (int x, int y, const int64 time) +void ComponentPeer::handleMouseExit (const Point& position, const int64 time) { jassert (component->isValidComponent()); updateCurrentModifiers(); if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; } @@ -76335,12 +76338,7 @@ void ComponentPeer::sendFakeMouseMove() throw() && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()) { if (! isMinimised()) - { - int realX, realY, realW, realH; - getBounds (realX, realY, realW, realH); - - component->bounds_.setBounds (realX, realY, realW, realH); - } + component->bounds_ = getBounds(); const Point pos (component->getMouseXYRelative()); @@ -76360,8 +76358,7 @@ void ComponentPeer::handleMessage (const Message& message) if (message.intParameter1 == fakeMouseMoveMessage) { if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()) - handleMouseMove (message.intParameter2, - message.intParameter3, + handleMouseMove (Point (message.intParameter2, message.intParameter3), Time::currentTimeMillis()); } } @@ -76540,15 +76537,13 @@ void ComponentPeer::handleMovedOrResized() { const ComponentDeletionWatcher deletionChecker (component); - int realX, realY, realW, realH; - getBounds (realX, realY, realW, realH); - - const bool wasMoved = (component->getX() != realX || component->getY() != realY); - const bool wasResized = (component->getWidth() != realW || component->getHeight() != realH); + const Rectangle newBounds (getBounds()); + const bool wasMoved = (component->getPosition() != newBounds.getPosition()); + const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight()); if (wasMoved || wasResized) { - component->bounds_.setBounds (realX, realY, realW, realH); + component->bounds_ = newBounds; if (wasResized) component->repaint(); @@ -76649,7 +76644,7 @@ static FileDragAndDropTarget* findDragAndDropTarget (Component* c, return 0; } -void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) +void ComponentPeer::handleFileDragMove (const StringArray& files, const Point& position) { updateCurrentModifiers(); @@ -76660,7 +76655,7 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) FileDragAndDropTarget* newTarget = 0; - Component* const compUnderMouse = component->getComponentAt (x, y); + Component* const compUnderMouse = component->getComponentAt (position); if (compUnderMouse != lastDragAndDropCompUnderMouse) { @@ -76677,7 +76672,7 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) if (newTarget != 0) { Component* const targetComp = dynamic_cast (newTarget); - const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); + const Point pos (component->relativePositionToOtherComponent (targetComp, position)); dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast (newTarget)); newTarget->fileDragEnter (files, pos.getX(), pos.getY()); @@ -76692,7 +76687,7 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) if (newTarget != 0) { Component* const targetComp = dynamic_cast (newTarget); - const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); + const Point pos (component->relativePositionToOtherComponent (targetComp, position)); newTarget->fileDragMove (files, pos.getX(), pos.getY()); } @@ -76700,15 +76695,15 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) void ComponentPeer::handleFileDragExit (const StringArray& files) { - handleFileDragMove (files, -1, -1); + handleFileDragMove (files, Point (-1, -1)); jassert (dragAndDropTargetComponent == 0); lastDragAndDropCompUnderMouse = 0; } -void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y) +void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point& position) { - handleFileDragMove (files, x, y); + handleFileDragMove (files, position); if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted()) { @@ -76729,7 +76724,7 @@ void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y) return; } - const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); + const Point pos (component->relativePositionToOtherComponent (targetComp, position)); target->filesDropped (files, pos.getX(), pos.getY()); } } @@ -214765,28 +214760,21 @@ public: repaintNowIfTransparent(); } - void getBounds (int& x, int& y, int& w, int& h) const + const Rectangle getBounds() const { RECT r; GetWindowRect (hwnd, &r); - x = r.left; - y = r.top; - w = r.right - x; - h = r.bottom - y; + Rectangle bounds (r.left, r.top, r.right - r.left, r.bottom - r.top); HWND parentH = GetParent (hwnd); if (parentH != 0) { GetWindowRect (parentH, &r); - x -= r.left; - y -= r.top; + bounds.translate (-r.left, -r.top); } - x += windowBorder.getLeft(); - y += windowBorder.getTop(); - w -= windowBorder.getLeftAndRight(); - h -= windowBorder.getTopAndBottom(); + return windowBorder.subtractedFrom (bounds); } const Point getScreenPosition() const @@ -215478,7 +215466,7 @@ private: } updateKeyModifiers(); - handleMouseEnter (x, y, mouseEventTime); + handleMouseEnter (Point (x, y), mouseEventTime); } else if (! isDragging) { @@ -215499,7 +215487,7 @@ private: if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond) { lastMouseTime = now; - handleMouseMove (x, y, mouseEventTime); + handleMouseMove (Point (x, y), mouseEventTime); } } } @@ -215511,7 +215499,7 @@ private: if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond) { lastMouseTime = now; - handleMouseDrag (x, y, mouseEventTime); + handleMouseDrag (Point (x, y), mouseEventTime); } } } @@ -215537,7 +215525,7 @@ private: updateKeyModifiers(); isDragging = true; - handleMouseDown (x, y, getMouseEventTime()); + handleMouseDown (Point (x, y), getMouseEventTime()); } void doMouseUp (const int x, const int y, const WPARAM wParam) @@ -215575,7 +215563,7 @@ private: if (numButtons == 0 && hwnd == GetCapture()) ReleaseCapture(); - handleMouseUp (oldModifiers, x, y, getMouseEventTime()); + handleMouseUp (oldModifiers, Point (x, y), getMouseEventTime()); } void doCaptureChanged() @@ -215603,8 +215591,8 @@ private: const DWORD mp = GetMessagePos(); - handleMouseExit (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(), - GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(), + handleMouseExit (Point (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(), + GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop()), getMouseEventTime()); } } @@ -215863,8 +215851,7 @@ private: HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { updateFileList (pDataObject); - const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); - owner->handleFileDragMove (files, pos.getX(), pos.getY()); + owner->handleFileDragMove (files, owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); *pdwEffect = DROPEFFECT_COPY; return S_OK; } @@ -215877,8 +215864,7 @@ private: HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { - const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); - owner->handleFileDragMove (files, pos.getX(), pos.getY()); + owner->handleFileDragMove (files, owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); *pdwEffect = DROPEFFECT_COPY; return S_OK; } @@ -215886,8 +215872,7 @@ private: HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { updateFileList (pDataObject); - const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); - owner->handleFileDragDrop (files, pos.getX(), pos.getY()); + owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); *pdwEffect = DROPEFFECT_COPY; return S_OK; } @@ -218284,8 +218269,8 @@ static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, GetWindowRect (hwnd, &activeXRect); GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect); - const int mx = GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left; - const int my = GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top; + const Point mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left, + GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top); const int64 mouseEventTime = getMouseEventTime(); const int oldModifiers = currentModifiers; @@ -218295,21 +218280,21 @@ static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, { case WM_MOUSEMOVE: if (ModifierKeys (currentModifiers).isAnyMouseButtonDown()) - peer->handleMouseDrag (mx, my, mouseEventTime); + peer->handleMouseDrag (mousePos, mouseEventTime); else - peer->handleMouseMove (mx, my, mouseEventTime); + peer->handleMouseMove (mousePos, mouseEventTime); break; case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: - peer->handleMouseDown (mx, my, mouseEventTime); + peer->handleMouseDown (mousePos, mouseEventTime); break; case WM_LBUTTONUP: case WM_MBUTTONUP: case WM_RBUTTONUP: - peer->handleMouseUp (oldModifiers, mx, my, mouseEventTime); + peer->handleMouseUp (oldModifiers, mousePos, mouseEventTime); break; default: @@ -219547,9 +219532,8 @@ public: void repaint() { - int x, y, w, h; - nativeWindow->getBounds (x, y, w, h); - nativeWindow->repaint (0, 0, w, h); + const Rectangle bounds (nativeWindow->getBounds()); + nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight()); } void swapBuffers() @@ -231497,9 +231481,6 @@ static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | Butto | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask | ExposureMask | StructureNotifyMask | FocusChangeMask; -static int pointerMap[5]; -static Point lastMousePos; - enum MouseButtons { NoButton = 0, @@ -231510,10 +231491,10 @@ enum MouseButtons WheelDown = 5 }; -static void getMousePos (int& x, int& y, int& mouseMods) throw() +static const Point getMousePos (int& mouseMods) throw() { Window root, child; - int winx, winy; + int x, y, winx, winy; unsigned int mask; mouseMods = 0; @@ -231529,15 +231510,12 @@ static void getMousePos (int& x, int& y, int& mouseMods) throw() } else { - if ((mask & Button1Mask) != 0) - mouseMods |= ModifierKeys::leftButtonModifier; - - if ((mask & Button2Mask) != 0) - mouseMods |= ModifierKeys::middleButtonModifier; - - if ((mask & Button3Mask) != 0) - mouseMods |= ModifierKeys::rightButtonModifier; + if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier; + if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier; + if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier; } + + return Point (x, y); } static int AltMask = 0; @@ -231628,8 +231606,8 @@ void ModifierKeys::updateCurrentModifiers() throw() const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw() { - int x, y, mouseMods; - getMousePos (x, y, mouseMods); + int mouseMods; + getMousePos (mouseMods); currentModifiers &= ~ModifierKeys::allMouseButtonModifiers; currentModifiers |= mouseMods; @@ -231770,59 +231748,6 @@ static bool isShmAvailable() throw() } #endif -static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image) -{ - ScopedXLock xlock; - - const int width = image.getWidth(); - const int height = image.getHeight(); - HeapBlock colour (width * height); - int index = 0; - - for (int y = 0; y < height; ++y) - for (int x = 0; x < width; ++x) - colour[index++] = image.getPixelAt (x, y).getARGB(); - - XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap, - 0, (char*) colour, width, height, 32, 0); - - Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display), - width, height, 24); - - GC gc = XCreateGC (display, pixmap, 0, 0); - XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height); - XFreeGC (display, gc); - - return pixmap; -} - -static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image) -{ - ScopedXLock xlock; - - const int width = image.getWidth(); - const int height = image.getHeight(); - const int stride = (width + 7) >> 3; - HeapBlock mask; - mask.calloc (stride * height); - const bool msbfirst = (BitmapBitOrder (display) == MSBFirst); - - for (int y = 0; y < height; ++y) - { - for (int x = 0; x < width; ++x) - { - const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); - const int offset = y * stride + (x >> 3); - - if (image.getPixelAt (x, y).getAlpha() >= 128) - mask[offset] |= bit; - } - } - - return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display), - (char*) mask, width, height, 1, 0, 1); -} - class XBitmapImage : public Image { public: @@ -232159,18 +232084,8 @@ public: } } - void getBounds (int& x, int& y, int& w, int& h) const - { - x = wx; - y = wy; - w = ww; - h = wh; - } - - const Point getScreenPosition() const - { - return Point (wx, wy); - } + const Rectangle getBounds() const { return Rectangle (wx, wy, ww, wh); } + const Point getScreenPosition() const { return Point (wx, wy); } const Point relativePositionToGlobal (const Point& relativePosition) { @@ -232482,6 +232397,59 @@ public: repainter->performAnyPendingRepaintsNow(); } + static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image) + { + ScopedXLock xlock; + + const int width = image.getWidth(); + const int height = image.getHeight(); + HeapBlock colour (width * height); + int index = 0; + + for (int y = 0; y < height; ++y) + for (int x = 0; x < width; ++x) + colour[index++] = image.getPixelAt (x, y).getARGB(); + + XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap, + 0, (char*) colour, width, height, 32, 0); + + Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display), + width, height, 24); + + GC gc = XCreateGC (display, pixmap, 0, 0); + XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height); + XFreeGC (display, gc); + + return pixmap; + } + + static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image) + { + ScopedXLock xlock; + + const int width = image.getWidth(); + const int height = image.getHeight(); + const int stride = (width + 7) >> 3; + HeapBlock mask; + mask.calloc (stride * height); + const bool msbfirst = (BitmapBitOrder (display) == MSBFirst); + + for (int y = 0; y < height; ++y) + { + for (int x = 0; x < width; ++x) + { + const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); + const int offset = y * stride + (x >> 3); + + if (image.getPixelAt (x, y).getAlpha() >= 128) + mask[offset] |= bit; + } + } + + return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display), + (char*) mask, width, height, 1, 0, 1); + } + void setIcon (const Image& newIcon) { const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2; @@ -232713,7 +232681,7 @@ public: if (buttonMsg) { toFront (true); - handleMouseDown (buttonPressEvent->x, buttonPressEvent->y, + handleMouseDown (Point (buttonPressEvent->x, buttonPressEvent->y), getEventTime (buttonPressEvent->time)); } else if (wheelUpMsg || wheelDownMsg) @@ -232722,7 +232690,7 @@ public: getEventTime (buttonPressEvent->time)); } - lastMousePos = Point (0x100000, 0x100000); + clearLastMousePos(); break; } @@ -232743,10 +232711,10 @@ public: updateKeyModifiers (buttonRelEvent->state); handleMouseUp (oldModifiers, - buttonRelEvent->x, buttonRelEvent->y, + Point (buttonRelEvent->x, buttonRelEvent->y), getEventTime (buttonRelEvent->time)); - lastMousePos = Point (0x100000, 0x100000); + clearLastMousePos(); break; } @@ -232793,9 +232761,9 @@ public: } if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0) - handleMouseMove (mousePos.getX(), mousePos.getY(), getEventTime (movedEvent->time)); + handleMouseMove (mousePos, getEventTime (movedEvent->time)); else - handleMouseDrag (mousePos.getX(), mousePos.getY(), getEventTime (movedEvent->time)); + handleMouseDrag (mousePos, getEventTime (movedEvent->time)); } break; @@ -232803,7 +232771,7 @@ public: case EnterNotify: { - lastMousePos = Point (0x100000, 0x100000); + clearLastMousePos(); const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing; if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0 @@ -232811,7 +232779,7 @@ public: { updateKeyModifiers (enterEvent->state); - handleMouseEnter (enterEvent->x, enterEvent->y, getEventTime (enterEvent->time)); + handleMouseEnter (Point (enterEvent->x, enterEvent->y), getEventTime (enterEvent->time)); entered = true; } @@ -232832,7 +232800,7 @@ public: { updateKeyModifiers (leaveEvent->state); - handleMouseExit (leaveEvent->x, leaveEvent->y, getEventTime (leaveEvent->time)); + handleMouseExit (Point (leaveEvent->x, leaveEvent->y), getEventTime (leaveEvent->time)); entered = false; } @@ -233788,7 +233756,7 @@ private: updateDraggedFileList (clientMsg); if (dragAndDropFiles.size() > 0) - handleFileDragMove (dragAndDropFiles, dropPos.getX(), dropPos.getY()); + handleFileDragMove (dragAndDropFiles, dropPos); } } @@ -233804,7 +233772,7 @@ private: resetDragAndDrop(); if (files.size() > 0) - handleFileDragDrop (files, lastPos.getX(), lastPos.getY()); + handleFileDragDrop (files, lastPos); } void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg) @@ -233944,11 +233912,22 @@ private: Atom XA_OtherMime, dragAndDropCurrentMimeType; Window dragAndDropSourceWindow; - unsigned int allowedActions [5]; - unsigned int allowedMimeTypeAtoms [3]; + unsigned int allowedActions[5]; + unsigned int allowedMimeTypeAtoms[3]; Array srcMimeTypeAtomList; + + static int pointerMap[5]; + static Point lastMousePos; + + static void clearLastMousePos() throw() + { + lastMousePos = Point (0x100000, 0x100000); + } }; +int LinuxComponentPeer::pointerMap[5]; +Point LinuxComponentPeer::lastMousePos; + void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars) { if (enableOrDisable) @@ -234094,9 +234073,8 @@ bool Desktop::canUseSemiTransparentWindows() throw() const Point Desktop::getMousePosition() { - int x, y, mouseMods; - getMousePos (x, y, mouseMods); - return Point (x, y); + int mouseMods; + return getMousePos (mouseMods); } void Desktop::setMousePosition (const Point& newPosition) @@ -240701,8 +240679,9 @@ public: void setPosition (int x, int y); void setSize (int w, int h); void setBounds (int x, int y, int w, int h, const bool isNowFullScreen); - void getBounds (int& x, int& y, int& w, int& h, const bool global) const; - void getBounds (int& x, int& y, int& w, int& h) const; + + const Rectangle getBounds() const; + const Rectangle getBounds (const bool global) const; const Point getScreenPosition() const; const Point relativePositionToGlobal (const Point& relativePosition); const Point globalPositionToRelative (const Point& screenPosition); @@ -240795,7 +240774,7 @@ static int64 getMouseTime (UIEvent* e) + (int64) ([e timestamp] * 1000.0); } -int juce_lastMouseX = 0, juce_lastMouseY = 0; +JUCE_NAMESPACE::Point juce_lastMousePos; - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event { @@ -240809,17 +240788,14 @@ int juce_lastMouseX = 0, juce_lastMouseY = 0; case 1: // One finger.. { CGPoint p = [[t objectAtIndex: 0] locationInView: self]; + const JUCE_NAMESPACE::Point pos ((int) p.x, (int) p.y); currentModifiers |= getModifierForButtonNumber (0); + juce_lastMousePos = pos + owner->getScreenPosition(); - int x, y, w, h; - owner->getBounds (x, y, w, h, true); - juce_lastMouseX = x + (int) p.x; - juce_lastMouseY = y + (int) p.y; - - owner->handleMouseMove ((int) p.x, (int) p.y, getMouseTime (event)); + owner->handleMouseMove (pos, getMouseTime (event)); if (owner != 0) - owner->handleMouseDown ((int) p.x, (int) p.y, getMouseTime (event)); + owner->handleMouseDown (pos, getMouseTime (event)); } default: @@ -240840,13 +240816,10 @@ int juce_lastMouseX = 0, juce_lastMouseY = 0; case 1: // One finger.. { CGPoint p = [[t objectAtIndex: 0] locationInView: self]; + const JUCE_NAMESPACE::Point pos ((int) p.x, (int) p.y); + juce_lastMousePos = pos + owner->getScreenPosition(); - int x, y, w, h; - owner->getBounds (x, y, w, h, true); - juce_lastMouseX = x + (int) p.x; - juce_lastMouseY = y + (int) p.y; - - owner->handleMouseDrag ((int) p.x, (int) p.y, getMouseTime (event)); + owner->handleMouseDrag (pos, getMouseTime (event)); } default: @@ -240867,15 +240840,12 @@ int juce_lastMouseX = 0, juce_lastMouseY = 0; case 1: // One finger.. { CGPoint p = [[t objectAtIndex: 0] locationInView: self]; - - int x, y, w, h; - owner->getBounds (x, y, w, h, true); - juce_lastMouseX = x + (int) p.x; - juce_lastMouseY = y + (int) p.y; + const JUCE_NAMESPACE::Point pos ((int) p.x, (int) p.y); + juce_lastMousePos = pos + owner->getScreenPosition(); const int oldMods = currentModifiers; currentModifiers &= ~getModifierForButtonNumber (0); - owner->handleMouseUp (oldMods, (int) p.x, (int) p.y, getMouseTime (event)); + owner->handleMouseUp (oldMods, pos, getMouseTime (event)); } default: @@ -241062,7 +241032,7 @@ void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNo } } -void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const +const Rectangle UIViewComponentPeer::getBounds (const bool global) const { CGRect r = [view frame]; @@ -241074,45 +241044,28 @@ void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool r.origin.y += wr.origin.y; } - x = (int) r.origin.x; - y = (int) r.origin.y; - w = (int) r.size.width; - h = (int) r.size.height; + return Rectangle ((int) r.origin.x, (int) r.origin.y, + (int) r.size.width, (int) r.size.height); } -void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const +const Rectangle UIViewComponentPeer::getBounds() const { - getBounds (x, y, w, h, ! isSharedWindow); + return getBounds (! isSharedWindow); } -int UIViewComponentPeer::getScreenX() const +const Point UIViewComponentPeer::getScreenPosition() const { - int x, y, w, h; - getBounds (x, y, w, h, true); - return x; -} - -int UIViewComponentPeer::getScreenY() const -{ - int x, y, w, h; - getBounds (x, y, w, h, true); - return y; + return getBounds (true).getPosition(); } -void UIViewComponentPeer::relativePositionToGlobal (int& x, int& y) +const Point UIViewComponentPeer::relativePositionToGlobal (const Point& relativePosition) { - int wx, wy, ww, wh; - getBounds (wx, wy, ww, wh, true); - x += wx; - y += wy; + return relativePosition + getScreenPosition(); } -void UIViewComponentPeer::globalPositionToRelative (int& x, int& y) +const Point UIViewComponentPeer::globalPositionToRelative (const Point& screenPosition) { - int wx, wy, ww, wh; - getBounds (wx, wy, ww, wh, true); - x -= wx; - y -= wy; + return screenPosition + getScreenPosition(); } CGRect UIViewComponentPeer::constrainRect (CGRect r) @@ -241408,7 +241361,7 @@ bool Desktop::canUseSemiTransparentWindows() throw() const Point Desktop::getMousePosition() { - return Point (juce_lastMouseX, juce_lastMouseY); + return juce_lastMousePos; } void Desktop::setMousePosition (const Point&) @@ -245174,8 +245127,8 @@ public: void setPosition (int x, int y); void setSize (int w, int h); void setBounds (int x, int y, int w, int h, const bool isNowFullScreen); - void getBounds (int& x, int& y, int& w, int& h, const bool global) const; - void getBounds (int& x, int& y, int& w, int& h) const; + const Rectangle getBounds (const bool global) const; + const Rectangle getBounds() const; const Point getScreenPosition() const; const Point relativePositionToGlobal (const Point& relativePosition); const Point globalPositionToRelative (const Point& screenPosition); @@ -245661,11 +245614,10 @@ static int64 getMouseTime (NSEvent* e) + (int64) ([e timestamp] * 1000.0); } -static void getMousePos (NSEvent* e, NSView* view, int& x, int& y) +static const Point getMousePos (NSEvent* e, NSView* view) { NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil]; - x = roundToInt (p.x); - y = roundToInt ([view frame].size.height - p.y); + return Point (roundToInt (p.x), roundToInt ([view frame].size.height - p.y)); } static int getModifierForButtonNumber (const NSInteger num) @@ -245846,7 +245798,7 @@ void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNo } } -void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const +const Rectangle NSViewComponentPeer::getBounds (const bool global) const { NSRect r = [view frame]; @@ -245856,29 +245808,24 @@ void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool NSRect wr = [[view window] frame]; r.origin.x += wr.origin.x; r.origin.y += wr.origin.y; - - y = (int) ([[[NSScreen screens] objectAtIndex:0] frame].size.height - r.origin.y - r.size.height); + r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height; } else { - y = (int) ([[view superview] frame].size.height - r.origin.y - r.size.height); + r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height; } - x = (int) r.origin.x; - w = (int) r.size.width; - h = (int) r.size.height; + return Rectangle ((int) r.origin.x, (int) r.size.width, (int) r.size.width, (int) r.size.height); } -void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const +const Rectangle NSViewComponentPeer::getBounds() const { - getBounds (x, y, w, h, ! isSharedWindow); + return getBounds (! isSharedWindow); } const Point NSViewComponentPeer::getScreenPosition() const { - int x, y, w, h; - getBounds (x, y, w, h, true); - return Point (x, y); + return getBounds (true).getPosition(); } const Point NSViewComponentPeer::relativePositionToGlobal (const Point& relativePosition) @@ -246222,10 +246169,7 @@ void NSViewComponentPeer::redirectMouseDown (NSEvent* ev) { updateModifiers (ev); currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseDown (x, y, getMouseTime (ev)); + handleMouseDown (getMousePos (ev, view), getMouseTime (ev)); } void NSViewComponentPeer::redirectMouseUp (NSEvent* ev) @@ -246233,10 +246177,7 @@ void NSViewComponentPeer::redirectMouseUp (NSEvent* ev) const int oldMods = currentModifiers; updateModifiers (ev); currentModifiers &= ~getModifierForButtonNumber ([ev buttonNumber]); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseUp (oldMods, x, y, getMouseTime (ev)); + handleMouseUp (oldMods, getMousePos (ev, view), getMouseTime (ev)); showArrowCursorIfNeeded(); } @@ -246244,38 +246185,26 @@ void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev) { updateModifiers (ev); currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseDrag (x, y, getMouseTime (ev)); + handleMouseDrag (getMousePos (ev, view), getMouseTime (ev)); } void NSViewComponentPeer::redirectMouseMove (NSEvent* ev) { updateModifiers (ev); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseMove (x, y, getMouseTime (ev)); + handleMouseMove (getMousePos (ev, view), getMouseTime (ev)); showArrowCursorIfNeeded(); } void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev) { updateModifiers (ev); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseEnter (x, y, getMouseTime (ev)); + handleMouseEnter (getMousePos (ev, view), getMouseTime (ev)); } void NSViewComponentPeer::redirectMouseExit (NSEvent* ev) { updateModifiers (ev); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseExit (x, y, getMouseTime (ev)); + handleMouseExit (getMousePos (ev, view), getMouseTime (ev)); } void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev) @@ -246305,8 +246234,7 @@ BOOL NSViewComponentPeer::sendDragCallback (int type, id sender return false; NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil]; - int x = (int) p.x; - int y = (int) ([view frame].size.height - p.y); + const Point pos ((int) p.x, (int) ([view frame].size.height - p.y)); StringArray files; @@ -246326,11 +246254,11 @@ BOOL NSViewComponentPeer::sendDragCallback (int type, id sender return false; if (type == 0) - handleFileDragMove (files, x, y); + handleFileDragMove (files, pos); else if (type == 1) handleFileDragExit (files); else if (type == 2) - handleFileDragDrop (files, x, y); + handleFileDragDrop (files, pos); return true; } diff --git a/juce_amalgamated.h b/juce_amalgamated.h index fbb58c7436..48951fbc8c 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -12270,7 +12270,7 @@ public: virtual void setBounds (int x, int y, int w, int h, const bool isNowFullScreen) = 0; - virtual void getBounds (int& x, int& y, int& w, int& h) const = 0; + virtual const Rectangle getBounds() const = 0; virtual const Point getScreenPosition() const = 0; @@ -12336,21 +12336,21 @@ public: virtual void performAnyPendingRepaintsNow() = 0; - void handleMouseEnter (int x, int y, const int64 time); - void handleMouseMove (int x, int y, const int64 time); - void handleMouseDown (int x, int y, const int64 time); - void handleMouseDrag (int x, int y, const int64 time); - void handleMouseUp (const int oldModifiers, int x, int y, const int64 time); - void handleMouseExit (int x, int y, const int64 time); + void handleMouseEnter (const Point& position, const int64 time); + void handleMouseMove (const Point& position, const int64 time); + void handleMouseDown (const Point& position, const int64 time); + void handleMouseDrag (const Point& position, const int64 time); + void handleMouseUp (const int oldModifiers, const Point& position, const int64 time); + void handleMouseExit (const Point& position, const int64 time); void handleMouseWheel (const int amountX, const int amountY, const int64 time); void sendFakeMouseMove() throw(); void handleUserClosingWindow(); - void handleFileDragMove (const StringArray& files, int x, int y); + void handleFileDragMove (const StringArray& files, const Point& position); void handleFileDragExit (const StringArray& files); - void handleFileDragDrop (const StringArray& files, int x, int y); + void handleFileDragDrop (const StringArray& files, const Point& position); void clearMaskedRegion() throw(); @@ -12585,6 +12585,8 @@ public: Component* getComponentAt (const int x, const int y); + Component* getComponentAt (const Point& position); + void repaint() throw(); void repaint (const int x, const int y, diff --git a/src/gui/components/juce_Component.cpp b/src/gui/components/juce_Component.cpp index 2c65bf964b..5aa7a4426a 100644 --- a/src/gui/components/juce_Component.cpp +++ b/src/gui/components/juce_Component.cpp @@ -1106,6 +1106,11 @@ bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChil return (c == this) || (returnTrueIfWithinAChild && isParentOf (c)); } +Component* Component::getComponentAt (const Point& position) +{ + return getComponentAt (position.getX(), position.getY()); +} + Component* Component::getComponentAt (const int x, const int y) { if (flags.visibleFlag diff --git a/src/gui/components/juce_Component.h b/src/gui/components/juce_Component.h index e5218982de..cba3f435c6 100644 --- a/src/gui/components/juce_Component.h +++ b/src/gui/components/juce_Component.h @@ -770,6 +770,17 @@ public: */ Component* getComponentAt (const int x, const int y); + /** Returns the component at a certain point within this one. + + @param position the co-ordinates to test, relative to this component's top-left. + @returns the component that is at this position - which may be 0, this component, + or one of its children. Note that overlapping siblings that might actually + be in the way are not taken into account by this method - to account for these, + instead call getComponentAt on the top-level parent of this component. + @see hitTest, contains, reallyContains + */ + Component* getComponentAt (const Point& position); + //============================================================================== /** Marks the whole component as needing to be redrawn. diff --git a/src/gui/components/special/juce_MagnifierComponent.cpp b/src/gui/components/special/juce_MagnifierComponent.cpp index 8af123d227..8efd5e02be 100644 --- a/src/gui/components/special/juce_MagnifierComponent.cpp +++ b/src/gui/components/special/juce_MagnifierComponent.cpp @@ -83,12 +83,10 @@ public: peer->textInputRequired (position); } - void getBounds (int& x, int& y, int& w, int& h) const + const Rectangle getBounds() const { - x = magnifierComp->getScreenX(); - y = magnifierComp->getScreenY(); - w = component->getWidth(); - h = component->getHeight(); + return Rectangle (magnifierComp->getScreenX(), magnifierComp->getScreenY(), + component->getWidth(), component->getHeight()); } const Point getScreenPosition() const @@ -290,37 +288,37 @@ void MagnifierComponent::childBoundsChanged (Component* c) void MagnifierComponent::mouseDown (const MouseEvent& e) { if (peer != 0) - peer->handleMouseDown (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseDown (Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseUp (const MouseEvent& e) { if (peer != 0) - peer->handleMouseUp (e.mods.getRawFlags(), scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseUp (e.mods.getRawFlags(), Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseDrag (const MouseEvent& e) { if (peer != 0) - peer->handleMouseDrag (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseDrag (Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseMove (const MouseEvent& e) { if (peer != 0) - peer->handleMouseMove (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseMove (Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseEnter (const MouseEvent& e) { if (peer != 0) - peer->handleMouseEnter (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseEnter (Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseExit (const MouseEvent& e) { if (peer != 0) - peer->handleMouseExit (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds()); + peer->handleMouseExit (Point (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds()); } void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy) diff --git a/src/gui/components/windows/juce_ComponentPeer.cpp b/src/gui/components/windows/juce_ComponentPeer.cpp index e68880d506..0da654dfb1 100644 --- a/src/gui/components/windows/juce_ComponentPeer.cpp +++ b/src/gui/components/windows/juce_ComponentPeer.cpp @@ -102,38 +102,38 @@ void ComponentPeer::updateCurrentModifiers() throw() } //============================================================================== -void ComponentPeer::handleMouseEnter (int x, int y, const int64 time) +void ComponentPeer::handleMouseEnter (const Point& position, const int64 time) { jassert (component->isValidComponent()); updateCurrentModifiers(); - Component* c = component->getComponentAt (x, y); + Component* c = component->getComponentAt (position); const ComponentDeletionWatcher deletionChecker (component); if (c != Component::componentUnderMouse && Component::componentUnderMouse != 0) { jassert (Component::componentUnderMouse->isValidComponent()); - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; if (deletionChecker.hasBeenDeleted()) return; - c = component->getComponentAt (x, y); + c = component->getComponentAt (position); } Component::componentUnderMouse = c; if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time); } } -void ComponentPeer::handleMouseMove (int x, int y, const int64 time) +void ComponentPeer::handleMouseMove (const Point& position, const int64 time) { jassert (component->isValidComponent()); updateCurrentModifiers(); @@ -141,27 +141,27 @@ void ComponentPeer::handleMouseMove (int x, int y, const int64 time) fakeMouseMessageSent = false; const ComponentDeletionWatcher deletionChecker (component); - Component* c = component->getComponentAt (x, y); + Component* c = component->getComponentAt (position); if (c != Component::componentUnderMouse) { if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; if (deletionChecker.hasBeenDeleted()) return; // if this window has just been deleted.. - c = component->getComponentAt (x, y); + c = component->getComponentAt (position); } Component::componentUnderMouse = c; if (c != 0) { - const Point relPos (component->relativePositionToOtherComponent (c, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (c, position)); c->internalMouseEnter (relPos.getX(), relPos.getY(), time); if (deletionChecker.hasBeenDeleted()) @@ -171,53 +171,53 @@ void ComponentPeer::handleMouseMove (int x, int y, const int64 time) if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseMove (relPos.getX(), relPos.getY(), time); } } -void ComponentPeer::handleMouseDown (int x, int y, const int64 time) +void ComponentPeer::handleMouseDown (const Point& position, const int64 time) { Desktop::getInstance().incrementMouseClickCounter(); updateCurrentModifiers(); if (ModifierKeys::getCurrentModifiers().getNumMouseButtonsDown() == 1) { - Component::componentUnderMouse = component->getComponentAt (x, y); + Component::componentUnderMouse = component->getComponentAt (position); if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseDown (relPos.getX(), relPos.getY(), time); } } } -void ComponentPeer::handleMouseDrag (int x, int y, const int64 time) +void ComponentPeer::handleMouseDrag (const Point& position, const int64 time) { updateCurrentModifiers(); if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseDrag (relPos.getX(), relPos.getY(), time); } } -void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const int64 time) +void ComponentPeer::handleMouseUp (const int oldModifiers, const Point& position, const int64 time) { updateCurrentModifiers(); if (ModifierKeys (oldModifiers).getNumMouseButtonsDown() == 1) { const ComponentDeletionWatcher deletionChecker (component); - Component* c = component->getComponentAt (x, y); + Component* c = component->getComponentAt (position); if (c != Component::componentUnderMouse) { if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time); if (Component::componentUnderMouse != 0) @@ -226,14 +226,14 @@ void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const i if (deletionChecker.hasBeenDeleted()) return; - c = component->getComponentAt (x, y); + c = component->getComponentAt (position); } Component::componentUnderMouse = c; if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time); } } @@ -241,21 +241,21 @@ void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const i { if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time); } } } } -void ComponentPeer::handleMouseExit (int x, int y, const int64 time) +void ComponentPeer::handleMouseExit (const Point& position, const int64 time) { jassert (component->isValidComponent()); updateCurrentModifiers(); if (Component::componentUnderMouse != 0) { - const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, Point (x, y))); + const Point relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position)); Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time); Component::componentUnderMouse = 0; } @@ -276,12 +276,7 @@ void ComponentPeer::sendFakeMouseMove() throw() && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()) { if (! isMinimised()) - { - int realX, realY, realW, realH; - getBounds (realX, realY, realW, realH); - - component->bounds_.setBounds (realX, realY, realW, realH); - } + component->bounds_ = getBounds(); const Point pos (component->getMouseXYRelative()); @@ -301,8 +296,7 @@ void ComponentPeer::handleMessage (const Message& message) if (message.intParameter1 == fakeMouseMoveMessage) { if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()) - handleMouseMove (message.intParameter2, - message.intParameter3, + handleMouseMove (Point (message.intParameter2, message.intParameter3), Time::currentTimeMillis()); } } @@ -483,15 +477,13 @@ void ComponentPeer::handleMovedOrResized() { const ComponentDeletionWatcher deletionChecker (component); - int realX, realY, realW, realH; - getBounds (realX, realY, realW, realH); - - const bool wasMoved = (component->getX() != realX || component->getY() != realY); - const bool wasResized = (component->getWidth() != realW || component->getHeight() != realH); + const Rectangle newBounds (getBounds()); + const bool wasMoved = (component->getPosition() != newBounds.getPosition()); + const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight()); if (wasMoved || wasResized) { - component->bounds_.setBounds (realX, realY, realW, realH); + component->bounds_ = newBounds; if (wasResized) component->repaint(); @@ -593,7 +585,7 @@ static FileDragAndDropTarget* findDragAndDropTarget (Component* c, return 0; } -void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) +void ComponentPeer::handleFileDragMove (const StringArray& files, const Point& position) { updateCurrentModifiers(); @@ -604,7 +596,7 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) FileDragAndDropTarget* newTarget = 0; - Component* const compUnderMouse = component->getComponentAt (x, y); + Component* const compUnderMouse = component->getComponentAt (position); if (compUnderMouse != lastDragAndDropCompUnderMouse) { @@ -621,7 +613,7 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) if (newTarget != 0) { Component* const targetComp = dynamic_cast (newTarget); - const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); + const Point pos (component->relativePositionToOtherComponent (targetComp, position)); dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast (newTarget)); newTarget->fileDragEnter (files, pos.getX(), pos.getY()); @@ -636,7 +628,7 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) if (newTarget != 0) { Component* const targetComp = dynamic_cast (newTarget); - const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); + const Point pos (component->relativePositionToOtherComponent (targetComp, position)); newTarget->fileDragMove (files, pos.getX(), pos.getY()); } @@ -644,15 +636,15 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y) void ComponentPeer::handleFileDragExit (const StringArray& files) { - handleFileDragMove (files, -1, -1); + handleFileDragMove (files, Point (-1, -1)); jassert (dragAndDropTargetComponent == 0); lastDragAndDropCompUnderMouse = 0; } -void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y) +void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point& position) { - handleFileDragMove (files, x, y); + handleFileDragMove (files, position); if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted()) { @@ -673,7 +665,7 @@ void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y) return; } - const Point pos (component->relativePositionToOtherComponent (targetComp, Point (x, y))); + const Point pos (component->relativePositionToOtherComponent (targetComp, position)); target->filesDropped (files, pos.getX(), pos.getY()); } } diff --git a/src/gui/components/windows/juce_ComponentPeer.h b/src/gui/components/windows/juce_ComponentPeer.h index a71cb744d9..52ed3976b9 100644 --- a/src/gui/components/windows/juce_ComponentPeer.h +++ b/src/gui/components/windows/juce_ComponentPeer.h @@ -147,7 +147,7 @@ public: If the native window is contained in another window, then the co-ordinates are relative to the parent window's origin, not the screen origin. */ - virtual void getBounds (int& x, int& y, int& w, int& h) const = 0; + virtual const Rectangle getBounds() const = 0; /** Returns the x-position of this window, relative to the screen's origin. */ virtual const Point getScreenPosition() const = 0; @@ -290,12 +290,12 @@ public: virtual void performAnyPendingRepaintsNow() = 0; //============================================================================== - void handleMouseEnter (int x, int y, const int64 time); - void handleMouseMove (int x, int y, const int64 time); - void handleMouseDown (int x, int y, const int64 time); - void handleMouseDrag (int x, int y, const int64 time); - void handleMouseUp (const int oldModifiers, int x, int y, const int64 time); - void handleMouseExit (int x, int y, const int64 time); + void handleMouseEnter (const Point& position, const int64 time); + void handleMouseMove (const Point& position, const int64 time); + void handleMouseDown (const Point& position, const int64 time); + void handleMouseDrag (const Point& position, const int64 time); + void handleMouseUp (const int oldModifiers, const Point& position, const int64 time); + void handleMouseExit (const Point& position, const int64 time); void handleMouseWheel (const int amountX, const int amountY, const int64 time); /** Causes a mouse-move callback to be made asynchronously. */ @@ -303,9 +303,9 @@ public: void handleUserClosingWindow(); - void handleFileDragMove (const StringArray& files, int x, int y); + void handleFileDragMove (const StringArray& files, const Point& position); void handleFileDragExit (const StringArray& files); - void handleFileDragDrop (const StringArray& files, int x, int y); + void handleFileDragDrop (const StringArray& files, const Point& position); //============================================================================== /** Resets the masking region. diff --git a/src/native/linux/juce_linux_Windowing.cpp b/src/native/linux/juce_linux_Windowing.cpp index 9725c8c549..2cc1635fe4 100644 --- a/src/native/linux/juce_linux_Windowing.cpp +++ b/src/native/linux/juce_linux_Windowing.cpp @@ -110,9 +110,6 @@ static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | Butto | ExposureMask | StructureNotifyMask | FocusChangeMask; //============================================================================== -static int pointerMap[5]; -static Point lastMousePos; - enum MouseButtons { NoButton = 0, @@ -123,10 +120,10 @@ enum MouseButtons WheelDown = 5 }; -static void getMousePos (int& x, int& y, int& mouseMods) throw() +static const Point getMousePos (int& mouseMods) throw() { Window root, child; - int winx, winy; + int x, y, winx, winy; unsigned int mask; mouseMods = 0; @@ -142,15 +139,12 @@ static void getMousePos (int& x, int& y, int& mouseMods) throw() } else { - if ((mask & Button1Mask) != 0) - mouseMods |= ModifierKeys::leftButtonModifier; - - if ((mask & Button2Mask) != 0) - mouseMods |= ModifierKeys::middleButtonModifier; - - if ((mask & Button3Mask) != 0) - mouseMods |= ModifierKeys::rightButtonModifier; + if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier; + if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier; + if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier; } + + return Point (x, y); } //============================================================================== @@ -243,8 +237,8 @@ void ModifierKeys::updateCurrentModifiers() throw() const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw() { - int x, y, mouseMods; - getMousePos (x, y, mouseMods); + int mouseMods; + getMousePos (mouseMods); currentModifiers &= ~ModifierKeys::allMouseButtonModifiers; currentModifiers |= mouseMods; @@ -386,61 +380,6 @@ static bool isShmAvailable() throw() } #endif -//============================================================================== -static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image) -{ - ScopedXLock xlock; - - const int width = image.getWidth(); - const int height = image.getHeight(); - HeapBlock colour (width * height); - int index = 0; - - for (int y = 0; y < height; ++y) - for (int x = 0; x < width; ++x) - colour[index++] = image.getPixelAt (x, y).getARGB(); - - XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap, - 0, (char*) colour, width, height, 32, 0); - - Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display), - width, height, 24); - - GC gc = XCreateGC (display, pixmap, 0, 0); - XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height); - XFreeGC (display, gc); - - return pixmap; -} - -static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image) -{ - ScopedXLock xlock; - - const int width = image.getWidth(); - const int height = image.getHeight(); - const int stride = (width + 7) >> 3; - HeapBlock mask; - mask.calloc (stride * height); - const bool msbfirst = (BitmapBitOrder (display) == MSBFirst); - - for (int y = 0; y < height; ++y) - { - for (int x = 0; x < width; ++x) - { - const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); - const int offset = y * stride + (x >> 3); - - if (image.getPixelAt (x, y).getAlpha() >= 128) - mask[offset] |= bit; - } - } - - return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display), - (char*) mask, width, height, 1, 0, 1); -} - - //============================================================================== class XBitmapImage : public Image { @@ -781,18 +720,8 @@ public: } } - void getBounds (int& x, int& y, int& w, int& h) const - { - x = wx; - y = wy; - w = ww; - h = wh; - } - - const Point getScreenPosition() const - { - return Point (wx, wy); - } + const Rectangle getBounds() const { return Rectangle (wx, wy, ww, wh); } + const Point getScreenPosition() const { return Point (wx, wy); } const Point relativePositionToGlobal (const Point& relativePosition) { @@ -1104,6 +1033,59 @@ public: repainter->performAnyPendingRepaintsNow(); } + static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image) + { + ScopedXLock xlock; + + const int width = image.getWidth(); + const int height = image.getHeight(); + HeapBlock colour (width * height); + int index = 0; + + for (int y = 0; y < height; ++y) + for (int x = 0; x < width; ++x) + colour[index++] = image.getPixelAt (x, y).getARGB(); + + XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap, + 0, (char*) colour, width, height, 32, 0); + + Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display), + width, height, 24); + + GC gc = XCreateGC (display, pixmap, 0, 0); + XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height); + XFreeGC (display, gc); + + return pixmap; + } + + static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image) + { + ScopedXLock xlock; + + const int width = image.getWidth(); + const int height = image.getHeight(); + const int stride = (width + 7) >> 3; + HeapBlock mask; + mask.calloc (stride * height); + const bool msbfirst = (BitmapBitOrder (display) == MSBFirst); + + for (int y = 0; y < height; ++y) + { + for (int x = 0; x < width; ++x) + { + const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); + const int offset = y * stride + (x >> 3); + + if (image.getPixelAt (x, y).getAlpha() >= 128) + mask[offset] |= bit; + } + } + + return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display), + (char*) mask, width, height, 1, 0, 1); + } + void setIcon (const Image& newIcon) { const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2; @@ -1336,7 +1318,7 @@ public: if (buttonMsg) { toFront (true); - handleMouseDown (buttonPressEvent->x, buttonPressEvent->y, + handleMouseDown (Point (buttonPressEvent->x, buttonPressEvent->y), getEventTime (buttonPressEvent->time)); } else if (wheelUpMsg || wheelDownMsg) @@ -1345,7 +1327,7 @@ public: getEventTime (buttonPressEvent->time)); } - lastMousePos = Point (0x100000, 0x100000); + clearLastMousePos(); break; } @@ -1366,10 +1348,10 @@ public: updateKeyModifiers (buttonRelEvent->state); handleMouseUp (oldModifiers, - buttonRelEvent->x, buttonRelEvent->y, + Point (buttonRelEvent->x, buttonRelEvent->y), getEventTime (buttonRelEvent->time)); - lastMousePos = Point (0x100000, 0x100000); + clearLastMousePos(); break; } @@ -1416,9 +1398,9 @@ public: } if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0) - handleMouseMove (mousePos.getX(), mousePos.getY(), getEventTime (movedEvent->time)); + handleMouseMove (mousePos, getEventTime (movedEvent->time)); else - handleMouseDrag (mousePos.getX(), mousePos.getY(), getEventTime (movedEvent->time)); + handleMouseDrag (mousePos, getEventTime (movedEvent->time)); } break; @@ -1426,7 +1408,7 @@ public: case EnterNotify: { - lastMousePos = Point (0x100000, 0x100000); + clearLastMousePos(); const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing; if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0 @@ -1434,7 +1416,7 @@ public: { updateKeyModifiers (enterEvent->state); - handleMouseEnter (enterEvent->x, enterEvent->y, getEventTime (enterEvent->time)); + handleMouseEnter (Point (enterEvent->x, enterEvent->y), getEventTime (enterEvent->time)); entered = true; } @@ -1455,7 +1437,7 @@ public: { updateKeyModifiers (leaveEvent->state); - handleMouseExit (leaveEvent->x, leaveEvent->y, getEventTime (leaveEvent->time)); + handleMouseExit (Point (leaveEvent->x, leaveEvent->y), getEventTime (leaveEvent->time)); entered = false; } @@ -2415,7 +2397,7 @@ private: updateDraggedFileList (clientMsg); if (dragAndDropFiles.size() > 0) - handleFileDragMove (dragAndDropFiles, dropPos.getX(), dropPos.getY()); + handleFileDragMove (dragAndDropFiles, dropPos); } } @@ -2431,7 +2413,7 @@ private: resetDragAndDrop(); if (files.size() > 0) - handleFileDragDrop (files, lastPos.getX(), lastPos.getY()); + handleFileDragDrop (files, lastPos); } void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg) @@ -2571,11 +2553,23 @@ private: Atom XA_OtherMime, dragAndDropCurrentMimeType; Window dragAndDropSourceWindow; - unsigned int allowedActions [5]; - unsigned int allowedMimeTypeAtoms [3]; + unsigned int allowedActions[5]; + unsigned int allowedMimeTypeAtoms[3]; Array srcMimeTypeAtomList; + + static int pointerMap[5]; + static Point lastMousePos; + + static void clearLastMousePos() throw() + { + lastMousePos = Point (0x100000, 0x100000); + } }; +int LinuxComponentPeer::pointerMap[5]; +Point LinuxComponentPeer::lastMousePos; + + //============================================================================== void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars) { @@ -2727,9 +2721,8 @@ bool Desktop::canUseSemiTransparentWindows() throw() const Point Desktop::getMousePosition() { - int x, y, mouseMods; - getMousePos (x, y, mouseMods); - return Point (x, y); + int mouseMods; + return getMousePos (mouseMods); } void Desktop::setMousePosition (const Point& newPosition) diff --git a/src/native/mac/juce_iphone_UIViewComponentPeer.mm b/src/native/mac/juce_iphone_UIViewComponentPeer.mm index 464d8784ba..51cc88f2f8 100644 --- a/src/native/mac/juce_iphone_UIViewComponentPeer.mm +++ b/src/native/mac/juce_iphone_UIViewComponentPeer.mm @@ -91,8 +91,9 @@ public: void setPosition (int x, int y); void setSize (int w, int h); void setBounds (int x, int y, int w, int h, const bool isNowFullScreen); - void getBounds (int& x, int& y, int& w, int& h, const bool global) const; - void getBounds (int& x, int& y, int& w, int& h) const; + + const Rectangle getBounds() const; + const Rectangle getBounds (const bool global) const; const Point getScreenPosition() const; const Point relativePositionToGlobal (const Point& relativePosition); const Point globalPositionToRelative (const Point& screenPosition); @@ -191,7 +192,7 @@ static int64 getMouseTime (UIEvent* e) + (int64) ([e timestamp] * 1000.0); } -int juce_lastMouseX = 0, juce_lastMouseY = 0; +JUCE_NAMESPACE::Point juce_lastMousePos; //============================================================================== - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event @@ -206,17 +207,14 @@ int juce_lastMouseX = 0, juce_lastMouseY = 0; case 1: // One finger.. { CGPoint p = [[t objectAtIndex: 0] locationInView: self]; + const JUCE_NAMESPACE::Point pos ((int) p.x, (int) p.y); currentModifiers |= getModifierForButtonNumber (0); + juce_lastMousePos = pos + owner->getScreenPosition(); - int x, y, w, h; - owner->getBounds (x, y, w, h, true); - juce_lastMouseX = x + (int) p.x; - juce_lastMouseY = y + (int) p.y; - - owner->handleMouseMove ((int) p.x, (int) p.y, getMouseTime (event)); + owner->handleMouseMove (pos, getMouseTime (event)); if (owner != 0) - owner->handleMouseDown ((int) p.x, (int) p.y, getMouseTime (event)); + owner->handleMouseDown (pos, getMouseTime (event)); } default: @@ -237,13 +235,10 @@ int juce_lastMouseX = 0, juce_lastMouseY = 0; case 1: // One finger.. { CGPoint p = [[t objectAtIndex: 0] locationInView: self]; + const JUCE_NAMESPACE::Point pos ((int) p.x, (int) p.y); + juce_lastMousePos = pos + owner->getScreenPosition(); - int x, y, w, h; - owner->getBounds (x, y, w, h, true); - juce_lastMouseX = x + (int) p.x; - juce_lastMouseY = y + (int) p.y; - - owner->handleMouseDrag ((int) p.x, (int) p.y, getMouseTime (event)); + owner->handleMouseDrag (pos, getMouseTime (event)); } default: @@ -264,15 +259,12 @@ int juce_lastMouseX = 0, juce_lastMouseY = 0; case 1: // One finger.. { CGPoint p = [[t objectAtIndex: 0] locationInView: self]; - - int x, y, w, h; - owner->getBounds (x, y, w, h, true); - juce_lastMouseX = x + (int) p.x; - juce_lastMouseY = y + (int) p.y; + const JUCE_NAMESPACE::Point pos ((int) p.x, (int) p.y); + juce_lastMousePos = pos + owner->getScreenPosition(); const int oldMods = currentModifiers; currentModifiers &= ~getModifierForButtonNumber (0); - owner->handleMouseUp (oldMods, (int) p.x, (int) p.y, getMouseTime (event)); + owner->handleMouseUp (oldMods, pos, getMouseTime (event)); } default: @@ -465,7 +457,7 @@ void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNo } } -void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const +const Rectangle UIViewComponentPeer::getBounds (const bool global) const { CGRect r = [view frame]; @@ -477,45 +469,28 @@ void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool r.origin.y += wr.origin.y; } - x = (int) r.origin.x; - y = (int) r.origin.y; - w = (int) r.size.width; - h = (int) r.size.height; -} - -void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const -{ - getBounds (x, y, w, h, ! isSharedWindow); + return Rectangle ((int) r.origin.x, (int) r.origin.y, + (int) r.size.width, (int) r.size.height); } -int UIViewComponentPeer::getScreenX() const +const Rectangle UIViewComponentPeer::getBounds() const { - int x, y, w, h; - getBounds (x, y, w, h, true); - return x; + return getBounds (! isSharedWindow); } -int UIViewComponentPeer::getScreenY() const +const Point UIViewComponentPeer::getScreenPosition() const { - int x, y, w, h; - getBounds (x, y, w, h, true); - return y; + return getBounds (true).getPosition(); } -void UIViewComponentPeer::relativePositionToGlobal (int& x, int& y) +const Point UIViewComponentPeer::relativePositionToGlobal (const Point& relativePosition) { - int wx, wy, ww, wh; - getBounds (wx, wy, ww, wh, true); - x += wx; - y += wy; + return relativePosition + getScreenPosition(); } -void UIViewComponentPeer::globalPositionToRelative (int& x, int& y) +const Point UIViewComponentPeer::globalPositionToRelative (const Point& screenPosition) { - int wx, wy, ww, wh; - getBounds (wx, wy, ww, wh, true); - x -= wx; - y -= wy; + return screenPosition + getScreenPosition(); } CGRect UIViewComponentPeer::constrainRect (CGRect r) @@ -818,7 +793,7 @@ bool Desktop::canUseSemiTransparentWindows() throw() const Point Desktop::getMousePosition() { - return Point (juce_lastMouseX, juce_lastMouseY); + return juce_lastMousePos; } void Desktop::setMousePosition (const Point&) diff --git a/src/native/mac/juce_mac_NSViewComponentPeer.mm b/src/native/mac/juce_mac_NSViewComponentPeer.mm index b717e0cf0d..ddf9e11184 100644 --- a/src/native/mac/juce_mac_NSViewComponentPeer.mm +++ b/src/native/mac/juce_mac_NSViewComponentPeer.mm @@ -133,8 +133,8 @@ public: void setPosition (int x, int y); void setSize (int w, int h); void setBounds (int x, int y, int w, int h, const bool isNowFullScreen); - void getBounds (int& x, int& y, int& w, int& h, const bool global) const; - void getBounds (int& x, int& y, int& w, int& h) const; + const Rectangle getBounds (const bool global) const; + const Rectangle getBounds() const; const Point getScreenPosition() const; const Point relativePositionToGlobal (const Point& relativePosition); const Point globalPositionToRelative (const Point& screenPosition); @@ -642,11 +642,10 @@ static int64 getMouseTime (NSEvent* e) + (int64) ([e timestamp] * 1000.0); } -static void getMousePos (NSEvent* e, NSView* view, int& x, int& y) +static const Point getMousePos (NSEvent* e, NSView* view) { NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil]; - x = roundToInt (p.x); - y = roundToInt ([view frame].size.height - p.y); + return Point (roundToInt (p.x), roundToInt ([view frame].size.height - p.y)); } static int getModifierForButtonNumber (const NSInteger num) @@ -829,7 +828,7 @@ void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNo } } -void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const +const Rectangle NSViewComponentPeer::getBounds (const bool global) const { NSRect r = [view frame]; @@ -839,29 +838,24 @@ void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool NSRect wr = [[view window] frame]; r.origin.x += wr.origin.x; r.origin.y += wr.origin.y; - - y = (int) ([[[NSScreen screens] objectAtIndex:0] frame].size.height - r.origin.y - r.size.height); + r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height; } else { - y = (int) ([[view superview] frame].size.height - r.origin.y - r.size.height); + r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height; } - x = (int) r.origin.x; - w = (int) r.size.width; - h = (int) r.size.height; + return Rectangle ((int) r.origin.x, (int) r.size.width, (int) r.size.width, (int) r.size.height); } -void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const +const Rectangle NSViewComponentPeer::getBounds() const { - getBounds (x, y, w, h, ! isSharedWindow); + return getBounds (! isSharedWindow); } const Point NSViewComponentPeer::getScreenPosition() const { - int x, y, w, h; - getBounds (x, y, w, h, true); - return Point (x, y); + return getBounds (true).getPosition(); } const Point NSViewComponentPeer::relativePositionToGlobal (const Point& relativePosition) @@ -1207,10 +1201,7 @@ void NSViewComponentPeer::redirectMouseDown (NSEvent* ev) { updateModifiers (ev); currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseDown (x, y, getMouseTime (ev)); + handleMouseDown (getMousePos (ev, view), getMouseTime (ev)); } void NSViewComponentPeer::redirectMouseUp (NSEvent* ev) @@ -1218,10 +1209,7 @@ void NSViewComponentPeer::redirectMouseUp (NSEvent* ev) const int oldMods = currentModifiers; updateModifiers (ev); currentModifiers &= ~getModifierForButtonNumber ([ev buttonNumber]); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseUp (oldMods, x, y, getMouseTime (ev)); + handleMouseUp (oldMods, getMousePos (ev, view), getMouseTime (ev)); showArrowCursorIfNeeded(); } @@ -1229,38 +1217,26 @@ void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev) { updateModifiers (ev); currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseDrag (x, y, getMouseTime (ev)); + handleMouseDrag (getMousePos (ev, view), getMouseTime (ev)); } void NSViewComponentPeer::redirectMouseMove (NSEvent* ev) { updateModifiers (ev); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseMove (x, y, getMouseTime (ev)); + handleMouseMove (getMousePos (ev, view), getMouseTime (ev)); showArrowCursorIfNeeded(); } void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev) { updateModifiers (ev); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseEnter (x, y, getMouseTime (ev)); + handleMouseEnter (getMousePos (ev, view), getMouseTime (ev)); } void NSViewComponentPeer::redirectMouseExit (NSEvent* ev) { updateModifiers (ev); - int x, y; - getMousePos (ev, view, x, y); - - handleMouseExit (x, y, getMouseTime (ev)); + handleMouseExit (getMousePos (ev, view), getMouseTime (ev)); } void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev) @@ -1291,8 +1267,7 @@ BOOL NSViewComponentPeer::sendDragCallback (int type, id sender return false; NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil]; - int x = (int) p.x; - int y = (int) ([view frame].size.height - p.y); + const Point pos ((int) p.x, (int) ([view frame].size.height - p.y)); StringArray files; @@ -1312,11 +1287,11 @@ BOOL NSViewComponentPeer::sendDragCallback (int type, id sender return false; if (type == 0) - handleFileDragMove (files, x, y); + handleFileDragMove (files, pos); else if (type == 1) handleFileDragExit (files); else if (type == 2) - handleFileDragDrop (files, x, y); + handleFileDragDrop (files, pos); return true; } diff --git a/src/native/windows/juce_win32_ActiveXComponent.cpp b/src/native/windows/juce_win32_ActiveXComponent.cpp index d16e19076f..bb739fc7d7 100644 --- a/src/native/windows/juce_win32_ActiveXComponent.cpp +++ b/src/native/windows/juce_win32_ActiveXComponent.cpp @@ -342,8 +342,8 @@ static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, GetWindowRect (hwnd, &activeXRect); GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect); - const int mx = GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left; - const int my = GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top; + const Point mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left, + GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top); const int64 mouseEventTime = getMouseEventTime(); const int oldModifiers = currentModifiers; @@ -353,21 +353,21 @@ static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, { case WM_MOUSEMOVE: if (ModifierKeys (currentModifiers).isAnyMouseButtonDown()) - peer->handleMouseDrag (mx, my, mouseEventTime); + peer->handleMouseDrag (mousePos, mouseEventTime); else - peer->handleMouseMove (mx, my, mouseEventTime); + peer->handleMouseMove (mousePos, mouseEventTime); break; case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: - peer->handleMouseDown (mx, my, mouseEventTime); + peer->handleMouseDown (mousePos, mouseEventTime); break; case WM_LBUTTONUP: case WM_MBUTTONUP: case WM_RBUTTONUP: - peer->handleMouseUp (oldModifiers, mx, my, mouseEventTime); + peer->handleMouseUp (oldModifiers, mousePos, mouseEventTime); break; default: diff --git a/src/native/windows/juce_win32_OpenGLComponent.cpp b/src/native/windows/juce_win32_OpenGLComponent.cpp index be107e0f7f..c14a6b0f27 100644 --- a/src/native/windows/juce_win32_OpenGLComponent.cpp +++ b/src/native/windows/juce_win32_OpenGLComponent.cpp @@ -288,9 +288,8 @@ public: void repaint() { - int x, y, w, h; - nativeWindow->getBounds (x, y, w, h); - nativeWindow->repaint (0, 0, w, h); + const Rectangle bounds (nativeWindow->getBounds()); + nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight()); } void swapBuffers() diff --git a/src/native/windows/juce_win32_Windowing.cpp b/src/native/windows/juce_win32_Windowing.cpp index ce98b5e705..55095ea8de 100644 --- a/src/native/windows/juce_win32_Windowing.cpp +++ b/src/native/windows/juce_win32_Windowing.cpp @@ -566,28 +566,21 @@ public: repaintNowIfTransparent(); } - void getBounds (int& x, int& y, int& w, int& h) const + const Rectangle getBounds() const { RECT r; GetWindowRect (hwnd, &r); - x = r.left; - y = r.top; - w = r.right - x; - h = r.bottom - y; + Rectangle bounds (r.left, r.top, r.right - r.left, r.bottom - r.top); HWND parentH = GetParent (hwnd); if (parentH != 0) { GetWindowRect (parentH, &r); - x -= r.left; - y -= r.top; + bounds.translate (-r.left, -r.top); } - x += windowBorder.getLeft(); - y += windowBorder.getTop(); - w -= windowBorder.getLeftAndRight(); - h -= windowBorder.getTopAndBottom(); + return windowBorder.subtractedFrom (bounds); } const Point getScreenPosition() const @@ -1290,7 +1283,7 @@ private: } updateKeyModifiers(); - handleMouseEnter (x, y, mouseEventTime); + handleMouseEnter (Point (x, y), mouseEventTime); } else if (! isDragging) { @@ -1311,7 +1304,7 @@ private: if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond) { lastMouseTime = now; - handleMouseMove (x, y, mouseEventTime); + handleMouseMove (Point (x, y), mouseEventTime); } } } @@ -1323,7 +1316,7 @@ private: if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond) { lastMouseTime = now; - handleMouseDrag (x, y, mouseEventTime); + handleMouseDrag (Point (x, y), mouseEventTime); } } } @@ -1349,7 +1342,7 @@ private: updateKeyModifiers(); isDragging = true; - handleMouseDown (x, y, getMouseEventTime()); + handleMouseDown (Point (x, y), getMouseEventTime()); } void doMouseUp (const int x, const int y, const WPARAM wParam) @@ -1387,7 +1380,7 @@ private: if (numButtons == 0 && hwnd == GetCapture()) ReleaseCapture(); - handleMouseUp (oldModifiers, x, y, getMouseEventTime()); + handleMouseUp (oldModifiers, Point (x, y), getMouseEventTime()); } void doCaptureChanged() @@ -1415,8 +1408,8 @@ private: const DWORD mp = GetMessagePos(); - handleMouseExit (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(), - GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(), + handleMouseExit (Point (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(), + GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop()), getMouseEventTime()); } } @@ -1677,8 +1670,7 @@ private: HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { updateFileList (pDataObject); - const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); - owner->handleFileDragMove (files, pos.getX(), pos.getY()); + owner->handleFileDragMove (files, owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); *pdwEffect = DROPEFFECT_COPY; return S_OK; } @@ -1691,8 +1683,7 @@ private: HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { - const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); - owner->handleFileDragMove (files, pos.getX(), pos.getY()); + owner->handleFileDragMove (files, owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); *pdwEffect = DROPEFFECT_COPY; return S_OK; } @@ -1700,8 +1691,7 @@ private: HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { updateFileList (pDataObject); - const Point pos (owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); - owner->handleFileDragDrop (files, pos.getX(), pos.getY()); + owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point (mousePos.x, mousePos.y))); *pdwEffect = DROPEFFECT_COPY; return S_OK; }