/* Copyright (c) 2006 J.W.Opitz, All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.jwopitz.containers { import flash.events.Event; import flash.events.FocusEvent; import flash.events.MouseEvent; import mx.controls.LinkButton; import mx.core.EventPriority; import mx.controls.Alert; [Style(name="titleLinkButtonStyle", type="String", inherit="no")] [Style(name="titleStyleOver", type="String", inherit="no")] [Event (name='titleClick', type='flash.events.MouseEvent')] public class LinkTitlePod extends Pod { protected var _titleLinkBtn:LinkButton; protected var _isTitleActive:Boolean = true; protected var _titleStyle:Object; public var allowTitleEvtPassThru:Boolean = false override protected function createChildren ():void { super.createChildren(); titleTextField.mouseEnabled = false; if (!_titleLinkBtn){ _titleLinkBtn = new LinkButton(); _titleLinkBtn.buttonMode = isTitleActive; _titleLinkBtn.enabled = isTitleActive; _titleLinkBtn.mouseEnabled = isTitleActive; _titleLinkBtn.owner = this; _titleLinkBtn.styleName = getStyle("titleLinkButtonStyle"); _titleLinkBtn.addEventListener(MouseEvent.CLICK, titleLinkBtn_onClick, false, EventPriority.DEFAULT_HANDLER); _titleLinkBtn.addEventListener(MouseEvent.MOUSE_DOWN, titleLinkBtn_onMouseDown, false, EventPriority.DEFAULT_HANDLER); _titleLinkBtn.addEventListener(MouseEvent.MOUSE_UP, titleLinkBtn_onMouseUp, false, EventPriority.DEFAULT_HANDLER); _titleLinkBtn.addEventListener(MouseEvent.MOUSE_OUT, titleLinkBtn_onMouseOut, false, EventPriority.DEFAULT_HANDLER); _titleLinkBtn.addEventListener(MouseEvent.MOUSE_OVER, titleLinkBtn_onMouseOver, false, EventPriority.DEFAULT_HANDLER); _titleLinkBtn.addEventListener(FocusEvent.FOCUS_IN, titleLinkBtn_onFocusIn, false, EventPriority.DEFAULT_HANDLER); _titleLinkBtn.addEventListener(FocusEvent.FOCUS_OUT, titleLinkBtn_onFocusOut, false, EventPriority.DEFAULT_HANDLER); var i:int = titleBar.getChildIndex(titleTextField) - 1; titleBar.addChildAt(_titleLinkBtn, i); } } override protected function layoutChrome (unscaledWidth:Number, unscaledHeight:Number):void { super.layoutChrome(unscaledWidth, unscaledHeight); _titleLinkBtn.setActualSize(titleTextField.getExplicitOrMeasuredWidth(), titleTextField.getExplicitOrMeasuredHeight()); _titleLinkBtn.move(titleTextField.x, titleTextField.y); } // // title link button evt handlers //-----------------------------------------------------------// protected function titleLinkBtn_onClick (evt:MouseEvent):void { evt.stopPropagation(); if (isTitleActive) dispatchEvent(createTitleBarMouseEvent('titleClick', evt)); } protected function titleLinkBtn_onMouseDown (evt:MouseEvent):void { if (!allowTitleEvtPassThru) evt.stopPropagation(); } protected function titleLinkBtn_onMouseUp (evt:MouseEvent):void { if (!allowTitleEvtPassThru) evt.stopPropagation(); } protected function titleLinkBtn_onMouseOut (evt:MouseEvent):void { evt.stopPropagation(); _titleStyle = getStyle("titleStyleName"); titleTextField.styleName = _titleStyle; } protected function titleLinkBtn_onMouseOver (evt:MouseEvent):void { evt.stopPropagation(); _titleStyle = getStyle("titleStyleOver"); if (_titleStyle == null) _titleStyle = getStyle("titleStyleName"); if (isTitleActive) titleTextField.styleName = _titleStyle; } protected function titleLinkBtn_onFocusIn (evt:FocusEvent):void { _titleStyle = getStyle("titleStyleOver"); if (_titleStyle == null) _titleStyle = getStyle("titleStyleName"); if (isTitleActive) titleTextField.styleName = _titleStyle; } protected function titleLinkBtn_onFocusOut (evt:FocusEvent):void { _titleStyle = getStyle("titleStyleName"); titleTextField.styleName = _titleStyle; } // // getters/setters //-----------------------------------------------------------// /** * Flag indicating whether the Pod's title is interactive or not. */ public function get isTitleActive ():Boolean { return _isTitleActive; } /** * @private */ public function set isTitleActive (value:Boolean):void { _isTitleActive = value; if (_titleLinkBtn){ _titleLinkBtn.buttonMode = value; _titleLinkBtn.enabled = value; _titleLinkBtn.mouseEnabled = value; } dispatchEvent(new Event('titleActiveChange')); } } }