<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vincent Gable's Blog &#187; NSWindow</title>
	<atom:link href="http://vgable.com/blog/tag/nswindow/feed/" rel="self" type="application/rss+xml" />
	<link>http://vgable.com/blog</link>
	<description>my weblog.</description>
	<lastBuildDate>Tue, 29 Nov 2011 22:20:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>NSWindow setResizable:</title>
		<link>http://vgable.com/blog/2008/04/11/nswindow-setresizable/</link>
		<comments>http://vgable.com/blog/2008/04/11/nswindow-setresizable/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 06:12:39 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[MacOSX]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[Interface]]></category>
		<category><![CDATA[NSWindow]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/2008/04/11/nswindow-setresizable/</guid>
		<description><![CDATA[-[NSWindow setResizable:(BOOL)] does not exist. But, here is a way to get that effect as long as the window was resizable when created. (I don&#8217;t know of a way to make a window resizeable if it was first created unresizeable). The basic idea is to show/hide the resizing controls, and implement delegate functions that prevent [...]]]></description>
			<content:encoded><![CDATA[<p><code>-[NSWindow setResizable:(BOOL)]</code> does not exist.  But, here is a way to get that effect as long as the window was resizable when created.   (I don&#8217;t know of a way to make a window resizeable if it was first created unresizeable).</p>
<p>The basic idea is to show/hide the resizing controls, and implement delegate functions that prevent the window from being resized when the resizing controls are hidden.</p>
<pre>//show or hide hide the window's resizing controls:
[[window standardWindowButton:NSWindowZoomButton] setHidden:!resizable];
[window setShowsResizeIndicator:resizable];</pre>
<p>Note that  <code>setShowsResizeIndicator:</code> only shows/hides the resize-indicator in the lower-right of the window.  It will <b>not</b> make the window non-resizeable.</p>
<p>To keep the window from being resized when <code>showsResizeIndicator</code> is false, implement  the delegate methods:</p>
<pre>- (NSSize)windowWillResize:(NSWindow *) window toSize:(NSSize)newSize
{
	if([window showsResizeIndicator])
		return newSize; //resize happens
	else
		return [window frame].size; //no change
}

- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
{
	//let the zoom happen iff showsResizeIndicator is YES
	return [window showsResizeIndicator];
}</pre>
<h3>No Delegate Hack</h3>
<p>Finally, there is a hack that avoids using delegate methods, although I don&#8217;t recommend it.</p>
<pre>[[window standardWindowButton:NSWindowZoomButton] setHidden:!resizable];
[window setShowsResizeIndicator:resizable];
CGFloat resizeIncrements = resizable ? 1 : MAXFLOAT;
[window setResizeIncrements:NSMakeSize(resizeIncrements, resizeIncrements)];
</pre>
<p><code>setResizeIncrements</code> &#8220;Restricts the user’s ability to resize the receiver so the width and height change by multiples of width and height increments.&#8221;  So setting it to <code>MAXFLOAT x MAXFLOAT</code> means that the user can&#8217;t resize the window, because they won&#8217;t have a  big enough screen.  Note that this won&#8217;t disable the &#8220;zoom&#8221; function, although the user probably couldn&#8217;t use it with the zoom button hidden.</p>
<p>This approach uses slightly fewer lines of code, but it is more brittle and indirect, since it depends on the screen-size, not if the window is (visibly) resizeable.  I wouldn&#8217;t use it over delegates.  But here it is.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2008/04/11/nswindow-setresizable/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

