mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 13:10:59 +00:00
Popup fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5381 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6b0668e035
commit
7f6cc95d63
3 changed files with 74 additions and 82 deletions
|
@ -1,3 +1,8 @@
|
|||
Fri Dec 3 14:53:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSPopUpButtonCell.m: arbitrary hacks to get window positioning
|
||||
correct - NSWindow still needs some fixing.
|
||||
|
||||
Fri Dec 3 14:41:00 1999 Michael Hanni <mhanni@sprintmail.com>
|
||||
|
||||
* Source/NSPopUpButtonCell.m: more fixes, issues remain.
|
||||
|
|
|
@ -13,91 +13,90 @@ typedef enum {
|
|||
{
|
||||
NSMenu *_menu;
|
||||
NSMenuItem *_selectedItem;
|
||||
int _selectedIndex;
|
||||
struct __pbcFlags {
|
||||
unsigned int pullsDown:1;
|
||||
unsigned int preferredEdge:3;
|
||||
unsigned int menuIsAttached:1;
|
||||
unsigned int usesItemFromMenu:1;
|
||||
unsigned int altersStateOfSelectedItem:1;
|
||||
unsigned int decoding:1;
|
||||
unsigned int arrowPosition:2;
|
||||
unsigned int pullsDown: 1;
|
||||
unsigned int preferredEdge: 3;
|
||||
unsigned int menuIsAttached: 1;
|
||||
unsigned int usesItemFromMenu: 1;
|
||||
unsigned int altersStateOfSelectedItem: 1;
|
||||
unsigned int decoding: 1;
|
||||
unsigned int arrowPosition: 2;
|
||||
} _pbcFlags;
|
||||
}
|
||||
|
||||
- (id)initTextCell:(NSString *)stringValue pullsDown:(BOOL)pullDown;
|
||||
- (id) initTextCell: (NSString*)stringValue pullsDown: (BOOL)pullDown;
|
||||
|
||||
// Overrides behavior of NSCell. This is the menu for the popup, not a
|
||||
// context menu. PopUpButtonCells do not have context menus.
|
||||
- (void)setMenu:(NSMenu *)menu;
|
||||
- (NSMenu *)menu;
|
||||
- (void) setMenu: (NSMenu*)menu;
|
||||
- (NSMenu*) menu;
|
||||
|
||||
// Behavior settings
|
||||
- (void)setPullsDown:(BOOL)flag;
|
||||
- (BOOL)pullsDown;
|
||||
- (void) setPullsDown: (BOOL)flag;
|
||||
- (BOOL) pullsDown;
|
||||
|
||||
- (void)setAutoenablesItems:(BOOL)flag;
|
||||
- (BOOL)autoenablesItems;
|
||||
- (void) setAutoenablesItems: (BOOL)flag;
|
||||
- (BOOL) autoenablesItems;
|
||||
|
||||
- (void)setPreferredEdge:(NSRectEdge)edge;
|
||||
- (NSRectEdge)preferredEdge;
|
||||
- (void) setPreferredEdge: (NSRectEdge)edge;
|
||||
- (NSRectEdge) preferredEdge;
|
||||
|
||||
- (void)setUsesItemFromMenu:(BOOL)flag;
|
||||
- (BOOL)usesItemFromMenu;
|
||||
- (void) setUsesItemFromMenu: (BOOL)flag;
|
||||
- (BOOL) usesItemFromMenu;
|
||||
|
||||
- (void)setAltersStateOfSelectedItem:(BOOL)flag;
|
||||
- (BOOL)altersStateOfSelectedItem;
|
||||
- (void) setAltersStateOfSelectedItem: (BOOL)flag;
|
||||
- (BOOL) altersStateOfSelectedItem;
|
||||
|
||||
// Adding and removing items
|
||||
- (void)addItemWithTitle:(NSString *)title;
|
||||
- (void)addItemsWithTitles:(NSArray *)itemTitles;
|
||||
- (void)insertItemWithTitle:(NSString *)title atIndex:(int)index;
|
||||
- (void) addItemWithTitle: (NSString*)title;
|
||||
- (void) addItemsWithTitles: (NSArray*)itemTitles;
|
||||
- (void) insertItemWithTitle: (NSString*)title atIndex: (int)index;
|
||||
|
||||
- (void)removeItemWithTitle:(NSString *)title;
|
||||
- (void)removeItemAtIndex:(int)index;
|
||||
- (void)removeAllItems;
|
||||
- (void) removeItemWithTitle: (NSString*)title;
|
||||
- (void) removeItemAtIndex: (int)index;
|
||||
- (void) removeAllItems;
|
||||
|
||||
|
||||
// Accessing the items
|
||||
- (NSArray *)itemArray;
|
||||
- (int)numberOfItems;
|
||||
- (NSArray*) itemArray;
|
||||
- (int) numberOfItems;
|
||||
|
||||
- (int)indexOfItem:(id <NSMenuItem>)item;
|
||||
- (int)indexOfItemWithTitle:(NSString *)title;
|
||||
- (int)indexOfItemWithTag:(int)tag;
|
||||
- (int)indexOfItemWithRepresentedObject:(id)obj;
|
||||
- (int)indexOfItemWithTarget:(id)target andAction:(SEL)actionSelector;
|
||||
- (int) indexOfItem: (id <NSMenuItem>)item;
|
||||
- (int) indexOfItemWithTitle: (NSString*)title;
|
||||
- (int) indexOfItemWithTag: (int)tag;
|
||||
- (int) indexOfItemWithRepresentedObject: (id)obj;
|
||||
- (int) indexOfItemWithTarget: (id)target andAction: (SEL)actionSelector;
|
||||
|
||||
- (id <NSMenuItem>)itemAtIndex:(int)index;
|
||||
- (id <NSMenuItem>)itemWithTitle:(NSString *)title;
|
||||
- (id <NSMenuItem>)lastItem;
|
||||
- (id <NSMenuItem>) itemAtIndex: (int)index;
|
||||
- (id <NSMenuItem>) itemWithTitle: (NSString*)title;
|
||||
- (id <NSMenuItem>) lastItem;
|
||||
|
||||
|
||||
// Dealing with selection
|
||||
- (void)selectItem:(id <NSMenuItem>)item;
|
||||
- (void)selectItemAtIndex:(int)index;
|
||||
- (void)selectItemWithTitle:(NSString *)title;
|
||||
- (void)setTitle:(NSString *)aString;
|
||||
- (void) selectItem: (id <NSMenuItem>)item;
|
||||
- (void) selectItemAtIndex: (int)index;
|
||||
- (void) selectItemWithTitle: (NSString*)title;
|
||||
- (void) setTitle: (NSString*)aString;
|
||||
|
||||
- (id <NSMenuItem>)selectedItem;
|
||||
- (int)indexOfSelectedItem;
|
||||
- (void)synchronizeTitleAndSelectedItem;
|
||||
- (id <NSMenuItem>) selectedItem;
|
||||
- (int) indexOfSelectedItem;
|
||||
- (void) synchronizeTitleAndSelectedItem;
|
||||
|
||||
|
||||
// Title conveniences
|
||||
- (NSString *)itemTitleAtIndex:(int)index;
|
||||
- (NSArray *)itemTitles;
|
||||
- (NSString *)titleOfSelectedItem;
|
||||
- (NSString*) itemTitleAtIndex: (int)index;
|
||||
- (NSArray*) itemTitles;
|
||||
- (NSString*) titleOfSelectedItem;
|
||||
|
||||
- (void)attachPopUpWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
|
||||
- (void) attachPopUpWithFrame: (NSRect)cellFrame inView: (NSView*)controlView;
|
||||
|
||||
- (void)dismissPopUp;
|
||||
- (void)performClickWithFrame:(NSRect)frame inView:(NSView *)controlView;
|
||||
- (void) dismissPopUp;
|
||||
- (void) performClickWithFrame: (NSRect)frame inView: (NSView*)controlView;
|
||||
|
||||
// Arrow position for bezel style and borderless popups.
|
||||
- (NSPopUpArrowPosition)arrowPosition;
|
||||
- (void)setArrowPosition:(NSPopUpArrowPosition)position;
|
||||
- (NSPopUpArrowPosition) arrowPosition;
|
||||
- (void) setArrowPosition: (NSPopUpArrowPosition)position;
|
||||
@end
|
||||
|
||||
/* Notifications */
|
||||
extern const NSString *NSPopUpButtonCellWillPopUpNotification;
|
||||
extern const NSString*NSPopUpButtonCellWillPopUpNotification;
|
||||
|
|
|
@ -74,8 +74,6 @@
|
|||
_menu = [[NSMenu alloc] initWithTitle: @""];
|
||||
[_menu _setOwnedByPopUp: YES];
|
||||
|
||||
_selectedIndex = 0;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -185,7 +183,7 @@
|
|||
if (index < 0)
|
||||
index = 0;
|
||||
if (index > [_menu numberOfItems])
|
||||
index = [_menu numberOfitems];
|
||||
index = [_menu numberOfItems];
|
||||
|
||||
[anItem setTitle: title];
|
||||
[anItem setTarget: self];
|
||||
|
@ -271,30 +269,25 @@
|
|||
// Dealing with selection
|
||||
- (void) selectItem: (id <NSMenuItem>)item
|
||||
{
|
||||
id selectedItem = [_menu itemAtIndex: _selectedIndex];
|
||||
|
||||
if (!item)
|
||||
{
|
||||
if (_pbcFlags.altersStateOfSelectedItem)
|
||||
[selectedItem setState: NSOffState];
|
||||
[_selectedItem setState: NSOffState];
|
||||
|
||||
_selectedIndex = -1;
|
||||
_selectedItem = nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_pbcFlags.altersStateOfSelectedItem)
|
||||
{
|
||||
[selectedItem setState: NSOffState];
|
||||
[_selectedItem setState: NSOffState];
|
||||
}
|
||||
_selectedIndex = [self indexOfItem: item];
|
||||
selectedItem = [_menu itemAtIndex: _selectedIndex];
|
||||
_selectedItem = item;
|
||||
if (_pbcFlags.altersStateOfSelectedItem)
|
||||
{
|
||||
[selectedItem setState: NSOnState];
|
||||
[_selectedItem setState: NSOnState];
|
||||
}
|
||||
}
|
||||
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
}
|
||||
|
||||
- (void) selectItemAtIndex: (int)index
|
||||
|
@ -340,12 +333,12 @@
|
|||
|
||||
- (id <NSMenuItem>) selectedItem
|
||||
{
|
||||
return [self itemAtIndex: _selectedIndex];
|
||||
return _selectedItem;
|
||||
}
|
||||
|
||||
- (int) indexOfSelectedItem
|
||||
{
|
||||
return _selectedIndex;
|
||||
return [_menu indexOfItem: _selectedItem];
|
||||
}
|
||||
|
||||
- (void) synchronizeTitleAndSelectedItem
|
||||
|
@ -355,14 +348,12 @@
|
|||
|
||||
if ([_menu numberOfItems] == 0)
|
||||
{
|
||||
_selectedIndex = -1;
|
||||
_selectedItem = nil;
|
||||
}
|
||||
else if (_pbcFlags.pullsDown)
|
||||
{
|
||||
_selectedIndex = 0;
|
||||
// [self selectItem: [self itemAtIndex: 0]];
|
||||
[self selectItem: [self itemAtIndex: 0]];
|
||||
}
|
||||
/*
|
||||
else
|
||||
{
|
||||
int index = [[_menu menuRepresentation] highlightedItemIndex];
|
||||
|
@ -371,7 +362,6 @@
|
|||
index = 0;
|
||||
[self selectItemAtIndex: index];
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// Title conveniences
|
||||
|
@ -397,8 +387,8 @@
|
|||
|
||||
- (NSString *) titleOfSelectedItem
|
||||
{
|
||||
if (_selectedIndex >= 0)
|
||||
return [[self itemAtIndex: _selectedIndex] title];
|
||||
if (_selectedItem != nil)
|
||||
return [_selectedItem title];
|
||||
else
|
||||
return @"";
|
||||
}
|
||||
|
@ -427,9 +417,9 @@ NSLog(@"cF %@", NSStringFromRect(cellFrame));
|
|||
|
||||
[_aCenter postNotification: _aNotif];
|
||||
|
||||
scratchRect = [[controlView superview] convertRect: scratchRect toView: nil];
|
||||
scratchRect.origin
|
||||
= [[controlView window] convertBaseToScreen: cellFrame.origin];
|
||||
scratchRect.origin = NSMakePoint(0,0);
|
||||
scratchRect = [controlView convertRect: scratchRect toView: nil];
|
||||
scratchRect.origin = [[controlView window] convertBaseToScreen: scratchRect.origin];
|
||||
|
||||
[[_menu menuRepresentation] _setCellSize: cellFrame.size];
|
||||
[_menu sizeToFit];
|
||||
|
@ -448,13 +438,13 @@ NSLog(@"cF %@", NSStringFromRect(cellFrame));
|
|||
{
|
||||
winf.origin.y += ([self indexOfSelectedItem] * scratchRect.size.height);
|
||||
}
|
||||
|
||||
winf.origin.y -= 22; /* HACK */
|
||||
NSLog(@"winf %@", NSStringFromRect(winf));
|
||||
|
||||
NSLog(@"here comes the popup.");
|
||||
|
||||
[[_menu window] setFrame: winf display: YES];
|
||||
[[_menu window] orderFront: nil];
|
||||
[[_menu window] orderFrontRegardless];
|
||||
}
|
||||
|
||||
- (void) dismissPopUp
|
||||
|
@ -523,12 +513,10 @@ 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];
|
||||
|
|
Loading…
Reference in a new issue