mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +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
3b077dae8a
commit
4a7cd92c2d
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>
|
||||
|
||||
* Source/NSSliderCell.m (-closestTickMarkValueToValue:,
|
||||
|
|
|
@ -926,6 +926,13 @@ static NSMapTable *viewInfo = 0;
|
|||
[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)
|
||||
{
|
||||
GSCellRect aRect;
|
||||
|
@ -1136,78 +1143,89 @@ static NSMapTable *viewInfo = 0;
|
|||
if (resizeScreenRect)
|
||||
{
|
||||
cellFrame = [self convertRect: cellFrame toView: nil];
|
||||
screenRect.size = cellFrame.size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the frame
|
||||
*/
|
||||
screenFrame = screenRect;
|
||||
screenFrame.origin = screenRect.origin;
|
||||
screenFrame.size = cellFrame.size;
|
||||
if (items > 0)
|
||||
{
|
||||
float f;
|
||||
|
||||
if (_horizontal == NO)
|
||||
{
|
||||
f = screenRect.size.height * (items - 1);
|
||||
f = cellFrame.size.height * (items - 1);
|
||||
screenFrame.size.height += f + _leftBorderOffset;
|
||||
screenFrame.origin.y -= f;
|
||||
screenFrame.size.width += _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
|
||||
if (selectedItemIndex != -1)
|
||||
{
|
||||
screenFrame.origin.y
|
||||
+= screenRect.size.height * selectedItemIndex;
|
||||
+= cellFrame.size.height * selectedItemIndex;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
f = screenRect.size.width * (items - 1);
|
||||
f = cellFrame.size.width * (items - 1);
|
||||
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
|
||||
if (selectedItemIndex != -1)
|
||||
{
|
||||
screenFrame.origin.x -= screenRect.size.width * selectedItemIndex;
|
||||
screenFrame.origin.x -= cellFrame.size.width * selectedItemIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update position, if needed, using the preferredEdge
|
||||
if ([_attachedMenu _ownedByPopUp])
|
||||
if (selectedItemIndex == -1)
|
||||
{
|
||||
// Per Cocoa documentation, the selected cell should always show up
|
||||
// over the button for popups. For pull down menus, the preferred
|
||||
// edge is relevant. This is also apparent from testing under Cocoa.
|
||||
if ([[_attachedMenu _owningPopUp] pullsDown])
|
||||
// FIXME if screen space is tight at the preferred edge attach
|
||||
// the menu at the opposite edge
|
||||
screenFrame.origin.y -= cellFrame.size.height;
|
||||
switch (edge)
|
||||
{
|
||||
// Handle the Y edge...
|
||||
/*
|
||||
if ([[[_attachedMenu _owningPopUp] controlView] isFlipped])
|
||||
{
|
||||
if (edge == NSMaxYEdge)
|
||||
{
|
||||
screenFrame.origin.y += screenRect.size.height;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (edge == NSMinYEdge)
|
||||
{
|
||||
screenFrame.origin.y += screenRect.size.height;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Handle the X edge...
|
||||
if (edge == NSMaxXEdge)
|
||||
{
|
||||
screenFrame.origin.x += screenRect.size.width;
|
||||
}
|
||||
else if (edge == NSMinXEdge)
|
||||
{
|
||||
screenFrame.origin.x -= screenRect.size.width;
|
||||
}
|
||||
default:
|
||||
case NSMinYEdge:
|
||||
break;
|
||||
case NSMaxYEdge:
|
||||
screenFrame.origin.y +=
|
||||
screenFrame.size.height + screenRect.size.height - _leftBorderOffset;
|
||||
break;
|
||||
case NSMinXEdge:
|
||||
screenFrame.origin.y += screenRect.size.height;
|
||||
screenFrame.origin.x -= screenFrame.size.width;
|
||||
break;
|
||||
case NSMaxXEdge:
|
||||
screenFrame.origin.y += screenRect.size.height;
|
||||
screenFrame.origin.x += screenRect.size.width + _leftBorderOffset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -646,8 +646,11 @@ static NSImage *_pbc_image[5];
|
|||
[[_menu menuRepresentation] setHighlightedItemIndex:
|
||||
[_menu indexOfItem: _selectedItem]];
|
||||
|
||||
[[_menu menuRepresentation] setNeedsDisplayForItemAtIndex:
|
||||
[_menu indexOfItem: oldSelectedItem]];
|
||||
if (oldSelectedItem)
|
||||
{
|
||||
[[_menu menuRepresentation] setNeedsDisplayForItemAtIndex:
|
||||
[_menu indexOfItem: oldSelectedItem]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) selectItemAtIndex: (int)index
|
||||
|
@ -669,6 +672,32 @@ static NSImage *_pbc_image[5];
|
|||
[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
|
||||
{
|
||||
id <NSMenuItem> anItem;
|
||||
|
@ -688,6 +717,7 @@ static NSImage *_pbc_image[5];
|
|||
else
|
||||
{
|
||||
anItem = [_menu itemAtIndex: 0];
|
||||
[anItem setTitle: aString];
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -830,8 +860,14 @@ static NSImage *_pbc_image[5];
|
|||
|
||||
if (_pbcFlags.pullsDown)
|
||||
selectedItem = -1;
|
||||
else
|
||||
selectedItem = [self indexOfSelectedItem];
|
||||
else
|
||||
{
|
||||
selectedItem = [self indexOfSelectedItem];
|
||||
if (selectedItem == -1)
|
||||
{
|
||||
selectedItem = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedItem > 0)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue