Fixes for NSPopUp.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5380 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Michael Silva 1999-12-03 21:38:43 +00:00
parent 7afa138f94
commit 6b0668e035
6 changed files with 54 additions and 48 deletions

View file

@ -1,3 +1,9 @@
Fri Dec 3 14:41:00 1999 Michael Hanni <mhanni@sprintmail.com>
* Source/NSPopUpButtonCell.m: more fixes, issues remain.
* Source/NSPopUpButton.m: additions to deal with above.
* Source/NSMenuView.m: ditto.
Fri Dec 3 14:53:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSOpenPanel.m: ([-browser:selectCellWithString:inColumn:])

View file

@ -13,6 +13,7 @@ typedef enum {
{
NSMenu *_menu;
NSMenuItem *_selectedItem;
int _selectedIndex;
struct __pbcFlags {
unsigned int pullsDown:1;
unsigned int preferredEdge:3;

View file

@ -94,6 +94,11 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
- (void)_setOwnedByPopUp: (BOOL)flag
{
menu_is_beholdenToPopUpButton = flag;
if (flag == YES)
{
[titleView removeFromSuperviewWithoutNeedingDisplay];
}
}
- (void) dealloc
@ -222,16 +227,7 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
keyEquivalent: (NSString *)charCode
atIndex: (unsigned int)index
{
id anItem;
// FIXME
// if (menu_is_beholdenToPopUpButton)
// {
// anItem = [NSPopUpButtonCell new];
// [anItem setTarget: menu_popb];
// }
// else
anItem = [NSMenuItem new];
id anItem = [NSMenuItem new];
[anItem setTitle: aString];
[anItem setAction: aSelector];
@ -986,6 +982,13 @@ static NSString* NSMenuLocationsKey = @"NSMenuLocations";
if (menu_changed)
[self sizeToFit];
if (menu_is_beholdenToPopUpButton)
{
menu_is_visible = YES;
[aWindow orderFront: nil];
return;
}
if (menu_supermenu && ![self isTornOff]) // query super menu for
{ // position
[aWindow setFrameOrigin: [menu_supermenu locationForSubmenu: self]];

View file

@ -481,9 +481,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
accumulatedOffset += neededKeyEquivalentWidth + menuv_horizontalEdgePad;
// Calculate frame size.
#if 0
if (![menuv_menu _isBeholdenToPopUpButton])
#endif
if (![menuv_menu _ownedByPopUp])
cellSize.width = accumulatedOffset + 3; // Add the border width
[self setFrameSize: NSMakeSize(cellSize.width + 1, howHigh)];
@ -491,16 +489,6 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
menuv_needsSizing = NO;
}
- (void) sizeToFitForPopUpButton
{
int howHigh = ([menuv_items_link count] * cellSize.height);
if ([window contentView] == self)
[window setContentSize: NSMakeSize(cellSize.width,howHigh)];
else
[self setFrame: NSMakeRect(0,0,cellSize.width,howHigh)];
}
- (float)stateImageOffset
{
if (menuv_needsSizing)

View file

@ -186,15 +186,11 @@ id _nspopupbuttonCellClass = nil;
- (void) selectItemAtIndex: (int)index
{
[cell selectItemAtIndex: index];
[self synchronizeTitleAndSelectedItem];
}
- (void) selectItemWithTitle: (NSString *)title
{
[cell selectItemWithTitle: title];
[self synchronizeTitleAndSelectedItem];
}
- (int) numberOfItems
@ -278,6 +274,10 @@ id _nspopupbuttonCellClass = nil;
[cell synchronizeTitleAndSelectedItem];
[self sizeToFit];
NSLog(@"synchronizeTitleAndSelectedItem");
[self setNeedsDisplay: YES];
}
- (void) sizeToFit

View file

@ -74,6 +74,8 @@
_menu = [[NSMenu alloc] initWithTitle: @""];
[_menu _setOwnedByPopUp: YES];
_selectedIndex = 0;
return self;
}
@ -269,25 +271,30 @@
// Dealing with selection
- (void) selectItem: (id <NSMenuItem>)item
{
id selectedItem = [_menu itemAtIndex: _selectedIndex];
if (!item)
{
if (_pbcFlags.altersStateOfSelectedItem)
[_selectedItem setState: NSOffState];
[selectedItem setState: NSOffState];
_selectedItem = nil;
_selectedIndex = -1;
}
else
{
if (_pbcFlags.altersStateOfSelectedItem)
{
[_selectedItem setState: NSOffState];
[selectedItem setState: NSOffState];
}
_selectedItem = item;
_selectedIndex = [self indexOfItem: item];
selectedItem = [_menu itemAtIndex: _selectedIndex];
if (_pbcFlags.altersStateOfSelectedItem)
{
[_selectedItem setState: NSOnState];
[selectedItem setState: NSOnState];
}
}
[self synchronizeTitleAndSelectedItem];
}
- (void) selectItemAtIndex: (int)index
@ -333,12 +340,12 @@
- (id <NSMenuItem>) selectedItem
{
return _selectedItem;
return [self itemAtIndex: _selectedIndex];
}
- (int) indexOfSelectedItem
{
return [_menu indexOfItem: _selectedItem];
return _selectedIndex;
}
- (void) synchronizeTitleAndSelectedItem
@ -348,12 +355,14 @@
if ([_menu numberOfItems] == 0)
{
_selectedItem = nil;
_selectedIndex = -1;
}
else if (_pbcFlags.pullsDown)
{
[self selectItem: [self itemAtIndex: 0]];
_selectedIndex = 0;
// [self selectItem: [self itemAtIndex: 0]];
}
/*
else
{
int index = [[_menu menuRepresentation] highlightedItemIndex];
@ -362,6 +371,7 @@
index = 0;
[self selectItemAtIndex: index];
}
*/
}
// Title conveniences
@ -387,8 +397,8 @@
- (NSString *) titleOfSelectedItem
{
if (_selectedItem != nil)
return [_selectedItem title];
if (_selectedIndex >= 0)
return [[self itemAtIndex: _selectedIndex] title];
else
return @"";
}
@ -401,6 +411,8 @@
NSRect scratchRect = cellFrame;
NSRect winf;
NSLog(@"cF %@", NSStringFromRect(cellFrame));
_aNotif = [NSNotification
notificationWithName: NSPopUpButtonCellWillPopUpNotification
object: controlView
@ -415,6 +427,7 @@
[_aCenter postNotification: _aNotif];
scratchRect = [[controlView superview] convertRect: scratchRect toView: nil];
scratchRect.origin
= [[controlView window] convertBaseToScreen: cellFrame.origin];
@ -431,15 +444,6 @@
winf.origin = scratchRect.origin;
winf.origin.y += scratchRect.size.height - winf.size.height;
/*
* Small hack to fix line up.
*/
winf.origin.x += 1;
winf.origin.y -= 1;
//NSLog(@"butf %@", NSStringFromRect(butf));
if (!_pbcFlags.pullsDown)
{
winf.origin.y += ([self indexOfSelectedItem] * scratchRect.size.height);
@ -450,7 +454,7 @@ NSLog(@"winf %@", NSStringFromRect(winf));
NSLog(@"here comes the popup.");
[[_menu window] setFrame: winf display: YES];
[[_menu window] orderFrontRegardless];
[[_menu window] orderFront: nil];
}
- (void) dismissPopUp
@ -505,6 +509,8 @@ NSLog(@"winf %@", NSStringFromRect(winf));
[super drawWithFrame: cellFrame inView: view];
[self _drawText: [self titleOfSelectedItem] inFrame: cellFrame];
if (_pbcFlags.pullsDown)
{
aImage = [NSImage imageNamed: @"common_3DArrowDown"];
@ -517,10 +523,12 @@ NSLog(@"winf %@", NSStringFromRect(winf));
size = [aImage size];
position.x = cellFrame.origin.x + cellFrame.size.width - size.width - 4;
position.y = MAX(NSMidY(cellFrame) - (size.height/2.), 0.);
/*
* Images are always drawn with their bottom-left corner at the origin
* so we must adjust the position to take account of a flipped view.
*/
if ([control_view isFlipped])
position.y += size.height;
[aImage compositeToPoint: position operation: NSCompositeCopy];