NSPopUpButton is too smart for it's own good
NSPopUpButton is too smart for it's own good
- Subject: NSPopUpButton is too smart for it's own good
- From: Steve Bennett <email@hidden>
- Date: Thu, 07 Feb 2002 12:37:17 -0500
Hi!
The topic of discussion today is NSPopUpButton. We're trying to move over
some behavior of an older Carbon app to Cocoa, and make it work fairly close
to the old app. All very nice until we got to our Popup control, and
discovered that NSPopUpButton does a lot of work for you. Unfortunately,
it's work we *don't* want, and can't figure out how to turn off. I turn
here to see if anyone has good answers for these issues. I'm going to cover
each problem area seperately. There are good reasons for doing each thing
described, but if I go into them this message will get *really* long, so
just take each item as a given.
1) We prefer to use the Popup style, not the Drop down style. This isn't
really a problem, although using the Drop down style might fix one of our
issues. We use Popup style because there's always a single item
selected/checked, and would like the menu to start on that item.
2) Items with the same name. The menu is constructed dynamically, and quite
frequently there are items in the menu with the same exact name. These come
from user defined values, which could match each other, or one of the other
items in the menu. Selecting among these items has somewhat different
behavior depending on where they appear in the menu. (They end up with
different target/action settings...)
Unfortunately, the NSPopUpButton control assumes that if you add an item
into the menu with the same name as another item in the menu, you're
actually replacing that item. We've hacked around this for now by adding
stuff to the end of duplicate names, but that causes it's own issues.
3) Setting the title. Depending on the item selected, the title that needs
to be displayed may or may not match the text of the menu item. (Some items
bring up a sheet to get more info, and the title reflects the additional
info...) We use the setTitle method to change the title. This has a bunch
of side effects:
- When we select an item, it overwrites our title. We tried overriding the
synchronizeTitleAndSelectedItem method to make it do nothing, but it wasn't
very effective.
- When we call setTitle, it selects the item with that name in the menu,
which may not be what we want. (With our hack for #2, we have to be very
careful to set the title with the same additional stuff at the end, or it
will select the wrong item...)
- When we call setTitle and the name *isn't* in the menu, it sometimes adds
a temporary menu item to the end of the menu with that name and selects it.
Unfortunately, setTitle isn't documented yet, so it's not clear what it's
actually supposed to do. We *might* be able to fix some of this behavior
with a drop-down list, but I'm not certain.
Anyone have suggestions on how to get this control to stop doing what it
thinks I want, and does only what I tell it to?
-->Steve Bennett
_______________________________________________
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.