Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multiple choice NSPopupButton ?

569 views
Skip to first unread message

slashlos

unread,
Apr 11, 2008, 8:58:26 PM4/11/08
to
I've decided (hopefully well received) on using a popup button as a
multiple selection control. I use the item's tag values as a bit
position whose mask I keep in index 0; a user selecting this item clears
the entire mask while other item selections toggle that item 'tag' bit.

It's done like this action:

- (void)processPopup:(id)sender
{
unsigned long value;
int i, tag = [[sender selectedItem] tag];

if (![sender indexOfSelectedItem])
{
for (i=1; i<[sender numberOfItems]; i++)
{
[[sender itemAtIndex:i] setState:NSOffState];
}
[[sender itemAtIndex:0] setTag:(value=0)];
tag = 0;
}
else
{
BOOL state = [[sender selectedItem] state];

// tag at index 0 keeps our mask
value = [[sender itemAtIndex:0] tag];
[[sender selectedItem] setState:state];
if (state)
value |= 1<<tag;
else
value ^= 1<<tag;

[[sender itemAtIndex:0] setTag:value];
}

// Tooltip has our name
NSLog(@"%@(%09x) = '%@' %d:%d",
[sender toolTip], value,
[[sender selectedItem] title], tag,
[[sender selectedItem] state]);
}


But the question is how can I get the visual to mimic the model? Do I
need to sub-class the popup button so I can have multiple selections?
--
/los "I was a teenage net-random"

Gregory Weston

unread,
Apr 12, 2008, 7:12:33 AM4/12/08
to
In article <48000931$0$30484$607e...@cv.net>,
slashlos <slas...@optimum.net> wrote:

> I've decided (hopefully well received) on using a popup button as a
> multiple selection control.

It won't be well-received. It breaks the semantics of the control and
won't look or behave the way users are used to popup buttons looking and
behaving. From the HIG:

"Use a pop-up menu to present up to 12 _mutually_exclusive_ choices ...."
...
"Avoid using pop-up menus ... [w]hen more than one simultaneous
selection is appropriate, such as in a list of text styles (from which
users might choose both bold and italic). In this situation, you should
instead use checkboxes or a pull-down menu in which checkmarks appear."


> But the question is how can I get the visual to mimic the model? Do I
> need to sub-class the popup button so I can have multiple selections?

That's a start. You also have to worry about how you're going to display
the appropriate title (considering the standard behavior is to show the
last item selected) to indicate multiple selections and how you're going
to make that title *meaningful* in the inherently-limited horizontal
space you'll have available.

The short form is: If you find yourself having to do this much work to
get a standard control to work in Cocoa, you're probably abusing the
control which means you're probably going to annoy users who are
confused by your UI.

slashlos

unread,
Apr 12, 2008, 10:22:31 AM4/12/08
to
Gregory Weston wrote:

>> But the question is how can I get the visual to mimic the model? Do I
>> need to sub-class the popup button so I can have multiple selections?
>
> That's a start. You also have to worry about how you're going to display
> the appropriate title (considering the standard behavior is to show the
> last item selected) to indicate multiple selections and how you're going
> to make that title *meaningful* in the inherently-limited horizontal
> space you'll have available.

Well, the title for these will either be 'all','none' or 'mixed' or the
attribute name. While I like the modal list display or choices, the
scope of options is leading me towards an IB (ctrl/click) centric
property sheet; they are smaller, can be moved and sized.

These movable windows/sheets also don't appear to require subclassing
aside from the cells they use so I might start to creating a mock-up. I
think it should be straight forward, based on the 'HUD' (heads up
display?) window style; maybe there's a sample someplace ?

slashlos

unread,
Apr 20, 2008, 9:39:26 AM4/20/08
to
Gregory Weston wrote:

> ...
> "Avoid using pop-up menus ... [w]hen more than one simultaneous
> selection is appropriate, such as in a list of text styles (from which
> users might choose both bold and italic). In this situation, you should
> instead use checkboxes or a pull-down menu in which checkmarks appear."

Ok; went the drop down way, and the earlier snippet requires a change:

<
BOOL state = [[sender selectedItem] state];
>

BOOL state = ![[sender selectedItem] state];

All's well!

0 new messages