#include #include #include "GraphicToolbox.h" @implementation NSPopUpButtonCell (theme) /* * What would be nice and natural is to make this drawing using the same code * that is used to draw cells in the menu. * This looks like a mess to do in this framework. * * Well, here is an attempt to make this work. */ - (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView { NSMenuItemCell *aCell; // Save last view drawn to if (_control_view != controlView) _control_view = controlView; // Transparent buttons never draw if (_buttoncell_is_transparent) return; // Do nothing if cell's frame rect is zero if (NSIsEmptyRect(cellFrame)) return; // Do nothing if the window is deferred if ([[controlView window] gState] == 0) return; /* * Get the NSMenuItemCell of the selected item, or create a temporary * NSMenuItemCell to at least draw our control if items array is empty. */ if ([_menu numberOfItems] > 0) { aCell = [[_menu menuRepresentation] menuItemCellForItemAtIndex: [self indexOfSelectedItem]]; } else { NSMenuItem *anItem = [NSMenuItem new]; //[anItem setImage: _pbc_image[_pbcFlags.pullsDown]]; aCell = [NSMenuItemCell new]; /* We need this menu item because NSMenuItemCell gets its contents * from the menuItem not from what is set in the cell */ [aCell setMenuItem: anItem]; /* We need to set the menu view so we trigger the special case * popupbutton code in NSMenuItemCell */ [aCell setMenuView: [_menu menuRepresentation]]; /* We need to calc our size to get images placed correctly */ [aCell calcSize]; RELEASE(anItem); } /* Turn off highlighting so the NSPopUpButton looks right */ [aCell setHighlighted: NO]; [aCell drawWithFrame: cellFrame inView: controlView]; //[aCell buttondrawInteriorWithFrame: cellFrame inView: controlView]; //[aCell idrawWithFrame: cellFrame inView: controlView]; /* Draw our own interior so we pick up our dotted frame */ //[self drawInteriorWithFrame: cellFrame inView: controlView]; /* Rehighlight item for consistency */ [aCell setHighlighted: YES]; /* Release the cell to restore balance if menu items array is empty*/ if ([_menu numberOfItems] == 0) { RELEASE (aCell); } } /* FIXME: This needs to be removed in favor of allowing the cell to draw * our NSDottedRect. */ - (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)view { // Transparent buttons never draw if (_buttoncell_is_transparent) return; //cellFrame = [self drawingRectForBounds: cellFrame]; if (_cell.shows_first_responder && [[view window] firstResponder] == view) NSDottedFrameRect(cellFrame); } @end