• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Duplicating Apple search field UI
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Duplicating Apple search field UI


  • Subject: Re: Duplicating Apple search field UI
  • From: email@hidden
  • Date: Sun, 9 Feb 2003 22:43:36 +0100

On dimanche, fivrier 9, 2003, at 07:24 PM, Andrew Pinski wrote:

I say file a bug about it than ask here for sample code, this is a
list provided by Apple and run by Apple but not the right way to
communicate with Apple, this has been mentioned some many time by
people at Apple (now including me) and by other people.

Some code that might help (since filing a bug is not the fastest solution).

I didn't implement everything yet but it looks like the Apple control (I'm only using the methods implemented by the Apple version) and it solves 3 issues I saw in previous posts:
- it does not use 3 cells
- it's getting the end of edition in 100% of cases
- there's no issue with the height of the control.

What's left mainly:
- handling the stop stuff
- handling the _delegate stuff
- handling the drawing of the focus
- the text font is not the one used in Mail.app. I think it's one point bigger.

Must be a matter of 2-3 hours (I lost my usual 30 minutes finding the fieldEditor correct rect)

#import <AppKit/AppKit.h>

@interface WBSearchTextField : NSTextField
{
NSImage * _leftCapImage;
NSImage * _middleImage;
NSImage * _rightCapImage;
NSImage * _completeImage;
NSMutableArray * _stopImages;
//struct _flags;
}

- (BOOL)isDisplayingGraySearchScope;
- (void)displayGraySearchScopeIfAppropriate:(BOOL) aBool;
- (void)removeGraySearchScope;
- (BOOL)becomeFirstResponder;
- (void)selectText:(id)sender;
- (void)awakeFromNib;
- (void)_loadImagesIfNecessary;
- (void)dealloc;
- (NSImage *) backgroundImage;
- (void)setFrameSize:(NSSize) newSize;
- (void)drawRect:(NSRect) aFrame;
- (void)mouseDown:(NSEvent *) theEvent;
//- (void)_cancelKey:fp12;
- (void)resetCursorRects;
- (void)showCancelButton:(BOOL) aBool;
- (void)throbCancelButton:(BOOL) aBool;
//- (void)heartBeat:(struct ? *)fp12;
- (void)setNeedsDisplay:(BOOL) aBool;
- (void)setKeyboardFocusRingNeedsDisplayInRect:(NSRect) aFrame;
- (void)textDidEndEditing:(NSNotification *)notification;
- (void)_setFocusNeedsDisplay;

@end

/*
- (void)searchPopupChanged:fp12;
- (void)searchIndex:fp12;
- (void)clearSearch:fp12;
- (void)searchFinished:fp12;
- (void)performSearch:fp12;
*/


-----8<------8<-----8<-----8<------8<--------8<------

#import "WBSearchTextField.h"

#define WBSERACHTEXTFIELD_MIN_WIDTH 34

static NSImage * _leftCapImage_=nil;
static NSImage * _middleImage_=nil;
static NSImage * _rightCapImage_=nil;

@implementation WBSearchTextField

- (BOOL)isDisplayingGraySearchScope
{
// A COMPLETER

return YES;

}
- (void)displayGraySearchScopeIfAppropriate:(BOOL) aBool
{
}

- (void)removeGraySearchScope
{
}

- (BOOL) becomeFirstResponder
{
return YES;
}

- (void)selectText:(id)sender
{
NSLog(@"selectText");
}

- (void)awakeFromNib
{
//[super awakeFromNib];

[self _loadImagesIfNecessary];

[[self cell] setDrawsBackground:YES];

[[self cell] setBordered:NO];

[[self cell] setBezeled:NO];

// Build the image

_completeImage=[[self backgroundImage] retain];

NSLog(@"awakeFromNib");

[self setStringValue:@"toto"];
}

- (void)_loadImagesIfNecessary
{
if (_leftCapImage_==nil)
{
_leftCapImage_=[[NSImage imageNamed:@"LeftSearchCap"] retain];
}

if (_middleImage_==nil)
{
_middleImage_=[[NSImage imageNamed:@"MiddleSearch"] retain];
}

if (_rightCapImage_==nil)
{
_rightCapImage_=[[NSImage imageNamed:@"RightSearchCap"] retain];
}

_leftCapImage=_leftCapImage_;

_middleImage=_middleImage_;

_rightCapImage=_rightCapImage_;

}

- (void)dealloc
{
// A COMPLETER

[_completeImage release];

[super dealloc];
}

- (NSImage *) backgroundImage
{
NSRect tBounds;
float tWidth;

NSImage * tImage;

tBounds=[self bounds];

tImage=[[NSImage alloc] initWithSize:tBounds.size];

tWidth=tBounds.size.width;

if (tImage!=nil)
{
NSSize tSize;
float tStartPointX;
float tEndPointX;

[tImage setFlipped:NO];

[tImage lockFocus];

// Left cap

tSize=[_leftCapImage size];

tStartPointX=tSize.width;

tWidth-=tSize.width;

[_leftCapImage compositeToPoint:NSMakePoint(0,0) operation:NSCompositeSourceOver];

// Right cap

tSize=[_rightCapImage size];

tWidth-=tSize.width;

tEndPointX=tBounds.size.width-tSize.width;

[_rightCapImage compositeToPoint:NSMakePoint(tBounds.size.width-tSize.width,0) operation:NSCompositeSourceOver];

// Middle section

if (tEndPointX>=tStartPointX)
{
tSize=[_middleImage size];

[NSBezierPath clipRect:NSMakeRect(tStartPointX,0,tWidth,tBounds.size.height)];

for(;tStartPointX<tEndPointX;tStartPointX+=tSize.width)
{
[_middleImage compositeToPoint:NSMakePoint(tStartPointX,0) operation:NSCompositeSourceOver];
}
}

[tImage unlockFocus];
}

return tImage;
}

- (void)setFrameSize:(NSSize) newSize
{
//if (newSize.width==22)
{
if (newSize.width>=WBSERACHTEXTFIELD_MIN_WIDTH)
{
[super setFrameSize:newSize];

if (_completeImage!=nil)
{
[_completeImage release];
}

_completeImage=[[self backgroundImage] retain];


}
}
}

- (void)drawRect:(NSRect) aFrame
{
NSRect tBounds;

tBounds=[self bounds];

// Draw background

if (_completeImage!=nil)
{
[_completeImage compositeToPoint:NSMakePoint(0,tBounds.size.height) operation:NSCompositeSourceOver];
}

/*{
NSRect focusRingFrame = [self bounds];
focusRingFrame.size.height -= 2.0;
[NSGraphicsContext saveGraphicsState];
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSBezierPath bezierPathWithRect: NSInsetRect(focusRingFrame,4,4)]
fill];
[NSGraphicsContext restoreGraphicsState];
}*/

//[self backgroundImage];

NSLog(@"drawRect");

[[self cell] drawWithFrame:NSMakeRect(25,4,tBounds.size.width- 33,tBounds.size.height-6) inView:self];

//[super drawRect:aFrame];
}

- (void)mouseDown:(NSEvent *) theEvent
{
NSPoint tMouseLoc=[self convertPoint:[theEvent locationInWindow] fromView:nil];
NSRect tRect;
NSRect tBounds=[self bounds];

// Check if the click is on the PopUp (the rect is not the correct one)

tRect=NSMakeRect(0,0,24,tBounds.size.height);

if (NSMouseInRect(tMouseLoc,tRect,[self isFlipped])==YES)
{
// Show the Pop-up

// A COMPLETER
}
else
{
// This is the part that is not obvious

[[self cell] editWithFrame:NSMakeRect(25,4,tBounds.size.width- 33,tBounds.size.height-6)
inView:self
editor:[[self window] fieldEditor:YES forObject:self]
delegate:self
event:theEvent];
}

//[super mouseDown:theEvent];
}

//- (void)_cancelKey:fp12;

- (void)resetCursorRects
{
NSLog(@"resetCursorRects");

[super resetCursorRects];
}

- (void)showCancelButton:(BOOL) aBool
{
}

- (void)throbCancelButton:(BOOL) aBool
{
}

//- (void)heartBeat:(struct ? *)fp12;

- (void)setNeedsDisplay:(BOOL) aBool
{
[super setNeedsDisplay:aBool];
}

- (void)setKeyboardFocusRingNeedsDisplayInRect:(NSRect) aFrame
{
NSLog(@"setKeyboardFocusRingNeedsDisplayInRect");

//[super setKeyboardFocusRingNeedsDisplayInRect:NSZeroRect];
}

- (void)textDidEndEditing:(NSNotification *)notification
{
NSLog(@"textDidEndEditing");

if (_delegate!=nil)
{

}
}

- (void)_setFocusNeedsDisplay
{
}

@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Duplicating Apple search field UI (From: Andrew Pinski <email@hidden>)

  • Prev by Date: Re: NSTextView && keyboard
  • Next by Date: help! always getting this strange error
  • Previous by thread: Re: Duplicating Apple search field UI
  • Next by thread: Re: Duplicating Apple search field UI
  • Index(es):
    • Date
    • Thread