NSPopUpButtonCell within NSTextFieldCell: disappearing text
Michael Dupuis
smokinmonkey at yahoo.com
Fri Aug 3 19:39:20 PDT 2007
Greetings,
I'm trying to implement a "complex" NSTextFieldCell,
based originally on ImageAndTextCell from the
DraggableOutlineView demo app, and I've got most of
what I need working, but I'm having one problem I
can't seem to resolve: When I have an
NSPopupButtonCell within my NSTextFieldCell, popping
up the menu for the button causes the text field text
to vanish until the menu tracking is done. I could see
the text of the NSTextFieldCell maybe not getting
redrawn potentially, but why it gets blanked out
completely while the menu is displayed, and then comes
back perfectly when the menu is dismissed I can't
understand.
A little code (some details omitted for brevity:
in drawWithFrame: inView:
I draw my image, just like the sample code, then call
super:
[super drawWithFrame:cellFrame inView:controlView];
then draw my popup button:
[popUpButtonCellOne drawWithFrame:
NSMakeRect(POPUP_X_OFFSET, cellFrame.origin.y +
POPUP_Y_OFFSET, 150.0, 24.0) inView:controlView];
popUpButtonCellOne is retained by a static right now
and is created like this:
if (popUpButtonCellOne == nil)
{
popUpButtonCellOne = [[NSPopUpButtonCell alloc]
init];
[popUpButtonCellOne addItemWithTitle:@"One"];
[popUpButtonCellOne addItemWithTitle:@"Two"];
[popUpButtonCellOne addItemWithTitle:@"Three"];
[popUpButtonCellOne setBordered:NO];
}
Ok, so with just this, the popup button never gets a
mouse down when you click on the cell, so to remedy
that, I tried a bunch of things and settled on
implementing trackMouse::::
(I know, I can use something other than NSBezierPath
for this)
NSPoint point =
[controlView convertPoint:[theEvent
locationInWindow] fromView:nil];
NSBezierPath *path = [NSBezierPath bezierPathWithRect:
NSMakeRect(POPUP_X_OFFSET, cellFrame.origin.y +
POPUP_Y_OFFSET, 150.0, 24.0)];
if ([path containsPoint:point])
{
[popUpButtonCellOne trackMouse:theEvent inRect:
NSMakeRect(POPUP_X_OFFSET, cellFrame.origin.y +
POPUP_Y_OFFSET, 150.0, 24.0)
ofView:controlView
untilMouseUp:flag];
}
returning YES when I'm done. This all works, except
for the problem I mentioned. Is there something I'm
overlooking, or misunderstanding? It is possible that
I should be passing the mouse down to the popup in
another method other than trackMouse?
TIA, Michael
____________________________________________________________________________________
Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545469
More information about the MacOSX-dev
mailing list