NSPopUpButton/XGPopUpButton additions.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4424 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Michael Silva 1999-06-17 21:07:38 +00:00
parent 8ab2a93c25
commit 27853bc47b
4 changed files with 101 additions and 27 deletions

View file

@ -1,3 +1,11 @@
1999-06-17 Michael Hanni <mhanni@sprintmail.com>
* Source/NSPopUpButton.m: half way implemented. Most still in
backend, but that will change soon. PopUp and PullDown work,
however the entire event mechanism needs to be implemented.
* Tools/Functions.m: added definitions for new NSDraw* functions
used in NSPopUp.
Thu Jun 17 16:20:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSTextContainer.m: New by jagapen@whitewater.chem.wisc.edu

View file

@ -31,6 +31,7 @@
#include <AppKit/NSButton.h>
#include <AppKit/NSMenuItem.h>
#include <AppKit/NSMenu.h>
@class NSString;
@class NSArray;
@ -39,10 +40,16 @@
@class NSFont;
@class NSMatrix;
@interface NSPopUpButtonMatrix : NSMenuMatrix
{
}
- (id) initWithFrame: (NSRect)rect;
@end
@interface NSPopUpButton : NSButton <NSCoding>
{
// Attributes
NSMutableArray *list_items;
NSPopUpButtonMatrix *list_items;
NSRect list_rect;
int selected_item;
id pub_target;

View file

@ -7,6 +7,8 @@
Author: Scott Christley <scottc@net-community.com>
Date: 1996
Author: Michael Hanni <mhanni@sprintmail.com>
Date: June 1999
This file is part of the GNUstep GUI Library.
@ -32,6 +34,41 @@
#include <AppKit/NSApplication.h>
#include <AppKit/NSMenu.h>
@implementation NSPopUpButtonMatrix
- (id) initWithFrame: (NSRect)rect
{
[super initWithFrame: rect];
cellSize = NSMakeSize (rect.size.width, rect.size.height);
return self;
}
- (void) _resizeMenuForCellSize
{
}
/* This is here so we can overide the use of NSMenuItem with
NSPopUpButtonCell once that cellClass is finished.
- (id <NSMenuItem>)insertItemWithTitle: (NSString*)aString
action: (SEL)aSelector
keyEquivalent: (NSString*)charCode
atIndex: (unsigned int)index
{
id menuCell = [[[NSPopUpButton cellClass] new] autorelease];
[menuCell setFont: menuFont];
[menuCell setTitle: aString];
[menuCell setAction: aSelector];
[menuCell setKeyEquivalent: charCode];
[cells insertObject: menuCell atIndex: index];
return menuCell;
}
*/
@end
//
// NSPopUpButton implementation
//
@ -67,7 +104,7 @@
pullsDown:(BOOL)flag
{
[super initWithFrame:frameRect];
list_items = [NSMutableArray new];
list_items = [[NSPopUpButtonMatrix alloc] initWithFrame:frameRect];
is_up = NO;
pulls_down = flag;
selected_item = 0;
@ -109,10 +146,10 @@
//
- (void)addItemWithTitle:(NSString *)title
{
id item = [[[NSMenu cellClass] new] autorelease];
[list_items addObject:item];
[item setTitle:title];
[list_items insertItemWithTitle:title
action:nil
keyEquivalent:nil
atIndex:[[list_items itemArray] count]];
[self synchronizeTitleAndSelectedItem];
}
@ -127,10 +164,10 @@
- (void)insertItemWithTitle:(NSString *)title
atIndex:(unsigned int)index
{
id item = [[[NSMenu cellClass] new] autorelease];
[list_items insertObject:item atIndex:index];
[item setTitle:title];
[list_items insertItemWithTitle:title
action:@selector(iveBeenHitCaptain:)
keyEquivalent:nil
atIndex:index];
[self synchronizeTitleAndSelectedItem];
}
@ -139,7 +176,7 @@
//
- (void)removeAllItems
{
[list_items removeAllObjects];
[(NSMutableArray *)[list_items itemArray] removeAllObjects];
}
- (void)removeItemWithTitle:(NSString *)title
@ -147,12 +184,12 @@
int index = [self indexOfItemWithTitle:title];
if (index != NSNotFound)
[list_items removeObjectAtIndex:index];
[(NSMutableArray *)[list_items itemArray] removeObjectAtIndex:index];
}
- (void)removeItemAtIndex:(int)index
{
[list_items removeObjectAtIndex:index];
[(NSMutableArray *)[list_items itemArray] removeObjectAtIndex:index];
}
//
@ -160,10 +197,10 @@
//
- (int)indexOfItemWithTitle:(NSString *)title
{
int i, count = [list_items count];
int i, count = [[list_items itemArray] count];
for (i = 0; i < count; i++)
if ([[[list_items objectAtIndex:i] title] isEqual:title])
if ([[[[list_items itemArray] objectAtIndex:i] title] isEqual:title])
return i;
return NSNotFound;
@ -176,31 +213,31 @@
- (int)numberOfItems
{
return [list_items count];
return [[list_items itemArray] count];
}
- (id <NSMenuItem>)itemAtIndex:(int)index
{
return [list_items objectAtIndex:index];
return [[list_items itemArray] objectAtIndex:index];
}
- (NSArray *)itemArray
{
return list_items;
return [list_items itemArray];
}
- (NSString *)itemTitleAtIndex:(int)index
{
return [[list_items objectAtIndex:index] title];
return [[[list_items itemArray] objectAtIndex:index] title];
}
- (NSArray *)itemTitles
{
int i, count = [list_items count];
int i, count = [[list_items itemArray] count];
NSMutableArray* titles = [NSMutableArray arrayWithCapacity:count];
for (i = 0; i < count; i++)
[titles addObject:[[list_items objectAtIndex:i] title]];
[titles addObject:[[[list_items itemArray] objectAtIndex:i] title]];
return titles;
}
@ -210,21 +247,21 @@
int index = [self indexOfItemWithTitle:title];
if (index != NSNotFound)
return [list_items objectAtIndex:index];
return [[list_items itemArray] objectAtIndex:index];
return nil;
}
- (id <NSMenuItem>)lastItem
{
if ([list_items count])
return [list_items lastObject];
if ([[list_items itemArray] count])
return [[list_items itemArray] lastObject];
else
return nil;
}
- (id <NSMenuItem>)selectedItem
{
return [list_items objectAtIndex:selected_item];
return [[list_items itemArray] objectAtIndex:selected_item];
}
- (NSString *)titleOfSelectedItem
@ -247,7 +284,7 @@
- (void)selectItemAtIndex:(int)index
{
if ((index >= 0) && (index < [list_items count]))
if ((index >= 0) && (index < [[list_items itemArray] count]))
{
selected_item = index;
[self synchronizeTitleAndSelectedItem];
@ -298,10 +335,12 @@
//
- (void)mouseDown:(NSEvent *)theEvent
{
NSLog(@"mouseDown:");
}
- (void)mouseUp:(NSEvent *)theEvent
{
NSLog(@"mouseUp:");
}
- (void)mouseMoved:(NSEvent *)theEvent
@ -310,8 +349,11 @@
- (NSView *)hitTest:(NSPoint)aPoint
{
NSLog(@"hitTest:");
// First check ourselves
if ([self mouse:aPoint inRect:bounds]) return self;
// if ([self mouse:aPoint inRect:bounds]) return self;
if ([self mouse:aPoint inRect:[self frame]]) return self;
return nil;
}
@ -321,6 +363,19 @@
//
- (void)drawRect:(NSRect)rect
{
id aCell;
aCell = [[list_items itemArray] objectAtIndex:selected_item];
[aCell drawWithFrame:rect inView: self];
rect.origin.x = rect.size.width - 14;
rect.origin.y = rect.size.height/2 - 3;
if (pulls_down == NO)
NSDrawPopupNibble(NSMakePoint(rect.origin.x, rect.origin.y));
else
NSDrawDownArrow(NSMakePoint(rect.origin.x, rect.origin.y));
}
//

View file

@ -55,6 +55,10 @@ void NSDrawGrayBezel(NSRect aRect, NSRect clipRect)
{}
void NSDrawGroove(NSRect aRect, NSRect clipRect)
{}
void NSDrawPopupNibble(NSPoint aPoint)
{}
void NSDrawDownArrow(NSPoint aPoint)
{}
void PSlineto(float x, float y)
{}
void PSmoveto(float x, float y)