Re: help for NSMatrix -> action cell
Re: help for NSMatrix -> action cell
- Subject: Re: help for NSMatrix -> action cell
- From: Ricky Sharp <email@hidden>
- Date: Tue, 13 Nov 2007 15:37:53 -0600
On Nov 13, 2007, at 12:02 AM, shengjun_guan (管聲俊) wrote:
I create one image browser application use NSMatrix .
I show the file's image and file's name inside the Cell. Of course i
make the Class: myCell which base from NSCell .And overwrite the
NSCell's method: drawWithFrame: inView: to show the image in up
content ,and text in down content .
---FOLLOW IS THE CODE of drawWithFrame: inView: IN MY CELL CLASS-----
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
if ((title != nil) || (image != nil))
{
NSRect imageFrame,textFrame, tempFrame;
NSDivideRect(cellFrame, &imageFrame, &textFrame,
cellFrame.size.height - 15, NSMinYEdge);
[image setFlipped:YES];
[image drawInRect:imageFrame fromRect:NSMakeRect(0,0,[image
size].width,[image size].height) operation:NSCompositeSourceOver
fraction:1.0];
if ((cellFrame.size.width - [[title string] length] * 4) / 2 >= 0)
{
textFrame.origin.x += (cellFrame.size.width - [title length] *
4) / 2;
}
textFrame.origin.y += 25;
[title drawInRect:textFrame];
}
[super drawWithFrame:cellFrame inView:controlView];
}
And , i have realizied that open the image file with Preview when
double click the Cell.
Now, i want to realizied to rename. When click the down content of
the Cell, like the TextFied, user can input the
new Text. How can i do. need I use NSView to replace NSMatrix ?
You can definitely keep using a cell. Check out Apple's sample:
/Examples/AppKit/DragNDropOutlineView/
Specifically, look at the class ImageAndTextCell.
When you run the application, you can double-click on the text next to
an icon to edit it. This is achieved by implementing
editWithFrame:inView:editor:delegate:event:. I believe you also want
to implement selectWithFrame:inView:editor:delegate:start:length:.
That class shows examples of both methods.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden