NSSlider's mouseDown implementation
NSSlider's mouseDown implementation
- Subject: NSSlider's mouseDown implementation
- From: email@hidden
- Date: Mon, 20 May 2002 13:13:03 -0500
I am trying to implement a custom view for NSStatusItems to mimic the
behavior of apple's volume control item(the one in the upper right hand
corner of the screen). I don' t want the slider to track the mouse
movement until the mouse has moved over the knob in the slider.
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint mouseLoc = [theEvent locationInWindow];
BOOL isInside = [self mouse:mouseLoc inRect:[imageView frame]],
isInsideSlider, isInsideSliderKnob;
BOOL keepOn = YES;
NSRect aRect;
int knobThickness;
double sliderValue;
int sliderLoc;
NSLog(@"Entering Status Item's mouseDown handler");
if(isInside){
[self setIsHighlighted:YES];
[self setNeedsDisplay:YES];
[sliderWindow makeKeyAndOrderFront:self];
}
while (keepOn) {
theEvent = [[self window] nextEventMatchingMask:
NSLeftMouseUpMask |
NSLeftMouseDraggedMask];
mouseLoc = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
/*determine the rect that the slider occupies and put it in aRect */
isInsideSlider = [self mouse:mouseLoc inRect:aRect];
/* [imageView frame] is my custom view */
isInside = [self mouse:mouseLoc inRect:[imageView frame]];
/*determine the rect that the slider knob occupies and put it in
aRect */
isInsideSliderKnob = [self mouse:mouseLoc inRect:aRect];
switch ([theEvent type]) {
case NSLeftMouseDragged:
NSLog(@"Entering NSLeftMouseDragged case");
[self setIsHighlighted:isInside | isInsideSlider];
if(isInsideSliderKnob){
NSLog(@"Entering NSSlider's mouseDown handler");
/*************************************************************************
**************
after entering the slider's mouseDown message, the knob will not
follow the mouse until it goes back to my custom view and enters the
slider area again. Why is this? How can I fix it?
**************************************************************************
**************/
[volumeSlider mouseDown:theEvent];
NSLog(@"Left NSSlider's mouseDown handler");
if([[[self window] currentEvent] type] == NSLeftMouseUp){
NSLog(@"Entering LeftMouseUp if statement");
[self setIsHighlighted:NO];
[sliderWindow close];
keepOn = NO;
}
}
break;
case NSLeftMouseUp:
NSLog(@"Entering mouseUp case");
//if (isInside) [self doSomethingSignificant];
[self setIsHighlighted:NO];
[sliderWindow close];
keepOn = NO;
break;
default:
/* Ignore any other kind of event. */
break;
}
[self setNeedsDisplay:YES];
};
return;
}
I have debugged the program and I can see that the slider knob rect and
the slider rect are being determined correctly. If I watch the log, I
can see that the slider's mouseDown message is not sent until the mouse
is over the knob, but the knob does not begin tracking when I want it to.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.