Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
i can't figure out how to make my mainWindow (with a toolbar) to resize itself to my mainSheet (in other words, make the sheet fit perfectly inside the mainWindow's view)... i'm using setFrame:animate:display for the resize, but it's not taking into account that there's a toolbar on the mainWindow, so the resize is the same width of the mainSheet, but a little shorter:

Code:
[mainWindow setFrame:[mainSheet frame] display:YES animate:YES];
[NSApp mainSheet modalForWindow:mainWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];

please help... :(
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
ok... 10 years later :rolleyes: ...

this code could probably be more optimized, but it seems to work well...

Code:
NSSize SheetSize = [Sheet frame].size;
NSPoint SheetPoint = [Sheet frame].origin;
NSToolbar *toolbar = [mainWindow toolbar];
			
	if(toolbar && [toolbar isVisible])
		{
		[mainWindow setFrame:NSMakeRect(SheetPoint.x, SheetPoint.y, SheetSize.width, SheetSize.height + 55) display:YES animate:YES];
		[NSApp beginSheet:Sheet modalForWindow:mainWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
		}
		else
		{
		[mainWindow setFrame:NSMakeRect(SheetPoint.x, SheetPoint.y, SheetSize.width, SheetSize.height) display:YES animate:YES];
		[NSApp beginSheet:Sheet modalForWindow:mainWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
		}

through trial and error i figured out that my toolbar is 55 pixels in height... the toolbar's height will never change in my app so even though it's kinda ghetto to get the toolbar's height this way, it's fine for me... for learning purposes, i'm very open to knowing a better way to write this method if anyone has any thoughts or examples...
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
You could try subtracting the window's content height from its frame height. See NSWindow's frameRectForContentRect: and contentRectForFrameRect: methods.
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
You could try subtracting the window's content height from its frame height. See NSWindow's frameRectForContentRect: and contentRectForFrameRect: methods.

wow that really did make the coding a lot easier ;)... thanks for that... the following code seems perfect now, and i no longer have to ask if the toolbar is visible or not...:

Code:
NSSize SheetSize = [sheet contentRectForFrameRect:[sheet frame]].size;
NSSize MainWindowFrame = [mainWindow frame].size;
NSSize MainWindowContent = [mainWindow contentRectForFrameRect:[mainWindow frame]].size;
NSPoint SheetPoint = [mainWindow contentRectForFrameRect:[mainWindow frame]].origin;

[mainWindow setFrame:NSMakeRect(SheetPoint.x, SheetPoint.y, SheetSize.width, (SheetSize.height + (MainWindowFrame.height - MainWindowContent.height))) display:YES animate:YES];
[NSApp beginSheet:sheet modalForWindow:mainWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];

tasty... ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.