mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 22:00:46 +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
02d80a510c
commit
018ad81664
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>
|
Fri Dec 3 14:41:00 1999 Michael Hanni <mhanni@sprintmail.com>
|
||||||
|
|
||||||
* Source/NSPopUpButtonCell.m: more fixes, issues remain.
|
* Source/NSPopUpButtonCell.m: more fixes, issues remain.
|
||||||
|
|
|
@ -13,91 +13,90 @@ 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;
|
||||||
unsigned int menuIsAttached:1;
|
unsigned int menuIsAttached: 1;
|
||||||
unsigned int usesItemFromMenu:1;
|
unsigned int usesItemFromMenu: 1;
|
||||||
unsigned int altersStateOfSelectedItem:1;
|
unsigned int altersStateOfSelectedItem: 1;
|
||||||
unsigned int decoding:1;
|
unsigned int decoding: 1;
|
||||||
unsigned int arrowPosition:2;
|
unsigned int arrowPosition: 2;
|
||||||
} _pbcFlags;
|
} _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
|
// Overrides behavior of NSCell. This is the menu for the popup, not a
|
||||||
// context menu. PopUpButtonCells do not have context menus.
|
// context menu. PopUpButtonCells do not have context menus.
|
||||||
- (void)setMenu:(NSMenu *)menu;
|
- (void) setMenu: (NSMenu*)menu;
|
||||||
- (NSMenu *)menu;
|
- (NSMenu*) menu;
|
||||||
|
|
||||||
// Behavior settings
|
// Behavior settings
|
||||||
- (void)setPullsDown:(BOOL)flag;
|
- (void) setPullsDown: (BOOL)flag;
|
||||||
- (BOOL)pullsDown;
|
- (BOOL) pullsDown;
|
||||||
|
|
||||||
- (void)setAutoenablesItems:(BOOL)flag;
|
- (void) setAutoenablesItems: (BOOL)flag;
|
||||||
- (BOOL)autoenablesItems;
|
- (BOOL) autoenablesItems;
|
||||||
|
|
||||||
- (void)setPreferredEdge:(NSRectEdge)edge;
|
- (void) setPreferredEdge: (NSRectEdge)edge;
|
||||||
- (NSRectEdge)preferredEdge;
|
- (NSRectEdge) preferredEdge;
|
||||||
|
|
||||||
- (void)setUsesItemFromMenu:(BOOL)flag;
|
- (void) setUsesItemFromMenu: (BOOL)flag;
|
||||||
- (BOOL)usesItemFromMenu;
|
- (BOOL) usesItemFromMenu;
|
||||||
|
|
||||||
- (void)setAltersStateOfSelectedItem:(BOOL)flag;
|
- (void) setAltersStateOfSelectedItem: (BOOL)flag;
|
||||||
- (BOOL)altersStateOfSelectedItem;
|
- (BOOL) altersStateOfSelectedItem;
|
||||||
|
|
||||||
// Adding and removing items
|
// Adding and removing items
|
||||||
- (void)addItemWithTitle:(NSString *)title;
|
- (void) addItemWithTitle: (NSString*)title;
|
||||||
- (void)addItemsWithTitles:(NSArray *)itemTitles;
|
- (void) addItemsWithTitles: (NSArray*)itemTitles;
|
||||||
- (void)insertItemWithTitle:(NSString *)title atIndex:(int)index;
|
- (void) insertItemWithTitle: (NSString*)title atIndex: (int)index;
|
||||||
|
|
||||||
- (void)removeItemWithTitle:(NSString *)title;
|
- (void) removeItemWithTitle: (NSString*)title;
|
||||||
- (void)removeItemAtIndex:(int)index;
|
- (void) removeItemAtIndex: (int)index;
|
||||||
- (void)removeAllItems;
|
- (void) removeAllItems;
|
||||||
|
|
||||||
|
|
||||||
// Accessing the items
|
// Accessing the items
|
||||||
- (NSArray *)itemArray;
|
- (NSArray*) itemArray;
|
||||||
- (int)numberOfItems;
|
- (int) numberOfItems;
|
||||||
|
|
||||||
- (int)indexOfItem:(id <NSMenuItem>)item;
|
- (int) indexOfItem: (id <NSMenuItem>)item;
|
||||||
- (int)indexOfItemWithTitle:(NSString *)title;
|
- (int) indexOfItemWithTitle: (NSString*)title;
|
||||||
- (int)indexOfItemWithTag:(int)tag;
|
- (int) indexOfItemWithTag: (int)tag;
|
||||||
- (int)indexOfItemWithRepresentedObject:(id)obj;
|
- (int) indexOfItemWithRepresentedObject: (id)obj;
|
||||||
- (int)indexOfItemWithTarget:(id)target andAction:(SEL)actionSelector;
|
- (int) indexOfItemWithTarget: (id)target andAction: (SEL)actionSelector;
|
||||||
|
|
||||||
- (id <NSMenuItem>)itemAtIndex:(int)index;
|
- (id <NSMenuItem>) itemAtIndex: (int)index;
|
||||||
- (id <NSMenuItem>)itemWithTitle:(NSString *)title;
|
- (id <NSMenuItem>) itemWithTitle: (NSString*)title;
|
||||||
- (id <NSMenuItem>)lastItem;
|
- (id <NSMenuItem>) lastItem;
|
||||||
|
|
||||||
|
|
||||||
// Dealing with selection
|
// Dealing with selection
|
||||||
- (void)selectItem:(id <NSMenuItem>)item;
|
- (void) selectItem: (id <NSMenuItem>)item;
|
||||||
- (void)selectItemAtIndex:(int)index;
|
- (void) selectItemAtIndex: (int)index;
|
||||||
- (void)selectItemWithTitle:(NSString *)title;
|
- (void) selectItemWithTitle: (NSString*)title;
|
||||||
- (void)setTitle:(NSString *)aString;
|
- (void) setTitle: (NSString*)aString;
|
||||||
|
|
||||||
- (id <NSMenuItem>)selectedItem;
|
- (id <NSMenuItem>) selectedItem;
|
||||||
- (int)indexOfSelectedItem;
|
- (int) indexOfSelectedItem;
|
||||||
- (void)synchronizeTitleAndSelectedItem;
|
- (void) synchronizeTitleAndSelectedItem;
|
||||||
|
|
||||||
|
|
||||||
// Title conveniences
|
// Title conveniences
|
||||||
- (NSString *)itemTitleAtIndex:(int)index;
|
- (NSString*) itemTitleAtIndex: (int)index;
|
||||||
- (NSArray *)itemTitles;
|
- (NSArray*) itemTitles;
|
||||||
- (NSString *)titleOfSelectedItem;
|
- (NSString*) titleOfSelectedItem;
|
||||||
|
|
||||||
- (void)attachPopUpWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
|
- (void) attachPopUpWithFrame: (NSRect)cellFrame inView: (NSView*)controlView;
|
||||||
|
|
||||||
- (void)dismissPopUp;
|
- (void) dismissPopUp;
|
||||||
- (void)performClickWithFrame:(NSRect)frame inView:(NSView *)controlView;
|
- (void) performClickWithFrame: (NSRect)frame inView: (NSView*)controlView;
|
||||||
|
|
||||||
// Arrow position for bezel style and borderless popups.
|
// Arrow position for bezel style and borderless popups.
|
||||||
- (NSPopUpArrowPosition)arrowPosition;
|
- (NSPopUpArrowPosition) arrowPosition;
|
||||||
- (void)setArrowPosition:(NSPopUpArrowPosition)position;
|
- (void) setArrowPosition: (NSPopUpArrowPosition)position;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
/* Notifications */
|
/* Notifications */
|
||||||
extern const NSString *NSPopUpButtonCellWillPopUpNotification;
|
extern const NSString*NSPopUpButtonCellWillPopUpNotification;
|
||||||
|
|
|
@ -74,8 +74,6 @@
|
||||||
_menu = [[NSMenu alloc] initWithTitle: @""];
|
_menu = [[NSMenu alloc] initWithTitle: @""];
|
||||||
[_menu _setOwnedByPopUp: YES];
|
[_menu _setOwnedByPopUp: YES];
|
||||||
|
|
||||||
_selectedIndex = 0;
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +183,7 @@
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
index = 0;
|
index = 0;
|
||||||
if (index > [_menu numberOfItems])
|
if (index > [_menu numberOfItems])
|
||||||
index = [_menu numberOfitems];
|
index = [_menu numberOfItems];
|
||||||
|
|
||||||
[anItem setTitle: title];
|
[anItem setTitle: title];
|
||||||
[anItem setTarget: self];
|
[anItem setTarget: self];
|
||||||
|
@ -271,30 +269,25 @@
|
||||||
// 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];
|
||||||
|
|
||||||
_selectedIndex = -1;
|
_selectedItem = nil;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_pbcFlags.altersStateOfSelectedItem)
|
if (_pbcFlags.altersStateOfSelectedItem)
|
||||||
{
|
{
|
||||||
[selectedItem setState: NSOffState];
|
[_selectedItem setState: NSOffState];
|
||||||
}
|
}
|
||||||
_selectedIndex = [self indexOfItem: item];
|
_selectedItem = 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
|
||||||
|
@ -340,12 +333,12 @@
|
||||||
|
|
||||||
- (id <NSMenuItem>) selectedItem
|
- (id <NSMenuItem>) selectedItem
|
||||||
{
|
{
|
||||||
return [self itemAtIndex: _selectedIndex];
|
return _selectedItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int) indexOfSelectedItem
|
- (int) indexOfSelectedItem
|
||||||
{
|
{
|
||||||
return _selectedIndex;
|
return [_menu indexOfItem: _selectedItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) synchronizeTitleAndSelectedItem
|
- (void) synchronizeTitleAndSelectedItem
|
||||||
|
@ -355,14 +348,12 @@
|
||||||
|
|
||||||
if ([_menu numberOfItems] == 0)
|
if ([_menu numberOfItems] == 0)
|
||||||
{
|
{
|
||||||
_selectedIndex = -1;
|
_selectedItem = nil;
|
||||||
}
|
}
|
||||||
else if (_pbcFlags.pullsDown)
|
else if (_pbcFlags.pullsDown)
|
||||||
{
|
{
|
||||||
_selectedIndex = 0;
|
[self selectItem: [self itemAtIndex: 0]];
|
||||||
// [self selectItem: [self itemAtIndex: 0]];
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int index = [[_menu menuRepresentation] highlightedItemIndex];
|
int index = [[_menu menuRepresentation] highlightedItemIndex];
|
||||||
|
@ -371,7 +362,6 @@
|
||||||
index = 0;
|
index = 0;
|
||||||
[self selectItemAtIndex: index];
|
[self selectItemAtIndex: index];
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Title conveniences
|
// Title conveniences
|
||||||
|
@ -397,8 +387,8 @@
|
||||||
|
|
||||||
- (NSString *) titleOfSelectedItem
|
- (NSString *) titleOfSelectedItem
|
||||||
{
|
{
|
||||||
if (_selectedIndex >= 0)
|
if (_selectedItem != nil)
|
||||||
return [[self itemAtIndex: _selectedIndex] title];
|
return [_selectedItem title];
|
||||||
else
|
else
|
||||||
return @"";
|
return @"";
|
||||||
}
|
}
|
||||||
|
@ -427,9 +417,9 @@ NSLog(@"cF %@", NSStringFromRect(cellFrame));
|
||||||
|
|
||||||
[_aCenter postNotification: _aNotif];
|
[_aCenter postNotification: _aNotif];
|
||||||
|
|
||||||
scratchRect = [[controlView superview] convertRect: scratchRect toView: nil];
|
scratchRect.origin = NSMakePoint(0,0);
|
||||||
scratchRect.origin
|
scratchRect = [controlView convertRect: scratchRect toView: nil];
|
||||||
= [[controlView window] convertBaseToScreen: cellFrame.origin];
|
scratchRect.origin = [[controlView window] convertBaseToScreen: scratchRect.origin];
|
||||||
|
|
||||||
[[_menu menuRepresentation] _setCellSize: cellFrame.size];
|
[[_menu menuRepresentation] _setCellSize: cellFrame.size];
|
||||||
[_menu sizeToFit];
|
[_menu sizeToFit];
|
||||||
|
@ -448,13 +438,13 @@ NSLog(@"cF %@", NSStringFromRect(cellFrame));
|
||||||
{
|
{
|
||||||
winf.origin.y += ([self indexOfSelectedItem] * scratchRect.size.height);
|
winf.origin.y += ([self indexOfSelectedItem] * scratchRect.size.height);
|
||||||
}
|
}
|
||||||
|
winf.origin.y -= 22; /* HACK */
|
||||||
NSLog(@"winf %@", NSStringFromRect(winf));
|
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] orderFront: nil];
|
[[_menu window] orderFrontRegardless];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dismissPopUp
|
- (void) dismissPopUp
|
||||||
|
@ -523,12 +513,10 @@ 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];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue