 |
 |
Progromattically adding NSViews...
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Pittsburgh
Status:
Offline
|
|
For a my brushedMetalNSWindow framework, I'm attempting to progromatically add NSViews to an NSWindow declared in interface builder. Unfortunately, the progromatically generated NSViews aren't showing up on the screen at all. (after over 20 hours of bashing my head I'm gonna crack!
Are there any good examples of adding NSviews progromatically?
I think I've downloaded all the Obj-C / Cocoa / OS X dev / OpenStep references in existance yet to no avail.
I've pasted some of the code below...
<font face = "courier">[theView display];</font>
--> properly invokes the custom NSView's drawRect routine
<font face = "courier">[theView setNeedsDisplay:YES];</font>
--> doesn't do anything
The answer to this odity would probably explain alot.
Here's the custom class of NSWindow's initWithContentRect:... routine that I'm using to add additional custom NSViews
<font face = "courier">
- (id)initWithContentRect  NSRect)contentRect styleMask  unsigned int)aStyle backing  NSBackingStoreType)bufferingType defer  BOOL)flag
{
self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
if (self)
{
theWindowDraggingView = [[WindowDraggingView alloc]
initWithFrame:NSMakeRect(0, 0, contentRect.size.width, contentRect.size.height)];
[theWindowDraggingView retain];
...
</font>
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jun 2001
Location: Pleasant Valley, NY
Status:
Offline
|
|
Two things.. 1) Are you adding your view to the window? That seems pretty obvious but it's not in your code, so I don't know. See -[NSWindow setContentView:] and 2) You don't need to retain theWindowDraggingView if you use alloc to create it (which you are)
Matt
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Pittsburgh
Status:
Offline
|
|
Originally posted by mreda:
<STRONG>Two things.. 1) Are you adding your view to the window? That seems pretty obvious but it's not in your code, so I don't know. See -[NSWindow setContentView:] and 2) You don't need to retain theWindowDraggingView if you use alloc to create it (which you are)
Matt</STRONG>
Thanks for the reply...
(1) I'm definately using [NSWindow setContentView:] (see following posts that I origonally posted to the Apple OS X dev board.
(2) Yep, retain isn't needed. Thanks for the reminder. I've rewritten the code so many times now that I'm starting to purposely add things which, according to the documentation, aren't needed.
Maybe the following two posts will clarify the mystery 
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Pittsburgh
Status:
Offline
|
|
I just noticed some other odities:
If I set the content view of a window to a custom NSView, the custom view's drawRect funtion is never called even via [[NSWindow contentView] display].
However, if I set the contentView to [[NSView alloc] initWithFrame:someRect], and then add the custom NSView as a subview of the contentView, the custom view's drawRect function is called when invoking [[NSWindow contentView] display].
This is kind of a pain since its just an extra NSView with no subviews except for the one that I actually want to be the windows contentView.
Yet either way the view don't draw themselves... ? I've checked the coordinates, and verified the custom view's superview and window. Yet even filling the view's frame with blackColor doesn't have any effect.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Pittsburgh
Status:
Offline
|
|
Even more details:
While in the custom NSView's drawRect routine...
Drawing into or filling the view's visibleRect doesn't have any visible results.
I've verified the visible rect at various points during execution... It seems as if the drawing routines are drawing into views that have a visibleRect and exist in the view hierarchy.
[[theWindow contentView] display] indeed invokes the correct drawRect routines yet nothing shows up.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status:
Offline
|
|
Originally posted by dfiler:
<STRONG>[[theWindow contentView] display]</STRONG>
have you tried [[theWindow contentView] setNeedsDisplay:YES] ?
just a guess...
[edit: just noticed you have tried that -- never mind]
[ 11-11-2001: Message edited by: seb2 ]
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Pittsburgh
Status:
Offline
|
|
Originally posted by seb2:
<STRONG>
have you tried [[theWindow contentView] setNeedsDisplay:YES] ?
just a guess...
[edit: just noticed you have tried that -- never mind]
[ 11-11-2001: Message edited by: seb2 ]</STRONG>
I think this is one of the important clues here...
<font face = "courier">[[theWindow contentView] setNeedsDisplay:YES]</font>
-- never results in drawRect being called
<font face = "courier">[[theWindow contentView] display]</font>
-- properly calls drawRect since its designed to do it 'now' instead of when the window server gets around to it.
This caused me to investigate the view's visibleRect, figuring that if the window server doesn't want to call drawRect, it might be because none of the view is visible. The visibleRect checked out OK as far as I could tell.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jun 2001
Location: Pleasant Valley, NY
Status:
Offline
|
|
I don't really have anything else to offer off the top of my head, but if you want to email the code to me, I would be willing to take a look at it.
Matt
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Pittsburgh
Status:
Offline
|
|
Originally posted by mreda:
<STRONG>I don't really have anything else to offer off the top of my head, but if you want to email the code to me, I would be willing to take a look at it.
Matt</STRONG>
Thanks, i'll do that in the morning when I have time to clean up my messy code...
However, I seem to have made some progress!
In my custom window's init methods, I make sure to immediately call the super's init and then to work with the NSWindow it returns. Turns out, you can't add views to the NSWindow until after its subclasses have returned the newly inited customNSWindow.
I wish there was better documentation! I've read everything the included developer docs and Learning Cocoa have to say about these topics. Guess I'll read em another 30 times
Am I correct in pursueing the following tact?
I intend to subclass NSWindowController and use its windowDidLoad: method as the proper location to add NSViews to a newly initialized window. Is there a way to do this from within NSWindow without needing a window controller?
Maybe I should check to see if this actually works before elaborating
I only assume that it'll work since adding the NSViews from within <font face = "courier">[customNSWindow mouseDown:]</font> worked!
[ 11-13-2001: Message edited by: dfiler ]
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Just out of curiosity, what happens if you define the window programmtically and then change the NSView's programmtically?
F-bacher
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
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
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|