|
|
Using NSView addSubview:
|
|
|
|
Professional Poster
Join Date: Sep 2000
Location: Texas
Status:
Offline
|
|
In my latest program, I am adding NSViews. There is something similiar to this:
while(I get the next thing)
{
NSView* view = [nextthing theView];
NSRange frame = [view bounds];
[view setFrame:NSMakeRect(0.0,height,112.0,frame.size.he ight)];
[theView addSubview:view positioned:1 relativeTo:nil];
[theView setNeedsDisplay:YES];
height += frame.size.height;
}
This will add my view that I am getting and place it in my theView which is the view of the window. Everything displays great, what I am having problems with is that only the latest NSView will accept mouse clicks. Now here are my thoughts:
1. I obtain the click in the window then find out if is inside of a NSRect and if that NSRect corresponds to one of the views. If it does, then I will need to switch to that view and let it do its thing.
I do not know how to switch to that view. Any ideas or am I going down the wrong trail?
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Jun 2001
Location: Savoy, IL USA
Status:
Offline
|
|
Originally posted by djohnson:
In my latest program, I am adding NSViews. There is something similiar to this:
while(I get the next thing)
{
NSView* view = [nextthing theView];
NSRange frame = [view bounds];
[view setFrame:NSMakeRect(0.0,height,112.0,frame.size.he ight)];
[theView addSubview:view positioned:1 relativeTo:nil];
[theView setNeedsDisplay:YES];
height += frame.size.height;
}
This will add my view that I am getting and place it in my theView which is the view of the window. Everything displays great, what I am having problems with is that only the latest NSView will accept mouse clicks. Now here are my thoughts:
1. I obtain the click in the window then find out if is inside of a NSRect and if that NSRect corresponds to one of the views. If it does, then I will need to switch to that view and let it do its thing.
I do not know how to switch to that view. Any ideas or am I going down the wrong trail?
What kind of NSView or NSView subclasses is this? If you're directly subclassing NSView, make sure that you override acceptsFirstMouse:. If it's some kind of NSControl or whatever, that shouldn't matter, I guess. Anyway, you shouldn't need to do anything to mouseDown: in the window; the event should get propagated properly to the subviews, if you're doing everything else correctly.
The reason that the last view added might be getting the mouse clicks is that it's become the first responder. Maybe look into that angle, as well.
Maybe if you could post a little more info on what the subviews that you're adding actually are, and what you're trying to accomplish, that might be helpful.
|
Software Architect, CodeTek Studios, Inc.
12" AlBook 867 (Combo drive) 640 MB/40 GB (work development machine) -- TiBook 400MHz/384MB/10GB (home machine)
CodeTek VirtualDesktop Pro: Power multitasking! -- DockExtender: Powerful, efficient launcher for Apps, Docs and everything else!
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Sep 2000
Location: Texas
Status:
Offline
|
|
Sure, the subviews are buttons. This is why it is messing with my head... I am directly subclassing NSView. Does this help any?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|