mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 03:40:47 +00:00
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:
parent
8ab2a93c25
commit
27853bc47b
4 changed files with 101 additions and 27 deletions
|
@ -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>
|
Thu Jun 17 16:20:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
* Source/NSTextContainer.m: New by jagapen@whitewater.chem.wisc.edu
|
* Source/NSTextContainer.m: New by jagapen@whitewater.chem.wisc.edu
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include <AppKit/NSButton.h>
|
#include <AppKit/NSButton.h>
|
||||||
#include <AppKit/NSMenuItem.h>
|
#include <AppKit/NSMenuItem.h>
|
||||||
|
#include <AppKit/NSMenu.h>
|
||||||
|
|
||||||
@class NSString;
|
@class NSString;
|
||||||
@class NSArray;
|
@class NSArray;
|
||||||
|
@ -39,10 +40,16 @@
|
||||||
@class NSFont;
|
@class NSFont;
|
||||||
@class NSMatrix;
|
@class NSMatrix;
|
||||||
|
|
||||||
|
@interface NSPopUpButtonMatrix : NSMenuMatrix
|
||||||
|
{
|
||||||
|
}
|
||||||
|
- (id) initWithFrame: (NSRect)rect;
|
||||||
|
@end
|
||||||
|
|
||||||
@interface NSPopUpButton : NSButton <NSCoding>
|
@interface NSPopUpButton : NSButton <NSCoding>
|
||||||
{
|
{
|
||||||
// Attributes
|
// Attributes
|
||||||
NSMutableArray *list_items;
|
NSPopUpButtonMatrix *list_items;
|
||||||
NSRect list_rect;
|
NSRect list_rect;
|
||||||
int selected_item;
|
int selected_item;
|
||||||
id pub_target;
|
id pub_target;
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
Author: Scott Christley <scottc@net-community.com>
|
Author: Scott Christley <scottc@net-community.com>
|
||||||
Date: 1996
|
Date: 1996
|
||||||
|
Author: Michael Hanni <mhanni@sprintmail.com>
|
||||||
|
Date: June 1999
|
||||||
|
|
||||||
This file is part of the GNUstep GUI Library.
|
This file is part of the GNUstep GUI Library.
|
||||||
|
|
||||||
|
@ -32,6 +34,41 @@
|
||||||
#include <AppKit/NSApplication.h>
|
#include <AppKit/NSApplication.h>
|
||||||
#include <AppKit/NSMenu.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
|
// NSPopUpButton implementation
|
||||||
//
|
//
|
||||||
|
@ -67,7 +104,7 @@
|
||||||
pullsDown:(BOOL)flag
|
pullsDown:(BOOL)flag
|
||||||
{
|
{
|
||||||
[super initWithFrame:frameRect];
|
[super initWithFrame:frameRect];
|
||||||
list_items = [NSMutableArray new];
|
list_items = [[NSPopUpButtonMatrix alloc] initWithFrame:frameRect];
|
||||||
is_up = NO;
|
is_up = NO;
|
||||||
pulls_down = flag;
|
pulls_down = flag;
|
||||||
selected_item = 0;
|
selected_item = 0;
|
||||||
|
@ -109,10 +146,10 @@
|
||||||
//
|
//
|
||||||
- (void)addItemWithTitle:(NSString *)title
|
- (void)addItemWithTitle:(NSString *)title
|
||||||
{
|
{
|
||||||
id item = [[[NSMenu cellClass] new] autorelease];
|
[list_items insertItemWithTitle:title
|
||||||
|
action:nil
|
||||||
[list_items addObject:item];
|
keyEquivalent:nil
|
||||||
[item setTitle:title];
|
atIndex:[[list_items itemArray] count]];
|
||||||
[self synchronizeTitleAndSelectedItem];
|
[self synchronizeTitleAndSelectedItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,10 +164,10 @@
|
||||||
- (void)insertItemWithTitle:(NSString *)title
|
- (void)insertItemWithTitle:(NSString *)title
|
||||||
atIndex:(unsigned int)index
|
atIndex:(unsigned int)index
|
||||||
{
|
{
|
||||||
id item = [[[NSMenu cellClass] new] autorelease];
|
[list_items insertItemWithTitle:title
|
||||||
|
action:@selector(iveBeenHitCaptain:)
|
||||||
[list_items insertObject:item atIndex:index];
|
keyEquivalent:nil
|
||||||
[item setTitle:title];
|
atIndex:index];
|
||||||
[self synchronizeTitleAndSelectedItem];
|
[self synchronizeTitleAndSelectedItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +176,7 @@
|
||||||
//
|
//
|
||||||
- (void)removeAllItems
|
- (void)removeAllItems
|
||||||
{
|
{
|
||||||
[list_items removeAllObjects];
|
[(NSMutableArray *)[list_items itemArray] removeAllObjects];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeItemWithTitle:(NSString *)title
|
- (void)removeItemWithTitle:(NSString *)title
|
||||||
|
@ -147,12 +184,12 @@
|
||||||
int index = [self indexOfItemWithTitle:title];
|
int index = [self indexOfItemWithTitle:title];
|
||||||
|
|
||||||
if (index != NSNotFound)
|
if (index != NSNotFound)
|
||||||
[list_items removeObjectAtIndex:index];
|
[(NSMutableArray *)[list_items itemArray] removeObjectAtIndex:index];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeItemAtIndex:(int)index
|
- (void)removeItemAtIndex:(int)index
|
||||||
{
|
{
|
||||||
[list_items removeObjectAtIndex:index];
|
[(NSMutableArray *)[list_items itemArray] removeObjectAtIndex:index];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -160,10 +197,10 @@
|
||||||
//
|
//
|
||||||
- (int)indexOfItemWithTitle:(NSString *)title
|
- (int)indexOfItemWithTitle:(NSString *)title
|
||||||
{
|
{
|
||||||
int i, count = [list_items count];
|
int i, count = [[list_items itemArray] count];
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
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 i;
|
||||||
|
|
||||||
return NSNotFound;
|
return NSNotFound;
|
||||||
|
@ -176,31 +213,31 @@
|
||||||
|
|
||||||
- (int)numberOfItems
|
- (int)numberOfItems
|
||||||
{
|
{
|
||||||
return [list_items count];
|
return [[list_items itemArray] count];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id <NSMenuItem>)itemAtIndex:(int)index
|
- (id <NSMenuItem>)itemAtIndex:(int)index
|
||||||
{
|
{
|
||||||
return [list_items objectAtIndex:index];
|
return [[list_items itemArray] objectAtIndex:index];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *)itemArray
|
- (NSArray *)itemArray
|
||||||
{
|
{
|
||||||
return list_items;
|
return [list_items itemArray];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)itemTitleAtIndex:(int)index
|
- (NSString *)itemTitleAtIndex:(int)index
|
||||||
{
|
{
|
||||||
return [[list_items objectAtIndex:index] title];
|
return [[[list_items itemArray] objectAtIndex:index] title];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *)itemTitles
|
- (NSArray *)itemTitles
|
||||||
{
|
{
|
||||||
int i, count = [list_items count];
|
int i, count = [[list_items itemArray] count];
|
||||||
NSMutableArray* titles = [NSMutableArray arrayWithCapacity:count];
|
NSMutableArray* titles = [NSMutableArray arrayWithCapacity:count];
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
[titles addObject:[[list_items objectAtIndex:i] title]];
|
[titles addObject:[[[list_items itemArray] objectAtIndex:i] title]];
|
||||||
|
|
||||||
return titles;
|
return titles;
|
||||||
}
|
}
|
||||||
|
@ -210,21 +247,21 @@
|
||||||
int index = [self indexOfItemWithTitle:title];
|
int index = [self indexOfItemWithTitle:title];
|
||||||
|
|
||||||
if (index != NSNotFound)
|
if (index != NSNotFound)
|
||||||
return [list_items objectAtIndex:index];
|
return [[list_items itemArray] objectAtIndex:index];
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id <NSMenuItem>)lastItem
|
- (id <NSMenuItem>)lastItem
|
||||||
{
|
{
|
||||||
if ([list_items count])
|
if ([[list_items itemArray] count])
|
||||||
return [list_items lastObject];
|
return [[list_items itemArray] lastObject];
|
||||||
else
|
else
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id <NSMenuItem>)selectedItem
|
- (id <NSMenuItem>)selectedItem
|
||||||
{
|
{
|
||||||
return [list_items objectAtIndex:selected_item];
|
return [[list_items itemArray] objectAtIndex:selected_item];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)titleOfSelectedItem
|
- (NSString *)titleOfSelectedItem
|
||||||
|
@ -247,7 +284,7 @@
|
||||||
|
|
||||||
- (void)selectItemAtIndex:(int)index
|
- (void)selectItemAtIndex:(int)index
|
||||||
{
|
{
|
||||||
if ((index >= 0) && (index < [list_items count]))
|
if ((index >= 0) && (index < [[list_items itemArray] count]))
|
||||||
{
|
{
|
||||||
selected_item = index;
|
selected_item = index;
|
||||||
[self synchronizeTitleAndSelectedItem];
|
[self synchronizeTitleAndSelectedItem];
|
||||||
|
@ -298,10 +335,12 @@
|
||||||
//
|
//
|
||||||
- (void)mouseDown:(NSEvent *)theEvent
|
- (void)mouseDown:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
|
NSLog(@"mouseDown:");
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseUp:(NSEvent *)theEvent
|
- (void)mouseUp:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
|
NSLog(@"mouseUp:");
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseMoved:(NSEvent *)theEvent
|
- (void)mouseMoved:(NSEvent *)theEvent
|
||||||
|
@ -310,8 +349,11 @@
|
||||||
|
|
||||||
- (NSView *)hitTest:(NSPoint)aPoint
|
- (NSView *)hitTest:(NSPoint)aPoint
|
||||||
{
|
{
|
||||||
|
NSLog(@"hitTest:");
|
||||||
|
|
||||||
// First check ourselves
|
// 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;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -321,6 +363,19 @@
|
||||||
//
|
//
|
||||||
- (void)drawRect:(NSRect)rect
|
- (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));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -55,6 +55,10 @@ void NSDrawGrayBezel(NSRect aRect, NSRect clipRect)
|
||||||
{}
|
{}
|
||||||
void NSDrawGroove(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 PSlineto(float x, float y)
|
||||||
{}
|
{}
|
||||||
void PSmoveto(float x, float y)
|
void PSmoveto(float x, float y)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue