Re: Re: Scrolling text in Status Item - adding a menu
Re: Re: Scrolling text in Status Item - adding a menu
- Subject: Re: Re: Scrolling text in Status Item - adding a menu
- From: "Alan Smith" <email@hidden>
- Date: Mon, 30 Oct 2006 21:55:35 -0500
Hi guys,
Eric: I suggest you try NSMenu's
+ (void)popUpContextMenu:(NSMenu *)*menu*
withEvent:(NSEvent<http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSEvent>*)
*event* forView:(NSView<http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSView>*)
*view.
*You can put that in mouseDown or some such place and pass in the event.
You can't use both a menu and a view, Apple's docs say so. When you setView
it gives you complete control over the item and disables all other actions
and drawing methods.
Mercer: I too wanted to know how this was done, quite some time ago, so I
contacted Apple directly. Here is a snippet from the code I recieved, it
should be all you need.
// This was in awakeFromNib:
//
// mVolumeBox is just a NSBox surounding the volume slider
//
[mVolumeButton sendActionOn:NSLeftMouseDownMask];
// Add tracking rect so that -mouseEntered and -mouseExited are called
[mVolumeBox addTrackingRect:[mVolumeBox bounds] owner:self userData:nil
assumeInside:NO];
- (IBAction) showVolumeWindow:(id)sender
{
NSRect buttonFrame; // Frame of mVolumeButton in window
coordinates
NSRect windowFrame; // Frame of mVolumeWindow in screen
coordinates
// Position the volume window near the volume button
buttonFrame = [mVolumeButton convertRect:[mVolumeButton bounds]
toView:nil];
windowFrame = [mVolumeWindow frame];
windowFrame.origin = [[mVolumeButton window] convertBaseToScreen:
buttonFrame.origin];
[mVolumeWindow setFrame:windowFrame display:YES];
// Show window
[self makeWindowVisibleAtFullAlpha];
}
- (void) mouseEntered:(NSEvent*)event
{
[self makeWindowVisibleAtFullAlpha];
}
- (void) mouseExited:(NSEvent*)event
{
[self startFadeOutTimerWithDuration:0.75];
}
- (void) makeWindowVisibleAtFullAlpha
{
[self setFadeOutTimer:nil withStartTime:0 duration:0];
[mVolumeWindow setAlphaValue:1.0];
[mOwnerWindow addChildWindow:mVolumeWindow ordered:NSWindowAbove];
[mVolumeWindow orderFront:self];
}
That should do it. You probably don't need all of the above code.
Good luck guys!
Peace, Alan
--
// Quotes from yours truly -------------------------
"You don't forget, you just don't remember."
"Maturity resides in the mind."
"Silence is the Universe's greatest gift."
"When the World realizes that religion really is unimportant, then it shall
evolve."
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden