help for NSMatrix -> action cell

  • Hi all,

    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 ?

    any reply is welcome . thanks a lot.

    --Tom
  • On Nov 13, 2007, at 12:02 AM, shengjun_guan (ºÞÁn«T) 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:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today