 |
 |
MediaDock help
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
I've got an application I started working on over a year ago and forgot about until just recently. I thought it would be nice for some people to have a media dock in addition to the regular dock - it would be a place to hold CDs, DVDs, and other mountable media. I think it's decent, and I'd love to at least put it out there, but there are two things that are currently holding me back:
1) The current way that I figure out when a users mouse has entered a region above my window (whether the window is active or not) is by polling the system every .1 seconds. This seems somewhat inefficient; is there a better way?
2) It seems that weird things happen right after contextual menus end that originated from an NSMenu. More specifically, it seems that the views window loses some sort of focus level and stops receiving mouseMoved events, but the application still reports to be active (I have no other windows, what possibly could be active?). So, this question has two parts. A solution would be to generate a mouse click on the window when the menu ends. I haven't been able to produce this mouse click successfully. The second part of the solution alludes me as well: how do I find out when my popped up contextual menu has ended?
3) I've asked this question many times, but I have never received an answer. I guess it won't hurt to ask again - how do I make menus that create their submenus and subitems on the fly? I need to do this because when media is added to the dock, I don't want to have to load all the different subpaths into memory (which on most hard drives would take forever) while the menu is being generated. Instead, I want each submenu and items to be generated when the user needs them (one step ahead would be nice, but that's something I can figure out once I get the basic idea done above). You see this behavior in the dock if you click-hold on a hard drive or CD - I'd like to be able to do this in MediaDock as well. Is there a call back in the Carbon Menu Manager that I should be using?
http://homepage.mac.com/fahrenba/med.../mediaDock.dmg
Thanks,
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
Pretty darn impressive!
Any plans on releasing the source?
Wish I could just post the answers to your questions. I did a couple searches and scanned through my projects and didn't really come up with anything that would help. And, as is usual for me, nothing's just coming to mind. 
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
So... is there a reason why I can't find a way to populate an NSMenu while a user is navigating through it? Is this a sign that I'm missing something that the "in" croud of programmers gets? Is this something I just have to bash my head against the wall a million times and from the numbness I find the great insight, or does no one here know?
I just feel frustrated because for little things like this I never seem to get an answer from anywhere.
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2003
Location: Hilton Head Island, SC
Status:
Offline
|
|
You'll need to build your NSMenu dynamically. I don't have any code laying around, but I was able to find a quick tutorial on building a dynamic NSMenu over at Cocoa Dev Center. Here's the link : http://cocoadevcentral.com/articles/000036.php#000036
Let me know if this doesn't help....I'll see about throwing some code together.
-Brian
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Thanks Brian. Actually, what that article describes is different that what I'm dealing with. Here's the problem:
When a user click-holds the dock, the menu pops up. But that menu already has it's submenus created (at least as described in the example). Try dragging your harddrive to the right hand side of the dock. If you click-hold on it, a menu will pop up and you'll hear some grinding. When you go into a subdirectory (say Applications), you'll hear some more grinding and a sub-level is displayed. This is the behavior I'm looking for: menu's with x-menu items that have submenus that are generated when the user requests them (by mousing over the item).
Why do I want this behavior? Well, OS X has several hundred thousand files on it, and to create all the sub menus at one time would:
a) take forever
b) hog a lot of memory
c) be inefficient
So, I essentially want to have this setup:
Before user mouses over Applications item:
Root Menu:
Applications -> nil
Library -> nil
System -> nil
Users ->nil
After user mouses over Applications item:
Root Menu:
Applications
Acrobat Reader
Adress Book
...
Library -> nil
System -> nil
Users ->nil
Does that make sense?
Thanks,
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2003
Location: Hilton Head Island, SC
Status:
Offline
|
|
So, you want to have the functionality of a dynamic popup menu that you can use to navigate media (HD, CD, network)? I dragged my HD to my dock and used it's context menu to navigate folders & subfolers...I assume this is what you're wanting to implement. I've got some free time coming up this week and will see what I can come up with. Gimme a few days to 'play'...
-Brian
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status:
Offline
|
|
This source to this is already available...I found it on osx.hyperjeff.net
|
|
Luke
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Originally posted by sandsl:
This source to this is already available...I found it on osx.hyperjeff.net
That source is a little old, but it has most of the guts of what my current source looks like. Hrmm... I probably should update the source some time in the near future...
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
I've made some progress on the menu issue. It seems that I need to use the Carbon Event Manager instead of the Carbon Menu Manager.
One menu event constant looks very interesting:
kEventMenuPopulate
Sent when an application should dynamically create a menu. You should use this event instead of kEventMenuOpening as the Menu Manager sends it before it searches a menu for a matching command key sequence; therefore you can use this event to dynamically add menu items that have command-key equivalents, making them selectable even if the menu itself is never displayed. The kEventMenuPopulate event is sent just once during a menu tracking session, even if the menu is opened and closed multiple times; the kEventWindowOpening event is sent each time the menu opens.
To determine whether this event was triggered by a command-key sequence, you should examine the kEventParamMenuContext parameter for the kMenuContextKeyMatching flag. If the event corresponds to the actual display of a menu, the kEventContextMenuBarTracking or kEventContextPopUpTracking flags are set.
Available in CarbonLib 1.5 and later, and Mac OS X v.10.1 and later. Note that in CarbonLib 1.6 and Mac OS X v.10.2 and later, the Menu Manager sends this event before it searches a menu for a matching command ID. To determine if this event was triggered by a command ID, check for the kMenuContextCommandIDSearch flag in the kEventParamMenuContext parameter. If that flag is set, the command ID that triggered this event is contained in the kEventParamMenuCommand parameter.
Now, how to deal with the Carbon Event Manager
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Sweetness. Now to see if I can figure this part out:
Creating and Registering an Event Handler
The function for installing an event handler is called InstallEventHandler:
OSStatus InstallEventHandler (EventTargetRef target,
EventHandlerUPP handlerProc,
UInt32 numTypes,
const EventTypeSpec* typeList,
void* userData,
EventHandlerRef* handlerRef);
The second parameter, handlerProc, is a universal procedure pointer (UPP) to your handler routine. The conversion function NewEventHandlerUPP returns a UPP of the required type; for instance,
EventHandlerUPP handlerUPP;
handlerUPP = NewEventHandlerUPP(ThisHandler);
(where ThisHandler is the name of your handler routine).
The target parameter to InstallEventHandler identifies the event target on which the handler is to be installed. You can obtain a reference to the desired target by calling one of the following functions: GetApplicationEventTarget, GetWindowEventTarget, GetMenuEventTarget, or GetControlEventTarget.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Any one got an idea why "Hi" doesn't get printed out at all? I'm opening mu menus, they're being properly init'ed and everything...
Code:
#import "MDMenu.h"
#import <Carbon/Carbon.h>
@implementation MDMenu
///////////////////////////////////////////////////////
// I'm making a lot of use out of this subclass, eh? //
///////////////////////////////////////////////////////
MenuRef _NSGetCarbonMenu(NSMenu *menu);
OSStatus MDMenuEventHandlerCallback (
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent,
void *inUserData
)
{
NSLog(@"HI!");
return noErr;
}
- (id)init
{
self = [super init];
if(self)
{
MenuRef menuRef = _NSGetCarbonMenu(self);
EventTargetRef targRef= GetMenuEventTarget(menuRef);
EventHandlerUPP handlerUPP = NewEventHandlerUPP(MDMenuEventHandlerCallback);
EventTypeSpec eventTypes[] = {{kEventClassMenu, kEventMenuPopulate},
{kEventClassMenu, kEventMenuOpening}};
InstallEventHandler(targRef,handlerUPP,2,eventTypes,0,NULL);
}
return self;
}
@end
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
InstallEventHandler() is returning -50; Invalid value passed in a parameter.
HTH! 
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Originally posted by IamBob:
InstallEventHandler() is returning -50; Invalid value passed in a parameter.
HTH!
Thanks! Too bad the error message isn't a little more specific...
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
Got bored and went in search of more info...
http://www.omnigroup.com/mailman/arc...ch/024781.html
Basically, the relevant part is:
_NSGetCarbonMenu only
returns a non-null MenuRef the second time it's called, I assume
because the Carbon menu isn't created until the menu is actually
displayed

|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
I found something on CocoaDev that it works if you add it to the menu bar first. That's what I've been doing, and now it works! W00T!
So, menus now display how I want, although it seems like you can't click on folders and get them to open for some reason, even though the action method and target is set. If you'd like to see the progress, here it is:
http://homepage.mac.com/fahrenba/med.../mediaDock.dmg
Thanks all,
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|