Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSPopUpButton's popup menu in pulldown mode displaying fix #43

Merged
merged 1 commit into from Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions ChangeLog
@@ -1,3 +1,18 @@
2019-12-19 Sergii Stoian <stoyan255@gmail.com>

* Source/NSMenuView.m (setHighlightedItemIndex:): do not highlight first
item for pulldown popup button's menu.
(sizeToFit): removed commented useless code; fixed formatting.
(rectOfItemAtIndex:): draw first item cell of pulldown popup menu.
(setWindowFrameForAttachingToRect:onScreen:preferredEdge:popUpSelectedItem:):
remove useless (was used for old-style popup menu) positionning code for
popup menu. Check if owning popup is not pulldown before vertical
position correction.

* Source/NSPopUpButtonCell.m (attachPopUpWithFrame:inView:): make setting
selected item code more generic for pulldown and non-pulldown button.
Fixed formatting.

2019-12-18 Sergii Stoian <stoyan255@gmail.com>

* Source/NSBrowser.m (frameOfColumn:): shift up column only for browser
Expand Down
94 changes: 18 additions & 76 deletions Source/NSMenuView.m
Expand Up @@ -405,7 +405,15 @@ - (void) setHighlightedItemIndex: (NSInteger)index
}

// Set ivar to new index.
_highlightedItemIndex = index;
if ([_attachedMenu _ownedByPopUp] &&
index == 0 && [[_attachedMenu _owningPopUp] pullsDown])
{
_highlightedItemIndex = -1;
}
else
{
_highlightedItemIndex = index;
}

// Highlight new
if (_highlightedItemIndex != -1)
Expand Down Expand Up @@ -764,15 +772,8 @@ - (void) sizeToFit
unsigned i;
unsigned howMany = [_itemCells count];
float currentX = HORIZONTAL_MENU_LEFT_PADDING;
// NSRect scRect = [[NSScreen mainScreen] frame];

GSIArrayRemoveAllItems(cellRects);

/*
scRect.size.height = [NSMenuView menuBarHeight];
[self setFrameSize: scRect.size];
_cellSize.height = scRect.size.height;
*/
_cellSize.height = [NSMenuView menuBarHeight];

if (howMany && isPullDown)
Expand Down Expand Up @@ -967,10 +968,9 @@ - (void) sizeToFit
}

[self setFrameSize: NSMakeSize(_cellSize.width + _leftBorderOffset,
[self totalHeight]
+ menuBarHeight)];
[_titleView setFrame: NSMakeRect (0, [self totalHeight],
NSWidth (_bounds), menuBarHeight)];
[self totalHeight] + menuBarHeight)];
[_titleView setFrame: NSMakeRect(0, [self totalHeight],
NSWidth (_bounds), menuBarHeight)];
}
_needsSizing = NO;
}
Expand Down Expand Up @@ -1048,13 +1048,6 @@ - (NSRect) rectOfItemAtIndex: (NSInteger)index
[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;
Expand Down Expand Up @@ -1212,37 +1205,6 @@ - (void) setWindowFrameForAttachingToRect: (NSRect)screenRect
if (_needsSizing)
[self sizeToFit];

/* FIXME: Perhaps all of this belongs into NSPopupButtonCell and
should be used to determine the proper screenRect to pass on into
this method.
*/
/* certain style of pulldowns don't want sizing on the _cellSize.height */
if ([_attachedMenu _ownedByPopUp])
{
NSPopUpButtonCell *bcell;

bcell = [_attachedMenu _owningPopUp];
if ([bcell pullsDown])
{
if ([bcell isBordered] == NO)
{
growHeight = NO;
}
else
{
switch ([bcell bezelStyle])
{
case NSRegularSquareBezelStyle:
case NSShadowlessSquareBezelStyle:
growHeight = NO;
break;
default:
break;
}
}
}
}

cellFrame = screenRect;

/*
Expand Down Expand Up @@ -1296,46 +1258,26 @@ - (void) setWindowFrameForAttachingToRect: (NSRect)screenRect
popUpFrame.size.width += borderOffsetInBaseCoords;
popUpFrame.origin.x -= borderOffsetInBaseCoords;

// 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])
{
popUpFrame.size.height -= cellFrame.size.height;
popUpFrame.origin.y += cellFrame.size.height;
}
}

// Compute position for popups, if needed
if (selectedItemIndex != -1)
if (selectedItemIndex != -1
&& [[_attachedMenu _owningPopUp] pullsDown] == NO)
{
popUpFrame.origin.y
+= cellFrame.size.height * selectedItemIndex;
popUpFrame.origin.y += cellFrame.size.height * selectedItemIndex;
}
}
else
{
f = cellFrame.size.width * (items - 1);
popUpFrame.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])
{
popUpFrame.size.width -= cellFrame.size.width;
}
}

// Compute position for popups, if needed
if (selectedItemIndex != -1)
if (selectedItemIndex != -1
&& [[_attachedMenu _owningPopUp] pullsDown] == NO)
{
popUpFrame.origin.x -= cellFrame.size.width * selectedItemIndex;
}
}
}
}

// Update position, if needed, using the preferredEdge
if (selectedItemIndex == -1)
Expand Down
21 changes: 12 additions & 9 deletions Source/NSPopUpButtonCell.m
Expand Up @@ -905,7 +905,7 @@ - (void) attachPopUpWithFrame: (NSRect)cellFrame
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSWindow *cvWin = [controlView window];
NSMenuView *mr = [_menu menuRepresentation];
NSInteger selectedItem;
NSInteger selectedItem;

[nc postNotificationName: NSPopUpButtonCellWillPopUpNotification
object: self];
Expand All @@ -918,14 +918,17 @@ - (void) attachPopUpWithFrame: (NSRect)cellFrame
cellFrame.origin = [cvWin convertBaseToScreen: cellFrame.origin];

if (_pbcFlags.pullsDown)
selectedItem = -1;
{
selectedItem = -1;
}
else
{
selectedItem = [self indexOfSelectedItem];
if (selectedItem == -1)
{
selectedItem = 0;
}
}

if (selectedItem == -1)
{
selectedItem = 0;
}

if (selectedItem > 0)
Expand Down Expand Up @@ -953,9 +956,9 @@ - (void) attachPopUpWithFrame: (NSRect)cellFrame
selectedItem: selectedItem];

[nc addObserver: self
selector: @selector(_handleNotification:)
name: NSMenuDidSendActionNotification
object: _menu];
selector: @selector(_handleNotification:)
name: NSMenuDidSendActionNotification
object: _menu];
}

/**
Expand Down