Merge branch 'master' of github.com:gnustep/libs-gui into NSGridView_NSStackView_branch

This commit is contained in:
Gregory John Casamento 2020-12-14 10:15:02 -05:00
commit 5be2cc4154
7 changed files with 274 additions and 330 deletions

View file

@ -1,13 +1,34 @@
2020-12-13 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSSearchFieldCell.m: Use GSTheme to display the popup.
2020-12-12 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSSearchField.m,
* Source/NSSearchFieldCell.m: Small cleanups in formatting and
int types.
2020-12-11 Riccardo Mottola <rm@gnu.org>
* Source/GSToolbarView.m,
Use centerScanRect to correct Items frame and avoid flickering.
2020-12-06 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSToolbarFrameworkPrivate.h,
* Source/GSToolbarView.m,
* Source/NSToolbar.m: Minor changes to format code, remove unused
methods and introduce some new helper methods.
2020-11-29 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSMenuView.m (-mouseDown:): Protect against _window going
away during tracking.
2020-11-23 Riccardo <rm@gnu.org>
2020-11-23 Riccardo Mottola <rm@gnu.org>
* Source/NSPopUpButtonCell.m (release):
Use standard setMenu: in release and avoid leaking the Menu. (Proposed by Fred)
2020-11-03 Riccardo Mottola <rm@gnu.org>
* Source/NSBitmapImageRep+JPEG.m (_JPEGRepresentationWithProperties:):

View file

@ -57,7 +57,7 @@ typedef enum {
GSToolbarClippedItemsButton *_clippedItemsMark;
unsigned int _borderMask;
NSRect _rectAvailable;
float _heightFromLayout;
CGFloat _heightFromLayout;
}
+ (NSUInteger) draggedItemIndex;

View file

@ -3,7 +3,7 @@
<abstract>The toolbar view class.</abstract>
Copyright (C) 2004-2015 Free Software Foundation, Inc.
Copyright (C) 2004-2020 Free Software Foundation, Inc.
Author: Quentin Mathe <qmathe@club-internet.fr>
Date: January 2004
@ -546,8 +546,8 @@ static NSUInteger draggedItemIndex = NSNotFound;
- (void) _handleBackViewsFrame
{
float x = 0;
float newHeight = 0;
CGFloat x = 0;
CGFloat newHeight = 0;
NSArray *subviews = [_clipView subviews];
NSEnumerator *e = [[_toolbar items] objectEnumerator];
NSToolbarItem *item;
@ -592,13 +592,14 @@ static NSUInteger draggedItemIndex = NSNotFound;
BOOL mustAdjustNext = NO;
CGFloat x = 0, visibleItemsMinWidth = 0, backViewsWidth = 0;
NSMutableArray *variableWidthItems = [NSMutableArray array];
int flexibleItemsCount = 0, maxWidthItemsCount = 0;
unsigned flexibleItemsCount = 0, maxWidthItemsCount = 0;
CGFloat spacePerFlexItem, extraSpace = 0;
CGFloat toolbarWidth = [self frame].size.width;
int i, n = [items count];
NSUInteger i, n;
NSMutableArray *visibleItems = [NSMutableArray array];
static const int FlexItemWeight = 4; // non-space flexible item counts as much as 4 flexible spaces
n = [items count];
if (n == 0)
return;
@ -686,10 +687,10 @@ static NSUInteger draggedItemIndex = NSNotFound;
if ([item _isFlexibleSpace])
{
NSRect backViewFrame = [backView frame];
[backView setFrame: NSMakeRect(x, backViewFrame.origin.y,
spacePerFlexItem,
backViewFrame.size.height)];
NSRect newFrameRect = NSMakeRect(x, backViewFrame.origin.y,
spacePerFlexItem,
backViewFrame.size.height);
[backView setFrame: [self centerScanRect:newFrameRect]];
mustAdjustNext = YES;
}
else if ([variableWidthItems indexOfObjectIdenticalTo:item] != NSNotFound)
@ -698,17 +699,19 @@ static NSUInteger draggedItemIndex = NSNotFound;
CGFloat maxFlex = [item maxSize].width - [item minSize].width;
CGFloat flexAmount = MIN(maxFlex, spacePerFlexItem * FlexItemWeight);
CGFloat newWidth = [item minSize].width + flexAmount + 2 * InsetItemViewX;
[backView setFrame: NSMakeRect(x, backViewFrame.origin.y,
newWidth,
backViewFrame.size.height)];
NSRect newFrameRect = NSMakeRect(x, backViewFrame.origin.y,
newWidth,
backViewFrame.size.height);
[backView setFrame: [self centerScanRect: newFrameRect]];
mustAdjustNext = YES;
}
else if (mustAdjustNext)
{
NSRect backViewFrame = [backView frame];
[backView setFrame: NSMakeRect(x, backViewFrame.origin.y,
backViewFrame.size.width, backViewFrame.size.height)];
NSRect newFrameRect = NSMakeRect(x, backViewFrame.origin.y,
backViewFrame.size.width,
backViewFrame.size.height);
[backView setFrame: [self centerScanRect: newFrameRect]];
}
view = [item view];
if (view != nil)
@ -760,7 +763,7 @@ static NSUInteger draggedItemIndex = NSNotFound;
- (void) _manageClipView
{
NSRect clipViewFrame = [_clipView frame];
int count = [[_toolbar items] count];
NSUInteger count = [[_toolbar items] count];
// Retrieve the back views which should be visible now that the resize
// process has been taken in account
NSArray *visibleBackViews = [self _visibleBackViews];
@ -802,8 +805,8 @@ static NSUInteger draggedItemIndex = NSNotFound;
}
}
- (void) _reload
{
- (void) _reload
{
// First, we resize
[self _handleBackViewsFrame];
[self _takeInAccountFlexibleSpaces];
@ -818,9 +821,9 @@ static NSUInteger draggedItemIndex = NSNotFound;
// Accessors private methods
- (float) _heightFromLayout
- (CGFloat) _heightFromLayout
{
float height = _heightFromLayout;
CGFloat height = _heightFromLayout;
if (_borderMask & GSToolbarViewBottomBorder)
{
@ -844,11 +847,12 @@ static NSUInteger draggedItemIndex = NSNotFound;
{
NSArray *items = [_toolbar items];
NSView *backView, *view;
int i, n = [items count];
NSUInteger i, n;
float backViewsWidth = 0, toolbarWidth = [self frame].size.width;
NSMutableArray *visibleBackViews = [NSMutableArray array];
n = [items count];
for (i = 0; i < n; i++)
{
NSToolbarItem *item = [items objectAtIndex:i];
@ -888,12 +892,13 @@ static NSUInteger draggedItemIndex = NSNotFound;
- (NSMenu *) menuForEvent: (NSEvent *)event
{
NSMenu *menu = [[[NSMenu alloc] initWithTitle: @""] autorelease];
id <NSMenuItem> customize = [menu insertItemWithTitle: _(@"Customize Toolbar") action:@selector(runCustomizationPalette:) keyEquivalent:@"" atIndex:0];
NSMenu *menu = [[NSMenu alloc] initWithTitle: @""];
id <NSMenuItem> customize = [menu insertItemWithTitle: _(@"Customize Toolbar")
action: @selector(runCustomizationPalette:)
keyEquivalent: @""
atIndex: 0];
[customize setTarget: _toolbar];
return menu;
return AUTORELEASE(menu);
}
@end

View file

@ -62,22 +62,22 @@ static Class usedCellClass;
usedCellClass = factoryId ? factoryId : [NSSearchFieldCell class];
}
- (NSArray *) recentSearches
- (NSArray*) recentSearches
{
return [[self cell] recentSearches];
}
- (NSString *) recentsAutosaveName
- (NSString*) recentsAutosaveName
{
return [[self cell] recentsAutosaveName];
}
- (void) setRecentSearches: (NSArray *)searches
- (void) setRecentSearches: (NSArray*)searches
{
[[self cell] setRecentSearches: searches];
}
- (void) setRecentsAutosaveName: (NSString *)name
- (void) setRecentsAutosaveName: (NSString*)name
{
[[self cell] setRecentsAutosaveName: name];
}
@ -88,9 +88,9 @@ static Class usedCellClass;
- (void) mouseDown: (NSEvent*)theEvent
{
[[self cell] trackMouse: theEvent
inRect: [self bounds]
ofView: self
untilMouseUp: YES];
inRect: [self bounds]
ofView: self
untilMouseUp: YES];
}
- (void) delete: (id)sender
@ -101,7 +101,7 @@ static Class usedCellClass;
}
// Cocoa only defines these methods on the cell, but nib loading targets the field itself
- (void) setSearchMenuTemplate: (NSMenu *)newTemplate
- (void) setSearchMenuTemplate: (NSMenu*)newTemplate
{
[[self cell] setSearchMenuTemplate: newTemplate];
}

View file

@ -1,15 +1,15 @@
/*
/*
NSSearchFieldCell.h
Text field cell class for text search
Copyright (C) 2004 Free Software Foundation, Inc.
Author: H. Nikolaus Schaller <hns@computer.org>
Date: Dec 2004
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: Mar 2006
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
@ -24,10 +24,10 @@
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
*/
#import <Foundation/NSArray.h>
#import <Foundation/NSException.h>
@ -46,6 +46,10 @@
#import "AppKit/NSSearchFieldCell.h"
#import "AppKit/NSWindow.h"
#import "GSGuiPrivate.h"
#define ICON_WIDTH 16
@interface NSSearchFieldCell (Private)
- (NSMenu *) _buildTemplate;
@ -59,26 +63,13 @@
@implementation NSSearchFieldCell
#define ICON_WIDTH 16
// Inlined method
static inline NSRect textCellFrameFromRect(NSRect cellRect)
// Not the drawed part, precises just the part which receives events
{
return NSMakeRect(cellRect.origin.x + ICON_WIDTH,
NSMinY(cellRect),
NSWidth(cellRect) - 2*ICON_WIDTH,
NSHeight(cellRect));
}
- (id) initTextCell:(NSString *)aString
- (id) initTextCell: (NSString*)aString
{
self = [super initTextCell: aString];
if (self)
{
NSButtonCell *c;
// NSMenu *template;
c = [[NSButtonCell alloc] initImageCell: nil];
[self setCancelButtonCell: c];
@ -91,9 +82,11 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
[self resetSearchButtonCell];
/* Don't set the searchMenuTemplate unless it is explicitly set in code or by a nib connection
template = [self _buildTemplate];
[self setSearchMenuTemplate: template];
RELEASE(template);
{
NSMenu *template;
template = [self _buildTemplate];
[self setSearchMenuTemplate: template];
}
*/
//_recent_searches = [[NSMutableArray alloc] init];
@ -116,7 +109,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
[super dealloc];
}
- (id) copyWithZone:(NSZone *) zone;
- (id) copyWithZone: (NSZone*)zone;
{
NSSearchFieldCell *c = [super copyWithZone: zone];
@ -132,24 +125,24 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
- (BOOL) isOpaque
{
// only if all components are opaque
return [super isOpaque] && [_cancel_button_cell isOpaque] &&
return [super isOpaque] && [_cancel_button_cell isOpaque] &&
[_search_button_cell isOpaque];
}
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
[_search_button_cell drawWithFrame: [self searchButtonRectForBounds: cellFrame]
[_search_button_cell drawWithFrame: [self searchButtonRectForBounds: cellFrame]
inView: controlView];
[super drawWithFrame: [self searchTextRectForBounds: cellFrame]
[super drawWithFrame: [self searchTextRectForBounds: cellFrame]
inView: controlView];
if ([[self stringValue] length] > 0)
[_cancel_button_cell drawWithFrame: [self cancelButtonRectForBounds: cellFrame]
[_cancel_button_cell drawWithFrame: [self cancelButtonRectForBounds: cellFrame]
inView: controlView];
}
- (BOOL) sendsWholeSearchString
{
return _sends_whole_search_string;
{
return _sends_whole_search_string;
}
- (void) setSendsWholeSearchString: (BOOL)flag
@ -158,8 +151,8 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
}
- (BOOL) sendsSearchStringImmediately
{
return _sends_search_string_immediatly;
{
return _sends_search_string_immediatly;
}
- (void) setSendsSearchStringImmediately: (BOOL)flag
@ -168,7 +161,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
}
- (NSInteger) maximumRecents
{
{
return _max_recents;
}
@ -193,18 +186,18 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
- (NSString *) recentsAutosaveName
{
return _recents_autosave_name;
return _recents_autosave_name;
}
- (void) setRecentsAutosaveName: (NSString *)name
- (void) setRecentsAutosaveName: (NSString*)name
{
ASSIGN(_recents_autosave_name, name);
[self _loadSearches];
}
- (void) setRecentSearches: (NSArray *)searches
- (void) setRecentSearches: (NSArray*)searches
{
int max;
NSInteger max;
NSMutableArray *mutableSearches;
max = [self maximumRecents];
@ -223,8 +216,8 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
_recent_searches = mutableSearches;
[self _saveSearches];
}
- (void) addToRecentSearches:(NSString *)searchTerm
- (void) addToRecentSearches: (NSString*)searchTerm
{
if (!_recent_searches)
{
@ -238,12 +231,12 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
}
}
- (NSMenu *) searchMenuTemplate
- (NSMenu*) searchMenuTemplate
{
return _menu_template;
}
- (void) setSearchMenuTemplate: (NSMenu *)menu
- (void) setSearchMenuTemplate: (NSMenu*)menu
{
ASSIGN(_menu_template, menu);
if (menu)
@ -258,22 +251,22 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
}
}
- (NSButtonCell *) cancelButtonCell
- (NSButtonCell*) cancelButtonCell
{
return _cancel_button_cell;
}
- (void) setCancelButtonCell: (NSButtonCell *)cell
- (void) setCancelButtonCell: (NSButtonCell*)cell
{
ASSIGN(_cancel_button_cell, cell);
}
- (NSButtonCell *) searchButtonCell
- (NSButtonCell*) searchButtonCell
{
return _search_button_cell;
}
- (void) setSearchButtonCell: (NSButtonCell *)cell
- (void) setSearchButtonCell: (NSButtonCell*)cell
{
ASSIGN(_search_button_cell, cell);
}
@ -281,7 +274,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
- (void) resetCancelButtonCell
{
NSButtonCell *c;
c = [self cancelButtonCell];
// configure the button
[c setButtonType: NSMomentaryChangeButton];
@ -310,8 +303,6 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
[c setEditable: NO];
[c setImagePosition: NSImageOnly];
[c setImage: [NSImage imageNamed: @"GSSearch"]];
// [c setAction: [self action]];
// [c setTarget: [self target]];
[c setAction: @selector(performClick:)];
[c setTarget: self];
[c sendActionOn: NSLeftMouseUpMask];
@ -322,7 +313,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
- (NSRect) cancelButtonRectForBounds: (NSRect)rect
{
NSRect part, clear;
NSDivideRect(rect, &clear, &part, ICON_WIDTH, NSMaxXEdge);
return clear;
}
@ -357,7 +348,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
- (NSRect) searchButtonRectForBounds: (NSRect)rect;
{
NSRect search, part;
NSDivideRect(rect, &search, &part, ICON_WIDTH, NSMinXEdge);
return search;
}
@ -380,9 +371,9 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
{
[self addToRecentSearches: [[[editor string] copy] autorelease]];
[super endEditing: editor];
[[NSNotificationCenter defaultCenter]
removeObserver: self
name: NSTextDidChangeNotification
[[NSNotificationCenter defaultCenter]
removeObserver: self
name: NSTextDidChangeNotification
object: editor];
}
@ -392,7 +383,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
delegate: (id)anObject
start: (NSInteger)selStart
length: (NSInteger)selLength
{
{
// constrain to visible text area
[super selectWithFrame: [self searchTextRectForBounds: aRect]
inView: controlView
@ -400,16 +391,16 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
delegate: anObject
start: selStart
length: selLength];
[[NSNotificationCenter defaultCenter]
addObserver: self
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(textDidChange:)
name: NSTextDidChangeNotification
name: NSTextDidChangeNotification
object: textObject];
}
- (BOOL) trackMouse: (NSEvent *)event
inRect: (NSRect)cellFrame
ofView: (NSView *)controlView
- (BOOL) trackMouse: (NSEvent *)event
inRect: (NSRect)cellFrame
ofView: (NSView *)controlView
untilMouseUp: (BOOL)untilMouseUp
{
NSRect rect;
@ -423,22 +414,22 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
rect = [self searchButtonRectForBounds: cellFrame];
if ([controlView mouse: thePoint inRect: rect])
{
return [[self searchButtonCell] trackMouse: event
inRect: rect
ofView: controlView
return [[self searchButtonCell] trackMouse: event
inRect: rect
ofView: controlView
untilMouseUp: untilMouseUp];
}
rect = [self cancelButtonRectForBounds: cellFrame];
if ([controlView mouse: thePoint inRect: rect])
{
return [[self cancelButtonCell] trackMouse: event
inRect: rect
ofView: controlView
return [[self cancelButtonCell] trackMouse: event
inRect: rect
ofView: controlView
untilMouseUp: untilMouseUp];
}
currentEditor = ([controlView isKindOfClass:[NSControl class]]
currentEditor = ([controlView isKindOfClass: [NSControl class]]
? [(NSControl *)controlView currentEditor]
: nil);
if (currentEditor)
@ -447,23 +438,24 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
return YES;
}
return [super trackMouse: event
return [super trackMouse: event
inRect: [self searchTextRectForBounds: cellFrame]
ofView: controlView
ofView: controlView
untilMouseUp: untilMouseUp];
}
- (void) resetCursorRect: (NSRect)cellFrame inView: (NSView *)controlView
{
[super resetCursorRect: textCellFrameFromRect(cellFrame)
[super resetCursorRect: [self searchTextRectForBounds: cellFrame]
inView: controlView];
}
- (void) textDidChange: (NSNotification *)notification
{
{
NSText *textObject;
[_control_view setNeedsDisplay:YES];
[_control_view setNeedsDisplay: YES];
// make textChanged send action (unless disabled)
if (_sends_whole_search_string)
{
@ -474,14 +466,14 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
textObject = [notification object];
// copy the current NSTextEdit string so that it can be read from the NSSearchFieldCell!
[self setStringValue: [textObject string]];
[NSApp sendAction:[self action] to:[self target] from:_control_view];
[NSApp sendAction: [self action] to: [self target] from: _control_view];
}
- (void) clearSearch:(id)sender
- (void) clearSearch: (id)sender
{
[self setStringValue:@""];
[NSApp sendAction:[self action] to:[self target] from:_control_view];
[_control_view setNeedsDisplay:YES];
[self setStringValue: @""];
[_control_view setNeedsDisplay: YES];
[NSApp sendAction: [self action] to: [self target] from: _control_view];
}
//
@ -538,7 +530,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
[aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &max];
[self setMaximumRecents: max];
}
[self resetCancelButtonCell];
[self resetSearchButtonCell];
}
@ -559,37 +551,37 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
NSMenuItem *item;
template = [[NSMenu alloc] init];
item = [[NSMenuItem alloc] initWithTitle: @"Recent searches"
item = [[NSMenuItem alloc] initWithTitle: _(@"Recent searches")
action: NULL
keyEquivalent: @""];
[item setTag: NSSearchFieldRecentsTitleMenuItemTag];
[template addItem: item];
RELEASE(item);
item = [[NSMenuItem alloc] initWithTitle: @"Recent search item"
item = [[NSMenuItem alloc] initWithTitle: _(@"Recent search item")
action: @selector(search:)
keyEquivalent: @""];
[item setTag: NSSearchFieldRecentsMenuItemTag];
[template addItem: item];
RELEASE(item);
item = [[NSMenuItem alloc] initWithTitle: @"Clear recent searches"
item = [[NSMenuItem alloc] initWithTitle: _(@"Clear recent searches")
action: @selector(_clearSearches:)
keyEquivalent: @""];
[item setTag: NSSearchFieldClearRecentsMenuItemTag];
[item setTarget: self];
[template addItem: item];
RELEASE(item);
item = [[NSMenuItem alloc] initWithTitle: @"No recent searches"
item = [[NSMenuItem alloc] initWithTitle: _(@"No recent searches")
action: NULL
keyEquivalent: @""];
[item setTag: NSSearchFieldNoRecentsMenuItemTag];
[template addItem: item];
RELEASE(item);
return template;
return AUTORELEASE(template);
}
- (void) _openPopup: (id)sender
@ -597,20 +589,20 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
NSMenu *template;
NSMenu *popupmenu;
NSMenuView *mr;
NSWindow *cvWin;
NSRect cellFrame;
int i;
int recentCount = [_recent_searches count];
NSPopUpButtonCell *pbcell = [[NSPopUpButtonCell alloc] initTextCell:nil pullsDown:NO];
int selectedItemIndex = -1, newSelectedItemIndex;
NSInteger i;
NSInteger recentCount = [_recent_searches count];
NSPopUpButtonCell *pbcell = [[NSPopUpButtonCell alloc] initTextCell: nil pullsDown: NO];
NSInteger selectedItemIndex = -1;
NSInteger newSelectedItemIndex;
template = [self searchMenuTemplate];
popupmenu = [[NSMenu alloc] init];
// Fill the popup menu
// Fill the popup menu
for (i = 0; i < [template numberOfItems]; i++)
{
int tag;
NSInteger tag;
NSMenuItem *item, *newItem = nil;
item = (NSMenuItem*)[template itemAtIndex: i];
@ -629,12 +621,12 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
if (recentCount > 0) // only show items with this tag if there are recent searches
{
newItem = [[item copy] autorelease];
[newItem setTarget:self];
[newItem setAction:@selector(_clearSearches:)];
[newItem setTarget: self];
[newItem setAction: @selector(_clearSearches:)];
}
}
else if (tag == NSSearchFieldNoRecentsMenuItemTag)
{
{
if (recentCount == 0) // only show items with this tag if there are NO recent searches
{
newItem = [[item copy] autorelease];
@ -642,15 +634,15 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
}
else if (tag == NSSearchFieldRecentsMenuItemTag)
{
int j;
NSInteger j;
for (j = 0; j < recentCount; j++)
{
id <NSMenuItem> searchItem = [popupmenu addItemWithTitle:
id <NSMenuItem> searchItem = [popupmenu addItemWithTitle:
[_recent_searches objectAtIndex: j]
action:
action:
@selector(_searchForRecent:)
keyEquivalent:
keyEquivalent:
[item keyEquivalent]];
[searchItem setTarget: self];
}
@ -664,42 +656,31 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
{
[popupmenu addItem: newItem];
}
}
}
[pbcell setMenu:popupmenu];
[pbcell selectItemAtIndex:selectedItemIndex];
[[popupmenu itemAtIndex:selectedItemIndex] setState:NSOffState]; // ensure that state resets fully
[[popupmenu itemAtIndex:selectedItemIndex] setState:NSOnState];
[pbcell setMenu: popupmenu];
[pbcell selectItemAtIndex: selectedItemIndex];
[pbcell setPreferredEdge: NSMinYEdge];
// Prepare to display the popup
cvWin = [_control_view window];
cellFrame = [_control_view frame];
cellFrame = [[_control_view superview] convertRect:cellFrame toView:nil]; // convert to window coordinates
cellFrame.origin = [cvWin convertBaseToScreen:cellFrame.origin]; // convert to screen coordinates
mr = [popupmenu menuRepresentation];
// Ask the MenuView to attach the menu to this rect
[mr setWindowFrameForAttachingToRect: cellFrame
onScreen: [cvWin screen]
preferredEdge: NSMinYEdge
popUpSelectedItem: -1];
// Last, display the window
[[mr window] orderFrontRegardless];
[pbcell attachPopUpWithFrame: cellFrame
inView: _control_view];
[mr mouseDown: [NSApp currentEvent]];
newSelectedItemIndex = [pbcell indexOfSelectedItem];
if (newSelectedItemIndex != selectedItemIndex && newSelectedItemIndex != -1
&& newSelectedItemIndex < [template numberOfItems])
{
int tag = [[template itemAtIndex:newSelectedItemIndex] tag];
NSInteger tag = [[template itemAtIndex: newSelectedItemIndex] tag];
if (tag != NSSearchFieldRecentsTitleMenuItemTag && tag != NSSearchFieldClearRecentsMenuItemTag
&& tag != NSSearchFieldNoRecentsMenuItemTag && tag != NSSearchFieldRecentsMenuItemTag
&& ![[template itemAtIndex:newSelectedItemIndex] isSeparatorItem])
&& ![[template itemAtIndex: newSelectedItemIndex] isSeparatorItem])
{
//new selected item within the template that's not a template special item
[[template itemAtIndex:selectedItemIndex] setState:NSOffState];
[[template itemAtIndex:newSelectedItemIndex] setState:NSOnState];
[[template itemAtIndex: selectedItemIndex] setState: NSOffState];
[[template itemAtIndex: newSelectedItemIndex] setState: NSOnState];
}
}
AUTORELEASE(popupmenu);
@ -727,7 +708,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
if (name)
{
list = [[NSUserDefaults standardUserDefaults]
list = [[NSUserDefaults standardUserDefaults]
stringArrayForKey: name];
[self setRecentSearches: list];
}
@ -740,7 +721,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
if (name && list)
{
[[NSUserDefaults standardUserDefaults]
[[NSUserDefaults standardUserDefaults]
setObject: list forKey: name];
}
}

View file

@ -76,19 +76,15 @@ static GSValidationCenter *vc = nil;
- (NSArray *) objectsWithValue: (id)value forKey: (NSString *)key
{
NSMutableArray *result = [NSMutableArray array];
NSArray *keys = [self valueForKey: key];
int i, n = 0;
if (keys == nil)
return nil;
n = [keys count];
int i = 0;
int n = [self count];
for (i = 0; i < n; i++)
{
if ([[keys objectAtIndex: i] isEqual: value])
id obj = [self objectAtIndex: i];
if ([[obj valueForKey: key] isEqual: value])
{
[result addObject: [self objectAtIndex: i]];
[result addObject: obj];
}
}
@ -230,26 +226,15 @@ static GSValidationCenter *vc = nil;
// this method unlike dealloc.
}
/*
* FIXME: Replace the deprecated method which follows by this one when -base
* NSObject will implement it.
*
- (id) valueForUndefinedKey: (NSString *)key
{
if ([key isEqualToString: @"window"] || [key isEqualToString: @"_window"])
return nil;
{
return nil;
}
return [super valueForUndefinedKey: key];
}
*/
- (id) handleQueryWithUnboundKey: (NSString *)key
{
if ([key isEqualToString: @"window"] || [key isEqualToString: @"_window"])
return [NSNull null];
return [super handleQueryWithUnboundKey: key];
}
- (NSMutableArray *) observers
{
@ -495,7 +480,7 @@ static GSValidationCenter *vc = nil;
+ (NSArray *) _toolbarsWithIdentifier: (NSString *)identifier
{
return [toolbars objectsWithValue: identifier
forKey: @"_identifier"];
forKey: @"_identifier"];
}
// Instance methods
@ -505,7 +490,9 @@ static GSValidationCenter *vc = nil;
NSToolbar *toolbarModel = nil;
if ((self = [super init]) == nil)
return nil;
{
return nil;
}
ASSIGN(_identifier, identifier);
@ -581,7 +568,7 @@ static GSValidationCenter *vc = nil;
{
if ([aCoder allowsKeyedCoding])
{
ASSIGN(_identifier, [aCoder decodeObjectForKey:@"NSToolbarIdentifier"]);
ASSIGN(_identifier, [aCoder decodeObjectForKey: @"NSToolbarIdentifier"]);
_items = [[NSMutableArray alloc] init];
ASSIGN(_interfaceBuilderItemsByIdentifier, [aCoder decodeObjectForKey: @"NSToolbarIBIdentifiedItems"]);
@ -618,11 +605,10 @@ static GSValidationCenter *vc = nil;
//NSLog(@"Toolbar dealloc %@", self);
[self _setToolbarView: nil];
// Use DESTROY ?
RELEASE(_identifier);
RELEASE(_selectedItemIdentifier);
RELEASE(_configurationDictionary);
RELEASE(_items);
DESTROY(_identifier);
DESTROY(_selectedItemIdentifier);
DESTROY(_configurationDictionary);
DESTROY(_items);
DESTROY(_interfaceBuilderItemsByIdentifier);
DESTROY(_interfaceBuilderAllowedItemIdentifiers);
@ -653,7 +639,9 @@ static GSValidationCenter *vc = nil;
- (id) valueForUndefinedKey: (NSString *)key
{
if ([key isEqualToString: @"window"] || [key isEqualToString: @"_window"])
return nil;
{
return nil;
}
return [super valueForUndefinedKey: key];
}
@ -679,6 +667,7 @@ static GSValidationCenter *vc = nil;
{
return;
}
if (_customizationPaletteIsRunning)
{
NSLog(@"Customization palette is already running for toolbar: %@", self);
@ -687,20 +676,22 @@ static GSValidationCenter *vc = nil;
if (!_visible)
{
[self setVisible:YES];
[self setVisible: YES];
}
palette = [GSToolbarCustomizationPalette palette];
if (palette != nil)
_customizationPaletteIsRunning = YES;
{
_customizationPaletteIsRunning = YES;
[palette showForToolbar: self];
[palette showForToolbar: self];
}
}
- (void) validateVisibleItems
{
NSEnumerator *e = [[self visibleItems] objectEnumerator];
NSEnumerator *e = [[self visibleItems] objectEnumerator];
NSToolbarItem *item = nil;
while ((item = [e nextObject]) != nil)
@ -802,7 +793,7 @@ static GSValidationCenter *vc = nil;
_displayMode = [[_configurationDictionary objectForKey: @"displayMode"] intValue];
// remove all items...
for(i = 0; i < [_items count]; i++)
for (i = 0; i < [_items count]; i++)
{
[self _removeItemAtIndex: 0 broadcast: YES];
}
@ -811,11 +802,11 @@ static GSValidationCenter *vc = nil;
i = 0;
items = [_configurationDictionary objectForKey: @"items"];
en = [items objectEnumerator];
while((item = [en nextObject]) != nil)
while ((item = [en nextObject]) != nil)
{
[self _insertItemWithItemIdentifier: item
atIndex: i++
broadcast: YES];
atIndex: i++
broadcast: YES];
}
}
@ -845,8 +836,7 @@ static GSValidationCenter *vc = nil;
if (_interfaceBuilderItemsByIdentifier == nil)
{
CHECK_REQUIRED_METHOD(toolbar:itemForItemIdentifier:
willBeInsertedIntoToolbar:);
CHECK_REQUIRED_METHOD(toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:);
}
if (_interfaceBuilderAllowedItemIdentifiers == nil)
{
@ -892,6 +882,12 @@ static GSValidationCenter *vc = nil;
return selectableIdentifiers;
}
- (NSArray *) _itemsWithIdentifier: (NSString *)identifier
{
return [[self items] objectsWithValue: identifier
forKey: @"_itemIdentifier"];
}
- (void) setSelectedItemIdentifier: (NSString *)identifier
{
NSArray *selectedItems;
@ -902,8 +898,7 @@ static GSValidationCenter *vc = nil;
BOOL updated = NO;
// First, we have to deselect the previous selected toolbar items
selectedItems = [[self items] objectsWithValue: [self selectedItemIdentifier]
forKey: @"_itemIdentifier"];
selectedItems = [self _itemsWithIdentifier: [self selectedItemIdentifier]];
e = [selectedItems objectEnumerator];
while ((item = [e nextObject]) != nil)
{
@ -911,31 +906,31 @@ static GSValidationCenter *vc = nil;
}
selectableIdentifiers = [self _selectableItemIdentifiers];
if ((selectableIdentifiers == nil)
|| ![selectableIdentifiers containsObject: identifier])
{
return;
}
if (selectableIdentifiers == nil)
return;
itemsToSelect = [self _itemsWithIdentifier: identifier];
e = [itemsToSelect objectEnumerator];
while ((item = [e nextObject]) != nil)
{
if (![item _selected])
{
[item _setSelected: YES];
}
updated = YES;
}
itemsToSelect = [_items objectsWithValue: identifier
forKey: @"_itemIdentifier"];
e = [itemsToSelect objectEnumerator];
while ((item = [e nextObject]) != nil)
{
if ([selectableIdentifiers containsObject: [item itemIdentifier]])
{
if (![item _selected])
[item _setSelected: YES];
updated = YES;
}
}
if (updated)
{
ASSIGN(_selectedItemIdentifier, identifier);
}
else
{
NSLog(@"Toolbar delegate returns no such selectable item identifiers");
}
if (updated)
{
ASSIGN(_selectedItemIdentifier, identifier);
}
else
{
NSLog(@"Toolbar delegate returns no such selectable item identifiers");
}
}
- (NSToolbarSizeMode) sizeMode
@ -948,14 +943,6 @@ static GSValidationCenter *vc = nil;
return _visible;
}
/**
* Sets the receivers delegate ... this is the object which will receive
* -toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:
* -toolbarAllowedItemIdentifiers: and -toolbarDefaultItemIdentifiers:
* messages.
*/
- (void) setDisplayMode: (NSToolbarDisplayMode)displayMode
{
[self _setDisplayMode: displayMode broadcast: YES];
@ -987,7 +974,7 @@ static GSValidationCenter *vc = nil;
{
if (_delegate != nil)
{
return [_delegate toolbarDefaultItemIdentifiers:self];
return [_delegate toolbarDefaultItemIdentifiers: self];
}
else
{
@ -1001,15 +988,13 @@ static GSValidationCenter *vc = nil;
*/
- (void) _build
{
NSToolbar *toolbarModel;
NSArray *wantedItemIdentifiers;
NSArray *wantedItemIdentifiers = nil;
NSEnumerator *e;
id itemIdentifier;
int i = 0;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *tableKey =
[NSString stringWithFormat: @"NSToolbar Config %@",_identifier];
NSDictionary *config = [defaults objectForKey: tableKey];
NSDictionary *config = [self _config];
// Switch off toolbar view reload
_build = YES;
if (config)
{
@ -1020,19 +1005,16 @@ static GSValidationCenter *vc = nil;
[self setDisplayMode: displayMode];
sizeMode = (NSToolbarSizeMode)[[config objectForKey: @"sizeMode"] intValue];
[self setSizeMode: sizeMode];
wantedItemIdentifiers = [config objectForKey: @"items"];
}
// Switch off toolbar view reload
_build = YES;
RELEASE(_items);
_items = [[NSMutableArray alloc] init];
toolbarModel = [self _toolbarModel];
wantedItemIdentifiers = [self _itemsFromConfig];
if(wantedItemIdentifiers == nil)
if (wantedItemIdentifiers == nil)
{
NSToolbar *toolbarModel = [self _toolbarModel];
if (toolbarModel != nil)
{
wantedItemIdentifiers =
@ -1043,6 +1025,7 @@ static GSValidationCenter *vc = nil;
wantedItemIdentifiers = [self _defaultItemIdentifiers];
}
}
if (wantedItemIdentifiers == nil)
{
_build = NO;
@ -1055,24 +1038,15 @@ static GSValidationCenter *vc = nil;
[self _insertItemWithItemIdentifier: itemIdentifier
atIndex: [_items count]
broadcast: NO];
i++;
}
_build = NO;
// Now do the toolbar view reload
if (_toolbarView != nil)
[_toolbarView _reload];
}
- (void) _resetConfig
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *tableKey =
[NSString stringWithFormat: @"NSToolbar Config %@",_identifier];
[defaults removeObjectForKey: tableKey];
[self _build];
}
- (BOOL) usesStandardBackgroundColor
{
return [_toolbarView _usesStandardBackgroundColor];
@ -1088,27 +1062,31 @@ static GSValidationCenter *vc = nil;
return [_items indexOfObjectIdenticalTo: item];
}
- (void) _insertPassivelyItem: (NSToolbarItem *)item atIndex: (int)newIndex
- (NSDictionary *) _config
{
if (![_items containsObject: item])
if (_identifier != nil)
{
if (newIndex > [_items count] - 1)
{
newIndex = [_items count] - 1;
}
else if(newIndex < 0)
{
newIndex = 0;
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *tableKey =
[NSString stringWithFormat: @"NSToolbar Config %@", _identifier];
[_items insertObject: item atIndex: newIndex];
return [defaults objectForKey: tableKey];
}
else
{
NSLog(@"Error: the toolbar already contains the item to insert.");
return nil;
}
}
- (void) _resetConfig
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *tableKey =
[NSString stringWithFormat: @"NSToolbar Config %@", _identifier];
[defaults removeObjectForKey: tableKey];
[self _build];
}
- (void) _saveConfig
{
if (_identifier != nil)
@ -1122,7 +1100,7 @@ static GSValidationCenter *vc = nil;
defaults = [NSUserDefaults standardUserDefaults];
tableKey =
[NSString stringWithFormat: @"NSToolbar Config %@",_identifier];
[NSString stringWithFormat: @"NSToolbar Config %@", _identifier];
config = [defaults objectForKey: tableKey];
@ -1165,29 +1143,6 @@ static GSValidationCenter *vc = nil;
return NO;
}
- (NSArray *) _itemsFromConfig
{
NSArray *items = nil;
if (_identifier != nil)
{
NSUserDefaults *defaults;
NSString *tableKey;
id config;
defaults = [NSUserDefaults standardUserDefaults];
tableKey =
[NSString stringWithFormat: @"NSToolbar Config %@",_identifier];
config = [defaults objectForKey: tableKey];
if (config != nil)
{
items = [config objectForKey: @"items"];
}
}
return items;
}
- (NSToolbar *) _toolbarModel
{
NSArray *linked;
@ -1199,12 +1154,11 @@ static GSValidationCenter *vc = nil;
{
toolbar = [linked objectAtIndex: 0];
// Toolbar model class must be identical to self class :
// an NSToolbar instance cannot use a NSToolbar instance as a model
// Toolbar model class must be identical to self class
if ([toolbar isMemberOfClass: [self class]] && toolbar != self)
return toolbar;
else
return nil;
{
return toolbar;
}
}
return nil;
@ -1254,7 +1208,7 @@ static GSValidationCenter *vc = nil;
\
while ((toolbar = [e nextObject]) != nil) \
{ \
if (toolbar != self && [self isMemberOfClass: [self class]]) \
if (toolbar != self && [toolbar isMemberOfClass: [self class]]) \
[toolbar signature]; \
} \
@ -1316,23 +1270,14 @@ static GSValidationCenter *vc = nil;
id item = [_items objectAtIndex: index];
RETAIN(item);
[self _performRemoveItem: item];
[self _concludeRemoveItem: item atIndex: index broadcast: broadcast];
RELEASE(item);
}
- (void) _performRemoveItem: (NSToolbarItem *)item
{
[_items removeObject: item];
[_toolbarView _reload];
[self _saveConfig];
}
- (void) _concludeRemoveItem: (NSToolbarItem *)item atIndex: (int)index broadcast: (BOOL)broadcast
{
[nc postNotificationName: NSToolbarDidRemoveItemNotification
object: self
userInfo: [NSDictionary dictionaryWithObject: item forKey: @"item"]];
RELEASE(item);
if (broadcast)
{
@ -1438,7 +1383,6 @@ static GSValidationCenter *vc = nil;
}
}
- (NSWindow*) _window
{
NSWindow *window = [_toolbarView window];
@ -1563,6 +1507,4 @@ static GSValidationCenter *vc = nil;
[self validateVisibleItems];
}
@end

View file

@ -40,7 +40,7 @@
- (void) _reload;
// Accessors
- (float) _heightFromLayout;
- (CGFloat) _heightFromLayout;
- (NSArray *) _visibleBackViews;
- (BOOL) _usesStandardBackgroundColor;
@ -86,17 +86,12 @@
// Few other private methods
- (void) _build;
- (int) _indexOfItem: (NSToolbarItem *)item;
- (void) _concludeRemoveItem: (NSToolbarItem *)item
atIndex: (int)index
broadcast: (BOOL)broadcast;
- (void) _insertPassivelyItem: (NSToolbarItem *)item atIndex: (int)newIndex;
- (void) _performRemoveItem: (NSToolbarItem *)item; // Used by drag setup
- (NSToolbar *) _toolbarModel;
- (void) _validate: (NSWindow *)observedWindow;
- (void) _toolbarViewWillMoveToSuperview: (NSView *)newSuperview;
- (NSDictionary *) _config;
- (void) _saveConfig;
- (void) _resetConfig;
- (NSArray *) _itemsFromConfig;
- (BOOL) _containsItemWithIdentifier: (NSString *) identifier;
// Accessors