Created
April 15, 2010 04:25
-
-
Save troygilbert/366677 to your computer and use it in GitHub Desktop.
AutoSizedWindow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.NativeWindow; | |
import flash.geom.Point; | |
import mx.core.ScrollPolicy; | |
import mx.core.Window; | |
public class AutoSizedWindow extends Window | |
{ | |
protected var _autoWidth:Boolean = true; | |
protected var _autoHeight:Boolean = true; | |
/** Auto-size width. **/ | |
public function get autoWidth():Boolean { return _autoWidth; } | |
public function set autoWidth(value:Boolean):void | |
{ | |
_autoWidth = value; | |
invalidateSize(); | |
} | |
/** Auto-size height. **/ | |
public function get autoHeight():Boolean { return _autoHeight; } | |
public function set autoHeight(value:Boolean):void | |
{ | |
_autoHeight = value; | |
invalidateSize(); | |
} | |
/** Measure. **/ | |
override protected function measure():void | |
{ | |
super.measure(); | |
if (nativeWindow.closed) return; | |
var chromeWidth:Number = nativeWindow.width - systemManager.stage.stageWidth; | |
var chromeHeight:Number = nativeWindow.height - systemManager.stage.stageHeight; | |
var idealWidth:Number = measuredWidth + chromeWidth; | |
var idealHeight:Number = measuredHeight + chromeHeight; | |
horizontalScrollPolicy = autoWidth ? ScrollPolicy.OFF : ScrollPolicy.AUTO; | |
verticalScrollPolicy = autoHeight ? ScrollPolicy.OFF : ScrollPolicy.AUTO; | |
if (autoWidth && autoHeight) | |
{ | |
nativeWindow.minSize = new Point(idealWidth, idealHeight); | |
nativeWindow.maxSize = new Point(idealWidth, idealHeight); | |
width = idealWidth; | |
height = idealHeight; | |
} | |
else if (autoWidth && !autoHeight) | |
{ | |
nativeWindow.minSize = new Point(idealWidth, NativeWindow.systemMinSize.y); | |
nativeWindow.maxSize = new Point(idealWidth, Math.min(idealHeight, NativeWindow.systemMaxSize.y)); | |
idealWidth += verticalScrollBar ? verticalScrollBar.width : 15; // this comes from mx/core/Window.as | |
width = idealWidth; | |
} | |
else if (!autoWidth && autoHeight) | |
{ | |
nativeWindow.minSize = new Point(NativeWindow.systemMinSize.x, idealHeight); | |
nativeWindow.maxSize = new Point(Math.min(idealWidth, NativeWindow.systemMaxSize.x), idealHeight); | |
idealHeight += horizontalScrollBar ? horizontalScrollBar.height : 15; // this comes from mx/core/Window.as | |
height = idealHeight; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment