Commit e15b82ad authored by Ken Thomases's avatar Ken Thomases Committed by Alexandre Julliard

winemac: Consolidate mouse button handling into -[WineApplicationController handleMouseButton:].

parent 72e89323
......@@ -61,6 +61,7 @@ enum {
WineWindow* lastTargetWindow;
BOOL forceNextMouseMoveAbsolute;
double mouseMoveDeltaX, mouseMoveDeltaY;
NSUInteger unmatchedMouseDowns;
NSMutableArray* orderedWineWindows;
......
......@@ -1219,6 +1219,87 @@ int macdrv_err_on;
}
}
- (void) handleMouseButton:(NSEvent*)theEvent
{
WineWindow* window = (WineWindow*)[theEvent window];
if ([window isKindOfClass:[WineWindow class]])
{
NSEventType type = [theEvent type];
BOOL pressed = (type == NSLeftMouseDown || type == NSRightMouseDown || type == NSOtherMouseDown);
CGPoint pt = CGEventGetLocation([theEvent CGEvent]);
BOOL process;
if (pressed)
{
// Test if the click was in the window's content area.
NSPoint nspoint = [self flippedMouseLocation:NSPointFromCGPoint(pt)];
NSRect contentRect = [window contentRectForFrameRect:[window frame]];
process = NSPointInRect(nspoint, contentRect);
if (process && [window styleMask] & NSResizableWindowMask)
{
// Ignore clicks in the grow box (resize widget).
HIPoint origin = { 0, 0 };
HIThemeGrowBoxDrawInfo info = { 0 };
HIRect bounds;
OSStatus status;
info.kind = kHIThemeGrowBoxKindNormal;
info.direction = kThemeGrowRight | kThemeGrowDown;
if ([window styleMask] & NSUtilityWindowMask)
info.size = kHIThemeGrowBoxSizeSmall;
else
info.size = kHIThemeGrowBoxSizeNormal;
status = HIThemeGetGrowBoxBounds(&origin, &info, &bounds);
if (status == noErr)
{
NSRect growBox = NSMakeRect(NSMaxX(contentRect) - bounds.size.width,
NSMinY(contentRect),
bounds.size.width,
bounds.size.height);
process = !NSPointInRect(nspoint, growBox);
}
}
if (process)
unmatchedMouseDowns |= NSEventMaskFromType(type);
}
else
{
NSEventType downType = type - 1;
NSUInteger downMask = NSEventMaskFromType(downType);
process = (unmatchedMouseDowns & downMask) != 0;
unmatchedMouseDowns &= ~downMask;
}
if (process)
{
macdrv_event* event;
event = macdrv_create_event(MOUSE_BUTTON, window);
event->mouse_button.button = [theEvent buttonNumber];
event->mouse_button.pressed = pressed;
event->mouse_button.x = pt.x;
event->mouse_button.y = pt.y;
event->mouse_button.time_ms = [self ticksForEventTime:[theEvent timestamp]];
[window.queue postEvent:event];
macdrv_release_event(event);
}
}
// Since mouse button events deliver absolute cursor position, the
// accumulating delta from move events is invalidated. Make sure
// next mouse move event starts over from an absolute baseline.
// Also, it's at least possible that the title bar widgets (e.g. close
// button, etc.) could enter an internal event loop on a mouse down that
// wouldn't exit until a mouse up. In that case, we'd miss any mouse
// dragged events and, after that, any notion of the cursor position
// computed from accumulating deltas would be wrong.
forceNextMouseMoveAbsolute = TRUE;
}
// Returns TRUE if the event was handled and caller should do nothing more
// with it. Returns FALSE if the caller should process it as normal and
// then call -didSendEvent:.
......@@ -1240,12 +1321,15 @@ int macdrv_err_on;
}
else if (type == NSLeftMouseDown || type == NSLeftMouseUp ||
type == NSRightMouseDown || type == NSRightMouseUp ||
type == NSOtherMouseDown || type == NSOtherMouseUp ||
type == NSScrollWheel)
type == NSOtherMouseDown || type == NSOtherMouseUp)
{
[self handleMouseButton:anEvent];
}
else if (type == NSScrollWheel)
{
// Since mouse button and scroll wheel events deliver absolute cursor
// position, the accumulating delta from move events is invalidated.
// Make sure next mouse move event starts over from an absolute baseline.
// Since scroll wheel events deliver absolute cursor position, the
// accumulating delta from move events is invalidated. Make sure next
// mouse move event starts over from an absolute baseline.
forceNextMouseMoveAbsolute = TRUE;
}
else if (type == NSKeyDown && ![anEvent isARepeat] && [anEvent keyCode] == kVK_Tab)
......
......@@ -250,13 +250,6 @@ static inline void fix_generic_modifiers_by_device(NSUInteger* modifiers)
}
}
/* By default, NSView will swallow right-clicks in an attempt to support contextual
menus. We need to bypass that and allow the event to make it to the window. */
- (void) rightMouseDown:(NSEvent*)theEvent
{
[[self window] rightMouseDown:theEvent];
}
- (void) addGLContext:(WineOpenGLContext*)context
{
if (!glContexts)
......@@ -839,23 +832,6 @@ static inline void fix_generic_modifiers_by_device(NSUInteger* modifiers)
[self checkTransparency];
}
- (void) postMouseButtonEvent:(NSEvent *)theEvent pressed:(int)pressed
{
CGPoint pt = CGEventGetLocation([theEvent CGEvent]);
macdrv_event* event;
event = macdrv_create_event(MOUSE_BUTTON, self);
event->mouse_button.button = [theEvent buttonNumber];
event->mouse_button.pressed = pressed;
event->mouse_button.x = pt.x;
event->mouse_button.y = pt.y;
event->mouse_button.time_ms = [[WineApplicationController sharedController] ticksForEventTime:[theEvent timestamp]];
[queue postEvent:event];
macdrv_release_event(event);
}
- (void) makeFocused:(BOOL)activate
{
WineApplicationController* controller = [WineApplicationController sharedController];
......@@ -1061,14 +1037,6 @@ static inline void fix_generic_modifiers_by_device(NSUInteger* modifiers)
/*
* ---------- NSResponder method overrides ----------
*/
- (void) mouseDown:(NSEvent *)theEvent { [self postMouseButtonEvent:theEvent pressed:1]; }
- (void) rightMouseDown:(NSEvent *)theEvent { [self mouseDown:theEvent]; }
- (void) otherMouseDown:(NSEvent *)theEvent { [self mouseDown:theEvent]; }
- (void) mouseUp:(NSEvent *)theEvent { [self postMouseButtonEvent:theEvent pressed:0]; }
- (void) rightMouseUp:(NSEvent *)theEvent { [self mouseUp:theEvent]; }
- (void) otherMouseUp:(NSEvent *)theEvent { [self mouseUp:theEvent]; }
- (void) keyDown:(NSEvent *)theEvent { [self postKeyEvent:theEvent]; }
- (void) keyUp:(NSEvent *)theEvent { [self postKeyEvent:theEvent]; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment