mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 17:10:37 +00:00
* Source/NSSearchField.m,
* Source/NSSearchFieldCell.m: Small cleanups in formatting and int types.
This commit is contained in:
parent
4004f549d7
commit
a0f0b8b147
3 changed files with 117 additions and 121 deletions
|
@ -1,3 +1,9 @@
|
|||
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,
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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,20 +63,8 @@
|
|||
|
||||
@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)
|
||||
|
@ -93,7 +85,6 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
/* 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);
|
||||
*/
|
||||
|
||||
//_recent_searches = [[NSMutableArray alloc] init];
|
||||
|
@ -116,7 +107,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) copyWithZone:(NSZone *) zone;
|
||||
- (id) copyWithZone: (NSZone*)zone;
|
||||
{
|
||||
NSSearchFieldCell *c = [super copyWithZone: zone];
|
||||
|
||||
|
@ -196,15 +187,15 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
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];
|
||||
|
@ -224,7 +215,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
[self _saveSearches];
|
||||
}
|
||||
|
||||
- (void) addToRecentSearches:(NSString *)searchTerm
|
||||
- (void) addToRecentSearches: (NSString*)searchTerm
|
||||
{
|
||||
if (!_recent_searches)
|
||||
{
|
||||
|
@ -238,12 +229,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 +249,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);
|
||||
}
|
||||
|
@ -310,8 +301,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];
|
||||
|
@ -438,7 +427,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
untilMouseUp: untilMouseUp];
|
||||
}
|
||||
|
||||
currentEditor = ([controlView isKindOfClass:[NSControl class]]
|
||||
currentEditor = ([controlView isKindOfClass: [NSControl class]]
|
||||
? [(NSControl *)controlView currentEditor]
|
||||
: nil);
|
||||
if (currentEditor)
|
||||
|
@ -455,14 +444,15 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
|
||||
- (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 +464,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: @""];
|
||||
[NSApp sendAction: [self action] to: [self target] from: _control_view];
|
||||
[_control_view setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -560,36 +550,36 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
|
||||
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
|
||||
|
@ -599,10 +589,10 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
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, newSelectedItemIndex;
|
||||
|
||||
template = [self searchMenuTemplate];
|
||||
popupmenu = [[NSMenu alloc] init];
|
||||
|
@ -610,7 +600,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
// 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,8 +619,8 @@ 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)
|
||||
|
@ -642,7 +632,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
}
|
||||
else if (tag == NSSearchFieldRecentsMenuItemTag)
|
||||
{
|
||||
int j;
|
||||
NSInteger j;
|
||||
|
||||
for (j = 0; j < recentCount; j++)
|
||||
{
|
||||
|
@ -666,16 +656,16 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
}
|
||||
}
|
||||
|
||||
[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];
|
||||
[[popupmenu itemAtIndex: selectedItemIndex] setState: NSOffState]; // ensure that state resets fully
|
||||
[[popupmenu itemAtIndex: selectedItemIndex] setState: NSOnState];
|
||||
|
||||
// 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
|
||||
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
|
||||
|
@ -692,7 +682,7 @@ static inline NSRect textCellFrameFromRect(NSRect cellRect)
|
|||
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])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue