mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 18:11:06 +00:00
Fixed NSTable, NSTab, and NSMenu.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4652 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b2dc24ac3e
commit
82f77b9dcd
7 changed files with 191 additions and 69 deletions
12
ChangeLog
12
ChangeLog
|
@ -6,6 +6,18 @@
|
|||
linkages between the NSTable* classes is by no means clear.
|
||||
* Source/NSTableColumn.m: if the datacell type has not been set
|
||||
and is asked for we create a standard NSTextFieldCell.
|
||||
* Source/NSTabView.m: implementation is at 90%. All delegate
|
||||
messages are sent as required (if possible) and tab selection is
|
||||
now by the spec. Also a small optimization in tab selection makes
|
||||
sure we don't reselect tabs that are already selected.
|
||||
* Source/NSMenu.m: redid alot of the insertItem: addItem: methods
|
||||
to unify under the one primitive method. Did the same for
|
||||
removeItem:. Also added all the rest of the NSMenu notifications:
|
||||
NSMenuDidAddItemNotification
|
||||
NSMenuDidRemoveItemNotification
|
||||
NSMenuDidChangeItemNotification.
|
||||
I think we need some setDelegate/delegate methods in here, no?
|
||||
* Source/externs.m: added references to new NSMenu notifications.
|
||||
|
||||
1999-07-25 Michael Hanni <mhanni@sprintmail.com>
|
||||
|
||||
|
|
|
@ -68,16 +68,29 @@
|
|||
- (id)initWithTitle:(NSString*)aTitle;
|
||||
|
||||
/* Setting up the menu commands */
|
||||
- (id <NSMenuItem>)addItemWithTitle:(NSString*)aString
|
||||
action:(SEL)aSelector
|
||||
keyEquivalent:(NSString*)charCode;
|
||||
- (id <NSMenuItem>)insertItemWithTitle:(NSString*)aString
|
||||
action:(SEL)aSelector
|
||||
keyEquivalent:(NSString*)charCode
|
||||
atIndex:(unsigned int)index;
|
||||
- (void)removeItem:(id <NSMenuItem>)anItem;
|
||||
- (void) insertItem: (id <NSMenuItem>)newItem
|
||||
atIndex: (int)index;
|
||||
- (id <NSMenuItem>) insertItemWithTitle: (NSString *)aString
|
||||
action: (SEL)aSelector
|
||||
keyEquivalent: (NSString *)charCode
|
||||
atIndex: (unsigned int)index;
|
||||
- (void) addItem: (id <NSMenuItem>)newItem;
|
||||
- (id <NSMenuItem>) addItemWithTitle: (NSString *)aString
|
||||
action: (SEL)aSelector
|
||||
keyEquivalent: (NSString *)keyEquiv;
|
||||
- (void) removeItem: (id <NSMenuItem>)anItem;
|
||||
- (void) removeItemAtIndex: (int)index;
|
||||
|
||||
- (NSArray*)itemArray;
|
||||
|
||||
- (int) indexOfItem: (id <NSMenuItem>)anObject;
|
||||
- (int) indexOfItemWithTitle: (NSString *)aTitle;
|
||||
- (int) indexOfItemWithTag: (int)aTag;
|
||||
- (int) indexOfItemWithTarget: (id)anObject
|
||||
andAction: (SEL)actionSelector;
|
||||
- (int) indexOfItemWithRepresentedObject: (id)anObject;
|
||||
- (int) indexOfItemWithSubmenu: (NSMenu *)anObject;
|
||||
|
||||
/* Finding menu items */
|
||||
- (id <NSMenuItem>)itemWithTag:(int)aTag;
|
||||
- (id <NSMenuItem>)itemWithTitle:(NSString*)aString;
|
||||
|
@ -135,5 +148,9 @@
|
|||
|
||||
extern NSString* const NSMenuDidSendActionNotification;
|
||||
extern NSString* const NSMenuWillSendActionNotification;
|
||||
extern NSString* const NSMenuDidAddItemNotification;
|
||||
extern NSString* const NSMenuDidRemoveItemNotification;
|
||||
extern NSString* const NSMenuDidChangeItemNotification;
|
||||
|
||||
|
||||
#endif // _GNUstep_H_NSMenu
|
||||
|
|
|
@ -91,12 +91,10 @@ typedef enum {
|
|||
@end
|
||||
|
||||
@interface NSObject(NSTabViewDelegate)
|
||||
/*
|
||||
- (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)tabView;
|
||||
tabViewDidSelectTabViewItemtabView:didSelectTabViewItem:
|
||||
tabViewShouldSelectTabViewItemtabView:shouldSelectTabViewItem:
|
||||
tabViewWillSelectTabViewItemtabView:willSelectTabViewItem:
|
||||
*/
|
||||
- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem;
|
||||
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem;
|
||||
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
|
||||
- (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)TabView;
|
||||
@end
|
||||
|
||||
#endif // _GNUstep_H_NSTabView
|
||||
|
|
|
@ -115,17 +115,34 @@ static NSZone *menuZone = NULL;
|
|||
- (void) insertItem: (id <NSMenuItem>)newItem
|
||||
atIndex: (int)index
|
||||
{
|
||||
NSNotificationCenter *nc;
|
||||
NSDictionary *d;
|
||||
|
||||
if ([(id)newItem conformsToProtocol: @protocol(NSMenuItem)])
|
||||
{
|
||||
if ([(id)newItem isKindOfClass: [NSMenuItemCell class]])
|
||||
[menu_items insertObject: newItem atIndex: index];
|
||||
{
|
||||
nc = [NSNotificationCenter defaultCenter];
|
||||
d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:index]
|
||||
forKey: @"NSMenuItemIndex"];
|
||||
[nc postNotificationName: NSMenuDidAddItemNotification
|
||||
object: self
|
||||
userInfo: d];
|
||||
|
||||
[menu_items insertObject: newItem atIndex: index];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// The item we received conformed to <NSMenuItem> which is good,
|
||||
// but it wasn't an NSMenuItemCell which is bad. Therefore, we
|
||||
// loop through the system and create an NSMenuItemCell for
|
||||
// this bad boy.
|
||||
|
||||
[self insertItemWithTitle: [newItem title]
|
||||
action: [newItem action]
|
||||
keyEquivalent: [newItem keyEquivalent]
|
||||
atIndex: index];
|
||||
[(NSMenuItem *)newItem release];
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -135,9 +152,9 @@ static NSZone *menuZone = NULL;
|
|||
}
|
||||
|
||||
- (id <NSMenuItem>) insertItemWithTitle: (NSString *)aString
|
||||
action: (SEL)aSelector
|
||||
keyEquivalent: (NSString *)charCode
|
||||
atIndex: (unsigned int)index
|
||||
action: (SEL)aSelector
|
||||
keyEquivalent: (NSString *)charCode
|
||||
atIndex: (unsigned int)index
|
||||
{
|
||||
id anItem = [NSMenuItemCell new];
|
||||
|
||||
|
@ -145,9 +162,11 @@ static NSZone *menuZone = NULL;
|
|||
[anItem setAction: aSelector];
|
||||
[anItem setKeyEquivalent: charCode];
|
||||
|
||||
[menu_items insertObject: anItem atIndex: index];
|
||||
// Insert the new item into the stream.
|
||||
|
||||
menu_changed = YES;
|
||||
[self insertItem:anItem atIndex:index];
|
||||
|
||||
// For returns sake.
|
||||
|
||||
return anItem;
|
||||
}
|
||||
|
@ -169,14 +188,28 @@ static NSZone *menuZone = NULL;
|
|||
|
||||
- (void) removeItem: (id <NSMenuItem>)anItem
|
||||
{
|
||||
[self removeItemAtIndex:[menu_items indexOfObject: anItem]];
|
||||
}
|
||||
|
||||
- (void) removeItemAtIndex: (int)index
|
||||
{
|
||||
NSNotificationCenter *nc;
|
||||
NSDictionary *d;
|
||||
id anItem = [menu_items objectAtIndex:index];
|
||||
|
||||
if (!anItem)
|
||||
return;
|
||||
|
||||
if ([(NSMenuItemCell *)anItem isKindOfClass: [NSMenuItemCell class]])
|
||||
{
|
||||
int _index = [menu_items indexOfObject: anItem];
|
||||
nc = [NSNotificationCenter defaultCenter];
|
||||
d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:index]
|
||||
forKey: @"NSMenuItemIndex"];
|
||||
[nc postNotificationName: NSMenuDidRemoveItemNotification
|
||||
object: self
|
||||
userInfo: d];
|
||||
|
||||
if (_index == -1)
|
||||
return;
|
||||
|
||||
[menu_items removeObjectAtIndex: _index];
|
||||
[menu_items removeObjectAtIndex: index];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -186,16 +219,19 @@ static NSZone *menuZone = NULL;
|
|||
menu_changed = YES;
|
||||
}
|
||||
|
||||
- (void) removeItemAtIndex: (int)index
|
||||
{
|
||||
[menu_items removeObjectAtIndex: index];
|
||||
|
||||
menu_changed = YES;
|
||||
}
|
||||
|
||||
- (void) itemChanged: (id <NSMenuItem>)anObject
|
||||
{
|
||||
// another nebulous method in NSMenu.
|
||||
// another nebulous method in NSMenu. Is this correct?
|
||||
|
||||
NSNotificationCenter *nc;
|
||||
NSDictionary *d;
|
||||
|
||||
nc = [NSNotificationCenter defaultCenter];
|
||||
d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:[self indexOfItem: anObject]]
|
||||
forKey: @"NSMenuItemIndex"];
|
||||
[nc postNotificationName: NSMenuDidChangeItemNotification
|
||||
object: self
|
||||
userInfo: d];
|
||||
}
|
||||
|
||||
- (id <NSMenuItem>) itemWithTag: (int)aTag
|
||||
|
|
|
@ -27,6 +27,12 @@
|
|||
{
|
||||
[tabViewItem _setTabView:self];
|
||||
[tab_items insertObject:tabViewItem atIndex:[tab_items count]];
|
||||
|
||||
if ([tab_delegate respondsToSelector:
|
||||
@selector(tabViewDidChangeNumberOfTabViewItems:)])
|
||||
{
|
||||
[tab_delegate tabViewDidChangeNumberOfTabViewItems:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)insertTabViewItem:(NSTabViewItem *)tabViewItem
|
||||
|
@ -34,6 +40,12 @@
|
|||
{
|
||||
[tabViewItem _setTabView:self];
|
||||
[tab_items insertObject:tabViewItem atIndex:index];
|
||||
|
||||
if ([tab_delegate respondsToSelector:
|
||||
@selector(tabViewDidChangeNumberOfTabViewItems:)])
|
||||
{
|
||||
[tab_delegate tabViewDidChangeNumberOfTabViewItems:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeTabViewItem:(NSTabViewItem *)tabViewItem
|
||||
|
@ -44,6 +56,12 @@
|
|||
return;
|
||||
|
||||
[tab_items removeObjectAtIndex:i];
|
||||
|
||||
if ([tab_delegate respondsToSelector:
|
||||
@selector(tabViewDidChangeNumberOfTabViewItems:)])
|
||||
{
|
||||
[tab_delegate tabViewDidChangeNumberOfTabViewItems:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (int)indexOfTabViewItem:(NSTabViewItem *)tabViewItem
|
||||
|
@ -53,8 +71,17 @@
|
|||
|
||||
- (int)indexOfTabViewItemWithIdentifier:(id)identifier
|
||||
{
|
||||
// the spec is confusing on this method.
|
||||
return 0;
|
||||
int howMany = [tab_items count];
|
||||
int i;
|
||||
|
||||
for (i=0;i<howMany;i++)
|
||||
{
|
||||
id anItem = [tab_items objectAtIndex:i];
|
||||
|
||||
if ([[anItem identifier] isEqual:identifier])
|
||||
return i;
|
||||
}
|
||||
return NSNotFound;
|
||||
}
|
||||
|
||||
- (int)numberOfTabViewItems
|
||||
|
@ -92,12 +119,54 @@
|
|||
[self selectTabViewItemAtIndex:tab_selected_item-1];
|
||||
}
|
||||
|
||||
- (NSTabViewItem *)selectedTabViewItem
|
||||
{
|
||||
return [tab_items objectAtIndex:tab_selected_item];
|
||||
}
|
||||
|
||||
- (void)selectTabViewItem:(NSTabViewItem *)tabViewItem
|
||||
{
|
||||
BOOL canSelect = YES;
|
||||
|
||||
if ([tab_delegate respondsToSelector:
|
||||
@selector(tabView:shouldSelectTabViewItem:)])
|
||||
{
|
||||
canSelect = [tab_delegate tabView:self
|
||||
shouldSelectTabViewItem:tabViewItem];
|
||||
}
|
||||
|
||||
if (canSelect)
|
||||
{
|
||||
if (tab_selected)
|
||||
{
|
||||
[tab_selected _setTabState:NSBackgroundTab];
|
||||
if ([tab_selected view])
|
||||
[[tab_selected view] removeFromSuperview];
|
||||
}
|
||||
|
||||
tab_selected = tabViewItem;
|
||||
|
||||
if ([tab_delegate respondsToSelector:
|
||||
@selector(tabView:willSelectTabViewItem:)])
|
||||
{
|
||||
[tab_delegate tabView:self willSelectTabViewItem:tab_selected];
|
||||
}
|
||||
|
||||
[tab_selected _setTabState:NSSelectedTab];
|
||||
if ([tab_selected view])
|
||||
[self addSubview:[tab_selected view]];
|
||||
|
||||
if ([tab_delegate respondsToSelector:
|
||||
@selector(tabView:didSelectTabViewItem:)])
|
||||
{
|
||||
[tab_delegate tabView:self didSelectTabViewItem:tab_selected];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)selectTabViewItemAtIndex:(int)index
|
||||
{
|
||||
[self selectTabViewItem:[tab_items objectAtIndex:index]];
|
||||
}
|
||||
|
||||
- (void)takeSelectedTabViewItemFromSender:(id)sender
|
||||
|
@ -146,7 +215,7 @@
|
|||
|
||||
- (void)setDelegate:(id)anObject
|
||||
{
|
||||
ASSIGN(tab_delegate, anObject);
|
||||
tab_delegate = anObject;
|
||||
}
|
||||
|
||||
- (id)delegate
|
||||
|
@ -184,7 +253,7 @@
|
|||
int howMany = [tab_items count];
|
||||
int i;
|
||||
NSRect previousRect;
|
||||
NSTabState previousState;
|
||||
int previousState = 0;
|
||||
|
||||
DPSgsave(ctxt);
|
||||
|
||||
|
@ -215,13 +284,9 @@
|
|||
NSTabViewItem *anItem = [tab_items objectAtIndex:i];
|
||||
NSTabState itemState;
|
||||
|
||||
// hack to simulate a selected tab other than tab one.
|
||||
// if (i == 0) [anItem _setTabState:NSSelectedTab];
|
||||
|
||||
itemState = [anItem tabState];
|
||||
|
||||
s = [anItem sizeOfLabel:NO];
|
||||
NSLog(@"Label: %@ Size: %d\n", [anItem label], (int)s.width);
|
||||
|
||||
if (i == 0) {
|
||||
|
||||
|
@ -322,10 +387,6 @@
|
|||
|
||||
for (i=0;i<howMany;i++) {
|
||||
NSTabViewItem *anItem = [tab_items objectAtIndex:i];
|
||||
NSRect tRect = [anItem _tabRect];
|
||||
|
||||
NSLog(@"point (%f, %f) and rect (%f, %f) (%f, %f)", point.x, point.y,
|
||||
tRect.origin.x, tRect.origin.y, tRect.size.width, tRect.size.height);
|
||||
|
||||
if(NSPointInRect(point,[anItem _tabRect]))
|
||||
return anItem;
|
||||
|
@ -338,31 +399,16 @@ tRect.origin.x, tRect.origin.y, tRect.size.width, tRect.size.height);
|
|||
{
|
||||
NSTabViewItem *anItem = [self tabViewItemAtPoint:aPoint];
|
||||
|
||||
if (anItem) {
|
||||
if (tab_selected) {
|
||||
[tab_selected _setTabState:NSBackgroundTab];
|
||||
if ([tab_selected view])
|
||||
[[tab_selected view] removeFromSuperview];
|
||||
if (anItem && ![anItem isEqual:tab_selected])
|
||||
{
|
||||
[self selectTabViewItem:anItem];
|
||||
}
|
||||
|
||||
tab_selected = anItem;
|
||||
[anItem _setTabState:NSSelectedTab];
|
||||
if ([anItem view]) {
|
||||
[self addSubview:[anItem view]];
|
||||
}
|
||||
}
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
|
||||
return [super hitTest:aPoint];
|
||||
}
|
||||
|
||||
/*
|
||||
- (BOOL) mouse: (NSPoint)aPoint inRect: (NSRect)aRect
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
// Coding.
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
|
|
|
@ -45,6 +45,10 @@
|
|||
tbcol_width = tbcol_minWidth;
|
||||
else
|
||||
tbcol_width = newWidth;
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: NSTableViewColumnDidResizeNotification
|
||||
object:tbcol_tableview];
|
||||
}
|
||||
|
||||
- (float)width
|
||||
|
@ -55,6 +59,9 @@
|
|||
- (void)setMinWidth:(float)minWidth
|
||||
{
|
||||
tbcol_minWidth = minWidth;
|
||||
|
||||
if (tbcol_width < minWidth)
|
||||
[self setWidth:minWidth];
|
||||
}
|
||||
|
||||
- (float)minWidth
|
||||
|
@ -65,11 +72,14 @@
|
|||
- (void)setMaxWidth:(float)maxWidth
|
||||
{
|
||||
tbcol_maxWidth = maxWidth;
|
||||
|
||||
if (tbcol_width > maxWidth)
|
||||
[self setWidth:maxWidth];
|
||||
}
|
||||
|
||||
- (float)maxWidth
|
||||
{
|
||||
return maxWidth;
|
||||
return tbcol_maxWidth;
|
||||
}
|
||||
|
||||
- (void)setResizable:(BOOL)flag
|
||||
|
@ -93,11 +103,11 @@
|
|||
changed = YES;
|
||||
}
|
||||
|
||||
if (cellSize.width > tbcol_maxWidth)
|
||||
tbcol_maxWidth = cellSize.width;
|
||||
if (cell_size.width > tbcol_maxWidth)
|
||||
tbcol_maxWidth = cell_size.width;
|
||||
|
||||
if (cellSize.width < tbcol_minWidth)
|
||||
tbcol_minWidth = cellSize.width;
|
||||
if (cell_size.width < tbcol_minWidth)
|
||||
tbcol_minWidth = cell_size.width;
|
||||
|
||||
if (changed)
|
||||
[tbcol_tableview setNeedsDisplay:YES];
|
||||
|
|
|
@ -261,6 +261,9 @@ NSString *NSViewBoundsDidChangeNotification
|
|||
// NSMenu notifications
|
||||
NSString* const NSMenuDidSendActionNotification = @"MenuDidSendAction";
|
||||
NSString* const NSMenuWillSendActionNotification = @"MenuWillSendAction";
|
||||
NSString* const NSMenuDidAddItemNotification = @"MenuDidAddItem";
|
||||
NSString* const NSMenuDidRemoveItemNotification = @"MenuDidRemoveItem";
|
||||
NSString* const NSMenuDidChangeItemNotification = @"MenuDidChangeItem";
|
||||
|
||||
// NSWindow notifications
|
||||
NSString *NSWindowDidBecomeKeyNotification = @"WindowDidBecomeKey";
|
||||
|
|
Loading…
Reference in a new issue