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 1999-12-03 21:38:43 +00:00
parent c7282de1b4
commit 02d80a510c
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> Fri Dec 3 14:53:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSOpenPanel.m: ([-browser:selectCellWithString:inColumn:]) * Source/NSOpenPanel.m: ([-browser:selectCellWithString:inColumn:])

View file

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

View file

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

View file

@ -481,9 +481,7 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
accumulatedOffset += neededKeyEquivalentWidth + menuv_horizontalEdgePad; accumulatedOffset += neededKeyEquivalentWidth + menuv_horizontalEdgePad;
// Calculate frame size. // Calculate frame size.
#if 0 if (![menuv_menu _ownedByPopUp])
if (![menuv_menu _isBeholdenToPopUpButton])
#endif
cellSize.width = accumulatedOffset + 3; // Add the border width cellSize.width = accumulatedOffset + 3; // Add the border width
[self setFrameSize: NSMakeSize(cellSize.width + 1, howHigh)]; [self setFrameSize: NSMakeSize(cellSize.width + 1, howHigh)];
@ -491,16 +489,6 @@ static float GSMenuBarHeight = 25.0; // A wild guess.
menuv_needsSizing = NO; 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 - (float)stateImageOffset
{ {
if (menuv_needsSizing) if (menuv_needsSizing)

View file

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

View file

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