• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to make NSWindow redraw vacated rects "ifNeeded"?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to make NSWindow redraw vacated rects "ifNeeded"?


  • Subject: Re: How to make NSWindow redraw vacated rects "ifNeeded"?
  • From: Jerry Krinock <email@hidden>
  • Date: Sun, 8 Apr 2007 15:37:15 -0700

On 2007 Apr, 08, at 13:23, Andrew Farmer wrote:

AppKit depends on the presence of an event loop for a lot of things, including redrawing views. I'm not exactly sure what you're trying to accomplish here, but it'll probably work better if you avoid sleeping outside the event loop. Use NSTimer and -[NSObject performSelector:withObject:afterDelay:] to implement delayed events.

Well, that sleeping is just because, before I posted that code, I was showing several windows in successtion and wanted a few seconds to look at each one. And then I thought it would be cool if I didn't have to hit "Quit" after each test, so I left it in there. I understand about the event loop, and it sounded promising Andrew, that the event loop might have to cycle before things get drawn, but in this case it does not matter. After my signature I have re-posted the code with that sleep and exit() simply removed. The window now stays up forever, but the problem is still the same.


As a general point, BTW, you should never need to call setNeedsDisplay, display, or displayIfNeeded on view objects. (Only exception is a view calling setNeedsDisplay on itself.) The view should otherwise be able to do redraw management for itself.

Yes, I agree with that. When I first wrote the code, I only sent - displayIfNeeded to the window, not the views. But the setNeedsDisplay messages in fact do neither harm nor good. - [NSWindow display], or the extra -orderFront, are the only things that seem to do any good.


Thanks,

Jerry Krinock

P.S. There is also a Really Weird way to solve the problem: If I - orderFront: the window before adding the NSBox subview, then the vacated rect gets redrawn by -displayIfNeeded as expected. A possibly related mystery is that I find -orderFront: is needed to get an NSProgressIndicator to start animating (with threaded animation).

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)noti {
   // Create window
   NSWindow* window = [[NSWindow alloc]
      initWithContentRect:NSMakeRect(0,0,300,100)
              styleMask:NSTitledWindowMask
               backing:NSBackingStoreBuffered
                 defer:NO] ;
   [window center] ;
    // Uncommenting this will fix the problem (Really Weird)!
    // [window orderFront:self] ;

   // Create a box and add to window
   NSBox* box ;
   box = [[NSBox alloc]
      initWithFrame:NSMakeRect(20,10,260,40)] ;
   [[window contentView] addSubview:box] ;

   [window orderFront:self] ;

   // Move box origin from y=10 up to y=50
   // (a) First, mark the current rect for redrawing
   //     This does not seem to have any effect!
   [box setNeedsDisplay:YES] ;
   // (b) Move it
   [box setFrame:NSMakeRect(20,50,260,40)] ;
   // (c) Mark the new rect as needing redrawing
   [box setNeedsDisplay:YES] ;

   // Update the window
   [window displayIfNeeded] ; // Not good enough!!
   // Uncomment the next line and it works as desired
   // [window display] ;
}

@end

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: How to make NSWindow redraw vacated rects "ifNeeded"?
      • From: Darkshadow <email@hidden>
    • Re: How to make NSWindow redraw vacated rects "ifNeeded"?
      • From: "Adam R. Maxwell" <email@hidden>
References: 
 >How to make NSWindow redraw vacated rects "ifNeeded"? (From: Jerry Krinock <email@hidden>)
 >Re: How to make NSWindow redraw vacated rects "ifNeeded"? (From: Andrew Farmer <email@hidden>)

  • Prev by Date: Re: Points
  • Next by Date: Re: How to make NSWindow redraw vacated rects "ifNeeded"?
  • Previous by thread: Re: How to make NSWindow redraw vacated rects "ifNeeded"?
  • Next by thread: Re: How to make NSWindow redraw vacated rects "ifNeeded"?
  • Index(es):
    • Date
    • Thread