Re: Menu-less popup buttons
Re: Menu-less popup buttons
- Subject: Re: Menu-less popup buttons
- From: Gwynne <email@hidden>
- Date: Sat, 22 May 2004 02:50:53 -0400
On May 20, 2004, at 7:22 PM, Shaun Wexler wrote:
In Carbon, one can create a popup button without the selected item
visible by creating the control in IB and shrinking it down to just
the width of the disclosure arrow (24 pixels). This does not work
with Cocoa's NSPopUpButton; the attempt causes the selected item area
to intrude on the disclosure arrow area. My question: Can you either
1) get the Cocoa button to draw the way the Carbon one does, 2) Embed
the Carbon version into a Cocoa window (my attempts at this have
failed miserably), or 3) Create a control that's just the arrow
instead of the entire popup menu?
Subclass NSPopUpButton. In -drawRect, save the graphics context, then
set your clipping region. Draw the button (with no text) using:
[[self cell] drawBorderAndBackgroundWithFrame:[self bounds]
inView:self];
Finally, restore your graphics context, then draw the text.
This didn't work; it continued to draw the button overlapped with the
menu item area. NSButtonCell's -setUsesItemFromMenu failed as well. I
finally found a Carbon Appearance API to draw the proper button:
DrawThemeButton(), with various options. Only one problem: I can't seem
to get a proper conversion from a view-local CoreGraphics-based NSRect
to the QuickDraw screen coordinates the Appearance APIs require. I've
tried various combinations of manual mathematics, NSWindow's
convertBaseToScreen, NSView's convertRect:toView:, etc. etc., and
nothing comes up quite right without hard-coding coordinates. I've even
overriden isFlipped to return YES, without any effect that I can see.
How do I convert an NSRect specifying bottom-up coordinates in
view-local coordinates to a (QuickDraw) Rect specifying top-down screen
coordinates? Or, how do I find a Cocoa/CoreGraphics equivalent to the
Appearance APIs?
-- Gwynne, key to the Code that runs us all
Formerly known as Sailor Quasar.
Email: email@hidden
Web:
http://musicimage.plasticchicken.com/
_______________________________________________
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.