Major fixes all around.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4677 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
michael 1999-07-30 22:10:02 +00:00
parent 0ac5790122
commit c32570418e
11 changed files with 542 additions and 390 deletions

View file

@ -1,3 +1,26 @@
1999-07-30 Michael Hanni <mhanni@sprintmail.com>
* Source/NSMenu.m: rewrote sections to handle new popupbutton
code. New initialiser - initWithPopUpButton:. New ivar
menu_isBeholdenToPopUpButton.
* Source/NSMenuView.m: ditto. removed code that dealt with
popupbutton.
* Source/NSPopUpButton.m: complete rewrite. now this class should
be almost completly MacOSX compliant. For kicks try
popupbuttons.app in core/Testing to see.
* Source/NSPopUpButtonCell.m: modifications to make NSPopUpButton
work. Also implemented representedObject as I think it should be.
* Source/NSTableColumn.m: fixes to make some things work a little
better.
* Source/NSTableView.m: fixes to make things behave. Still doesn't
compile in, but it is getting there. Modifications will have to
be made to NSScrollView before we can use this class.
* Source/NSTabView.m: fixed (- contentRect) for the no tabs case.
* Headers/NSMenu.h: mods for changes.
* Headers/NSPopUpButton.h: ditto.
* Headers/NSPopUpButtonCell.h: ditto, also changed to inherit from
NSMenuItemCell.
1999-07-29 Adam Fedor <fedor@gnu.org> 1999-07-29 Adam Fedor <fedor@gnu.org>
* Headers/gnustep/gui/NSEvent.h: Add AppKit dragging events. * Headers/gnustep/gui/NSEvent.h: Add AppKit dragging events.

View file

@ -60,7 +60,10 @@
BOOL menu_changed; BOOL menu_changed;
BOOL menu_is_tornoff; BOOL menu_is_tornoff;
id menu_popb;
// Private. // Private.
BOOL menu_is_beholdenToPopUpButton;
BOOL menu_follow_transient; BOOL menu_follow_transient;
BOOL menu_is_visible; BOOL menu_is_visible;

View file

@ -46,20 +46,14 @@
@interface NSPopUpButton : NSButton <NSCoding> @interface NSPopUpButton : NSButton <NSCoding>
{ {
// Attributes NSMenu *popb_menu;
NSMutableArray *list_items; BOOL popb_pullsDown;
NSMenuView *popb_view; BOOL popb_autoenableItems;
NSRect list_rect; int popb_selectedItem;
int selected_item;
id pub_target; id pub_target;
SEL pub_action; SEL pub_action;
BOOL is_up; BOOL is_up;
BOOL pulls_down;
NSMenuWindow *popb_win;
// Reserved for back-end use
void *be_pub_reserved;
} }
// //
@ -68,69 +62,45 @@
- (id)initWithFrame:(NSRect)frameRect - (id)initWithFrame:(NSRect)frameRect
pullsDown:(BOOL)flag; pullsDown:(BOOL)flag;
// - (void)setPullsDown:(BOOL)flag;
// Target and Action - (BOOL)pullsDown;
// - (void)setAutoenablesItems:(BOOL)flag;
- (SEL)action; - (BOOL)autoenablesItems;
- (void)setAction:(SEL)aSelector;
- (id)target;
- (void)setTarget:(id)anObject;
//
// Adding Items
//
- (void)addItemWithTitle:(NSString *)title; - (void)addItemWithTitle:(NSString *)title;
- (void)addItemsWithTitles:(NSArray *)itemTitles; - (void)addItemsWithTitles:(NSArray *)itemTitles;
- (void)insertItemWithTitle:(NSString *)title - (void)insertItemWithTitle:(NSString *)title
atIndex:(unsigned int)index; atIndex:(int)index;
//
// Removing Items
//
- (void)removeAllItems; - (void)removeAllItems;
- (void)removeItemWithTitle:(NSString *)title; - (void)removeItemWithTitle:(NSString *)title;
- (void)removeItemAtIndex:(int)index; - (void)removeItemAtIndex:(int)index;
- (id <NSMenuItem>)selectedItem;
// - (NSString *)titleOfSelectedItem;
// Querying the NSPopUpButton about Its Items
//
- (int)indexOfItemWithTitle:(NSString *)title;
- (int)indexOfSelectedItem; - (int)indexOfSelectedItem;
- (void)selectItem:(id <NSMenuItem>)anObject;
- (void)selectItemAtIndex:(int)index;
- (void)selectItemWithTitle:(NSString *)title;
- (int)numberOfItems; - (int)numberOfItems;
- (id <NSMenuItem>)itemAtIndex:(int)index;
- (NSArray *)itemArray; - (NSArray *)itemArray;
- (id <NSMenuItem>)itemAtIndex:(int)index;
- (NSString *)itemTitleAtIndex:(int)index; - (NSString *)itemTitleAtIndex:(int)index;
- (NSArray *)itemTitles; - (NSArray *)itemTitles;
- (id <NSMenuItem>)itemWithTitle:(NSString *)title; - (id <NSMenuItem>)itemWithTitle:(NSString *)title;
- (id <NSMenuItem>)lastItem; - (id <NSMenuItem>)lastItem;
- (id <NSMenuItem>)selectedItem; - (int)indexOfItem:(id <NSMenuItem>)anObject;
- (NSString*)titleOfSelectedItem; - (int)indexOfItemWithTag:(int)tag;
- (int)indexOfItemWithTitle:(NSString *)title;
// - (int)indexOfItemWithRepresentedObject:(id)anObject;
// Manipulating the NSPopUpButton - (int)indexOfItemWithTarget:(id)target
// andAction:(SEL)actionSelector;
- (NSFont *)font; - (void)setPreferredEdge:(NSRectEdge)edge;
- (BOOL)pullsDown; - (NSRectEdge)preferredEdge;
- (void)selectItemAtIndex:(int)index; - (int)setTitle:(NSString *)aString;
- (void)selectItemWithTitle:(NSString *)title;
- (void)setFont:(NSFont *)fontObject;
- (void)setPullsDown:(BOOL)flag;
- (void)setTitle:(NSString *)aString;
- (NSString *)stringValue;
- (void)synchronizeTitleAndSelectedItem; - (void)synchronizeTitleAndSelectedItem;
- (void)_popup:(NSNotification*)notification;
- (void)mouseDown:(NSEvent *)theEvent;
// - (id) initWithCoder: (NSCoder*)aDecoder;
// Displaying the NSPopUpButton's Items - (void) encodeWithCoder: (NSCoder*)aCoder;
//
- (BOOL)autoenablesItems;
- (void)setAutoenablesItems:(BOOL)flag;
//
// NSCoding protocol
//
- (void)encodeWithCoder:aCoder;
- initWithCoder:aDecoder;
@end @end
extern NSString *NSPopUpButtonWillPopUpNotification; extern NSString *NSPopUpButtonWillPopUpNotification;

View file

@ -1,6 +1,6 @@
#include <AppKit/NSMenuItem.h> #include <AppKit/NSMenuItem.h>
@interface NSPopUpButtonCell : NSMenuItem @interface NSPopUpButtonCell : NSMenuItemCell <NSMenuItem>
{ {
} }
@end @end

View file

@ -48,6 +48,8 @@
#include <AppKit/NSMenu.h> #include <AppKit/NSMenu.h>
#include <AppKit/NSMenuView.h> #include <AppKit/NSMenuView.h>
#include <AppKit/NSMenuItemCell.h> #include <AppKit/NSMenuItemCell.h>
#include <AppKit/NSPopUpButton.h>
#include <AppKit/NSPopUpButtonCell.h>
static NSZone *menuZone = NULL; static NSZone *menuZone = NULL;
@ -74,6 +76,57 @@ static NSZone *menuZone = NULL;
return [self initWithTitle: @"Menu"]; return [self initWithTitle: @"Menu"];
} }
- (id) initWithPopUpButton: (NSPopUpButton *)popb
{
NSRect aRect;
NSRect winRect = {{0, 0}, {20, 17}};
[super init];
// Create an array to store out cells.
menu_items = [NSMutableArray new];
// Create a NSMenuView to draw our cells.
aRect = [popb frame];
menu_view = [[NSMenuView alloc] initWithFrame: NSMakeRect(0,0,50,50)
cellSize: aRect.size];
// Set ourself as the menu for this view.
[menu_view setMenu: self];
// We have no supermenu.
menu_supermenu = nil;
menu_is_tornoff = NO;
menu_is_visible = NO;
menu_follow_transient = NO;
menu_is_beholdenToPopUpButton = YES;
ASSIGN(menu_popb, popb);
// menu_popb = popb;
menu_changed = YES;
/* According to the spec, menus do autoenable by default */
menu_autoenable = YES;
aWindow = [[NSMenuWindow alloc] initWithContentRect:winRect
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreRetained
defer: NO];
[[aWindow contentView] addSubview:menu_view];
return self;
}
- (id) popupButton
{
return menu_popb;
}
- (BOOL) _isBeholdenToPopUpButton
{
return menu_is_beholdenToPopUpButton;
}
- (id) initWithTitle: (NSString *)aTitle - (id) initWithTitle: (NSString *)aTitle
{ {
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
@ -99,6 +152,7 @@ static NSZone *menuZone = NULL;
menu_is_tornoff = NO; menu_is_tornoff = NO;
menu_is_visible = NO; menu_is_visible = NO;
menu_follow_transient = NO; menu_follow_transient = NO;
menu_is_beholdenToPopUpButton = NO;
menu_changed = YES; menu_changed = YES;
/* According to the spec, menus do autoenable by default */ /* According to the spec, menus do autoenable by default */
@ -158,7 +212,8 @@ static NSZone *menuZone = NULL;
if ([(id)newItem conformsToProtocol: @protocol(NSMenuItem)]) if ([(id)newItem conformsToProtocol: @protocol(NSMenuItem)])
{ {
if ([(id)newItem isKindOfClass: [NSMenuItemCell class]]) if ([(id)newItem isKindOfClass: [NSMenuItemCell class]]
|| [(id)newItem isKindOfClass: [NSPopUpButtonCell class]])
{ {
nc = [NSNotificationCenter defaultCenter]; nc = [NSNotificationCenter defaultCenter];
d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:index] d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:index]
@ -194,7 +249,15 @@ static NSZone *menuZone = NULL;
keyEquivalent: (NSString *)charCode keyEquivalent: (NSString *)charCode
atIndex: (unsigned int)index atIndex: (unsigned int)index
{ {
id anItem = [NSMenuItemCell new]; id anItem;
if (menu_is_beholdenToPopUpButton)
{
anItem = [NSPopUpButtonCell new];
[anItem setTarget: menu_popb];
}
else
anItem = [NSMenuItemCell new];
[anItem setTitle: aString]; [anItem setTitle: aString];
[anItem setAction: aSelector]; [anItem setAction: aSelector];
@ -238,7 +301,8 @@ static NSZone *menuZone = NULL;
if (!anItem) if (!anItem)
return; return;
if ([(NSMenuItemCell *)anItem isKindOfClass: [NSMenuItemCell class]]) if ([(NSMenuItemCell *)anItem isKindOfClass: [NSMenuItemCell class]]
|| [(id)anItem isKindOfClass: [NSPopUpButtonCell class]])
{ {
nc = [NSNotificationCenter defaultCenter]; nc = [NSNotificationCenter defaultCenter];
d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:index] d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:index]
@ -318,7 +382,8 @@ static NSZone *menuZone = NULL;
- (int) indexOfItem: (id <NSMenuItem>)anObject - (int) indexOfItem: (id <NSMenuItem>)anObject
{ {
if (![(NSMenuItemCell *)anObject isKindOfClass: [NSMenuItemCell class]]) if (![(NSMenuItemCell *)anObject isKindOfClass: [NSMenuItemCell class]]
|| [(id)anObject isKindOfClass: [NSPopUpButtonCell class]])
{ {
NSLog(@"You must use an NSMenuItemCell, or a derivative thereof.\n"); NSLog(@"You must use an NSMenuItemCell, or a derivative thereof.\n");
return -1; return -1;
@ -354,6 +419,16 @@ static NSZone *menuZone = NULL;
- (int) indexOfItemWithRepresentedObject: (id)anObject - (int) indexOfItemWithRepresentedObject: (id)anObject
{ {
int i;
for (i=0;i<[menu_items count];i++)
{
if ([[[menu_items objectAtIndex:i] representedObject]
isEqual:anObject])
{
return i;
}
}
return -1; return -1;
} }
@ -619,14 +694,26 @@ static NSZone *menuZone = NULL;
[menu_view sizeToFit]; [menu_view sizeToFit];
mFrame = [menu_view frame]; mFrame = [menu_view frame];
[titleView setFrameOrigin: NSMakePoint(0, mFrame.size.height)];
[titleView setFrameSize: NSMakeSize (mFrame.size.width,21)];
size.width = mFrame.size.width; size.width = mFrame.size.width;
size.height = mFrame.size.height+21; size.height = mFrame.size.height;
[aWindow setFrame: NSMakeRect(300,300,size.width,size.height) display: NO]; if (!menu_is_beholdenToPopUpButton)
[bWindow setFrame: NSMakeRect(300,300,size.width,size.height) display: NO]; {
[titleView setFrameOrigin: NSMakePoint(0, mFrame.size.height)];
[titleView setFrameSize: NSMakeSize (mFrame.size.width,21)];
size.height = mFrame.size.height+21;
[bWindow setFrame: NSMakeRect(300,300,size.width,size.height)
display: NO];
[aWindow setFrame: NSMakeRect(300,300,size.width,size.height)
display: YES];
}
else
{
[aWindow setContentSize: size];
}
// FIXME, popup sets itself up.
[menu_view setNeedsDisplay:YES]; [menu_view setNeedsDisplay:YES];
menu_changed = NO; menu_changed = NO;
@ -698,7 +785,7 @@ static NSZone *menuZone = NULL;
} }
menu_is_visible = YES; menu_is_visible = YES;
[aWindow orderFront:self]; [aWindow orderFront:nil];
} }
- (void) displayTransient - (void) displayTransient

View file

@ -87,19 +87,6 @@ static float GSMenuBarHeight = 25.0; // a guess.
return menuv_menu; return menuv_menu;
} }
// Or random items.
- (void) setPopUpButton: (NSPopUpButton *)popb;
{
ASSIGN(menuv_popb, popb);
menuv_items_link = [menuv_popb itemArray];
}
- (NSPopUpButton *)popupButton
{
return menuv_popb;
}
- (void)setHorizontal: (BOOL)flag - (void)setHorizontal: (BOOL)flag
{ {
menuv_horizontal = flag; menuv_horizontal = flag;
@ -316,7 +303,8 @@ static float GSMenuBarHeight = 25.0; // a guess.
neededWidth = aWidth; neededWidth = aWidth;
} }
cellSize.width = 7 + neededWidth + 7 + 7 + 5; if (![menuv_menu _isBeholdenToPopUpButton])
cellSize.width = 7 + neededWidth + 7 + 7 + 5;
if ([window contentView] == self) if ([window contentView] == self)
[window setContentSize: NSMakeSize(cellSize.width,howHigh)]; [window setContentSize: NSMakeSize(cellSize.width,howHigh)];
@ -671,16 +659,10 @@ cell do the following */
[self setHighlightedItemIndex: -1]; [self setHighlightedItemIndex: -1];
if (menuv_menu) [menuv_menu performActionForItem:
[menuv_menu performActionForItem: [menuv_items_link objectAtIndex: lastIndex]];
[menuv_items_link objectAtIndex: lastIndex]];
if (menuv_popb) if (![menuv_menu _isBeholdenToPopUpButton])
[menuv_popb performSelector:[selectedCell action] withObject:selectedCell];
/* If we are a menu */
if (menuv_menu)
{ {
while (!finished) while (!finished)
{ // "forward"cursive menu find. { // "forward"cursive menu find.
@ -707,14 +689,10 @@ cell do the following */
[window flushWindow]; [window flushWindow];
} }
} }
else
/* If we are a popup */
if (menuv_popb)
{ {
[menuv_popb close]; [menuv_menu close];
} }
} }
else else
{ {

View file

@ -72,310 +72,300 @@
- (id)initWithFrame:(NSRect)frameRect - (id)initWithFrame:(NSRect)frameRect
pullsDown:(BOOL)flag pullsDown:(BOOL)flag
{ {
[super initWithFrame:frameRect]; NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
list_items = [NSMutableArray new];
popb_view = [[NSMenuView alloc] initWithFrame:frameRect [super initWithFrame:frameRect];
cellSize: NSMakeSize (frameRect.size.width,
frameRect.size.height)]; /* Create our menu */
[popb_view setPopUpButton: self];
popb_menu = [[NSMenu alloc] initWithPopUpButton:self];
is_up = NO; is_up = NO;
pulls_down = flag; popb_pullsDown = flag;
selected_item = 0; popb_selectedItem = 0;
[super setTarget: self]; [super setTarget: self];
popb_win = [[NSMenuWindow alloc] initWithContentRect: frameRect /*
styleMask: NSBorderlessWindowMask * Set ourselves up to recieve the notification when we need to popup
backing: NSBackingStoreRetained * the menu.
defer: NO]; */
[popb_win setContentView: popb_view]; [defaultCenter addObserver: self
selector: @selector(_popup:)
name: NSPopUpButtonWillPopUpNotification
object: self];
return self; return self;
} }
- (void) close - (void)setMenu:(NSMenu *)menu
{ {
[popb_win orderOut: self];
} }
- (void) dealloc - (NSMenu *)menu
{ {
[list_items release]; return popb_menu;
[super dealloc];
} }
// - (void)setPullsDown:(BOOL)flag
// Target and Action
//
- (SEL)action
{ {
popb_pullsDown = flag;
}
- (BOOL)pullsDown
{
return popb_pullsDown;
}
- (void)setAutoenablesItems:(BOOL)flag
{
popb_autoenableItems = flag;
}
- (BOOL)autoenablesItems
{
return popb_autoenableItems;
}
- (void)addItemWithTitle:(NSString *)title
{
[self insertItemWithTitle: title atIndex: [self numberOfItems]];
}
- (void)addItemsWithTitles:(NSArray *)itemTitles
{
int i;
for (i=0;i<[itemTitles count];i++)
{
[self addItemWithTitle:[itemTitles objectAtIndex:i]];
}
}
- (void)insertItemWithTitle:(NSString *)title
atIndex:(int)index
{
[popb_menu insertItemWithTitle: title
action: @selector(_buttonPressed:)
keyEquivalent: @""
atIndex: index];
[self synchronizeTitleAndSelectedItem];
}
- (void)removeAllItems
{
int i;
for (i=0;i<[self numberOfItems];i++)
{
[popb_menu removeItemAtIndex:i];
}
[self synchronizeTitleAndSelectedItem];
}
- (void)removeItemWithTitle:(NSString *)title
{
[popb_menu removeItemAtIndex: [self indexOfItemWithTitle: title]];
[self synchronizeTitleAndSelectedItem];
}
- (void)removeItemAtIndex:(int)index
{
[popb_menu removeItemAtIndex: index];
[self synchronizeTitleAndSelectedItem];
}
- (id <NSMenuItem>)selectedItem
{
if (popb_selectedItem >= 0)
return [[popb_menu itemArray] objectAtIndex: popb_selectedItem];
else
return nil;
}
- (NSString *)titleOfSelectedItem
{
// FIXME
return [[[popb_menu itemArray] objectAtIndex: popb_selectedItem] title];
}
- (int)indexOfSelectedItem
{
// FIXME
return -1;
}
- (void)selectItem:(id <NSMenuItem>)anObject
{
[self selectItemAtIndex:[self indexOfItem: anObject]];
}
- (void)selectItemAtIndex:(int)index
{
if (index == -1)
{
popb_selectedItem = -1;
}
else
{
popb_selectedItem = index;
}
[self synchronizeTitleAndSelectedItem];
}
- (void)selectItemWithTitle:(NSString *)title
{
[self selectItemAtIndex:[self indexOfItemWithTitle: title]];
}
- (int)numberOfItems
{
return [popb_menu numberOfItems];
}
- (NSArray *)itemArray
{
return [popb_menu itemArray];
}
- (id <NSMenuItem>)itemAtIndex:(int)index
{
return [popb_menu itemAtIndex: index];
}
- (NSString *)itemTitleAtIndex:(int)index
{
return [[self itemAtIndex: index] title];
}
- (NSArray *)itemTitles
{
NSMutableArray *anArray = [NSMutableArray new];
int i;
for (i=0;i<[self numberOfItems];i++)
{
[anArray addObject:[[self itemAtIndex:i] title]];
}
return anArray;
}
- (id <NSMenuItem>)itemWithTitle:(NSString *)title
{
return [popb_menu itemWithTitle: title];
}
- (id <NSMenuItem>)lastItem
{
return [[popb_menu itemArray] lastObject];
}
- (int)indexOfItem:(id <NSMenuItem>)anObject
{
return [popb_menu indexOfItem: anObject];
}
- (int)indexOfItemWithTag:(int)tag
{
return [popb_menu indexOfItemWithTag: tag];
}
- (int)indexOfItemWithTitle:(NSString *)title
{
return [popb_menu indexOfItemWithTitle: title];
}
- (int)indexOfItemWithRepresentedObject:(id)anObject
{
return [popb_menu indexOfItemWithRepresentedObject: anObject];
}
- (int)indexOfItemWithTarget:(id)target
andAction:(SEL)actionSelector
{
return [popb_menu indexOfItemWithTarget: target andAction: actionSelector];
}
- (void)setPreferredEdge:(NSRectEdge)edge
{
// urph
}
- (NSRectEdge)preferredEdge
{
// urph
return -1;
}
- (int)setTitle:(NSString *)aString
{
}
- (SEL)action
{
return pub_action; return pub_action;
} }
- (void)setAction:(SEL)aSelector - (void)setAction:(SEL)aSelector
{ {
pub_action = aSelector; pub_action = aSelector;
} }
- (id)target - (id)target
{ {
return pub_target; return pub_target;
} }
- (void)setTarget:(id)anObject - (void)setTarget:(id)anObject
{ {
pub_target = anObject; pub_target = anObject;
} }
- (void)buttonSelected:(id)sender - (void)_buttonPressed:(id)sender
{ {
if (!pulls_down) if (!popb_pullsDown)
selected_item = [self indexOfItemWithTitle:[sender title]]; popb_selectedItem = [self indexOfItemWithRepresentedObject:[sender representedObject]];
else else
selected_item = 0; popb_selectedItem = 0;
[self synchronizeTitleAndSelectedItem]; [self synchronizeTitleAndSelectedItem];
[self close];
[self lockFocus]; [self lockFocus];
[self drawRect:[self frame]]; [self drawRect:[self frame]];
[self unlockFocus]; [self unlockFocus];
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
if (pub_target && pub_action) if (pub_target && pub_action)
[pub_target performSelector:pub_action withObject:self]; [pub_target performSelector:pub_action withObject:self];
} }
//
// Adding Items
//
- (void)addItemWithTitle:(NSString *)title
{
[self insertItemWithTitle:title atIndex:[list_items count]];
}
- (void)addItemsWithTitles:(NSArray *)itemTitles
{
int i, count = [itemTitles count];
for (i = 0; i < count; i++)
[self addItemWithTitle:[itemTitles objectAtIndex:i]];
}
- (void)insertItemWithTitle:(NSString *)title
atIndex:(unsigned int)index
{
id menuCell = [[NSPopUpButtonCell new] autorelease];
[menuCell setFont: [NSFont systemFontOfSize:12]];
[menuCell setTitle: title];
[menuCell setTarget: self];
[menuCell setAction: @selector(buttonSelected:)];
[menuCell setEnabled:YES];
[list_items insertObject: menuCell atIndex: index];
[self synchronizeTitleAndSelectedItem];
}
//
// Removing Items
//
- (void)removeAllItems
{
[list_items removeAllObjects];
}
- (void)removeItemWithTitle:(NSString *)title
{
int index = [self indexOfItemWithTitle:title];
if (index != NSNotFound)
[list_items removeObjectAtIndex:index];
}
- (void)removeItemAtIndex:(int)index
{
[list_items removeObjectAtIndex:index];
}
//
// Querying the NSPopUpButton about Its Items
//
- (int)indexOfItemWithTitle:(NSString *)title
{
int i, count = [list_items count];
for (i = 0; i < count; i++)
if ([[[list_items objectAtIndex:i] title] isEqual:title])
return i;
return NSNotFound;
}
- (int)indexOfSelectedItem
{
return selected_item;
}
- (int)numberOfItems
{
return [list_items count];
}
- (id <NSMenuItem>)itemAtIndex:(int)index
{
return [list_items objectAtIndex:index];
}
- (NSArray *)itemArray
{
return list_items;
}
- (NSString *)itemTitleAtIndex:(int)index
{
return [[list_items objectAtIndex:index] title];
}
- (NSArray *)itemTitles
{
int i, count = [list_items count];
NSMutableArray* titles = [NSMutableArray arrayWithCapacity:count];
for (i = 0; i < count; i++)
[titles addObject:[[list_items objectAtIndex:i] title]];
return titles;
}
- (id <NSMenuItem>)itemWithTitle:(NSString *)title
{
int index = [self indexOfItemWithTitle:title];
if (index != NSNotFound)
return [list_items objectAtIndex:index];
return nil;
}
- (id <NSMenuItem>)lastItem
{
if ([list_items count])
return [list_items lastObject];
else
return nil;
}
- (id <NSMenuItem>)selectedItem
{
return [list_items objectAtIndex:selected_item];
}
- (NSString *)titleOfSelectedItem
{
return [[self selectedItem] title];
}
//
// Manipulating the NSPopUpButton
//
- (NSFont *)font
{
return nil;
}
- (BOOL)pullsDown
{
return pulls_down;
}
- (void)selectItemAtIndex:(int)index
{
if ((index >= 0) && (index < [list_items count]))
{
selected_item = index;
[self synchronizeTitleAndSelectedItem];
}
}
- (void)selectItemWithTitle:(NSString *)title
{
int index = [self indexOfItemWithTitle:title];
if (index != NSNotFound)
[self selectItemAtIndex:index];
}
- (void)setFont:(NSFont *)fontObject
{}
- (void)setPullsDown:(BOOL)flag
{
pulls_down = flag;
}
- (void)setTitle:(NSString *)aString
{}
- (NSString *)stringValue
{
return nil;
}
- (void)synchronizeTitleAndSelectedItem - (void)synchronizeTitleAndSelectedItem
{ {
// if (!pulls_down) // urph
// [list_items setIndexOfSelectedItem:selected_item];
// else
// [list_items setIndexOfSelectedItem:0];
} }
// - (void)_popup:(NSNotification*)notification
// Displaying the NSPopUpButton's Items
//
- (BOOL)autoenablesItems
{ {
return NO; NSPopUpButton *popb = [notification object];
}
- (void)setAutoenablesItems:(BOOL)flag
{}
//
// Handle events
//
- (void)mouseDown:(NSEvent *)theEvent
{
NSNotificationCenter *nc;
NSPoint cP; NSPoint cP;
NSRect butf; NSRect butf;
NSRect winf; NSRect winf;
nc = [NSNotificationCenter defaultCenter]; butf = [popb frame];
[nc postNotificationName: NSPopUpButtonWillPopUpNotification butf = [[popb superview] convertRect: butf toView: nil];
object: self butf.origin = [[popb window] convertBaseToScreen: butf.origin];
userInfo: nil];
/* [[popb_menu menuView] sizeToFit];
* Get frame of this button in window coordinates,
* and origin in screen coordinates. winf = [NSMenuWindow frameRectForContentRect: [[popb_menu menuView] frame]
*/ styleMask: [[popb_menu window] styleMask]];
butf = [self frame];
butf = [[self superview] convertRect: butf toView: nil];
butf.origin = [[self window] convertBaseToScreen: butf.origin];
/*
* Determine frame size for a popup window capable of containing the
* menu view.
*/
[popb_view sizeToFitForPopUpButton];
[popb_view setFrameOrigin: NSMakePoint(0,0)];
winf = [NSMenuWindow frameRectForContentRect: [popb_view frame]
styleMask: [popb_win styleMask]];
/* /*
* Set popup window frame origin so that the top-left corner of the * Set popup window frame origin so that the top-left corner of the
* window lines up with the top-left corner of this button. * window lines up with the top-left corner of this button.
@ -393,31 +383,39 @@
//NSLog(@"butf %@", NSStringFromRect(butf)); //NSLog(@"butf %@", NSStringFromRect(butf));
//NSLog(@"winf %@", NSStringFromRect(winf)); //NSLog(@"winf %@", NSStringFromRect(winf));
if (pulls_down == NO) if (popb_pullsDown == NO)
{ {
winf.origin.y += (selected_item * butf.size.height); winf.origin.y += (popb_selectedItem * butf.size.height);
} }
[popb_win setFrame: winf display: YES]; // [[popb menu] sizeToFit];
[popb_win orderFrontRegardless]; [[[popb menu] window] setFrame: winf display:YES];
[popb_win display]; [[[popb menu] window] orderFront:nil];
}
cP = [theEvent locationInWindow];
cP = [[self window] convertBaseToScreen: cP]; - (void)mouseDown:(NSEvent *)theEvent
cP = [popb_win convertScreenToBase: cP]; {
NSNotificationCenter *nc;
[popb_view mouseDown:
[NSEvent mouseEventWithType: NSLeftMouseDragged nc = [NSNotificationCenter defaultCenter];
location: cP [nc postNotificationName: NSPopUpButtonWillPopUpNotification
object: self
userInfo: nil];
[[popb_menu menuView] mouseDown:
[NSEvent mouseEventWithType: NSLeftMouseDown
location: [[popb_menu window] mouseLocationOutsideOfEventStream]
modifierFlags: [theEvent modifierFlags] modifierFlags: [theEvent modifierFlags]
timestamp: [theEvent timestamp] timestamp: [theEvent timestamp]
windowNumber: [popb_win windowNumber] windowNumber: [[popb_menu window] windowNumber]
context: [theEvent context] context: [theEvent context]
eventNumber: [theEvent eventNumber] eventNumber: [theEvent eventNumber]
clickCount: [theEvent clickCount] clickCount: [theEvent clickCount]
pressure: [theEvent pressure]]]; pressure: [theEvent pressure]]];
} }
/*
- (void)mouseUp:(NSEvent *)theEvent - (void)mouseUp:(NSEvent *)theEvent
{ {
NSPoint cP; NSPoint cP;
@ -440,10 +438,7 @@
[popb_win orderOut: nil]; [popb_win orderOut: nil];
} }
*/
- (void)mouseMoved:(NSEvent *)theEvent
{
}
- (NSView *)hitTest:(NSPoint)aPoint - (NSView *)hitTest:(NSPoint)aPoint
{ {
@ -461,13 +456,13 @@
{ {
id aCell; id aCell;
if ([list_items count] == 0) if ([popb_menu numberOfItems] == 0)
return; return;
if (!pulls_down) if (!popb_pullsDown)
aCell = [list_items objectAtIndex:selected_item]; aCell = [[popb_menu itemArray] objectAtIndex:popb_selectedItem];
else else
aCell = [list_items objectAtIndex:0]; aCell = [[popb_menu itemArray] objectAtIndex:0];
[aCell drawWithFrame:rect inView:self]; [aCell drawWithFrame:rect inView:self];
} }
@ -478,7 +473,7 @@
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];
/*
[aCoder encodeObject: list_items]; [aCoder encodeObject: list_items];
[aCoder encodeRect: list_rect]; [aCoder encodeRect: list_rect];
[aCoder encodeValueOfObjCType: @encode(int) at: &selected_item]; [aCoder encodeValueOfObjCType: @encode(int) at: &selected_item];
@ -486,12 +481,13 @@
[aCoder encodeValueOfObjCType: @encode(SEL) at: &pub_action]; [aCoder encodeValueOfObjCType: @encode(SEL) at: &pub_action];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &is_up]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &is_up];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &pulls_down]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &pulls_down];
*/
} }
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {
[super initWithCoder: aDecoder]; [super initWithCoder: aDecoder];
/*
[aDecoder decodeValueOfObjCType: @encode(id) at: &list_items]; [aDecoder decodeValueOfObjCType: @encode(id) at: &list_items];
list_rect = [aDecoder decodeRect]; list_rect = [aDecoder decodeRect];
[aDecoder decodeValueOfObjCType: @encode(int) at: &selected_item]; [aDecoder decodeValueOfObjCType: @encode(int) at: &selected_item];
@ -499,8 +495,7 @@
[aDecoder decodeValueOfObjCType: @encode(SEL) at: &pub_action]; [aDecoder decodeValueOfObjCType: @encode(SEL) at: &pub_action];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &is_up]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &is_up];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &pulls_down]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &pulls_down];
*/
return self; return self;
} }
@end @end

View file

@ -46,6 +46,16 @@
return [super init]; return [super init];
} }
- (id)representedObject
{
if (cell_image)
{
return cell_image;
}
return contents;
}
- (void)drawWithFrame:(NSRect)cellFrame - (void)drawWithFrame:(NSRect)cellFrame
inView:(NSView*)view inView:(NSView*)view
{ {
@ -69,6 +79,12 @@
NSRectFill(arect); NSRectFill(arect);
} }
if (cell_image)
{
[self _drawImage:cell_image inFrame:cellFrame];
return;
}
[cell_font set]; [cell_font set];
point.y = rect.origin.y + (rect.size.height/2) - 4; point.y = rect.origin.y + (rect.size.height/2) - 4;
@ -89,9 +105,9 @@
if ([view isKindOfClass:[NSMenuView class]]) if ([view isKindOfClass:[NSMenuView class]])
{ {
NSPopUpButton *popb = [(NSMenuView *)view popupButton]; NSPopUpButton *popb = [[(NSMenuView *)view menu] popupButton];
if ([popb titleOfSelectedItem] == contents) if ([[[popb selectedItem] representedObject] isEqual: contents])
{ {
if ([popb pullsDown] == NO) if ([popb pullsDown] == NO)
[super _drawImage:[NSImage imageNamed:@"common_Nibble"] inFrame:rect]; [super _drawImage:[NSImage imageNamed:@"common_Nibble"] inFrame:rect];
@ -101,7 +117,8 @@
} }
else if ([view isKindOfClass:[NSPopUpButton class]]) else if ([view isKindOfClass:[NSPopUpButton class]])
{ {
if ([(NSPopUpButton *)view titleOfSelectedItem] == contents) if ([[[(NSPopUpButton *)view selectedItem] representedObject]
isEqual: contents])
{ {
if ([(NSPopUpButton *)view pullsDown] == NO) if ([(NSPopUpButton *)view pullsDown] == NO)
[super _drawImage:[NSImage imageNamed:@"common_Nibble"] inFrame:rect]; [super _drawImage:[NSImage imageNamed:@"common_Nibble"] inFrame:rect];

View file

@ -238,8 +238,7 @@
NSRect cRect = [self frame]; NSRect cRect = [self frame];
cRect.origin.x = 0; cRect.origin.x = 0;
// cRect.size.height += 1; cRect.origin.y = 0;
// cRect.size.width += 1;
if (tab_type == NSTopTabsBezelBorder) if (tab_type == NSTopTabsBezelBorder)
{ {

View file

@ -97,6 +97,8 @@
NSSize cell_size = [tbcol_cell cellSize]; NSSize cell_size = [tbcol_cell cellSize];
BOOL changed = NO; BOOL changed = NO;
// fix to use headerRectOfColumn:(int)columnIndex?
if (tbcol_width != cell_size.width) if (tbcol_width != cell_size.width)
{ {
tbcol_width = cell_size.width; tbcol_width = cell_size.width;

View file

@ -1,3 +1,5 @@
#include <AppKit/NSTableView.h>
@implementation NSTableView @implementation NSTableView
- (id)initWithFrame:(NSRect)frameRect - (id)initWithFrame:(NSRect)frameRect
{ {
@ -13,10 +15,14 @@
- (void)setDataSource:(id)anObject - (void)setDataSource:(id)anObject
{ {
if (![anObject respondsToSelector: @selector (numberOfRowsInTableView:)]
// This method raises an NSInternalInconistencyException if anObject || ![anObject respondsToSelector: @selector
// doesn't respond to either (tableView:objectValueForTableColumn:row:)])
// numberOfRowsInTableView: or tableView:objectValueForTableColumn:row:. {
[NSException raise: NSInternalInconsistencyException
format: @"Assigned data source does not respond to needed
methods."];
}
ASSIGN(tb_datasource, anObject); ASSIGN(tb_datasource, anObject);
@ -419,7 +425,8 @@ object with the NSTableView as the text delegate. */
//FIXME! 100 is a place keeper. //FIXME! 100 is a place keeper.
return NSMakeRect(0,(rowIndex - 1) * tabColRows, 100, tbv_rowHeight); return NSMakeRect(0,(rowIndex - 1) * tabColRows, [self frame].width,
tbv_rowHeight);
} }
- (NSRange)columnsInRect:(NSRect)aRect - (NSRange)columnsInRect:(NSRect)aRect
@ -554,8 +561,23 @@ object with the NSTableView as the text delegate. */
for (i=0;i<colsToDraw.length;i++) for (i=0;i<colsToDraw.length;i++)
{ {
// tableView:willDisplayCell:forTableColumn:row: NSCell *aCell = [[tbv_columns objectAtIndex:i] dataCell];
// now draw the cell. NSRect *colRect = [self rectOfColumn:i];
colRect.size.height = tbv_rowHeight;
colRect.origin.y = rowIndex * tbv_rowHeight;
if (i != 0)
colRect.origin.y += tbv_interCellSpacing.height;
[delegate tableView:self willDisplayCell:aCell forTableColumn:i
row:rowIndex];
[aCell setStringValue:[tbv_dataSource tableView: self
objectValueForTableColumn: i
row: rowIndex]];
[aCell drawWithFrame: colRect];
} }
} }
@ -579,5 +601,61 @@ object with the NSTableView as the text delegate. */
[[self superview] scrollToPoint:NSZeroPoint]; [[self superview] scrollToPoint:NSZeroPoint];
} }
// more, but not yet. - (BOOL)textShouldBeginEditing:(NSText *)textObject
{
if ([delegate respondsToSelector: @selector
(control:textShouldBeginEditing:)])
{
return [delegate control: self textShouldBeginEditing: textObject];
}
return YES;
}
- (void)textDidBeginEditing:(NSNotification *)aNotification
{
/*
[[NSNotificationCenter defaultCenter]
postNotificationName:NSControlTextDidBeginEditingNotification
object:self
*/
}
- (void)textDidChange:(NSNotification *)aNotification
{
NSControlTextDidChangeNotification
}
- (BOOL)textShouldEndEditing:(NSText *)textObject
{
if ([delegate respondsToSelector: @selector (control:textShouldEndEditing:)])
{
return [delegate control: self control:textShouldEndEditing:
textObject];
}
if (is new cell valid)
return YES;
return NO;
}
- (void)textDidEndEditing:(NSNotification *)aNotification
{
/* Updates the data source based on the newly-edited value and selects
another cell for editing if possible according to the character that ended
editing (Return, Tab, Backtab). aNotification is the NSNotification posted
by the field editor; see the NSText class specifications for more
information on this text delegate method. */
}
- (void)drawRect:(NSRect)rect
{
for (i=0; i<[self numberOfRows]; i++)
{
// FIXME this isn't really the clipRect now is it.
[self drawRow: i clipRect: [self rectOfRow: i]];
}
}
@end @end