Hi All, I'm using a NSPanel to mimic menu in Tiger these days. I think most of the job has been done except one small problem. What I want to do is that implementing something just behaves like a popUpButton. OK let's get into the point. I got a popUpButton, and I override its cell
@implementation MyPopUpButtonCell //setting panel frame which makes the panel attach to the popUpButton and makes the panel on the Screen, then panel orderFrontRegardless - (void) attachPopUpPanelMenu:(MyMenuPanel *)menuPanel inView:(NSView*)cv; // panel orderOut - (void) dismissPanelMenu; @end @implementation MyMenuPanel //subclass of NSPanel - (id)initWithContentRect:(NSRect)contentRect styleMask:(int)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation { self = [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation]; if(self) { [self setLevel:NSPopUpMenuWindowLevel]; [self setHasShadow:YES]; [self setWorksWhenModal:YES]; } return self; } /** * tracking Mouse Event . In my custom loop , to get every event in the queue. * check the event position , if happened in myMenuPanel dispatch the event , finish loop , popUpButtonCell dismiss the panel * if event happened outside window , finish loop , popUpButtonCell dismiss the panel * I don't need the menu highlight staff , so I don't start or handling the NSPeriodic event. * So everything works good . But if I switch the App to others . My menuPanel will be hided . because the NSPanel * hideOnDeactivate. The problem is , my App ,still is on active . I think the reason is event tracking loop is still on * It hasn't quit. So , I need find something when myPanelMenu be hidden to stop the loop. * Is there any suggestion on this? */ - (void) trackingMouseEvent:(NSEvent *) theEvent { unsigned eventMask = NSLeftMouseDownMask|NSLeftMouseUpMask|NSLeftMouseDragged; eventMask |= NSRightMouseDraggedMask|NSRightMouseDownMask|NSRightMouseUpMask; eventMask |= NSOtherMouseUpMask||NSOtherMouseDraggedMask||NSOtherMouseDownMask; eventMask |= NSPeriodicMask; NSDate *date = [NSDate distantFuture]; BOOL keepOn = YES; NSEvent *nextEvent; while(keepOn) { nextEvent = [NSApp nextEventMatchingMask:eventMask untilDate:date inMode:NSEventTrackingRunLoopMode dequeue:YES]; NSLog(@"%d %d %d %d %d %d %@ %d", [self isKeyWindow], [self isOpaque], [self isVisible], [NSApp isHidden], [NSApp isActive], [self canBecomeKeyWindow], [NSApp keyWindow], [[NSApp keyWindow] isMainWindow]); switch([nextEvent type]) { case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown: //ToDo dispatch to mouseDown method if(![nextEvent isEqual:theEvent]) { NSPoint location = [[self window] mouseLocationOutsideOfEventStream]; NSPoint viewLocation = [self convertPoint:location fromView:nil]; if([self mouse:viewLocation inRect:[self bounds]]) { [self mouseDown:theEvent]; } else keepOn = NO; } break; case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: //ToDo dispatch to mouseUp method if([nextEvent timestamp] - [theEvent timestamp] > 0.25) { NSPoint location = [[self window] mouseLocationOutsideOfEventStream]; NSPoint viewLocation = [self convertPoint:location fromView:nil]; if([self mouse:viewLocation inRect:[self bounds]]) { [self mouseUp:theEvent]; } keepOn = NO; } break; case NSLeftMouseDragged: case NSRightMouseDragged: case NSOtherMouseDragged: [self mouseDragged:theEvent]; break; default: break; } } } @end _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]