• 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
Length of NSWindow's stringWithSavedFrame result?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Length of NSWindow's stringWithSavedFrame result?


  • Subject: Length of NSWindow's stringWithSavedFrame result?
  • From: John Bartleson <email@hidden>
  • Date: Mon, 07 Mar 2011 21:38:40 -0800

In my NSDocument-based app I'm saving and restoring the window frame to/from an xattribute using
NSWindow's stringWithSavedFrame and setFrameFromString: methods.


During doc save in MyDocument.m I save the frame in an override of setFileURL:
- (void)setFileURL:(NSURL *)absoluteURL
{
[super setFileURL:absoluteURL];
// Save the window frame to the file's extended attributes
NSString *frameNSString = [[tableView window] stringWithSavedFrame];
// Only do the save if window frame exists.
// i.e., if we're called during document save, not during document init
if ( [frameNSString length] ) {
const char *frameCString = [frameNSString UTF8String];
int result = setxattr( [[absoluteURL path] fileSystemRepresentation],
[JBMainWindowXattrName UTF8String],
frameCString, strlen(frameCString) + 1,
0, 0 );
}
}


Upon doc load I restore the frame in an override of windowControllerDidLoadNib:
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
// For existing files, get the window frame from the file's extended attributes.
NSURL * theURL = [self fileURL];
if ( theURL ) { // If we're loading an existing file, rather than a new one
char frameCString [50];
ssize_t bytesRetrieved = getxattr( [[theURL path] fileSystemRepresentation],
[JBMainWindowXattrName UTF8String],
frameCString, 50,
0, 0 );
if ( bytesRetrieved > 0 ) {
[[tableView window] setFrameFromString:[NSString stringWithUTF8String:frameCString]];
}
}
}


This all works great. There's only one problem: the size of the string returned by stringWithSavedFrame.

On my single-monitor system, the returned string looks like this:
552 789 1312 260 0 0 1920 1178
i.e. eight integers, four representing the window frame and four representing the screen frame.
This takes about 30 bytes. I'm suspicious, though, that the 50 bytes I've allowed for the
string returned by getxattr in the second method above might not be enough on a multi-monitor
system. Can anyone tell us what the string returned by stringWithSavedFrame looks like on a
multi-monitor system?



----------------------------------------------------------
Vielen Dank to Uli Kusterer for the idea to use an xattribute for this, and for publishing his
UKXATTRMETADATASTORE wrapper class.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please 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: Length of NSWindow's stringWithSavedFrame result?
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: Crash with extra [CFString release] after changing a bound value in NSTextField
  • Next by Date: Re: NSThread
  • Previous by thread: Re: How to wait for methods with result/completion blocks to finish?
  • Next by thread: Re: Length of NSWindow's stringWithSavedFrame result?
  • Index(es):
    • Date
    • Thread