mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 12:00:52 +00:00
Fixed bug #12680 and further clean up of NSPopupButtonCell.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@21122 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
afe71bc4c7
commit
7084ee0b3b
3 changed files with 43 additions and 61 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2005-04-17 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSPopupButton.m (-keyDown:) Removed unneeded code.
|
||||
(-_handleNotification:): Moved method from here ...
|
||||
* Source/NSPopupButtonCell.m: ... to here.
|
||||
(-dismissPopUp, -attachPopUpWithFrame:inView:): Dis-/Connect self,
|
||||
not the control view, with notification centre. Fixes bug #12680.
|
||||
(-synchronizeTitleAndSelectedItem): Update the control view.
|
||||
(-trackMouse:inRect:ofView:untilMouseUp:): Removed unneeded code.
|
||||
(-attachPopUpWithFrame:inView:): Set the selected item to highlighted.
|
||||
|
||||
2005-04-17 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSColor.m: Implemented the missing keyed encoding methods.
|
||||
|
|
|
@ -335,22 +335,10 @@ this to return nil to indicate that we have no context menu.
|
|||
untilMouseUp: YES];
|
||||
}
|
||||
|
||||
/* Private method which covers an obscure case where the user uses the
|
||||
keyboard to open a popup, but subsequently uses the mouse to select
|
||||
an item. We'll never know this was done (and thus cannot dismiss
|
||||
the popUp) without getting this notification */
|
||||
- (void) _handleNotification: (NSNotification*)aNotification
|
||||
{
|
||||
NSString *name = [aNotification name];
|
||||
if ([name isEqual: NSMenuDidSendActionNotification] == YES)
|
||||
{
|
||||
[_cell dismissPopUp];
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) keyDown: (NSEvent*)theEvent
|
||||
{
|
||||
// FIXME: This method also handles the key events for the popup menu window,
|
||||
// as menu windows cannot become key window.
|
||||
if ([self isEnabled])
|
||||
{
|
||||
NSString *characters = [theEvent characters];
|
||||
|
@ -381,26 +369,17 @@ this to return nil to indicate that we have no context menu.
|
|||
menuView = [[_cell menu] menuRepresentation];
|
||||
if ([[menuView window] isVisible] == NO)
|
||||
{
|
||||
|
||||
// Attach the popUp
|
||||
[_cell attachPopUpWithFrame: _bounds
|
||||
inView: self];
|
||||
|
||||
|
||||
selectedIndex = [self indexOfSelectedItem];
|
||||
if (selectedIndex > -1)
|
||||
[menuView setHighlightedItemIndex: selectedIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedIndex = [menuView highlightedItemIndex];
|
||||
[[_cell menu] performActionForItemAtIndex: selectedIndex];
|
||||
|
||||
// Dismiss the popUp
|
||||
[_cell dismissPopUp];
|
||||
|
||||
// Update our selected item
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
if (selectedIndex > 0)
|
||||
{
|
||||
[[_cell menu] performActionForItemAtIndex: selectedIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -542,6 +542,10 @@ static NSImage *_pbc_image[2];
|
|||
{
|
||||
[self setMenuItem: nil];
|
||||
}
|
||||
|
||||
if (_control_view)
|
||||
if ([_control_view isKindOfClass: [NSControl class]])
|
||||
[(NSControl *)_control_view updateCell: self];
|
||||
}
|
||||
|
||||
// Title conveniences
|
||||
|
@ -598,6 +602,11 @@ static NSImage *_pbc_image[2];
|
|||
else
|
||||
selectedItem = [self indexOfSelectedItem];
|
||||
|
||||
if (selectedItem > 0)
|
||||
{
|
||||
[mr setHighlightedItemIndex: selectedItem];
|
||||
}
|
||||
|
||||
// Ask the MenuView to attach the menu to this rect
|
||||
[mr setWindowFrameForAttachingToRect: cellFrame
|
||||
onScreen: [cvWin screen]
|
||||
|
@ -607,11 +616,7 @@ static NSImage *_pbc_image[2];
|
|||
// Last, display the window
|
||||
[[mr window] orderFrontRegardless];
|
||||
|
||||
/* This covers an obscure case where the user subsequently
|
||||
uses the mouse to select an item. We'll never know
|
||||
this was done (and thus cannot dismiss the popUp) without
|
||||
getting this notification */
|
||||
[nc addObserver: controlView
|
||||
[nc addObserver: self
|
||||
selector: @selector(_handleNotification:)
|
||||
name: NSMenuDidSendActionNotification
|
||||
object: _menu];
|
||||
|
@ -621,12 +626,27 @@ static NSImage *_pbc_image[2];
|
|||
{
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[nc removeObserver: [self controlView]
|
||||
[nc removeObserver: self
|
||||
name: NSMenuDidSendActionNotification
|
||||
object: _menu];
|
||||
[_menu close];
|
||||
}
|
||||
|
||||
/* Private method handles all cases after doing a selection from
|
||||
the popup menu. Especially the obscure case where the user uses the
|
||||
keyboard to open a popup, but subsequently uses the mouse to select
|
||||
an item. We'll never know this was done (and thus cannot dismiss
|
||||
the popUp) without getting this notification */
|
||||
- (void) _handleNotification: (NSNotification*)aNotification
|
||||
{
|
||||
NSString *name = [aNotification name];
|
||||
if ([name isEqual: NSMenuDidSendActionNotification] == YES)
|
||||
{
|
||||
[self dismissPopUp];
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) trackMouse: (NSEvent *)theEvent
|
||||
inRect: (NSRect)cellFrame
|
||||
ofView: (NSView *)controlView
|
||||
|
@ -636,8 +656,6 @@ static NSImage *_pbc_image[2];
|
|||
NSWindow *menuWindow = [mr window];
|
||||
NSEvent *e;
|
||||
NSPoint p;
|
||||
int lastSelectedItem = [self indexOfSelectedItem];
|
||||
int highlightedItemIndex;
|
||||
|
||||
if ([self isEnabled] == NO)
|
||||
return NO;
|
||||
|
@ -668,32 +686,6 @@ static NSImage *_pbc_image[2];
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue