diff --git a/ChangeLog b/ChangeLog index ad1ae7ba5..186b6e0ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-02-14 Fred Kiefer + + * Source/NSPopupButton.m (-mouseDown:): Moved code from here ... + * Source/NSPopupButtonCell.m + (-trackMouse:inRect:ofView:untilMouseUp:): ... to here. This fixes + bug #9824. + 2005-02-14 Richard Frith-Macdoanld * Source/GSTitleView.m (-mouseDown:): Post an diff --git a/Source/NSPopUpButton.m b/Source/NSPopUpButton.m index fc4662199..b9000a86e 100644 --- a/Source/NSPopUpButton.m +++ b/Source/NSPopUpButton.m @@ -329,67 +329,10 @@ this to return nil to indicate that we have no context menu. - (void) mouseDown: (NSEvent*)theEvent { - NSMenuView *mr = [[_cell menu] menuRepresentation]; - NSWindow *menuWindow = [mr window]; - NSEvent *e; - NSPoint p; - int lastSelectedItem = [_cell indexOfSelectedItem]; - int highlightedItemIndex; - - if ([self isEnabled] == NO) - return; - - if ([[_cell menu] numberOfItems] == 0) - { - NSBeep (); - return; - } - - // Attach the popUp - [_cell attachPopUpWithFrame: _bounds - inView: self]; - - p = [_window convertBaseToScreen: [theEvent locationInWindow]]; - p = [menuWindow convertScreenToBase: p]; - - // Process events; we start menu events processing by converting - // this event to the menu window, and sending it there. - e = [NSEvent mouseEventWithType: [theEvent type] - location: p - modifierFlags: [theEvent modifierFlags] - timestamp: [theEvent timestamp] - windowNumber: [menuWindow windowNumber] - context: [theEvent context] - eventNumber: [theEvent eventNumber] - clickCount: [theEvent clickCount] - pressure: [theEvent pressure]]; - [NSApp sendEvent: e]; - - // Get highlighted item index from _cell because NSMenuView: - // - tells to NSPopUpButtonCell about current selected item index; - // - sets own selected item index to -1; - // - // So, at this point [mr highlightedItemIndex] always = -1 - highlightedItemIndex = [_cell indexOfSelectedItem]; - - // Selection remains unchanged if selected item is disabled - // or mouse left menu (highlightedItemIndex == -1). - if ( highlightedItemIndex < 0 - || highlightedItemIndex == lastSelectedItem - || [[self itemAtIndex: highlightedItemIndex] isEnabled] == NO) - { - [mr setHighlightedItemIndex: lastSelectedItem]; - } - else - { - [mr setHighlightedItemIndex: highlightedItemIndex]; - } - - // Dismiss the popUp - [_cell dismissPopUp]; - - // Update our selected item - [self synchronizeTitleAndSelectedItem]; + [_cell trackMouse: theEvent + inRect: [self bounds] + ofView: self + untilMouseUp: YES]; } /* Private method which covers an obscure case where the user uses the diff --git a/Source/NSPopUpButtonCell.m b/Source/NSPopUpButtonCell.m index 0ea90a556..50303aec2 100644 --- a/Source/NSPopUpButtonCell.m +++ b/Source/NSPopUpButtonCell.m @@ -632,6 +632,68 @@ static NSImage *_pbc_image[2]; ofView: (NSView *)controlView untilMouseUp: (BOOL)untilMouseUp { + NSMenuView *mr = [[self menu] menuRepresentation]; + NSWindow *menuWindow = [mr window]; + NSEvent *e; + NSPoint p; + int lastSelectedItem = [self indexOfSelectedItem]; + int highlightedItemIndex; + + if ([self isEnabled] == NO) + return NO; + + if ([[self menu] numberOfItems] == 0) + { + NSBeep (); + return NO; + } + + // Attach the popUp + [self attachPopUpWithFrame: cellFrame + inView: controlView]; + + p = [[controlView window] convertBaseToScreen: [theEvent locationInWindow]]; + p = [menuWindow convertScreenToBase: p]; + + // Process events; we start menu events processing by converting + // this event to the menu window, and sending it there. + e = [NSEvent mouseEventWithType: [theEvent type] + location: p + modifierFlags: [theEvent modifierFlags] + timestamp: [theEvent timestamp] + windowNumber: [menuWindow windowNumber] + context: [theEvent context] + eventNumber: [theEvent eventNumber] + clickCount: [theEvent clickCount] + pressure: [theEvent pressure]]; + [NSApp sendEvent: e]; + + // Get highlighted item index from cell because NSMenuView: + // - tells to NSPopUpButtonCell about current selected item index; + // - sets own selected item index to -1; + // + // So, at this point [mr highlightedItemIndex] always = -1 + highlightedItemIndex = [self indexOfSelectedItem]; + + // Selection remains unchanged if selected item is disabled + // or mouse left menu (highlightedItemIndex == -1). + if ( highlightedItemIndex < 0 + || highlightedItemIndex == lastSelectedItem + || [[self itemAtIndex: highlightedItemIndex] isEnabled] == NO) + { + [mr setHighlightedItemIndex: lastSelectedItem]; + } + else + { + [mr setHighlightedItemIndex: highlightedItemIndex]; + } + + // Dismiss the popUp + [self dismissPopUp]; + + // Update our selected item + [self synchronizeTitleAndSelectedItem]; + return NO; }