mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 13:50:37 +00:00
Fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4603 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ed083c7e2c
commit
5e552d5091
9 changed files with 233 additions and 359 deletions
22
ChangeLog
22
ChangeLog
|
@ -1,3 +1,25 @@
|
|||
1999-07-17 Michael Hanni <mhanni@sprintmail.com>
|
||||
|
||||
* Headers/gnustep/gui/NSMenuView.h: added new private interface.
|
||||
* Headers/gnustep/gui/NSPopUpButton.h: removed NSPopUpButtonMatrix
|
||||
and tidied some ivars.
|
||||
* Source/NSMenu.m: fixed a few problems.
|
||||
* Source/NSMenuItemCell.m: likewise.
|
||||
* Source/NSMenuView.m: added functionality (privately) so this
|
||||
class can be used to draw NSPopUpButton. Also made sizeToFit code
|
||||
only size the view, not the window.
|
||||
* Source/NSPopUpButton.m: removed NSPopUpButtonMatrix. Rewrote to
|
||||
use NSMenuView.
|
||||
* Source/NSPopUpButtonCell.m: rewrote portions to handle new
|
||||
system of NSMenuView.
|
||||
|
||||
1999-07-16 Michael Hanni <mhanni@sprintmail.com>
|
||||
|
||||
* Source/NSText.m: add a patch to NSText from Daniel to do some
|
||||
pasteboard related stuff. Also added a patch from Peter Rasmussen
|
||||
that addressed my hackish NSClipView scrolling code. Still a hack,
|
||||
but won't kill NSText if not used in conjunction with a ClipView.
|
||||
|
||||
1999-07-15 Michael Hanni <mhanni@sprintmail.com>
|
||||
|
||||
* Source/NSPopupButton.m: if (count) == 0, return early in drawing
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <AppKit/NSMenuItemCell.h>
|
||||
#include <AppKit/NSScreen.h>
|
||||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSPopUpButton.h>
|
||||
|
||||
@class NSFont;
|
||||
|
||||
|
@ -59,6 +60,9 @@
|
|||
float menuv_keyEqWidth;
|
||||
BOOL menuv_needsSizing;
|
||||
NSSize cellSize;
|
||||
@private
|
||||
NSPopUpButton *menuv_popb;
|
||||
id menuv_items_link;
|
||||
}
|
||||
+ (float)menuBarHeight;
|
||||
|
||||
|
@ -108,4 +112,11 @@
|
|||
- (BOOL)trackWithEvent:(NSEvent *)event;
|
||||
@end
|
||||
|
||||
@interface NSMenuView (Private)
|
||||
- (id) initWithFrame: (NSRect)aFrame
|
||||
cellSize: (NSSize)aSize;
|
||||
- (void) setPopUpButton: (NSPopUpButton *)popb;
|
||||
- (NSPopUpButton *) popupButton;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
Author: Michael Hanni <mhanni@sprintmail.com>
|
||||
Date: 1999
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -41,40 +43,11 @@
|
|||
@class NSMatrix;
|
||||
@class NSPopUpButton;
|
||||
|
||||
@interface NSPopUpButtonMatrix : NSControl <NSCopying>
|
||||
{
|
||||
NSMutableArray* cells;
|
||||
NSSize cellSize;
|
||||
NSMenu* menu;
|
||||
id selectedCell;
|
||||
NSRect selectedCellRect;
|
||||
BOOL pull_down;
|
||||
int selected_cell;
|
||||
NSPopUpButton *popup_button;
|
||||
}
|
||||
- initWithFrame:(NSRect)rect;
|
||||
- (id <NSMenuItem>)insertItemWithTitle:(NSString*)aString
|
||||
action:(SEL)aSelector
|
||||
keyEquivalent:(NSString*)charCode
|
||||
atIndex:(unsigned int)index;
|
||||
- (void)removeItem:(id <NSMenuItem>)anItem;
|
||||
- (NSArray*)itemArray;
|
||||
- (id <NSMenuItem>)itemWithTitle:(NSString*)aString;
|
||||
- (id <NSMenuItem>)itemWithTag:(int)aTag;
|
||||
- (NSRect)cellFrameAtRow:(int)index;
|
||||
- (NSSize)cellSize;
|
||||
- (void)setMenu:(NSMenu*)menu;
|
||||
- (void)setSelectedCell:(id)aCell;
|
||||
- (id)selectedCell;
|
||||
- (NSRect)selectedCellRect;
|
||||
- (void)setPopUpButton:(NSPopUpButton *)popb;
|
||||
- (void) setIndexOfSelectedItem:(int)itemNum;
|
||||
@end
|
||||
|
||||
@interface NSPopUpButton : NSButton <NSCoding>
|
||||
{
|
||||
// Attributes
|
||||
NSPopUpButtonMatrix *list_items;
|
||||
NSMutableArray *list_items;
|
||||
NSMenuView *popb_view;
|
||||
NSRect list_rect;
|
||||
int selected_item;
|
||||
id pub_target;
|
||||
|
|
|
@ -3,6 +3,16 @@
|
|||
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
Author: Michael Hanni <mhanni@sprintmail.com>
|
||||
Date: 1999
|
||||
|
||||
A completely rewritten version of the original source by Scott Christley.
|
||||
and:
|
||||
Author: Ovidiu Predescu <ovidiu@net-community.com>
|
||||
Date: May 1997
|
||||
and:
|
||||
Author: Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
Date: July 1998
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -103,9 +113,9 @@ static NSZone *menuZone = NULL;
|
|||
- (void)insertItem:(id <NSMenuItem>)newItem
|
||||
atIndex:(int)index
|
||||
{
|
||||
if ([newItem conformsToProtocol:@protocol(NSMenuItem)])
|
||||
if ([(id)newItem conformsToProtocol:@protocol(NSMenuItem)])
|
||||
{
|
||||
if ([newItem isKindOfClass:[NSMenuItemCell class]])
|
||||
if ([(id)newItem isKindOfClass:[NSMenuItemCell class]])
|
||||
[menu_items insertObject:newItem atIndex:index];
|
||||
else
|
||||
{
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
Author: Michael Hanni <mhanni@sprintmail.com>
|
||||
Date: 1999
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
Author: Michael Hanni <mhanni@sprintmail.com>
|
||||
Date: 1999
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -30,6 +32,9 @@
|
|||
|
||||
static float GSMenuBarHeight = 25.0; // a guess.
|
||||
|
||||
// These private methods are used in NSPopUpButton. For NSPB we need to be
|
||||
// able to init with a frame, but have a very custom cell size.
|
||||
|
||||
@implementation NSMenuView
|
||||
|
||||
// Class methods.
|
||||
|
@ -59,11 +64,22 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
return [super initWithFrame: aFrame];
|
||||
}
|
||||
|
||||
- (id)initWithFrame: (NSRect)aFrame
|
||||
cellSize: (NSSize)aSize
|
||||
{
|
||||
[self initWithFrame:aFrame];
|
||||
|
||||
cellSize = aSize;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// Our menu.
|
||||
|
||||
- (void)setMenu: (NSMenu *)menu
|
||||
{
|
||||
ASSIGN(menuv_menu, menu);
|
||||
menuv_items_link = [menuv_menu itemArray];
|
||||
}
|
||||
|
||||
- (NSMenu *)menu
|
||||
|
@ -71,6 +87,19 @@ 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;
|
||||
|
@ -110,7 +139,6 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
|
||||
- (void)setHighlightedItemIndex: (int)index
|
||||
{
|
||||
NSArray *menu_items = [menuv_menu itemArray];
|
||||
id anItem;
|
||||
BOOL _closeASubmenu = NO;
|
||||
|
||||
|
@ -118,17 +146,21 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
|
||||
if (index == -1) {
|
||||
if (menuv_highlightedItemIndex != -1) {
|
||||
anItem = [menu_items objectAtIndex: menuv_highlightedItemIndex];
|
||||
anItem = [menuv_items_link objectAtIndex: menuv_highlightedItemIndex];
|
||||
|
||||
[anItem highlight: NO
|
||||
withFrame: [self rectOfItemAtIndex: menuv_highlightedItemIndex]
|
||||
inView: self];
|
||||
|
||||
if ([anItem hasSubmenu] && ![[anItem target] isTornOff])
|
||||
[[anItem target] close];
|
||||
|
||||
[anItem setState: 0];
|
||||
menuv_highlightedItemIndex = -1;
|
||||
}
|
||||
} else if (index >= 0) {
|
||||
if ( menuv_highlightedItemIndex != -1 ) {
|
||||
anItem = [menu_items objectAtIndex: menuv_highlightedItemIndex];
|
||||
anItem = [menuv_items_link objectAtIndex: menuv_highlightedItemIndex];
|
||||
|
||||
[anItem highlight: NO
|
||||
withFrame: [self rectOfItemAtIndex: menuv_highlightedItemIndex]
|
||||
|
@ -141,7 +173,7 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
}
|
||||
|
||||
if (menuv_highlightedItemIndex != index) {
|
||||
anItem = [menu_items objectAtIndex: index];
|
||||
anItem = [menuv_items_link objectAtIndex: index];
|
||||
|
||||
[anItem highlight: YES
|
||||
withFrame: [self rectOfItemAtIndex: index]
|
||||
|
@ -149,7 +181,7 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
|
||||
[anItem setState: 1];
|
||||
|
||||
if ([anItem hasSubmenu])
|
||||
if ([anItem hasSubmenu] && ![[anItem target] isTornOff])
|
||||
[[anItem target] display];
|
||||
|
||||
// set ivar to new index
|
||||
|
@ -181,7 +213,7 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
|
||||
- (NSMenuItemCell *)menuItemCellForItemAtIndex: (int)index
|
||||
{
|
||||
return [[menuv_menu itemArray] objectAtIndex: index];
|
||||
return [menuv_items_link objectAtIndex: index];
|
||||
}
|
||||
|
||||
- (NSMenuView *)attachedMenuView
|
||||
|
@ -260,15 +292,15 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
- (void)sizeToFit
|
||||
{
|
||||
int i;
|
||||
int howMany = [[menuv_menu itemArray] count];
|
||||
int howHigh = (howMany * cellSize.height) + 21;
|
||||
int howMany = [menuv_items_link count];
|
||||
int howHigh = (howMany * cellSize.height);
|
||||
float neededWidth = 0;
|
||||
|
||||
for (i=0;i<[[menuv_menu itemArray] count];i++)
|
||||
for (i=0;i<howMany;i++)
|
||||
{
|
||||
float aWidth;
|
||||
|
||||
NSMenuItemCell *anItem = [[menuv_menu itemArray] objectAtIndex: i];
|
||||
NSMenuItemCell *anItem = [menuv_items_link objectAtIndex: i];
|
||||
aWidth = [anItem titleWidth];
|
||||
|
||||
if (aWidth > neededWidth)
|
||||
|
@ -277,8 +309,13 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
|
||||
cellSize.width = 7 + neededWidth + 7 + 7 + 5;
|
||||
|
||||
[[self window] setFrame: NSMakeRect(300,300,cellSize.width,howHigh) display: YES];
|
||||
[self setFrame: NSMakeRect(0,0,cellSize.width,howHigh-21)];
|
||||
[self setFrame: NSMakeRect(0,0,cellSize.width,howHigh)];
|
||||
}
|
||||
|
||||
- (void)sizeToFitForPopUpButton
|
||||
{
|
||||
int howHigh = ([menuv_items_link count] * cellSize.height);
|
||||
[self setFrame: NSMakeRect(0,0,cellSize.width,howHigh)];
|
||||
}
|
||||
|
||||
- (float)stateImageOffset
|
||||
|
@ -368,7 +405,7 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
|
||||
- (void)setNeedsDisplayForItemAtIndex: (int)index
|
||||
{
|
||||
[[[menuv_menu itemArray] objectAtIndex: index] setNeedsDisplay: YES];
|
||||
[[menuv_items_link objectAtIndex: index] setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
- (NSPoint)locationForSubmenu: (NSMenu *)aSubmenu
|
||||
|
@ -402,18 +439,18 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
- (void)drawRect: (NSRect)rect
|
||||
{
|
||||
int i;
|
||||
NSArray *menuCells = [menuv_menu itemArray];
|
||||
NSRect aRect = [self frame];
|
||||
int howMany = [menuv_items_link count];
|
||||
|
||||
// This code currently doesn't take intercell spacing into account. I'll
|
||||
// need to fix that.
|
||||
|
||||
aRect.origin.y = cellSize.height * ([menuCells count] - 1);
|
||||
aRect.origin.y = cellSize.height * (howMany - 1);
|
||||
aRect.size = cellSize;
|
||||
|
||||
for (i=0;i<[menuCells count];i++)
|
||||
for (i=0;i<howMany;i++)
|
||||
{
|
||||
id aCell = [menuCells objectAtIndex: i];
|
||||
id aCell = [menuv_items_link objectAtIndex: i];
|
||||
|
||||
[aCell drawWithFrame: aRect inView: self];
|
||||
aRect.origin.y -= cellSize.height;
|
||||
|
@ -439,7 +476,7 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
BOOL done = NO;
|
||||
NSApplication *theApp = [NSApplication sharedApplication];
|
||||
NSDate *theDistantFuture = [NSDate distantFuture];
|
||||
int theCount = [[menuv_menu itemArray] count];
|
||||
int theCount = [menuv_items_link count];
|
||||
id selectedCell;
|
||||
|
||||
// These 3 BOOLs are misnomers. I'll rename them later. -Michael. FIXME.
|
||||
|
@ -519,7 +556,7 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
NSRect aRect = [self rectOfItemAtIndex: lastIndex];
|
||||
if (lastLocation.y > aRect.origin.y
|
||||
&& lastLocation.y < aRect.origin.y + aRect.size.height
|
||||
&& [[[menuv_menu itemArray] objectAtIndex: lastIndex]
|
||||
&& [[menuv_items_link objectAtIndex: lastIndex]
|
||||
hasSubmenu])
|
||||
{
|
||||
weLeftMenu = YES;
|
||||
|
@ -569,25 +606,26 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
if (!weLeftMenu && !weRightMenu && !weWereOut
|
||||
&& menuv_highlightedItemIndex != -1)
|
||||
{
|
||||
if (![[[menuv_menu itemArray] objectAtIndex: menuv_highlightedItemIndex]
|
||||
if (![[menuv_items_link objectAtIndex: menuv_highlightedItemIndex]
|
||||
hasSubmenu])
|
||||
{
|
||||
BOOL finished = NO;
|
||||
NSMenu *aMenu = menuv_menu;
|
||||
|
||||
if (index >= 0 && index < theCount)
|
||||
selectedCell = [[menuv_menu itemArray] objectAtIndex: index];
|
||||
selectedCell = [menuv_items_link objectAtIndex: index];
|
||||
else
|
||||
selectedCell = nil;
|
||||
|
||||
[self setHighlightedItemIndex: -1];
|
||||
|
||||
if ([selectedCell action])
|
||||
[menuv_menu performActionForItem:
|
||||
[[menuv_menu itemArray] objectAtIndex: lastIndex]];
|
||||
NSLog(@"just mouseUp'ed.");
|
||||
|
||||
if ([selectedCell hasSubmenu])
|
||||
[[selectedCell target] close];
|
||||
if ([selectedCell action] && ![selectedCell target])
|
||||
[menuv_menu performActionForItem:
|
||||
[menuv_items_link objectAtIndex: lastIndex]];
|
||||
else
|
||||
[menuv_popb performSelector:[selectedCell action] withObject:selectedCell];
|
||||
|
||||
while (!finished)
|
||||
{ // "forward"cursive menu find.
|
||||
|
@ -606,7 +644,7 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
if ([aMenu supermenu] && ![aMenu isTornOff])
|
||||
{
|
||||
[[[aMenu supermenu] menuView] setHighlightedItemIndex: -1];
|
||||
[aMenu close];
|
||||
// [aMenu close];
|
||||
aMenu = [aMenu supermenu];
|
||||
}
|
||||
else
|
||||
|
@ -615,6 +653,17 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
[window flushWindow];
|
||||
}
|
||||
}
|
||||
else if ([[menuv_items_link objectAtIndex:
|
||||
menuv_highlightedItemIndex]
|
||||
hasSubmenu] && [[[menuv_items_link objectAtIndex:
|
||||
menuv_highlightedItemIndex] target] isTornOff])
|
||||
{
|
||||
// This code does not work. Please ignore. FIXME, Michael.
|
||||
// close transient.
|
||||
// [self setHighlightedItemIndex: -1];
|
||||
//
|
||||
// [[[menuv_menu supermenu] menuView] setHighlightedItemIndex: -1];
|
||||
}
|
||||
}
|
||||
else if (weRightMenu)
|
||||
{
|
||||
|
@ -653,7 +702,7 @@ static float GSMenuBarHeight = 25.0; // a guess.
|
|||
|
||||
NSLog(@"Urph.\n");
|
||||
|
||||
selectedCell = [[menuv_menu itemArray] objectAtIndex: lastIndex];
|
||||
selectedCell = [menuv_items_link objectAtIndex: lastIndex];
|
||||
if ([selectedCell hasSubmenu])
|
||||
{
|
||||
[self mouseUp:
|
||||
|
|
|
@ -34,243 +34,13 @@
|
|||
#include <AppKit/NSPopUpButtonCell.h>
|
||||
#include <AppKit/NSApplication.h>
|
||||
#include <AppKit/NSMenu.h>
|
||||
#include <AppKit/NSMenuView.h>
|
||||
#include <AppKit/NSFont.h>
|
||||
|
||||
@implementation NSPopUpButtonMatrix
|
||||
|
||||
// Class variables
|
||||
static NSFont* menuFont = nil;
|
||||
|
||||
- (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (id) initWithFrame: (NSRect)rect
|
||||
{
|
||||
[super initWithFrame: rect];
|
||||
cells = [NSMutableArray new];
|
||||
|
||||
selected_cell = 0;
|
||||
|
||||
cellSize = NSMakeSize (rect.size.width, rect.size.height);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
NSDebugLog (@"NSMenuMatrix of menu '%@' dealloc", [menu title]);
|
||||
|
||||
[cells release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
NSPopUpButtonMatrix* copy = [[isa allocWithZone: zone] initWithFrame: [self frame]];
|
||||
int i, count;
|
||||
|
||||
NSDebugLog (@"copy menu matrix of menu with title '%@'", [menu title]);
|
||||
for (i = 0, count = [cells count]; i < count; i++)
|
||||
{
|
||||
id aCell = [cells objectAtIndex: i];
|
||||
id cellCopy = [[aCell copyWithZone: zone] autorelease];
|
||||
|
||||
[copy->cells addObject: cellCopy];
|
||||
}
|
||||
|
||||
copy->cellSize = cellSize;
|
||||
copy->menu = menu;
|
||||
if (selectedCell)
|
||||
{
|
||||
int index = [cells indexOfObject: selectedCell];
|
||||
|
||||
copy->selectedCell = [[cells objectAtIndex: index] retain];
|
||||
}
|
||||
copy->selectedCellRect = selectedCellRect;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
- (void) _resizeMenuForCellSize
|
||||
{
|
||||
int i, count;
|
||||
float titleWidth;
|
||||
|
||||
/* Compute the new width of the menu cells matrix */
|
||||
cellSize.width = 0;
|
||||
count = [cells count];
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
titleWidth = [menuFont widthOfString:
|
||||
[[cells objectAtIndex: i] stringValue]];
|
||||
cellSize.width = MAX(titleWidth + ADDITIONAL_WIDTH, cellSize.width);
|
||||
}
|
||||
cellSize.width = MAX([menuFont widthOfString: [menu title]]
|
||||
+ ADDITIONAL_WIDTH,
|
||||
cellSize.width);
|
||||
|
||||
/* Resize the frame to hold all the menu cells */
|
||||
[super setFrameSize: NSMakeSize (cellSize.width,
|
||||
count ? (cellSize.height + INTERCELL_SPACE)*count - INTERCELL_SPACE : 0)];
|
||||
}
|
||||
|
||||
- (id <NSMenuItem>)insertItemWithTitle: (NSString*)aString
|
||||
action: (SEL)aSelector
|
||||
keyEquivalent: (NSString*)charCode
|
||||
atIndex: (unsigned int)index
|
||||
{
|
||||
id menuCell = [[NSPopUpButtonCell new] autorelease];
|
||||
|
||||
[menuCell setFont:[NSFont systemFontOfSize:12]];
|
||||
[menuCell setTitle: aString];
|
||||
// [menuCell setAction: aSelector];
|
||||
// [menuCell setKeyEquivalent: charCode];
|
||||
|
||||
[cells insertObject: menuCell atIndex: index];
|
||||
|
||||
return menuCell;
|
||||
}
|
||||
|
||||
- (void) setIndexOfSelectedItem:(int)itemNum
|
||||
{
|
||||
selected_cell = itemNum;
|
||||
}
|
||||
|
||||
- (NSString *)titleOfSelectedItem
|
||||
{
|
||||
return [[cells objectAtIndex:selected_cell] title];
|
||||
}
|
||||
|
||||
- (void)setPopUpButton:(NSPopUpButton *)popb
|
||||
{
|
||||
ASSIGN(popup_button, popb);
|
||||
}
|
||||
|
||||
- (void)setPullsDown:(BOOL)pull
|
||||
{
|
||||
pull_down = pull;
|
||||
}
|
||||
|
||||
- (BOOL)pullsDown
|
||||
{
|
||||
return pull_down;
|
||||
}
|
||||
|
||||
- (BOOL) performKeyEquivalent: (NSEvent*)theEvent
|
||||
{
|
||||
return [menu performKeyEquivalent: theEvent];
|
||||
}
|
||||
|
||||
- (void) removeItem: (id <NSMenuItem>)anItem
|
||||
{
|
||||
int row = [cells indexOfObject: anItem];
|
||||
|
||||
if (row == -1)
|
||||
return;
|
||||
|
||||
[cells removeObjectAtIndex: row];
|
||||
}
|
||||
|
||||
- (NSArray*) itemArray
|
||||
{
|
||||
return cells;
|
||||
}
|
||||
|
||||
- (id <NSMenuItem>) itemWithTitle: (NSString*)aString
|
||||
{
|
||||
unsigned i, count = [cells count];
|
||||
id menuCell;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
menuCell = [cells objectAtIndex: i];
|
||||
if ([[menuCell title] isEqual: aString])
|
||||
return menuCell;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id <NSMenuItem>) itemWithTag: (int)aTag
|
||||
{
|
||||
unsigned i, count = [cells count];
|
||||
id menuCell;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
menuCell = [cells objectAtIndex: i];
|
||||
if ([menuCell tag] == aTag)
|
||||
return menuCell;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSRect) cellFrameAtRow: (int)index
|
||||
{
|
||||
unsigned count = [cells count];
|
||||
NSRect rect;
|
||||
|
||||
NSAssert(index >= 0 && index < count+1, @"invalid row coordinate");
|
||||
|
||||
rect.origin.x = 0;
|
||||
rect.origin.y = (count - index - 1)
|
||||
* (cellSize.height + INTERCELL_SPACE);
|
||||
rect.size = cellSize;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
- (void)drawRect: (NSRect)rect
|
||||
{
|
||||
unsigned i = 0, count = [cells count];
|
||||
int max, howMany;
|
||||
NSRect aRect = [self frame];
|
||||
|
||||
// If there are no cells then just return
|
||||
if (count == 0) return;
|
||||
|
||||
aRect.origin.y = cellSize.height * (count - 1);
|
||||
aRect.size = cellSize;
|
||||
|
||||
for (i=0;i<count;i++)
|
||||
{
|
||||
id aCell = [cells objectAtIndex:i];
|
||||
|
||||
[aCell drawWithFrame:aRect inView:self];
|
||||
aRect.origin.y -= cellSize.height;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSSize) cellSize
|
||||
{
|
||||
return cellSize;
|
||||
}
|
||||
|
||||
- (void) setMenu: (NSMenu*)anObject
|
||||
{
|
||||
menu = anObject;
|
||||
}
|
||||
|
||||
- (void) setSelectedCell: (id)aCell
|
||||
{
|
||||
selectedCell = aCell;
|
||||
}
|
||||
|
||||
- (id) selectedCell
|
||||
{
|
||||
return selectedCell;
|
||||
}
|
||||
|
||||
- (NSRect) selectedCellRect
|
||||
{
|
||||
return selectedCellRect;
|
||||
}
|
||||
@end
|
||||
|
||||
//
|
||||
// NSPopUpButton implementation
|
||||
//
|
||||
|
||||
@implementation NSPopUpButton
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
@ -303,9 +73,13 @@ static NSFont* menuFont = nil;
|
|||
pullsDown:(BOOL)flag
|
||||
{
|
||||
[super initWithFrame:frameRect];
|
||||
list_items = [[NSPopUpButtonMatrix alloc] initWithFrame:frameRect];
|
||||
[list_items setPopUpButton:self];
|
||||
[list_items setPullsDown:flag];
|
||||
list_items = [NSMutableArray new];
|
||||
|
||||
popb_view = [[NSMenuView alloc] initWithFrame:frameRect
|
||||
cellSize: NSMakeSize (frameRect.size.width,
|
||||
frameRect.size.height)];
|
||||
[popb_view setPopUpButton: self];
|
||||
|
||||
is_up = NO;
|
||||
pulls_down = flag;
|
||||
selected_item = 0;
|
||||
|
@ -351,7 +125,11 @@ static NSFont* menuFont = nil;
|
|||
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
|
||||
[self close];
|
||||
|
||||
[self lockFocus];
|
||||
[self drawRect:[self frame]];
|
||||
[self unlockFocus];
|
||||
[self setNeedsDisplay:YES];
|
||||
|
||||
if (pub_target && pub_action)
|
||||
|
@ -363,11 +141,7 @@ static NSFont* menuFont = nil;
|
|||
//
|
||||
- (void)addItemWithTitle:(NSString *)title
|
||||
{
|
||||
[list_items insertItemWithTitle:title
|
||||
action:nil
|
||||
keyEquivalent:nil
|
||||
atIndex:[[list_items itemArray] count]];
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
[self insertItemWithTitle:title atIndex:[list_items count]];
|
||||
}
|
||||
|
||||
- (void)addItemsWithTitles:(NSArray *)itemTitles
|
||||
|
@ -381,10 +155,15 @@ static NSFont* menuFont = nil;
|
|||
- (void)insertItemWithTitle:(NSString *)title
|
||||
atIndex:(unsigned int)index
|
||||
{
|
||||
[list_items insertItemWithTitle:title
|
||||
action:@selector(iveBeenHitCaptain:)
|
||||
keyEquivalent:nil
|
||||
atIndex:index];
|
||||
id menuCell = [[NSPopUpButtonCell new] autorelease];
|
||||
|
||||
[menuCell setFont: [NSFont systemFontOfSize:12]];
|
||||
[menuCell setTitle: title];
|
||||
[menuCell setTarget: self];
|
||||
[menuCell setAction: @selector(buttonSelected:)];
|
||||
|
||||
[list_items insertObject: menuCell atIndex: index];
|
||||
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
}
|
||||
|
||||
|
@ -393,7 +172,7 @@ static NSFont* menuFont = nil;
|
|||
//
|
||||
- (void)removeAllItems
|
||||
{
|
||||
[(NSMutableArray *)[list_items itemArray] removeAllObjects];
|
||||
[list_items removeAllObjects];
|
||||
}
|
||||
|
||||
- (void)removeItemWithTitle:(NSString *)title
|
||||
|
@ -401,12 +180,12 @@ static NSFont* menuFont = nil;
|
|||
int index = [self indexOfItemWithTitle:title];
|
||||
|
||||
if (index != NSNotFound)
|
||||
[(NSMutableArray *)[list_items itemArray] removeObjectAtIndex:index];
|
||||
[list_items removeObjectAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)removeItemAtIndex:(int)index
|
||||
{
|
||||
[(NSMutableArray *)[list_items itemArray] removeObjectAtIndex:index];
|
||||
[list_items removeObjectAtIndex:index];
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -414,10 +193,10 @@ static NSFont* menuFont = nil;
|
|||
//
|
||||
- (int)indexOfItemWithTitle:(NSString *)title
|
||||
{
|
||||
int i, count = [[list_items itemArray] count];
|
||||
int i, count = [list_items count];
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
if ([[[[list_items itemArray] objectAtIndex:i] title] isEqual:title])
|
||||
if ([[[list_items objectAtIndex:i] title] isEqual:title])
|
||||
return i;
|
||||
|
||||
return NSNotFound;
|
||||
|
@ -430,31 +209,31 @@ static NSFont* menuFont = nil;
|
|||
|
||||
- (int)numberOfItems
|
||||
{
|
||||
return [[list_items itemArray] count];
|
||||
return [list_items count];
|
||||
}
|
||||
|
||||
- (id <NSMenuItem>)itemAtIndex:(int)index
|
||||
{
|
||||
return [[list_items itemArray] objectAtIndex:index];
|
||||
return [list_items objectAtIndex:index];
|
||||
}
|
||||
|
||||
- (NSArray *)itemArray
|
||||
{
|
||||
return [list_items itemArray];
|
||||
return list_items;
|
||||
}
|
||||
|
||||
- (NSString *)itemTitleAtIndex:(int)index
|
||||
{
|
||||
return [[[list_items itemArray] objectAtIndex:index] title];
|
||||
return [[list_items objectAtIndex:index] title];
|
||||
}
|
||||
|
||||
- (NSArray *)itemTitles
|
||||
{
|
||||
int i, count = [[list_items itemArray] count];
|
||||
int i, count = [list_items count];
|
||||
NSMutableArray* titles = [NSMutableArray arrayWithCapacity:count];
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
[titles addObject:[[[list_items itemArray] objectAtIndex:i] title]];
|
||||
[titles addObject:[[list_items objectAtIndex:i] title]];
|
||||
|
||||
return titles;
|
||||
}
|
||||
|
@ -464,21 +243,21 @@ static NSFont* menuFont = nil;
|
|||
int index = [self indexOfItemWithTitle:title];
|
||||
|
||||
if (index != NSNotFound)
|
||||
return [[list_items itemArray] objectAtIndex:index];
|
||||
return [list_items objectAtIndex:index];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id <NSMenuItem>)lastItem
|
||||
{
|
||||
if ([[list_items itemArray] count])
|
||||
return [[list_items itemArray] lastObject];
|
||||
if ([list_items count])
|
||||
return [list_items lastObject];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id <NSMenuItem>)selectedItem
|
||||
{
|
||||
return [[list_items itemArray] objectAtIndex:selected_item];
|
||||
return [list_items objectAtIndex:selected_item];
|
||||
}
|
||||
|
||||
- (NSString *)titleOfSelectedItem
|
||||
|
@ -501,7 +280,7 @@ static NSFont* menuFont = nil;
|
|||
|
||||
- (void)selectItemAtIndex:(int)index
|
||||
{
|
||||
if ((index >= 0) && (index < [[list_items itemArray] count]))
|
||||
if ((index >= 0) && (index < [list_items count]))
|
||||
{
|
||||
selected_item = index;
|
||||
[self synchronizeTitleAndSelectedItem];
|
||||
|
@ -534,10 +313,10 @@ static NSFont* menuFont = nil;
|
|||
|
||||
- (void)synchronizeTitleAndSelectedItem
|
||||
{
|
||||
if (!pulls_down)
|
||||
[list_items setIndexOfSelectedItem:selected_item];
|
||||
else
|
||||
[list_items setIndexOfSelectedItem:0];
|
||||
// if (!pulls_down)
|
||||
// [list_items setIndexOfSelectedItem:selected_item];
|
||||
// else
|
||||
// [list_items setIndexOfSelectedItem:0];
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -582,13 +361,13 @@ static NSFont* menuFont = nil;
|
|||
{
|
||||
id aCell;
|
||||
|
||||
if ([[list_items itemArray] count] == 0)
|
||||
if ([list_items count] == 0)
|
||||
return;
|
||||
|
||||
if (!pulls_down)
|
||||
aCell = [[list_items itemArray] objectAtIndex:selected_item];
|
||||
aCell = [list_items objectAtIndex:selected_item];
|
||||
else
|
||||
aCell = [[list_items itemArray] objectAtIndex:0];
|
||||
aCell = [list_items objectAtIndex:0];
|
||||
|
||||
[aCell drawWithFrame:rect inView:self];
|
||||
}
|
||||
|
|
|
@ -1,3 +1,29 @@
|
|||
/*
|
||||
NSPopUpButtonCell.m
|
||||
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
Author: Michael Hanni <mhanni@sprintmail.com>
|
||||
Date: 1999
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <gnustep/gui/config.h>
|
||||
#include <AppKit/NSColor.h>
|
||||
#include <AppKit/NSFont.h>
|
||||
|
@ -36,9 +62,11 @@
|
|||
arect.origin.y += 2;
|
||||
|
||||
if (cell_highlighted) {
|
||||
NSLog(@"highlighted.");
|
||||
[[NSColor whiteColor] set];
|
||||
NSRectFill(arect);
|
||||
} else {
|
||||
NSLog(@"unhighlighted.");
|
||||
[[NSColor lightGrayColor] set];
|
||||
NSRectFill(arect);
|
||||
}
|
||||
|
@ -61,6 +89,20 @@
|
|||
rect.origin.x = cellFrame.origin.x + cellFrame.size.width - (6 + 11);
|
||||
rect.origin.y = cellFrame.origin.y;
|
||||
|
||||
if ([view isKindOfClass:[NSMenuView class]])
|
||||
{
|
||||
NSPopUpButton *popb = [(NSMenuView *)view popupButton];
|
||||
|
||||
if ([popb titleOfSelectedItem] == contents)
|
||||
{
|
||||
if ([popb pullsDown] == NO)
|
||||
[super _drawImage:[NSImage imageNamed:@"common_Nibble"] inFrame:rect];
|
||||
else
|
||||
[super _drawImage:[NSImage imageNamed:@"common_3DArrowDown"] inFrame:rect];
|
||||
}
|
||||
}
|
||||
else if ([view isKindOfClass:[NSPopUpButton class]])
|
||||
{
|
||||
if ([(NSPopUpButton *)view titleOfSelectedItem] == contents)
|
||||
{
|
||||
if ([(NSPopUpButton *)view pullsDown] == NO)
|
||||
|
@ -68,5 +110,6 @@
|
|||
else
|
||||
[super _drawImage:[NSImage imageNamed:@"common_3DArrowDown"] inFrame:rect];
|
||||
}
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -457,27 +457,6 @@ static NSRange MakeRangeFromAbs(int a1,int a2)
|
|||
|
||||
}
|
||||
|
||||
- (BOOL) readSelectionFromPasteboard: (NSPasteboard*)pb
|
||||
{
|
||||
NSArray *types;
|
||||
NSString *string;
|
||||
NSRange range;
|
||||
|
||||
types = [pb types];
|
||||
if ([types containsObject: NSStringPboardType] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
string = [pb stringForType: NSStringPboardType];
|
||||
range = [self selectedRange];
|
||||
[self deleteRange: range backspace: NO];
|
||||
[self insertText: string];
|
||||
range.length = [string length];
|
||||
[self setSelectedRange: range];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL) writeSelectionToPasteboard: (NSPasteboard*)pb
|
||||
types: (NSArray*)sendTypes
|
||||
{
|
||||
|
@ -538,6 +517,9 @@ static NSRange MakeRangeFromAbs(int a1,int a2)
|
|||
} return NO;
|
||||
}
|
||||
|
||||
- (BOOL) readSelectionFromPasteboard: (NSPasteboard*)pb
|
||||
{ return [self performPasteOperation:pb];
|
||||
}
|
||||
|
||||
// begin: dragging of colors and files ---------------
|
||||
-(unsigned int) draggingEntered:(id <NSDraggingInfo>)sender
|
||||
|
@ -1012,7 +994,10 @@ NSLog(@"did set font");
|
|||
if([[lineLayoutInformation lastObject] type] == LineLayoutInfoType_Paragraph && NSMaxY(rect)<= newHeight)
|
||||
newHeight+=[[lineLayoutInformation lastObject] lineRect].size.height;
|
||||
|
||||
if ( [[self superview] isKindOfClass: [NSClipView class]] )
|
||||
tRect = [(NSClipView*)[self superview] documentVisibleRect];
|
||||
else
|
||||
tRect = [self bounds];
|
||||
|
||||
if (currentCursorY < tRect.size.height + tRect.origin.y -
|
||||
[[lineLayoutInformation lastObject] lineRect].size.height)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue