Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > A "smooth" resize in AS-Studio ?

A "smooth" resize in AS-Studio ?
Thread Tools
Mac Elite
Join Date: Sep 2001
Location: The Land of Beer and Chocolates
Status: Offline
Reply With Quote
Feb 8, 2002, 04:57 AM
 
I was wondering how you can make a window resize , but smoothly like in System Prefs .
Basically , I would want to tell a window "smooth resize to (300,400)" (you get the idea) .

Is that possible in AS-Studio ?
     
Mac Enthusiast
Join Date: Nov 2001
Status: Offline
Reply With Quote
Feb 8, 2002, 07:14 AM
 
Create Application.h and Application.m files using the standard NSApplication headers. Create a new method in Application.m:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
- (void)resizeWindow NSWindow *)window toHeight int)height toWidth int)width
{
NSRect windowFrame,newWindowFrame;
windowFrame = [NSWindow contentRectForFrameRect:[window frame] styleMask:[window styleMask]];
newWindowFrame = [NSWindow frameRectForContentRect:NSMakeRect(NSMinX(windowFr ame) - width,NSMaxY(windowFrame) - height,width,height) styleMask:[window styleMask]];

[window setFrame:newWindowFrame display:YES animate:YES];
}
</font>[/code]

And add it to the header file as well. This should work (if it doesn't change "NSMinX(windowFrame) - width" to "NSMinX(windowFrame)"--it's from memory. Just call this from your AS-S app:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
call method <font color = red>"resizeWindow:toHeight:toWidth:"</font>with parameters {window "MyProjectWindow, <font color = blue>212</font>, <font color = blue>345</font>}
</font>[/code]
as an example.

[ 02-08-2002: Message edited by: Ibson ]
     
Mac Elite
Join Date: Sep 2001
Location: The Land of Beer and Chocolates
Status: Offline
Reply With Quote
Feb 9, 2002, 04:24 AM
 
Thanks for the reply , but I can't figure out how to get it to work

Could you post exactly what I should write in the Application.h and Application.m files ?

Thanks
     
Mac Enthusiast
Join Date: Nov 2001
Status: Offline
Reply With Quote
Feb 9, 2002, 04:31 AM
 
Sorry --here's the full listing:

Application.h:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
#import &lt;AppKit/AppKit.h&gt;

@interface NSApplication (ApplicationName)

- (void)resizeWindow NSWindow *)window toHeight int)height toWidth int)width;

@end
</font>[/code]

Application.m:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
#import <font color = red>"Application.h"</font>

@implementation NSApplication (ApplicationName)

- (void)resizeWindow NSWindow *)window toHeight int)height toWidth int)width
{
NSRect windowFrame,newWindowFrame;
windowFrame = [NSWindow contentRectForFrameRect:[window frame] styleMask:[window styleMask]];
newWindowFrame = [NSWindow frameRectForContentRect:NSMakeRect(NSMinX(windowFr ame) - width,NSMaxY(windowFrame) - height,width,height) styleMask:[window styleMask]];

[window setFrame:newWindowFrame display:YES animate:YES];
}

@end
</font>[/code]

Hope this helps!
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Feb 9, 2002, 04:54 AM
 
Just wondering why you implemented it as a category of NSApplication? Seems a bit silly to me.
     
Mac Elite
Join Date: Sep 2001
Location: The Land of Beer and Chocolates
Status: Offline
Reply With Quote
Feb 9, 2002, 05:06 AM
 
Originally posted by Ibson:
<STRONG>Sorry --here's the full listing:

.....

Hope this helps!</STRONG>
Thanks a lot , it works now , but it has a side-effect : if I resize a window , the window doesn't stay where it was . Instead , it slides to the left . Do you know why ?
     
Mac Elite
Join Date: Sep 2001
Location: The Land of Beer and Chocolates
Status: Offline
Reply With Quote
Feb 9, 2002, 10:10 AM
 
Originally posted by Jan Van Boghout:
<STRONG>

Thanks a lot , it works now , but it has a side-effect : if I resize a window , the window doesn't stay where it was . Instead , it slides to the left . Do you know why ?</STRONG>
Sorry , I didn't read your first post completely
I didn't see "(if it doesn't change "NSMinX(windowFrame) - width" to "NSMinX(windowFrame)"

Now I did that and it works like it should , thanks a lot !
     
Mac Enthusiast
Join Date: Nov 2001
Status: Offline
Reply With Quote
Feb 9, 2002, 06:42 PM
 
Originally posted by Angus_D:
<STRONG>Just wondering why you implemented it as a category of NSApplication? Seems a bit silly to me.</STRONG>
True, but AppleScript Studio won't access methods that aren't a category of NSApplication. This is one of the major problems I've had using AS-S.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:40 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2