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>
* Headers/gnustep/gui/NSEvent.h: Add AppKit dragging events.

View file

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

View file

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

View file

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

View file

@ -48,6 +48,8 @@
#include <AppKit/NSMenu.h>
#include <AppKit/NSMenuView.h>
#include <AppKit/NSMenuItemCell.h>
#include <AppKit/NSPopUpButton.h>
#include <AppKit/NSPopUpButtonCell.h>
static NSZone *menuZone = NULL;
@ -74,6 +76,57 @@ static NSZone *menuZone = NULL;
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
{
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
@ -99,6 +152,7 @@ static NSZone *menuZone = NULL;
menu_is_tornoff = NO;
menu_is_visible = NO;
menu_follow_transient = NO;
menu_is_beholdenToPopUpButton = NO;
menu_changed = YES;
/* 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 isKindOfClass: [NSMenuItemCell class]])
if ([(id)newItem isKindOfClass: [NSMenuItemCell class]]
|| [(id)newItem isKindOfClass: [NSPopUpButtonCell class]])
{
nc = [NSNotificationCenter defaultCenter];
d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:index]
@ -194,7 +249,15 @@ static NSZone *menuZone = NULL;
keyEquivalent: (NSString *)charCode
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 setAction: aSelector];
@ -238,7 +301,8 @@ static NSZone *menuZone = NULL;
if (!anItem)
return;
if ([(NSMenuItemCell *)anItem isKindOfClass: [NSMenuItemCell class]])
if ([(NSMenuItemCell *)anItem isKindOfClass: [NSMenuItemCell class]]
|| [(id)anItem isKindOfClass: [NSPopUpButtonCell class]])
{
nc = [NSNotificationCenter defaultCenter];
d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:index]
@ -318,7 +382,8 @@ static NSZone *menuZone = NULL;
- (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");
return -1;
@ -354,6 +419,16 @@ static NSZone *menuZone = NULL;
- (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;
}
@ -619,14 +694,26 @@ static NSZone *menuZone = NULL;
[menu_view sizeToFit];
mFrame = [menu_view frame];
[titleView setFrameOrigin: NSMakePoint(0, mFrame.size.height)];
[titleView setFrameSize: NSMakeSize (mFrame.size.width,21)];
size.width = mFrame.size.width;
size.height = mFrame.size.height+21;
[aWindow setFrame: NSMakeRect(300,300,size.width,size.height) display: NO];
[bWindow setFrame: NSMakeRect(300,300,size.width,size.height) display: NO];
size.height = mFrame.size.height;
if (!menu_is_beholdenToPopUpButton)
{
[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_changed = NO;
@ -698,7 +785,7 @@ static NSZone *menuZone = NULL;
}
menu_is_visible = YES;
[aWindow orderFront:self];
[aWindow orderFront:nil];
}
- (void) displayTransient

View file

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

View file

@ -72,310 +72,300 @@
- (id)initWithFrame:(NSRect)frameRect
pullsDown:(BOOL)flag
{
[super initWithFrame:frameRect];
list_items = [NSMutableArray new];
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
popb_view = [[NSMenuView alloc] initWithFrame:frameRect
cellSize: NSMakeSize (frameRect.size.width,
frameRect.size.height)];
[popb_view setPopUpButton: self];
[super initWithFrame:frameRect];
/* Create our menu */
popb_menu = [[NSMenu alloc] initWithPopUpButton:self];
is_up = NO;
pulls_down = flag;
selected_item = 0;
popb_pullsDown = flag;
popb_selectedItem = 0;
[super setTarget: self];
popb_win = [[NSMenuWindow alloc] initWithContentRect: frameRect
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreRetained
defer: NO];
/*
* Set ourselves up to recieve the notification when we need to popup
* the menu.
*/
[popb_win setContentView: popb_view];
[defaultCenter addObserver: self
selector: @selector(_popup:)
name: NSPopUpButtonWillPopUpNotification
object: self];
return self;
}
- (void) close
- (void)setMenu:(NSMenu *)menu
{
[popb_win orderOut: self];
}
- (void) dealloc
- (NSMenu *)menu
{
[list_items release];
[super dealloc];
return popb_menu;
}
//
// Target and Action
//
- (SEL)action
- (void)setPullsDown:(BOOL)flag
{
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;
}
- (void)setAction:(SEL)aSelector
{
pub_action = aSelector;
}
- (id)target
{
return pub_target;
}
- (void)setTarget:(id)anObject
{
pub_target = anObject;
}
- (void)buttonSelected:(id)sender
- (void)_buttonPressed:(id)sender
{
if (!pulls_down)
selected_item = [self indexOfItemWithTitle:[sender title]];
if (!popb_pullsDown)
popb_selectedItem = [self indexOfItemWithRepresentedObject:[sender representedObject]];
else
selected_item = 0;
popb_selectedItem = 0;
[self synchronizeTitleAndSelectedItem];
[self close];
[self lockFocus];
[self drawRect:[self frame]];
[self unlockFocus];
[self setNeedsDisplay:YES];
if (pub_target && pub_action)
[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
{
// if (!pulls_down)
// [list_items setIndexOfSelectedItem:selected_item];
// else
// [list_items setIndexOfSelectedItem:0];
// urph
}
//
// Displaying the NSPopUpButton's Items
//
- (BOOL)autoenablesItems
- (void)_popup:(NSNotification*)notification
{
return NO;
}
- (void)setAutoenablesItems:(BOOL)flag
{}
//
// Handle events
//
- (void)mouseDown:(NSEvent *)theEvent
{
NSNotificationCenter *nc;
NSPopUpButton *popb = [notification object];
NSPoint cP;
NSRect butf;
NSRect winf;
nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName: NSPopUpButtonWillPopUpNotification
object: self
userInfo: nil];
butf = [popb frame];
butf = [[popb superview] convertRect: butf toView: nil];
butf.origin = [[popb window] convertBaseToScreen: butf.origin];
/*
* Get frame of this button in window coordinates,
* and origin in screen coordinates.
*/
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]];
[[popb_menu menuView] sizeToFit];
winf = [NSMenuWindow frameRectForContentRect: [[popb_menu menuView] frame]
styleMask: [[popb_menu window] styleMask]];
/*
* Set popup window frame origin so that the top-left corner of the
* window lines up with the top-left corner of this button.
@ -393,31 +383,39 @@
//NSLog(@"butf %@", NSStringFromRect(butf));
//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_win orderFrontRegardless];
[popb_win display];
cP = [theEvent locationInWindow];
cP = [[self window] convertBaseToScreen: cP];
cP = [popb_win convertScreenToBase: cP];
[popb_view mouseDown:
[NSEvent mouseEventWithType: NSLeftMouseDragged
location: cP
// [[popb menu] sizeToFit];
[[[popb menu] window] setFrame: winf display:YES];
[[[popb menu] window] orderFront:nil];
}
- (void)mouseDown:(NSEvent *)theEvent
{
NSNotificationCenter *nc;
nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName: NSPopUpButtonWillPopUpNotification
object: self
userInfo: nil];
[[popb_menu menuView] mouseDown:
[NSEvent mouseEventWithType: NSLeftMouseDown
location: [[popb_menu window] mouseLocationOutsideOfEventStream]
modifierFlags: [theEvent modifierFlags]
timestamp: [theEvent timestamp]
windowNumber: [popb_win windowNumber]
windowNumber: [[popb_menu window] windowNumber]
context: [theEvent context]
eventNumber: [theEvent eventNumber]
clickCount: [theEvent clickCount]
pressure: [theEvent pressure]]];
}
/*
- (void)mouseUp:(NSEvent *)theEvent
{
NSPoint cP;
@ -440,10 +438,7 @@
[popb_win orderOut: nil];
}
- (void)mouseMoved:(NSEvent *)theEvent
{
}
*/
- (NSView *)hitTest:(NSPoint)aPoint
{
@ -461,13 +456,13 @@
{
id aCell;
if ([list_items count] == 0)
if ([popb_menu numberOfItems] == 0)
return;
if (!pulls_down)
aCell = [list_items objectAtIndex:selected_item];
if (!popb_pullsDown)
aCell = [[popb_menu itemArray] objectAtIndex:popb_selectedItem];
else
aCell = [list_items objectAtIndex:0];
aCell = [[popb_menu itemArray] objectAtIndex:0];
[aCell drawWithFrame:rect inView:self];
}
@ -478,7 +473,7 @@
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[super encodeWithCoder: aCoder];
/*
[aCoder encodeObject: list_items];
[aCoder encodeRect: list_rect];
[aCoder encodeValueOfObjCType: @encode(int) at: &selected_item];
@ -486,12 +481,13 @@
[aCoder encodeValueOfObjCType: @encode(SEL) at: &pub_action];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &is_up];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &pulls_down];
*/
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
/*
[aDecoder decodeValueOfObjCType: @encode(id) at: &list_items];
list_rect = [aDecoder decodeRect];
[aDecoder decodeValueOfObjCType: @encode(int) at: &selected_item];
@ -499,8 +495,7 @@
[aDecoder decodeValueOfObjCType: @encode(SEL) at: &pub_action];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &is_up];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &pulls_down];
*/
return self;
}
@end

View file

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

View file

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

View file

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

View file

@ -1,3 +1,5 @@
#include <AppKit/NSTableView.h>
@implementation NSTableView
- (id)initWithFrame:(NSRect)frameRect
{
@ -13,10 +15,14 @@
- (void)setDataSource:(id)anObject
{
// This method raises an NSInternalInconistencyException if anObject
// doesn't respond to either
// numberOfRowsInTableView: or tableView:objectValueForTableColumn:row:.
if (![anObject respondsToSelector: @selector (numberOfRowsInTableView:)]
|| ![anObject respondsToSelector: @selector
(tableView:objectValueForTableColumn:row:)])
{
[NSException raise: NSInternalInconsistencyException
format: @"Assigned data source does not respond to needed
methods."];
}
ASSIGN(tb_datasource, anObject);
@ -419,7 +425,8 @@ object with the NSTableView as the text delegate. */
//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
@ -554,8 +561,23 @@ object with the NSTableView as the text delegate. */
for (i=0;i<colsToDraw.length;i++)
{
// tableView:willDisplayCell:forTableColumn:row:
// now draw the cell.
NSCell *aCell = [[tbv_columns objectAtIndex:i] dataCell];
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];
}
// 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