mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:10:47 +00:00
Fix display of pull down menus to not show their first item, which
holds the title, and fix the attachment of pull down menus to their button. In addition, fix -setTitle: to actually set the title of a pull down menu. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30807 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
667ad46abe
commit
bc7dabba43
3 changed files with 112 additions and 42 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
||||||
|
2010-06-22 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||||
|
|
||||||
|
* Source/NSMenuView.m (-rectOfItemAtIndex:,
|
||||||
|
-setWindowFrameForAttachingToRect:onScreen:preferredEdge:...):
|
||||||
|
* Source/NSPopUpButtonCell.m (-attachPopUpWithFrame:inView:):
|
||||||
|
Don't display the first item of a pull down menu, which holds its
|
||||||
|
title, and fix the attachment of pull down menus to their button.
|
||||||
|
|
||||||
|
* Source/NSPopUpButtonCell.m (-title:): Implement to return the
|
||||||
|
title of the menu.
|
||||||
|
* Source/NSPopUpButtonCell.m (-setTitle): Fix implementation to
|
||||||
|
actually change the title of a pull down menu.
|
||||||
|
|
||||||
|
* Source/NSPopUpButtonCell.m (-selectItem:): Prevent exception
|
||||||
|
when a horizontal menu does not have a selected item.
|
||||||
|
|
||||||
2010-06-21 Wolfgang Lux <wolfgang.lux@gmail.com>
|
2010-06-21 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||||
|
|
||||||
* Source/NSSliderCell.m (-closestTickMarkValueToValue:,
|
* Source/NSSliderCell.m (-closestTickMarkValueToValue:,
|
||||||
|
|
|
@ -926,6 +926,13 @@ static NSMapTable *viewInfo = 0;
|
||||||
[self sizeToFit];
|
[self sizeToFit];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The first item of a pull down menu holds its title and isn't displayed
|
||||||
|
if (index == 0 && [_attachedMenu _ownedByPopUp] &&
|
||||||
|
[[_attachedMenu _owningPopUp] pullsDown])
|
||||||
|
{
|
||||||
|
return NSZeroRect;
|
||||||
|
}
|
||||||
|
|
||||||
if (_horizontal == YES)
|
if (_horizontal == YES)
|
||||||
{
|
{
|
||||||
GSCellRect aRect;
|
GSCellRect aRect;
|
||||||
|
@ -1136,78 +1143,89 @@ static NSMapTable *viewInfo = 0;
|
||||||
if (resizeScreenRect)
|
if (resizeScreenRect)
|
||||||
{
|
{
|
||||||
cellFrame = [self convertRect: cellFrame toView: nil];
|
cellFrame = [self convertRect: cellFrame toView: nil];
|
||||||
screenRect.size = cellFrame.size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute the frame
|
* Compute the frame
|
||||||
*/
|
*/
|
||||||
screenFrame = screenRect;
|
screenFrame.origin = screenRect.origin;
|
||||||
|
screenFrame.size = cellFrame.size;
|
||||||
if (items > 0)
|
if (items > 0)
|
||||||
{
|
{
|
||||||
float f;
|
float f;
|
||||||
|
|
||||||
if (_horizontal == NO)
|
if (_horizontal == NO)
|
||||||
{
|
{
|
||||||
f = screenRect.size.height * (items - 1);
|
f = cellFrame.size.height * (items - 1);
|
||||||
screenFrame.size.height += f + _leftBorderOffset;
|
screenFrame.size.height += f + _leftBorderOffset;
|
||||||
screenFrame.origin.y -= f;
|
screenFrame.origin.y -= f;
|
||||||
screenFrame.size.width += _leftBorderOffset;
|
screenFrame.size.width += _leftBorderOffset;
|
||||||
screenFrame.origin.x -= _leftBorderOffset;
|
screenFrame.origin.x -= _leftBorderOffset;
|
||||||
|
|
||||||
|
// If the menu is a pull down menu the first item, which would
|
||||||
|
// appear at the top of the menu, holds the title and is omitted
|
||||||
|
if ([_attachedMenu _ownedByPopUp])
|
||||||
|
{
|
||||||
|
if ([[_attachedMenu _owningPopUp] pullsDown])
|
||||||
|
{
|
||||||
|
screenFrame.size.height -= cellFrame.size.height;
|
||||||
|
screenFrame.origin.y += cellFrame.size.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Compute position for popups, if needed
|
// Compute position for popups, if needed
|
||||||
if (selectedItemIndex != -1)
|
if (selectedItemIndex != -1)
|
||||||
{
|
{
|
||||||
screenFrame.origin.y
|
screenFrame.origin.y
|
||||||
+= screenRect.size.height * selectedItemIndex;
|
+= cellFrame.size.height * selectedItemIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f = screenRect.size.width * (items - 1);
|
f = cellFrame.size.width * (items - 1);
|
||||||
screenFrame.size.width += f;
|
screenFrame.size.width += f;
|
||||||
|
|
||||||
|
// If the menu is a pull down menu the first item holds the
|
||||||
|
// title and is omitted
|
||||||
|
if ([_attachedMenu _ownedByPopUp])
|
||||||
|
{
|
||||||
|
if ([[_attachedMenu _owningPopUp] pullsDown])
|
||||||
|
{
|
||||||
|
screenFrame.size.width -= cellFrame.size.width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Compute position for popups, if needed
|
// Compute position for popups, if needed
|
||||||
if (selectedItemIndex != -1)
|
if (selectedItemIndex != -1)
|
||||||
{
|
{
|
||||||
screenFrame.origin.x -= screenRect.size.width * selectedItemIndex;
|
screenFrame.origin.x -= cellFrame.size.width * selectedItemIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update position, if needed, using the preferredEdge
|
// Update position, if needed, using the preferredEdge
|
||||||
if ([_attachedMenu _ownedByPopUp])
|
if (selectedItemIndex == -1)
|
||||||
{
|
{
|
||||||
// Per Cocoa documentation, the selected cell should always show up
|
// FIXME if screen space is tight at the preferred edge attach
|
||||||
// over the button for popups. For pull down menus, the preferred
|
// the menu at the opposite edge
|
||||||
// edge is relevant. This is also apparent from testing under Cocoa.
|
screenFrame.origin.y -= cellFrame.size.height;
|
||||||
if ([[_attachedMenu _owningPopUp] pullsDown])
|
switch (edge)
|
||||||
{
|
{
|
||||||
// Handle the Y edge...
|
default:
|
||||||
/*
|
case NSMinYEdge:
|
||||||
if ([[[_attachedMenu _owningPopUp] controlView] isFlipped])
|
break;
|
||||||
{
|
case NSMaxYEdge:
|
||||||
if (edge == NSMaxYEdge)
|
screenFrame.origin.y +=
|
||||||
{
|
screenFrame.size.height + screenRect.size.height - _leftBorderOffset;
|
||||||
screenFrame.origin.y += screenRect.size.height;
|
break;
|
||||||
}
|
case NSMinXEdge:
|
||||||
}
|
screenFrame.origin.y += screenRect.size.height;
|
||||||
else
|
screenFrame.origin.x -= screenFrame.size.width;
|
||||||
{
|
break;
|
||||||
if (edge == NSMinYEdge)
|
case NSMaxXEdge:
|
||||||
{
|
screenFrame.origin.y += screenRect.size.height;
|
||||||
screenFrame.origin.y += screenRect.size.height;
|
screenFrame.origin.x += screenRect.size.width + _leftBorderOffset;
|
||||||
}
|
break;
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Handle the X edge...
|
|
||||||
if (edge == NSMaxXEdge)
|
|
||||||
{
|
|
||||||
screenFrame.origin.x += screenRect.size.width;
|
|
||||||
}
|
|
||||||
else if (edge == NSMinXEdge)
|
|
||||||
{
|
|
||||||
screenFrame.origin.x -= screenRect.size.width;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -646,8 +646,11 @@ static NSImage *_pbc_image[5];
|
||||||
[[_menu menuRepresentation] setHighlightedItemIndex:
|
[[_menu menuRepresentation] setHighlightedItemIndex:
|
||||||
[_menu indexOfItem: _selectedItem]];
|
[_menu indexOfItem: _selectedItem]];
|
||||||
|
|
||||||
[[_menu menuRepresentation] setNeedsDisplayForItemAtIndex:
|
if (oldSelectedItem)
|
||||||
[_menu indexOfItem: oldSelectedItem]];
|
{
|
||||||
|
[[_menu menuRepresentation] setNeedsDisplayForItemAtIndex:
|
||||||
|
[_menu indexOfItem: oldSelectedItem]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) selectItemAtIndex: (int)index
|
- (void) selectItemAtIndex: (int)index
|
||||||
|
@ -669,6 +672,32 @@ static NSImage *_pbc_image[5];
|
||||||
[self selectItem: anItem];
|
[self selectItem: anItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *)title
|
||||||
|
{
|
||||||
|
id <NSMenuItem> selectedItem;
|
||||||
|
|
||||||
|
if (!_pbcFlags.usesItemFromMenu)
|
||||||
|
{
|
||||||
|
selectedItem = _menuItem;
|
||||||
|
}
|
||||||
|
else if (_pbcFlags.pullsDown)
|
||||||
|
{
|
||||||
|
if ([_menu numberOfItems] == 0)
|
||||||
|
{
|
||||||
|
selectedItem = _menuItem;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selectedItem = [_menu itemAtIndex: 0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selectedItem = [self selectedItem];
|
||||||
|
}
|
||||||
|
return [selectedItem title];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) setTitle: (NSString *)aString
|
- (void) setTitle: (NSString *)aString
|
||||||
{
|
{
|
||||||
id <NSMenuItem> anItem;
|
id <NSMenuItem> anItem;
|
||||||
|
@ -688,6 +717,7 @@ static NSImage *_pbc_image[5];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
anItem = [_menu itemAtIndex: 0];
|
anItem = [_menu itemAtIndex: 0];
|
||||||
|
[anItem setTitle: aString];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -830,8 +860,14 @@ static NSImage *_pbc_image[5];
|
||||||
|
|
||||||
if (_pbcFlags.pullsDown)
|
if (_pbcFlags.pullsDown)
|
||||||
selectedItem = -1;
|
selectedItem = -1;
|
||||||
else
|
else
|
||||||
selectedItem = [self indexOfSelectedItem];
|
{
|
||||||
|
selectedItem = [self indexOfSelectedItem];
|
||||||
|
if (selectedItem == -1)
|
||||||
|
{
|
||||||
|
selectedItem = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedItem > 0)
|
if (selectedItem > 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue