{"id":25,"date":"2008-04-11T01:12:39","date_gmt":"2008-04-11T06:12:39","guid":{"rendered":"http:\/\/vgable.com\/blog\/2008\/04\/11\/nswindow-setresizable\/"},"modified":"2009-06-28T01:39:56","modified_gmt":"2009-06-28T06:39:56","slug":"nswindow-setresizable","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2008\/04\/11\/nswindow-setresizable\/","title":{"rendered":"NSWindow setResizable:"},"content":{"rendered":"<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>\n<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>\n<pre>\/\/show or hide hide the window's resizing controls:\n[[window standardWindowButton:NSWindowZoomButton] setHidden:!resizable];\n[window setShowsResizeIndicator:resizable];<\/pre>\n<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>\n<p>To keep the window from being resized when <code>showsResizeIndicator<\/code> is false, implement  the delegate methods:<\/p>\n<pre>- (NSSize)windowWillResize:(NSWindow *) window toSize:(NSSize)newSize\n{\n\tif([window showsResizeIndicator])\n\t\treturn newSize; \/\/resize happens\n\telse\n\t\treturn [window frame].size; \/\/no change\n}\n\n- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame\n{\n\t\/\/let the zoom happen iff showsResizeIndicator is YES\n\treturn [window showsResizeIndicator];\n}<\/pre>\n<h3>No Delegate Hack<\/h3>\n<p>Finally, there is a hack that avoids using delegate methods, although I don&#8217;t recommend it.<\/p>\n<pre>[[window standardWindowButton:NSWindowZoomButton] setHidden:!resizable];\n[window setShowsResizeIndicator:resizable];\nCGFloat resizeIncrements = resizable ? 1 : MAXFLOAT;\n[window setResizeIncrements:NSMakeSize(resizeIncrements, resizeIncrements)];\n<\/pre>\n<p><code>setResizeIncrements<\/code> &#8220;Restricts the user\u2019s 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>\n<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>\n","protected":false},"excerpt":{"rendered":"<p>-[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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3,5,4,13],"tags":[296,443],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-cocoa","category-macosx","category-objective-c","category-programming","category-sample-code","tag-interface","tag-nswindow"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":0,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}