toggle autosizing

is there any way to change my autosizing options programatically?

Everything that IB does is available programmatically, though you may not be able to do a given task via AppleScript without the Cocoa bridge. Changing springs and struts via Cocoa:

http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSView/setAutoresizingMask:

I don’t see an equivalent in the Studio reference docs:

http://developer.apple.com/documentation/AppleScript/Reference/StudioReference/sr4_container_suite/sr_container.html#//apple_ref/doc/uid/20011218-ASKContainerViewSuite.Classes.NSView

A search of the forum archives didn’t turn up much for me.

ok thats all very confusing for me, could you please point me in the right direction. so like if i wanted to set auto resizing for a webview by clicking the outer upper spring in IB what would i do. is it a call method, but which method do i use, and with what parameters?

thanks.

The one that Mikey-San linked to (setAutoresizingMask:), with the parameters that are stated in the documentation (mask).

ok, i tried a few things, neither of which worked. no errors, they just didnt make the view auto resize

call method "setAutoresizingMask:NSViewWidthSizable:NSViewHeightSizable:" with parameters {(view "view" of window "main"), true, true}

and

call method "setAutoresizingMask:NSViewWidthSizable:NSViewHeightSizable:" of (view "view" of window "main") with parameters {true, true}

Hi fiftyfour,

here an example:

property NSViewNotSizable : 0
property NSViewMinXMargin : 1
property NSViewWidthSizable : 2
property NSViewMaxXMargin : 4
property NSViewMinYMargin : 8
property NSViewHeightSizable : 16
property NSViewMaxYMargin : 32


...

call method "setAutoresizesSubviews:" of (call method "contentView" of (window "main")) with parameter yes 
-- tells the content view of your window to autoresize it's subviews (in case it not already does ...)

call method "setAutoresizingMask:" of (view "view" of window "main") with parameter NSViewWidthSizable + NSViewMaxYMargin
-- the argument of setAutoresizingMask is a bit mask - I simulated it here by simply adding some properties ...

hope that helps …

D.

thats not what i meant by autosizing, i meant the little spring things that you click in IB to make objects resize with the window. that example looks like it just resizes something.

I am pretty sure i understood, what you want … maybe you want to try it? :wink:

here an excerpt from the docs:

Resizing masks
These constants are used by setAutoresizingMask:.

enum {
NSViewNotSizable = 0,
NSViewMinXMargin = 1,
NSViewWidthSizable = 2,
NSViewMaxXMargin = 4,
NSViewMinYMargin = 8,
NSViewHeightSizable = 16,
NSViewMaxYMargin = 32
};
Constants
NSViewNotSizable
The receiver cannot be resized.

NSViewMinXMargin
The left margin between the receiver and its superview is flexible.

NSViewWidthSizable
The receiver’s width is flexible.

NSViewMaxXMargin
The right margin between the receiver and its superview is flexible.

NSViewMinYMargin
The bottom margin between the receiver and its superview is flexible.

NSViewHeightSizable
The receiver’s height is flexible.

NSViewMaxYMargin
The top margin between the receiver and its superview is flexible.

setAutoresizingMask:

yeah, i did notice that, haha. i tried whatyou posted above and it didnt work, i also noticed that it doesnt refer to the view anywhere, i see the call method “contentView” do i put the name of my view there? and does it matter that it’s a webview?

EDIT: i put the code in the wrong part of my app. so its almost working. when i resize it, the webview doesnt show scroll bars, and when i resize it, it covers all my buttons and stuff at the top of the window.

call method "setAutoresizingMask:" of referToYourViewSomehow with parameter anAppropriateInteger

Edit: What integer are you using?

thanks, that works, but i’m still missing the scroll bars.

Just a guess:

call method "setNeedsDisplay:" of referToYourViewSomehow

nope, still no scroll bars. i actually dont think it’s autosizing, because when i resize the window it just crops the webview.

Hi Fiftyfour,

here a little demo project that allows programmatically changes of the autosizing behaviour of a webview (loading this thread) … maybe it helps …

http://rapidshare.com/files/58712562/AutosizingAWebView.zip.html

D.

doesnt build. i tried cleanning it, didnt work.

[code]Building target “AutosizingAWebView” of project “AutosizingAWebView” with configuration “Release”

Checking Dependencies
CpResource build/Release/AutosizingAWebView.app/Contents/Resources/English.lproj/MainMenu.nib English.lproj/MainMenu.nib
cd /Users/evan/Desktop/AutosizingAWebView
/System/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -exclude CVS -exclude .svn -strip-debug-symbols -resolve-src-symlinks /Users/evan/Desktop/AutosizingAWebView/English.lproj/MainMenu.nib /Users/evan/Desktop/AutosizingAWebView/build/Release/AutosizingAWebView.app/Contents/Resources/English.lproj

Ld /Users/evan/Desktop/AutosizingAWebView/build/AutosizingAWebView.build/Release/AutosizingAWebView.build/Objects-normal/i386/AutosizingAWebView normal i386
cd /Users/evan/Desktop/AutosizingAWebView
/usr/bin/gcc-4.0 -o /Users/evan/Desktop/AutosizingAWebView/build/AutosizingAWebView.build/Release/AutosizingAWebView.build/Objects-normal/i386/AutosizingAWebView -L/Users/evan/Desktop/AutosizingAWebView/build/Release -F/Users/evan/Desktop/AutosizingAWebView/build/Release -filelist /Users/evan/Desktop/AutosizingAWebView/build/AutosizingAWebView.build/Release/AutosizingAWebView.build/Objects-normal/i386/AutosizingAWebView.LinkFileList -framework Cocoa -framework AppleScriptKit -arch i386 -Wl,-Y,1455 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk
/usr/bin/ld: warning /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Cocoa.framework/Cocoa cputype (18, architecture ppc) does not match cputype (7) for specified -arch flag: i386 (file not loaded)
/usr/bin/ld: warning /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/AppleScriptKit.framework/AppleScriptKit cputype (18, architecture ppc) does not match cputype (7) for specified -arch flag: i386 (file not loaded)
/usr/bin/ld: warning /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/…/…/…/libgcc_s.10.4.dylib cputype (18, architecture ppc) does not match cputype (7) for specified -arch flag: i386 (file not loaded)
/usr/bin/ld: warning /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/…/…/…/libSystem.dylib cputype (18, architecture ppc) does not match cputype (7) for specified -arch flag: i386 (file not loaded)
/usr/bin/ld: Undefined symbols:
___keymgr_dwarf2_register_sections
__cthread_init_routine
_atexit
_errno
_exit
_mach_init_routine
_ASKInitialize
_NSApplicationMain
/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/…/…/…/crt1.o reference to undefined ___keymgr_dwarf2_register_sections
/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/…/…/…/crt1.o reference to undefined __cthread_init_routine
/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/…/…/…/crt1.o reference to undefined _atexit
/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/…/…/…/crt1.o reference to undefined _errno
/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/…/…/…/crt1.o reference to undefined _exit
/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/…/…/…/crt1.o reference to undefined _mach_init_routine
/Users/evan/Desktop/AutosizingAWebView/build/AutosizingAWebView.build/Release/AutosizingAWebView.build/Objects-normal/i386/main.o reference to undefined _ASKInitialize
/Users/evan/Desktop/AutosizingAWebView/build/AutosizingAWebView.build/Release/AutosizingAWebView.build/Objects-normal/i386/main.o reference to undefined _NSApplicationMain
collect2: ld returned 1 exit status[/code]

sorry … it seems your Xcode does not like the build settings of mine … try this: open Project → ‘Edit Project Settings’ and set ‘Cross Develop Using Target SDK’ to ‘Current Mac OS’ …

EDIT: it builds in debug not release mode. So this is still confusing to me. I figured out with your app that my “mask” value is 18 for the autosizing options i want. so i put this in my code.

call method "setAutoresizesSubviews:" of (call method "contentView" of (window "main")) with parameter yes
call method "setAutoresizingMask:" of (view "view" of window "main") with parameter 18

and it still doesnt do anything.

anyone?

anyone???