discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: One question about subclass


From: address@hidden
Subject: Re: One question about subclass
Date: Thu, 25 Sep 2008 00:11:32 -0700 (PDT)
User-agent: G2/1.0

On 25 Sep., 04:27, Germán André Arias Santiago
<germanandre...@yahoo.com> wrote:
> I want make an app to solve some physics problems. Then my app have a panel 
> wiht many things (ball, cannon, wall, ....) to represent the problem. When a 
> user do click in some of this things, a NSViewImage is add into the 
> chalckbord (a NSView's subclass). I want let the user to move these things to 
> any position (with a drag operation). But, when I do click in one of this 
> things (NSImageView), the NSView don't get the NSEvent, then I can't move the 
> NSImageView with mouseDragged: method (in the NSView). Even if I add the 
> NSImageView with addSubview: positioned: relativeTo:   with the argument 
> NSWindowBelow. I don't know some method to delegate this event from 
> NSImageView to NSView. I tryed with Drag & Drop, but I only can move an image 
> from one NSImageView to another. Then I think in a subclass of NSImageView to 
> write the mouseDragged: method. I add this subclass in something like this

Hi,
I think your problem has a different cause than subclassing itself.

As fas as I understand, you have sort of a container view where you
want to allow to add/remove and drag subviews.

There are several aspects to consider:
1. subviews should not overlap or you may get unexpected graphical
results (there is no well defined stacking order for overlapping
subviews)
2. events are dispatched to the subview at the mouse location (unless
they overlap!) - method -[NSView hitTest:]
3. you may/should write your own container view that manages a list of
subcells (NSImageCell) to get much better control how drawing and
dragging works

Maybe, the classes NSToolbarView and NSTableHeaderView are examples
how to do that. There is code in drawRect: to draw their NSCell based
items and mouseDown: does a tracking loop to handle dragging.

-- hns


reply via email to

[Prev in Thread] Current Thread [Next in Thread]